bridge.models.hybrid.model_config#

Serializable Bridge extension of Megatron-LM’s Hybrid model config.

Module Contents#

Classes#

BridgeHybridModelConfig

Hybrid model config with strict overrides and callable serialization.

BridgeHybridMLAModelConfig

Hybrid model config with Multi-Latent Attention (MLA) in its attention layers.

Data#

API#

bridge.models.hybrid.model_config.logger#

‘getLogger(…)’

class bridge.models.hybrid.model_config.BridgeHybridModelConfig#

Bases: megatron.bridge.models.common.base.ModelConfigOverrideMixin, megatron.bridge.models.hybrid.hybrid_builder.HybridModelConfig, megatron.bridge.models.common.base.ModelConfig

Hybrid model config with strict overrides and callable serialization.

This is the HybridModel counterpart of BridgeGPTModelConfig. Outer Hybrid build fields and nested transformer fields keep one declared owner. Flat assignment remains convenient, but unknown names fail instead of silently creating phantom configuration. Subclasses can select a specialized transformer config, such as an MLA config, through transformer_config_class.

It keeps the construction contract of HybridModelProvider. validate() checks the settings without changing them, and finalize() runs it before appending mtp_hybrid_override_pattern to hybrid_layer_pattern once per MTP depth and deriving num_layers from the pattern. :class:~megatron.bridge.models.hybrid.BridgeHybridModelBuilder resolves stack-spec factories, the local attention backend and mamba_chunk_size.

Hugging Face source provenance is recorded in the inherited extra_checkpoint_metadata mapping, as for BridgeGPTModelConfig. hf_model_text_only records that the source checkpoint was projected to its language model, so a restored config reopens the same projection.

builder: ClassVar[str]#

‘megatron.bridge.models.hybrid.BridgeHybridModelBuilder’

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

None

_mirrored_transformer_fields: ClassVar[frozenset[str]]#

‘frozenset(…)’

hybrid_stack_spec: megatron.core.transformer.ModuleSpec | Callable[[], megatron.core.transformer.ModuleSpec] | Callable[[bridge.models.hybrid.model_config.BridgeHybridModelConfig], megatron.core.transformer.ModuleSpec] | None#

None

Stack spec, or a factory that takes no arguments or this config. None selects Bridge’s default.

mamba_chunk_size: int#

None

Chunk size of the Mamba scan.

hf_model_text_only: bool#

False

Whether the source HF checkpoint was projected to its language model.

validate() → None#

Check the Hybrid settings without changing the config.

Raises:

ValueError – If mamba_chunk_size is not positive or both pattern fields are set.

finalize() → None#

Validate, combine the hybrid layer patterns and derive num_layers, then finalize the transformer config.

Raises:

ValueError – If :meth:validate rejects the config or num_layers disagrees with hybrid_layer_pattern.

get_builder_cls() → type#

Resolve the configured builder through Bridge’s target allowlist.

as_dict() → dict[str, Any]#

Serialize the config with a symbolic activation function and a restorable pipeline layout.

classmethod from_dict(
data: dict[str, Any],
) → bridge.models.hybrid.model_config.BridgeHybridModelConfig#

Deserialize a config while restoring its activation callable.

class bridge.models.hybrid.model_config.BridgeHybridMLAModelConfig#

Bases: megatron.bridge.models.common.base.MLAModelConfigMixin, bridge.models.hybrid.model_config.BridgeHybridModelConfig

Hybrid model config with Multi-Latent Attention (MLA) in its attention layers.

The nested transformer config is an MLATransformerConfig. It alone stores and serializes rotary_base and rotary_percent, because MLA attention applies RoPE from them; on this config they are constructor arguments and views of the nested values (see MLAModelConfigMixin). Hybrid MLA families such as DeepSeek-V4 and GLM-5 subclass it, as their providers combine HybridModelProvider with an MLA config.

bridge.models.hybrid.model_config.__all__#

[‘BridgeHybridMLAModelConfig’, ‘BridgeHybridModelConfig’]