torchkit.utils.config

torchkit.utils.config.copy_config_and_replace(config, update_dict=None, freeze=False)[source]

Makes a copy of a config and optionally updates its values.

Parameters
  • config (ConfigDict) – The config to copy.

  • update_dict (Optional[ConfigDict], optional) – A config that will optionally update the copy. Defaults to None.

  • freeze (bool, optional) – Whether to freeze the config after the copy. Defaults to False.

Returns

A copy of the config.

Return type

Union[ConfigDict, FrozenConfigDict]

torchkit.utils.config.dump_config(exp_dir, config)[source]

Dump a config to disk.

Parameters
  • exp_dir (str) – Path to the experiment directory.

  • config (Union[ConfigDict, FrozenConfigDict]) – The config to dump.

Return type

None

torchkit.utils.config.load_config(exp_dir, config=None, freeze=False)[source]

Load a config from an experiment directory.

Parameters
  • exp_dir (str) – Path to the experiment directory.

  • config (Optional[ConfigDict], optional) – An optional config object to inplace update. If one isn’t provided, a new config object is returned. Defaults to None.

  • freeze (bool, optional) – Whether to freeze the config. Defaults to False.

Returns

The config file that was stored in the experiment directory.

Return type

Optional[Union[ConfigDict, FrozenConfigDict]]

torchkit.utils.config.validate_config(config, base_config, base_filename)[source]

Ensures a config inherits from a base config.

Parameters
  • config (ConfigDict) – The child config.

  • base_config (ConfigDict) – The base config.

  • base_filename (str) – Path to python file containing base config definition.

Raises

ValueError – if the base config contains keys that are not present in config.

Return type

None