[Python] Reproducible results of optuna when n_jobs=-1

Discussão em 'Python' iniciado por Stack, Junho 6, 2025.

  1. Stack

    Stack Membro Participativo

    I am currently working with Optuna and I have noticed that when I use n_jobs = -1, the TPESampler does not sample the exact same parameters for different study, even with the seed inside optuna.samplers.TPESampler(seed = 10) fixed. It seems that combining multiprocessing of optuna and get determinist results are incompatible.

    I really need my results to be reproducible, but I also need n_jobs = -1, otherwise the code will take to much time. I am fully aware that using n_jobs = 1 will remove this issue, but as I said, I don't want to use it because I have constraint on time.

    Is there a solution to this problem?

    The code:

    study1 = optuna.create_study(direction="maximize", sampler=optuna.samplers.TPESampler(seed = 10))
    study1.optimize(objective, n_trials=5, n_jobs = -1)

    study2 = optuna.create_study(direction="maximize", sampler=optuna.samplers.TPESampler(seed = 10))
    study2.optimize(objective, n_trials=5, n_jobs = -1)

    Continue reading...

Compartilhe esta Página