facebookresearch / hydra

Hydra is a framework for elegantly configuring complex applications
https://hydra.cc
MIT License
8.61k stars 619 forks source link

[Feature Request] Import config from another config #1214

Closed atemate closed 3 years ago

atemate commented 3 years ago

πŸš€ Feature Request

Hi! First of all, thanks for such a simple yet functional instrument! :heart: At my work, I am doing MLOps, where I need to run multiple codebases in different environments (docker images) with different parameters (say, version of code and model), and I find hydra to fit this use-case very easily!

But one feature I really lack: the possibility to share a common configuration via importing a config file in other config files. This common config file can contain a similar tree structure that can be used in other configs, for example:

β”œβ”€β”€ conf
β”‚   β”œβ”€β”€ constants.yaml
β”‚   └── train
β”‚       β”œβ”€β”€ mode.yaml
β”‚       └── postgresql.yaml
└── my_app.py
conf/constants.yaml
--
# @package _global_
const:
  images: 
    simple_ubuntu: ubuntu:latest
    torch_with_some_perks: pytorch/pytorch
  ...
# (free format)
conf/model/object_detection.yaml
--
# @package _group_
# @import ../constants.yaml
name: object_detection
image: ${const.images.torch_with_some_perks}  # use the `const` tree
...
conf/model/object_classification.yaml
--
# @package _group_
# @import ../constants.yaml
name: object_detection
image: ${const.images.simple_ubuntu}
...

Now, I need to hack (wrap with my own code) @hydra.main to achieve this.

  1. Can this already be supported natively Hydra?
  2. If not, is this feature liveable? if so, I'd be happy to work on it.
jieru-hu commented 3 years ago

Hi @yartem !

it seems like recursive defaults (WIP PR here, Design Doc here) is what are you asking for.

The feature is planned for Hydra 1.1 Please feel free to check out the PR and try it (I believe it's ready for dogfooding now :) )

omry commented 3 years ago

Yup, I believe the use case you are after is covered well by the new recursive defaults. It's getting ready to hit master, but as Jieru said it's in good enough shape for you to play with it from #1170).

I am going to close this, but feel free to continue the discussion here.

omry commented 3 years ago

By the way, I am always happy to see new use cases for Hydra! thanks for sharing!