bridge.models.common.base#

Module Contents#

Classes#

ModelConfigOverrideMixin

Route flat overrides to their declared owner and reject unknown fields.

_TransformerOwnedField

Outer name of a setting that the nested transformer config stores.

MLAModelConfigMixin

Nest an MLA transformer config, which owns the rotary settings that MLA attention applies.

ModelConfig

Bridge compatibility wrapper for Megatron-LM model configs.

Functions#

_init_var_names

Return the names of a dataclass’s InitVar arguments in the order its constructor passes them.

deserialize_model_config

Deserialize a builder config, including persisted enum and dtype values.

API#

bridge.models.common.base._init_var_names(config_cls: type) → list[str]#

Return the names of a dataclass’s InitVar arguments in the order its constructor passes them.

bridge.models.common.base.deserialize_model_config(
data: dict[str, Any],
) → megatron.training.models.base.ModelConfig#

Deserialize a builder config, including persisted enum and dtype values.

class bridge.models.common.base.ModelConfigOverrideMixin#

Route flat overrides to their declared owner and reject unknown fields.

Builder-backed model configs store Megatron-Core transformer settings in a nested transformer dataclass while exposing flat assignment for recipe compatibility. This mixin keeps that convenience without allowing typos to create phantom configuration attributes. Subclasses declare the nested config type through transformer_config_class.

transformer_config_class: ClassVar[type[megatron.bridge.models.transformer_config.TransformerConfig]]#

None

_mirrored_transformer_fields: ClassVar[frozenset[str]]#

‘frozenset(…)’

__setattr__(name: str, value: Any, /) → None#

Assign a declared outer or nested field and reject phantom fields.

__deepcopy__(memo: dict[int, Any]) → Any#

Deep-copy the outer config together with its nested transformer config.

Megatron Core’s builder configs forward attribute lookups they cannot resolve to the nested transformer config, and copy.deepcopy looks __deepcopy__ up on the instance. Without this method it would find the transformer config’s own and return a copy of the nested config alone, dropping the outer fields (seq_length, vocab_size, hooks and builder settings).

class bridge.models.common.base._TransformerOwnedField#

Outer name of a setting that the nested transformer config stores.

As the default of an InitVar, it keeps the setting out of the outer config’s fields, so the outer config neither stores nor serializes it. A value given to the constructor reaches __post_init__; reads and later assignments use the transformer config.

__set_name__(owner: type, name: str) → None#
__get__(instance: Any, owner: type | None = None) → Any#
__set__(instance: Any, value: Any) → None#
class bridge.models.common.base.MLAModelConfigMixin#

Nest an MLA transformer config, which owns the rotary settings that MLA attention applies.

Megatron Core’s MLA transformer config declares rotary_base and rotary_percent, as do the GPT and Hybrid model configs. MLA attention reads the nested values, so only the transformer config stores and serializes them. On this config they are constructor arguments and views of the nested values. __post_init__ checks a constructor value against the transformer config’s own value before copying it there: they must match unless the transformer config kept its default. List this mixin before the model config class it extends.

transformer_config_class: ClassVar[type[megatron.bridge.models.transformer_config.TransformerConfig]]#

None

rotary_base: dataclasses.InitVar[float | None]#

‘_TransformerOwnedField(…)’

rotary_percent: dataclasses.InitVar[float | None]#

‘_TransformerOwnedField(…)’

__post_init__(*constructor_values: Any) → None#
class bridge.models.common.base.ModelConfig#

Bases: megatron.training.models.base.ModelConfig

Bridge compatibility wrapper for Megatron-LM model configs.

as_dict() → dict[str, Any]#

Serialize nested configs without turning inferred CP defaults into overrides.

get_builder_cls() → type#

Get the appropriate builder type for this config.

classmethod from_dict(
data: dict[str, Any],
) → megatron.training.models.base.ModelConfig#

Deserialize config from dictionary with Bridge target validation.