Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list of a default config #1926

Closed
de-gozaru opened this issue Dec 16, 2021 · 3 comments
Closed

list of a default config #1926

de-gozaru opened this issue Dec 16, 2021 · 3 comments
Labels
enhancement Enhanvement request

Comments

@de-gozaru
Copy link

de-gozaru commented Dec 16, 2021

Hi,
I'm using Hydra 1.1 for deep learning application.
My conf directory has the following architecture:

├── conf
│   ├── config.yaml
│   ├── dataset
│   │   ├── imagenet.yaml
│   │   └── pascal.yaml
│   ├── architecture
│   │   ├── resnet.yaml
│   │   ├── alexnet.yaml
│   └── optimizer
│          ├── adam.yaml
│          └── sgd.yaml
└── main.py

my config.yaml has the following structure:

defaults:
  - dataset@trainset: imagenet
  - dataset@testset: imagenet
  - architecture: resnet
  - optimizer: adam

What I want to do is that, sometimes I want to use multiple train dataset, something like this

python3 main.py dataset@trainset=imagenet trainset.remove_class=cat

OR

python3 main.py dataset@trainset=[imagenet, pascal] trainset.remove_class=cat

is this possible with the current version? if not, is there a possible turnaround I can use?
I know that an append function is scheduled to be added in version 1.3.

Thank you in advance for your help!

@de-gozaru de-gozaru added the enhancement Enhanvement request label Dec 16, 2021
@jieru-hu
Copy link
Contributor

hi @de-gozaru
instead of using a list, try using a dict instead, it is better supported in Hydra.

would something like the following works?

python main.py +dataset@trainset.one=imagenet +dataset@trainset.two=pascal

then in your application, you can convert trainset's value into a list if needed.

@Jasha10
Copy link
Collaborator

Jasha10 commented Dec 16, 2021

Another option is to pass a list of config names at the command line:

$ python main.py 'dataset@trainset=[imagenet, pascal]'
trainset:
  imagenet:
    foo: bar
  pascal:
    baz: quz

Passing a list [imagenet, pascal] will cause the imagenet.yaml and pascal.yaml input configs to be merged; the result of the merge is placed in the trainset package. Note the single quotes in the above shell command may be necessary (depending on your shell). This example is working with the following setup:

from omegaconf import DictConfig, OmegaConf
import hydra

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

if __name__ == "__main__":
    my_app()
# conf/config.yaml
defaults:
  - dataset@trainset: ???

trainset: ???
# conf/dataset/imagenet.yaml
imagenet:
  foo: bar
# conf/dataset/pascal.yaml
pascal:
  baz: quz

As an alternative to passing a list of config names at the command-line (as in the example above), you could pass a list of config names in the config.yaml defaults list:

# conf/config.yaml
defaults:
  - dataset@trainset: [imagenet, pascal]

This is documented in the Defaults List page of the Hydra docs (see the note about "CONFIG_NAMES").

Edit: there is further documentation on passing a list of config names in Selecting multiple configs from a Config Group

@de-gozaru
Copy link
Author

Hi @jieru-hu @Jasha10
Thanks a lot for your help, both solutions are ok for me!
I'll try them out and get back to you if I have any question.
closing the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhanvement request
Projects
None yet
Development

No branches or pull requests

3 participants