bridge.training.utils.config_utils#

Module Contents#

Classes#

_ConfigContainerBase

Base configuration container for Megatron Hub configurations.

Data#

T

API#

bridge.training.utils.config_utils.T#

‘TypeVar(…)’

class bridge.training.utils.config_utils._ConfigContainerBase#

Base configuration container for Megatron Hub configurations.

Provides:

  • Custom validation

  • Versioning metadata

  • YAML/Dict serialization and deserialization

  • Dictionary-style attribute access (config[“attr”] and config.get(“attr”, default))

__version__: str#

‘0.1.0’

classmethod from_dict(
config_dict: dict[str, Any],
mode: megatron.bridge.utils.instantiate_utils.InstantiationMode = InstantiationMode.STRICT,
) bridge.training.utils.config_utils.T#

Create a config container from a dictionary using instantiate.

Parameters:
  • config_dict – Dictionary containing configuration

  • mode – Serialization mode (strict or lenient)

Returns:

A new instance of this class initialized with the dictionary values

classmethod from_yaml(
yaml_path: str,
mode: megatron.bridge.utils.instantiate_utils.InstantiationMode = InstantiationMode.LENIENT,
) bridge.training.utils.config_utils.T#

Create a config container from a YAML file.

Parameters:
  • yaml_path – Path to the YAML file

  • mode – Serialization mode (strict or lenient)

Returns:

A new instance of this class initialized with the YAML file values

to_dict() dict[str, Any]#

Convert the config container to a dictionary.

Also converts any nested dataclasses (both ConfigContainer and regular dataclasses) to dictionaries recursively.

Returns:

Dictionary representation of this config

classmethod _convert_value_to_dict(value: Any) Any#

Recursively convert a value to a dictionary representation.

Handles:

  • ConfigContainer instances (using to_dict)

  • Regular dataclasses (using asdict)

  • Lists and tuples (converting each element)

  • Dictionaries (converting each value)

  • Other types (kept as-is)

Parameters:

value – The value to convert

Returns:

The converted value

to_yaml(yaml_path: Optional[str] = None) None#

Save the config container to a YAML file.

Parameters:

yaml_path – Path where to save the YAML file

__deepcopy__(memo)#

Support for deep copying.