0

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)

gmr
  • 712
  • 6
  • 17

1 Answers1

1

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.

Omry Yadan
  • 31,280
  • 18
  • 64
  • 87
  • Thanks. Is there a chance that some kind of file inclusion method will be added in the future? It doesn't seem like either option is very good for this case. Regarding multiple primary configs, I already have multiple primary configs, and I would like to find ways to reduce the number of them or at least to reduce code duplication between them – gmr Feb 09 '23 at 14:58
  • Another issue I'm hitting that I guess is related to interpolations not knowing about files is that in subconfigs there is apparently no way to resolve variables relative to the subconfig. I either have to use absolute paths or very complicated relative paths, right? – gmr Feb 10 '23 at 10:43
  • You can refactor your configs to contain just the defaults list. You can also have a Defaults List in sub configs to further improve reuse. – Omry Yadan Feb 10 '23 at 16:05
  • Google OmegaConf relative interpolation. If you have more questions submit them separately. – Omry Yadan Feb 10 '23 at 16:06
  • You might find this useful as a pattern to improve reuse: https://hydra.cc/docs/patterns/configuring_experiments/ – Omry Yadan Feb 10 '23 at 16:08