bridge.training.utils.config_utils#

Module Contents#

Classes#

_ConfigContainerBase

Bridge config container that lets composite HF configs construct their children.

Functions#

_materialize_gtp_weight_shards

Preserve runtime GTP sizes in constructor fields before sanitizing configs.

create_ddp_config

Create a finalized Bridge DDP config for external model construction.

Data#

API#

bridge.training.utils.config_utils.logger#

‘getLogger(…)’

bridge.training.utils.config_utils._materialize_gtp_weight_shards(
value: Any,
_memo: dict[int, Any] | None = None,
) → Any#

Preserve runtime GTP sizes in constructor fields before sanitizing configs.

class bridge.training.utils.config_utils._ConfigContainerBase#

Bases: megatron.training.config.container.ConfigContainerBase

Bridge config container that lets composite HF configs construct their children.

Nested PreTrainedConfig values are emitted as plain mappings because their parent config owns child construction. Other dataclasses retain MCore’s recursive _target_ serialization.

Megatron Core serializes container sections with module-level helpers that do not dispatch to subclass hooks, so Bridge owns the traversal: every section and nested value goes through :meth:_convert_value_to_dict.

to_dict(
**section_overrides: Mapping[str, Any],
) → dict[str, Any]#

Convert the container to a dictionary through Bridge’s value conversion.

Parameters:

**section_overrides – Map a section name to field values that replace the section’s own values in the result, as in Megatron Core.

Returns:

Dictionary representation of this config with an importable _target_.

classmethod _overlay_section(
name: str,
section: Any,
overrides: Mapping[str, Any],
) → dict[str, Any]#

Return the serialized section with overrides in place of its own field values.

classmethod _convert_value_to_dict(value: Any) → Any#
classmethod _convert_generic_value_to_dict(value: Any) → Any#

Recursively convert containers, dataclasses and collections.

Nested values go back through :meth:_convert_value_to_dict so Bridge-specific conversions apply at any depth.

classmethod _convert_recipe_config_to_dict(
value: megatron.core.quantization.quant_config.RecipeConfig,
) → dict[str, Any]#

Convert an MCore quantization recipe to an instantiable mapping.

classmethod _convert_recipe_matcher_to_dict(
matcher: megatron.core.quantization.quant_config.Matcher,
) → dict[str, Any]#

Convert a quantization recipe matcher to an instantiable mapping.

classmethod _convert_pretrained_config_to_dict(
value: transformers.PreTrainedConfig,
*,
include_target: bool,
) → dict[str, Any]#
classmethod _convert_pretrained_config_value_to_dict(
value: Any,
) → Any#
bridge.training.utils.config_utils.create_ddp_config(
wrap_with_ddp: bool = True,
use_distributed_optimizer: bool = True,
use_megatron_fsdp: bool = False,
overrides: Mapping[str, object] | None = None,
finalize: bool = True,
) → object | None#

Create a finalized Bridge DDP config for external model construction.