0

I am trying to override the package in default list in a hierarchical configuration structure. As a simplified example:

I have conf/base.yaml

defaults:
  - _self_
  - env@_here_: env1
a: 1
b: 2

conf/env/env1.yaml

c: 5
d: 6

and conf/env/env2.yaml

c: 7
d: 8

When running my_app.py

import hydra
import omegaconf

@hydra.main(config_path="conf", config_name="base")
def my_app(cfg: omegaconf.DictConf) -> None:
    print(omegaconf.OmegaConf.to_yaml(cfg))

my_app()

I want to override env@_here_ from env1 to env2 using the CLI or any other method. I have gone through Hydra documentation a few times, but couldn't find how to do this.

Dee
  • 153
  • 3
  • 15
  • I believe there is a bug here. It should be possible to type `python my_app.py env@_global_=env2` at the command line, but currently this does not work. I've filed a bug report [here](https://github.com/facebookresearch/hydra/issues/1803). – Jasha Aug 30 '21 at 14:30
  • I followed the issue and the PR linked to it. Thanks – Dee Sep 01 '21 at 23:26

1 Answers1

1

In the current hydra release (Hydra 1.1.1) you can use:

python my_app.py env=env2

Due to a recent breaking change to improve consistency of Hydra's API, it will soon be necessary to do this:

python my_app.py env@_global_=env2

This breaking change will probably be a part of Hydra 1.1.2 or 1.2.0.

Side note: There are a few different ways to achieve the same result as you have in your example above. Your options include:

  • Using - env@_here_: env1 in base.yaml, which is what you did above.
  • Using - env@_global_: env1 in base.yaml
  • Using - env: env1 in base.yaml and adding a _global_ package header to env1.yaml and env2.yaml

conf/env/env1.yaml:

# @package _global_
c: 5
d: 6

conf/env/env2.yaml:

# @package _global_
c: 7
d: 8

The keyword _global_ refers to the top-level package in the output config produced by Hydra. You can read more here about the _global_ and _here_ keywords.

Jasha
  • 5,507
  • 2
  • 33
  • 44