Skip to content

Is it possible to split (and merge) config files (not for config groups)? #2251

Answered by Jasha10
hogru asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @hogru,
Here is an example using the Hydra defaults list to merge several yaml files into one file:

# conf/dataset.yaml
data: cifar10
# conf/hyperparameters.yaml
hparam1: 123
# conf/config.yaml
defaults:
  - hyperparameters
  - dataset
  - _self_

foo: bar
# my_app.py
from omegaconf import DictConfig, OmegaConf
import hydra

@hydra.main(version_base=None, config_path="conf", config_name="config")
def my_app(cfg: DictConfig) -> None:
    print(OmegaConf.to_yaml(cfg))

if __name__ == "__main__":
    my_app()
$ tree
├── conf
│   ├── config.yaml
│   ├── dataset.yaml
│   └── hyperparameters.yaml
└── my_app.py

$ python my_app.py
hparam1: 123
data: cifar10
foo: bar

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by hogru
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants