facebookresearch / hydra

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

[Bug] Deleting a key via CLI doesn't affect `_self_` #2959

Open YodaEmbedding opened 2 months ago

YodaEmbedding commented 2 months ago

🐛 Bug

Description

Input:

# dataset/imagenet.yaml

path: "/datasets/imagenet"
type: "ImageNetDataset"
# example.yaml

defaults:
  - dataset/imagenet
  - _self_

dataset:
  type: "Overriden"
# main.py

import hydra
import yaml
from omegaconf import DictConfig, OmegaConf

@hydra.main(version_base=None, config_path="conf")
def main(conf: DictConfig):
    print(yaml.dump(OmegaConf.to_container(conf, resolve=True)))

if __name__ == "__main__":
    main()

[Case 1]

python main.py --config-path=conf --config-name=example '~dataset'

Output:

dataset:
  type: Overridden

It seems that _self_ is not processed in the same way as the defaults list.


[Case 2]

python simple.py --config-path=conf --config-name=example '~dataset' dataset=imagenet

Output:

dataset:
  type: Overridden

Checklist

To reproduce

See above.

Expected Behavior

[Case 1] Output:

dataset: {}

[Case 2] Output:

dataset:
  path: "/datasets/imagenet"
  type: "ImageNetDataset"

System information

Additional context