parallelisation is not working in optuna
See original GitHub issueHow can we execute the code in parallel in optuna. The documentation is so naive about that. Suppose I have a test.py file which includes the following code:
study = optuna.create_study(
direction="maximize",
study_name="ali", #for parallel execution you need these couple of lines
storage="sqlite:///mydb.db",
load_if_exists= True, #to skip creating a new study if it already exists.
pruner = SuccessiveHalvingPruner(),
#pruner=HyperbandPruner(min_resource=1, max_resource=100, reduction_factor=3),
)
and I have another test2.py file which calls the test.py file like that:
import multiprocessing as mp
from concurrent.futures import ProcessPoolExecutor
import os
from multiprocessing import Pool
def run_process (process):
os.system('python {}'.format(process))
if __name__ == "__main__":
processes = ['TestDriver.py']
pool = Pool()
pool.map(run_process, processes)
pool.close
But the code:
- is not executed in parallel. I cannot see for example in the console: Trial 0 finsihed … Trial 1…
- The code creates two experiments in neptune.
Note to the questioner
If you are more comfortable with Stack Overflow, you may consider posting your question with the “optuna” tag there instead. Alternatively, for issues that would benefit from more of an interactive session with the developers, you may refer to the optuna/optuna chat on Gitter.
Issue Analytics
- State:
- Created 3 years ago
- Comments:16 (6 by maintainers)
Top Results From Across the Web
4. Easy Parallelization — Optuna 3.0.4 documentation
It's straightforward to parallelize optuna.study.Study.optimize() . If you want to manually execute Optuna optimization: start an RDB server (this example ...
Read more >optuna - How to set n_trials for multiple processes when using ...
When I execute code without parallel computation, n_trials in the optimize function means how many trials the program runs.
Read more >Parallel Hyperparameter Tuning With Optuna and Kubeflow ...
Parallelize hyperparameter searches over multiple threads or processes without modifying code · Automated search for optimal hyperparameters ...
Read more >optuna/optuna - Gitter
When using optuna in parallel (e.g. 4 GPUs running on different terminals with the same common database), how does n_trials and n_startup_trials behave?...
Read more >A Guide To Parallelism and Resources - the Ray documentation
Parallelism is determined by per trial resources (defaulting to 1 CPU, ... Troubleshooting: Occasionally, you may run into GPU memory issues when running...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think what ali3assi may be asking for is the good old n_jobs=-1: study.optimize(objective, n_trials=n_trials, n_jobs=-1)
This will utilize all the cores on your computer for the single study. However, depending on the complexity of the objective and number of trials, you will typically not see all cores utilized or 100% CPU usage. Also, since Optuna > 2.0, the n_jobs=-1 don’t really seem to be efficient in using multiple cores. Up until version 2.0, I can set n_jobs=-1 and launch multiple instances of Optuna and see my CPU usage hit 100% for 32 cores sustained. After 2.0, it seems that each study is locked to a process or there’s some limitations and this prevents my CPU usage scaling to 100%. The speed penalty is extreme.
For now, version 2.0 is gold to me.
What about distributed parallelism in Optuna using RDB? That is ok if your trial run is up to 100,000 or less, split or distributed between multiple instances of Optuna for the same study. It gets extremely slow after that. But due to the random seed initialization in the optimizers, you’d be better running multiple instances of Optuna to get a better tuned model or objective. At least in my own experience, I recover the best result from 5 instances/5 studies of 20,00 trials each versus one instance/study at 100,000 trials.
Hope this helps.
@HideakiImamura Thanks for your reply. I am on windows. But I need to parallelize the code on a pc of 48 cpus, I need to open 48 terminales?