2

When packaging a Hydra application and including a script as an entry point, one can call the script from the command line anywhere. When called the script will utilize the configuration that was included in the package. Is there a way to modify the config search path such that a different configuration can be passed along to the script?

For example:

app.py

import hydra


@hydra.main(config_path="conf", config_name="config")
def my_func(cfg):
    print(cfg)

config.yaml

key: value
another_key: second_value

Creating and installing this package with entry_points={"console_scripts": ["hydra_app_test = hydra_app_test.app:my_func"]}.

$ hydra_app_test
{'key': 'value', 'another_key': 'second_value'}

I would like to be able to define a local config and pass it to hydra_test_app. Is something like this possible?

some/config/path/config.yaml

key: not_value
mon: key
$ hydra_app_test --config-override=some/config/path
{'key': 'not_value', 'mon': 'key'}

I have tried using the --config-dir and --config-path overrides, but without any luck.

$ hydra_app_test --config-dir=some/config/path
{'key': 'value', 'another_key': 'second_value'}
$ hydra_app_test --config-path=some/config/path
Primary config module 'hydra_app_test.some.config.path' not found.
Check that it's correct and contains an __init__.py file

Interestingly enough this pattern works if you do not use the installed app, but run app.py as a script (with the requisite if __name__ == "__main__" logic)

python path/to/app.py --config-path=some/config/path
{'key': 'not_value', 'mon': 'key'}

Perhaps I am just missing something here, but it would seem you should be able to replicate the same behavior for both installed package scripts and python scripts.

Grr
  • 15,553
  • 7
  • 65
  • 85

2 Answers2

1

Use --config-dir|-cp to add a directory to the config path for a specific run. You can also use the hydra.searchpath config variable which can be overridden from the command line or from the primary config.

There is a page dedicated to the config search path here.

Omry Yadan
  • 31,280
  • 18
  • 64
  • 87
0

I have verified that this solutions works. I found this response in this feature request thread on the Hydra Github

Thread: https://github.com/facebookresearch/hydra/issues/874

Solution: https://github.com/facebookresearch/hydra/issues/874#issue-678621609

Basically any area of the config that you want to be overridable is set using a default config, this then allows the --config-dir flag to work in conjunction with a specified config file. The only caveat to this answer is that the new configs must be in a directory structure like the default configs.

Fanoway
  • 1
  • 2