Package syntax in defaults list overrides (structured configs) #2126
-
In addition to other keys required in an ML application (like trainer, model, etc), my top-level structured config has a from dataclasses import dataclass, field
from typing import Any, List
import hydra
from hydra.core.config_store import ConfigStore
from omegaconf import DictConfig, OmegaConf, MISSING
@dataclass
class MlConf:
datamodule: Any = DictConfig({'dataset': MISSING, 'prepper': None})
seed: int = 1234
@dataclass
class PrepConf:
crop_size: int = 224
@dataclass
class DatasetConf:
defaults: List[Any] = field(default_factory=lambda: [
{'override datamodule/prepper@_global_': 'crop'}, # FIXME what's the correct package syntax here?
])
batch_size: int = 2
cs = ConfigStore.instance()
cs.store('config', MlConf)
cs.store(group='datamodule/prepper', name='crop', node=PrepConf)
cs.store(group='datamodule/dataset', name='simple', node=DatasetConf)
@hydra.main(config_name='config', config_path=None)
def main(cfg):
print(OmegaConf.to_yaml(cfg))
if __name__ == '__main__':
main() My desired behavior is
The above code runs as expected to accomplish goals 1 and 2. However, I cannot get the 3rd goal to work
The desired/expected output would be
Based on the terminology docs for packages in Hydra 1.1.1, I thought that |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @addisonklinke, @dataclass
class DatasetConf:
defaults: List[Any] = field(default_factory=lambda: [
{'/datamodule/prepper@_group_': 'crop'},
])
batch_size: int = 2 There are three changes I've to DatasetConf's defaults list:
Why not use the
|
Beta Was this translation helpful? Give feedback.
Hi @addisonklinke,
The following will do the trick:
There are three changes I've to DatasetConf's defaults list:
"override"
keyworddatamodule/prepper
to/datamodule/prepper
_global_
to_group_
Why not use the
"override"
keyword?The error message you pasted above says "Could not find override ..."
The
"override"
keyword only applies you are using a defaults list to select an option from a group that is already present in some other config's defaults list. I'll circle back to give an example at…