Search code examples
pythonfb-hydra

Hydra runtime type checking does not work when config name specified in command line


The following code snippet works as expected when running the script without any parameters (execution stops because of missing argument in config):

if __name__ == '__main__':

    config_name = "csv_images_test"

    cs = ConfigStore.instance()
    cs.store(name=config_name, node=Config)

    @hydra.main(config_path="/hdd/twapi/configs/", config_name=config_name)
    def main(cfg: Config) -> None:
        print(OmegaConf.to_yaml(cfg))

    main()

How ever, when i specify this config name via command line, it seems that type checking is not happening:

python /hdd/twapi/src/config_structure.py --config-name=/hdd/twapi/configs/csv_images_test.yaml

Solution

  • In Hydra 1.0, the matching between the config and the matched schema is happening automatically when they share the same name. This is documented here.

    Hydra 1.1 which is still in development changes this behavior in favor of a more flexible usage of the Defaults List to match the schema to the config. See this.

    This is possible due to the new Defaults List implemented in Hydra 1.1, which supports Defaults List in arbitrary configs and not just the primary one.

    Learn more about it here.

    You can try Hydra 1.1 dev release (latest is 1.1.0dev4). See the primary readme of Hydra for installation instructions.