id: joblib_launcher
title: Joblib Launcher plugin
sidebar_label: Joblib Launcher plugin
The Joblib Launcher plugin provides a launcher for parallel tasks based on Joblib.Parallel.
Installation
This plugin requires Hydra 1.0 (Release candidate)
$ pip install hydra-joblib-launcher --pre
Usage
Once installed, add hydra/launcher=joblib to your command line. Alternatively, override hydra/launcher in your config:
defaults:
- hydra/launcher: joblib
By default, process-based parallelism using all available CPU cores is used. By overriding the default configuration, it is e.g. possible limit the number of parallel executions.
The default configuration packaged with the plugin is:
@dataclass
class JobLibLauncherConf(PluginConf):
cls: str = "hydra_plugins.hydra_joblib_launcher.JoblibLauncher"
params: JobLibConf = JobLibConf()
The JobLibConf class is defined here:
It looks like this:
@dataclass
class JobLibConf:
# maximum number of concurrently running jobs. if -1, all CPUs are used
n_jobs: int = -1
# allows to hard-code backend, otherwise inferred based on prefer and require
backend: Optional[str] = None
# processes or threads, soft hint to choose backend
prefer: str = "processes"
# null or sharedmem, sharedmem will select thread-based backend
require: Optional[str] = None
# if greater than zero, prints progress messages
verbose: int = 0
# timeout limit for each task
timeout: Optional[int] = None
# number of batches to be pre-dispatched
pre_dispatch: str = "2*n_jobs"
# number of atomic tasks to dispatch at once to each worker
batch_size: str = "auto"
# folder used for memmapping large arrays for sharing memory with workers
temp_folder: Optional[str] = None
# thresholds size of arrays that triggers automated memmapping
max_nbytes: Optional[str] = None
# memmapping mode for numpy arrays passed to workers
mmap_mode: str = "r"
See Joblib.Parallel documentation for full details about the parameters above.
An example application using this launcher is provided in the plugin repository.
Starting the app with python my_app.py --multirun task=1,2,3,4,5 will launch five parallel executions:
$ python my_app.py --multirun task=1,2,3,4,5
[HYDRA] Joblib.Parallel(n_jobs=-1,verbose=0,timeout=None,pre_dispatch=2*n_jobs,batch_size=auto,temp_folder=None,max_nbytes=None,mmap_mode=r,backend=loky) is launching 5 jobs
[HYDRA] Launching jobs, sweep output dir : multirun/2020-02-18/10-00-00
[__main__][INFO] - Process ID 14336 executing task 2 ...
[__main__][INFO] - Process ID 14333 executing task 1 ...
[__main__][INFO] - Process ID 14334 executing task 3 ...
[__main__][INFO] - Process ID 14335 executing task 4 ...
[__main__][INFO] - Process ID 14337 executing task 5 ...