Recursive i itialization and how to use config group inside another config group

388 views Asked by At

I am exploring the options of the recursive initialization in hydra. I was able to setup a working example based on this PR. When trying more advanced stuff, I stumbled upon the following problem. My directory structure is as follows:

config/
  config.yaml
    /tokenizer
      Tokenizer.yaml
    /normalizer
      Normalizer.yaml

The configs contain:

<config.yaml>
default:
  - tokenizer: Tokenizer

<Tokenizer.yaml>
_target_: some.path.Tokenizer
normalizer: Normalizer # I want this to be the Normalizer object after instantiation, but getting string. 

<Normalizer.yaml>
_target_: some.other.path.Normalizer
arg1: value1

I want to recursively instantiate the Tokenizer without the need to explicitly write all the arguments of the Normalizer since all of them are already mentioned in the Normalizer.yaml file. In other words, I would like to use the normalizer config group inside tokenizer config group. Right now, if I call tokenizer = instantiate(cfg.tokenizer), the result is a Tokenizer class object, but tokenizer.normalizer is a string Normalizer. If I use value interpolation and setup the project as follows:

<config.yaml>
default:
  - tokenizer: Tokenizer
  - normalizer: Normalizer

<Tokenizer.yaml>
_target_: some.path.Tokenizer
normalizer: ${normalizer} 

<Normalizer.yaml>
_target_: some.other.path.Normalizer
arg1: value1

The resulting variable tokenizer.normalizer is a dict containing args for Normalizer like so{"_target_": ...} instead of being an initialized Normalizer class. How can I avoid the need to explicitly repeat the definition of the normalizer inside the tokenizer config?

1

There are 1 answers

0
Omry Yadan On BEST ANSWER

I don't think what you want is supported right now. Please file a feature request with a minimal config, and an explanation of the current behavior and the desired behavior.