nemo_rl.utils.config#

Module Contents#

Functions#

resolve_path

Resolve a path relative to the base path.

load_config_with_inheritance

Load a config file with inheritance support.

load_config

Load a config file with inheritance support and convert it to an OmegaConf object.

parse_hydra_overrides

Parse and apply Hydra overrides to an OmegaConf config.

API#

nemo_rl.utils.config.resolve_path(base_path: pathlib.Path, path: str) pathlib.Path[source]#

Resolve a path relative to the base path.

nemo_rl.utils.config.load_config_with_inheritance(
config_path: Union[str, pathlib.Path],
base_dir: Optional[Union[str, pathlib.Path]] = None,
) omegaconf.DictConfig[source]#

Load a config file with inheritance support.

Parameters:
  • config_path – Path to the config file

  • base_dir – Base directory for resolving relative paths. If None, uses config_path’s directory

Returns:

Merged config dictionary

nemo_rl.utils.config.load_config(
config_path: Union[str, pathlib.Path],
) omegaconf.DictConfig[source]#

Load a config file with inheritance support and convert it to an OmegaConf object.

The config inheritance system supports:

  1. Single inheritance:

    # child.yaml
    defaults: parent.yaml
    common:
      value: 43
    
  2. Multiple inheritance:

    # child.yaml
    defaults:
      - parent1.yaml
      - parent2.yaml
    common:
      value: 44
    
  3. Nested inheritance:

    # parent.yaml
    defaults: grandparent.yaml
    common:
      value: 43
    
    # child.yaml
    defaults: parent.yaml
    common:
      value: 44
    
  4. Variable interpolation:

    # parent.yaml
    base_value: 42
    derived:
      value: ${base_value}
    
    # child.yaml
    defaults: parent.yaml
    base_value: 43  # This will update both base_value and derived.value
    

The system handles:

  • Relative and absolute paths

  • Multiple inheritance

  • Nested inheritance

  • Variable interpolation

The inheritance is resolved depth-first, with later configs overriding earlier ones. This means in multiple inheritance, the last config in the list takes precedence.

Parameters:

config_path – Path to the config file

Returns:

Merged config dictionary

exception nemo_rl.utils.config.OverridesError[source]#

Bases: Exception

Custom exception for Hydra override parsing errors.

Initialization

Initialize self. See help(type(self)) for accurate signature.

nemo_rl.utils.config.parse_hydra_overrides(
cfg: omegaconf.DictConfig,
overrides: list[str],
) omegaconf.DictConfig[source]#

Parse and apply Hydra overrides to an OmegaConf config.

Parameters:
  • cfg – OmegaConf config to apply overrides to

  • overrides – List of Hydra override strings

Returns:

Updated config with overrides applied

Raises:

OverridesError – If there’s an error parsing or applying overrides