Skip to main content
Version: Next

Customizing working directory pattern

ย Example

Below are a few examples of customizing output directory patterns.

Configuration for run#

Run output directory grouped by date:

hydra:  run:    dir: ./outputs/${now:%Y-%m-%d}/${now:%H-%M-%S}

Run output directory grouped by job name:

hydra:  run:    dir: outputs/${}/${now:%Y-%m-%d_%H-%M-%S}

Run output directory can contain user configuration variables:

hydra:  run:    dir: outputs/${now:%Y-%m-%d_%H-%M-%S}/opt:${optimizer.type}

Configuration for multirun#

We will run the application with same command but different configurations:

python --multirun a=a1,a2,a3 

Default multirun dir configurations:

hydra:  sweep:    dir: multirun/${now:%Y-%m-%d}/${now:%H-%M-%S}    subdir: ${hydra.job.num}
workding dir created
$ tree my_app -dmy_appโ”œโ”€โ”€ 0โ”œโ”€โ”€ 1โ””โ”€โ”€ 2

Similar configuration patterns in run can be applied to config multirun dir as well.

For example, multirun output directory grouped by job name, and sub dir by job num:

hydra:  sweep:    dir: ${}    subdir: ${hydra.job.num}
workding dir created
$ tree my_app -dmy_appโ”œโ”€โ”€ 0โ”œโ”€โ”€ 1โ””โ”€โ”€ 2

Using hydra.job.override_dirname#

ย Example

This field is populated automatically using your command line arguments and is typically being used as a part of your output directory pattern. It is meant to be used along with the configuration for working dir, especially in hydra.sweep.subdir.

If we run the example application with the following commandline overrides and configs:

python --multirun batch_size=32 learning_rate=0.1,0.01
hydra:  sweep:    dir: multirun    subdir: ${hydra.job.override_dirname}
working dir created
$ tree multirun -dmultirunโ”œโ”€โ”€ batch_size=32,learning_rate=0.01โ””โ”€โ”€ batch_size=32,learning_rate=0.1

You can further customized the output dir creation by configuringhydra.job.override_dirname.

In particular, the separator char = and the item separator char , can be modified by overriding hydra.job.config.override_dirname.kv_sep and hydra.job.config.override_dirname.item_sep. Command line override keys can also be automatically excluded from the generated override_dirname.

An example of a case where the exclude is useful is a random seed.

hydra:  run:    dir: output/${hydra.job.override_dirname}/seed=${seed}  job:    config:      override_dirname:        exclude_keys:          - seed

With this configuration, running

$ python --multirun  batch_size=32 learning_rate=0.1,0.01 seed=1,2

Would result in a directory structure like:

$ tree multirun -dmultirunโ”œโ”€โ”€ batch_size=32,learning_rate=0.01โ”‚ย ย  โ”œโ”€โ”€ seed=1โ”‚ย ย  โ””โ”€โ”€ seed=2โ””โ”€โ”€ batch_size=32,learning_rate=0.1    โ”œโ”€โ”€ seed=1    โ””โ”€โ”€ seed=2