0

I would like to use the # @package _global_ directive only on a specific part of my config. E.g. here I want my datamodule to be able to override an attribute of the trainer. Is there any way to do that?

Things I tried:

  1. Using # @package _global_ at the beginning but I don't want to change the file default.yaml (it's imported by other files).
  2. Using trainer@_global_
  3. Using /trainer
  4. Using _self_@_global_ (but it seems that it's not allowed and would apply all the rest of the config to _global_).

Tree:

conf
├── config.yaml
├── datamodule
│   ├── default.yaml
│   └── my_datamodule.yaml
└── trainer
    └── single_gpu.yaml

conf/datamodule/default.yaml

n_train_samples: null

conf/datamodule/my_datamodule.yaml

defaults:
  - default
  - _self_

batch_size: 32

# @package _global_
trainer:
    val_check_interval: 99999

Expected behaviour: datamodule: n_train_samples: null batch_size: 32 trainer: val_check_interval: 99999 gpus: 1

Actual behaviour: datamodule: n_train_samples: null batch_size: 32 trainer: val_check_interval: 99999999999999999 trainer: gpus: 1

Louis M
  • 4,036
  • 4
  • 21
  • 25
  • Currently there is no way to control the package in such a granular way. There are a few related feature requests on Hydra's issue tracker: [hydra#1913](https://github.com/facebookresearch/hydra/issues/1913) and [hydra#1983](https://github.com/facebookresearch/hydra/issues/1983). – Jasha Apr 15 '22 at 02:24
  • A fairly clunky workaround would be to create a file `conf/datamodule/my_trainer_settings.yaml` with a header `# @package _global_`. Adding the string `"my_trainer_settings"` to the defaults list of `conf/datamodule/my_datamodule.yaml` should then result in the desired output. – Jasha Apr 15 '22 at 02:38

0 Answers0