Search code examples
fb-hydra

In hydra, can I interpolate config from a file without using the defaults list?


Say I have a directory utility_configs that has a bunch of different configurations for different things that are useful in different situations. And then I want to be able to use these different configs in different places. For instance, maybe my model has many different places where I need something that is an "encoder" (really just a bit of network that maps an input to an output). I might have vary different encoders in my utility_configs directory, and I would like to be able to specify any of them anyplace I need an encoder (possibly then adjusting the number of input and output channels or other parameters). I am not seeing how to do this straightforwardly since it seems like the only way you can get data from a different file is using the defaults list. But that's not really a good fit here since I might need multiple different things from utility_configs and in multiple different places (including subconfigs)


Solution

  • You cannot interpolate into a file. Interpolation works on the current config object. Hydra can compose the config for you, after which you can use interpolation.

    You have multiple options:

    1. Have more than one primary config (with a defaults list). You can override which primary config to use via the command line (--config-name|-cn).
    2. Construct your defaults list in an ad-hoc manner via the command line using the +GROUP=OPTION notation (see this).

    About using a config in different places, take a look at config packages - which allows you to relocate the content of a config in the composed config object.

    I recommend going with 1.