Skip to main content

Hydra Experiment Sweeper

hydra is a great library to configure model trainings and numerical experiments. Via its --multirun facility, you can launch multiple jobs at a time and evaluate multiple combinations of settings such as learning rates and seeds easily. However, the built-in sweepers only accept sweep ranges on the command line, which means that reproducing a set of experiments for a paper or similar relies on you to remember or write down the exact invocation of hydra that produced the results in the first place.

hydra-experiment-sweeper lets you configure experiments via YAML. This way colleagues and yourself a year from now can re-run the same jobs with exactly the same parameters.

defaults:
  - override hydra/sweeper: experiment

hydra:
  sweeper:
    overrides:
      learning_rate: 1e-5,1e-6,1e-7
      # Any other overrides such as seeds, model, dataset, etc.

Installation

pip install hydra-experiment-sweeper

How to Use

The sweeper accepts any override syntax that hydra accepts on the command line as well as YAML lists for long values such as seeds or paths.

defaults:
  - override hydra/sweeper: experiment

hydra:
  sweeper:
    max_batch_size: 2
    overrides:
      model: linreg,svm
      learning_rate: range(0.1, 0.3, 0.1)
      seed:
        - 123
        - 42

Running this experiment with python example/train.py --config-name experiment -m launches the configured jobs.

Experiment invocation and output
$ python example/train.py -m
[2021-10-15 17:57:18,241][HYDRA] ExperimentSweeper(max_batch_size=2, overrides={'model': 'linreg,svm', 'learning_rate': 'range(0.1, 0.3, 0.1)', 'seed': [123, 42]}) sweeping
[2021-10-15 17:57:18,242][HYDRA] Sweep output dir : multirun/2021-10-15/17-57-18
[2021-10-15 17:57:18,796][HYDRA] Launching 2 jobs locally
[2021-10-15 17:57:18,796][HYDRA] 	#0 : model=linreg learning_rate=0.1 seed=123
model:
  model_type: linear_regression
seed: 123
learning_rate: 0.1

[2021-10-15 17:57:18,888][HYDRA] 	#1 : model=linreg learning_rate=0.1 seed=42
model:
  model_type: linear_regression
seed: 42
learning_rate: 0.1

[2021-10-15 17:57:18,982][HYDRA] Launching 2 jobs locally
[2021-10-15 17:57:18,982][HYDRA] 	#2 : model=linreg learning_rate=0.2 seed=123
model:
  model_type: linear_regression
seed: 123
learning_rate: 0.2

[2021-10-15 17:57:19,079][HYDRA] 	#3 : model=linreg learning_rate=0.2 seed=42
model:
  model_type: linear_regression
seed: 42
learning_rate: 0.2

[2021-10-15 17:57:19,171][HYDRA] Launching 2 jobs locally
[2021-10-15 17:57:19,171][HYDRA] 	#4 : model=svm learning_rate=0.1 seed=123
model:
  model_type: support_vector_machine
seed: 123
learning_rate: 0.1

[2021-10-15 17:57:19,290][HYDRA] 	#5 : model=svm learning_rate=0.1 seed=42
model:
  model_type: support_vector_machine
seed: 42
learning_rate: 0.1

[2021-10-15 17:57:19,405][HYDRA] Launching 2 jobs locally
[2021-10-15 17:57:19,405][HYDRA] 	#6 : model=svm learning_rate=0.2 seed=123
model:
  model_type: support_vector_machine
seed: 123
learning_rate: 0.2

[2021-10-15 17:57:19,497][HYDRA] 	#7 : model=svm learning_rate=0.2 seed=42
model:
  model_type: support_vector_machine
seed: 42
learning_rate: 0.2

You can still override parameters on the command line. Let's say you want to run the same experiment but instead of sweeping over the configured learning rates, you want to try a different order of magnitude. python example/train.py --config-name experiment -m learning_rate=1e-6,5e-5,1e-5 works just as you would expect with the built-in sweeper and overwrites the configured override.

Release files for hydra-experiment-sweeper 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hydra-experiment-sweeper 0.1.1
File Size Uploaded
hydra-experiment-sweeper-0.1.1.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hydra-experiment-sweeper 0.1.1
File Interpreter ABI Platform
hydra_experiment_sweeper-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.2 kB

Release files / hydra-experiment-sweeper-0.1.1.tar.gz

Download URL hydra-experiment-sweeper-0.1.1.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
429fb89ff3995a7c453709f792f63666b76310e03c16ef9960130303446813e1
BLAKE2b-256 checksum
How to use checksums
fa1720022b8e2ffa6c87c6b9b2ec607aa09712a61844b7a3bf4a107e897b05c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.26.0

Release files / hydra_experiment_sweeper-0.1.1-py3-none-any.whl

Download URL hydra_experiment_sweeper-0.1.1-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bdcde2cdfc9b90cb485c9c7f12fd75711ebc41495188e3e4ea316137ede1dc1e
BLAKE2b-256 checksum
How to use checksums
debfe3009898898a83e15aa4f6eabeaf1eed9159c5a52800ba4e352cacd0c646
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.26.0

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page