bridge.models.hybrid.hybrid_builder#
Module Contents#
Classes#
Bridge Hybrid config with transitional output-logit dtype support. |
|
Bridge Hybrid builder that prevents silent fallback on older MCore. |
|
Hybrid builder that resolves the stack spec the way |
Functions#
Return the default Hybrid stack spec with Transformer Engine layers. |
|
Hybrid stack specification for quantization with ModelOpt. |
|
Determine the most appropriate Hybrid stack specification based on configuration. |
|
Return a stack spec whose Mamba mixer uses the requested scan chunk size. |
|
Return a copy of a stack spec whose attention layers use Megatron Core’s local attention. |
Data#
API#
- bridge.models.hybrid.hybrid_builder.DEFAULT_MAMBA_CHUNK_SIZE#
128
- class bridge.models.hybrid.hybrid_builder.HybridModelConfig#
Bases:
megatron.training.models.hybrid.HybridModelConfigBridge Hybrid config with transitional output-logit dtype support.
- builder: ClassVar[str]#
‘megatron.bridge.models.hybrid.HybridModelBuilder’
- logit_dtype: torch.dtype | None#
None
- class bridge.models.hybrid.hybrid_builder.HybridModelBuilder#
Bases:
megatron.training.models.hybrid.HybridModelBuilderBridge Hybrid builder that prevents silent fallback on older MCore.
- build_model(
- pg_collection: megatron.core.process_groups_config.ProcessGroupCollection,
- pre_process: bool | None = None,
- post_process: bool | None = None,
- vp_stage: int | None = None,
Build a Hybrid stage after validating MCore logit-dtype support.
- bridge.models.hybrid.hybrid_builder.transformer_engine_hybrid_stack_spec() megatron.core.transformer.ModuleSpec#
Return the default Hybrid stack spec with Transformer Engine layers.
This is a named function (not a lambda) to allow proper serialization and reconstruction from checkpoints. Named functions can be imported via their module path, unlike lambdas.
- Returns:
Default Hybrid stack specification from megatron.core.
- bridge.models.hybrid.hybrid_builder.modelopt_hybrid_stack_spec(
- config: HybridModelConfig | None = None,
Hybrid stack specification for quantization with ModelOpt.
Uses Norm instead of TENorm and ColumnParallelLinear/RowParallelLinear instead of TE layers to enable proper quantizer insertion by ModelOpt.
- Parameters:
config – Optional Hybrid configuration object.
- Returns:
Module specification for quantization-ready Hybrid stack.
- bridge.models.hybrid.hybrid_builder.get_default_hybrid_stack_spec( ) megatron.core.transformer.ModuleSpec#
Determine the most appropriate Hybrid stack specification based on configuration.
- Parameters:
config – Hybrid configuration object.
- Returns:
Appropriate module specification based on config.
- bridge.models.hybrid.hybrid_builder.configure_mamba_chunk_size(
- stack_spec: megatron.core.transformer.ModuleSpec,
- chunk_size: int,
Return a stack spec whose Mamba mixer uses the requested scan chunk size.
- Parameters:
stack_spec – Hybrid stack specification.
chunk_size – Chunk size of the Mamba scan.
- Returns:
stack_specfor the default chunk size, otherwise a configured copy.
- bridge.models.hybrid.hybrid_builder.use_local_core_attention(
- stack_spec: megatron.core.transformer.ModuleSpec,
Return a copy of a stack spec whose attention layers use Megatron Core’s local attention.
- Parameters:
stack_spec – Hybrid stack specification.
- Returns:
A copy of
stack_specwithDotProductAttentionas its core attention.
- class bridge.models.hybrid.hybrid_builder.BridgeHybridModelBuilder#
Bases:
bridge.models.hybrid.hybrid_builder.HybridModelBuilderHybrid builder that resolves the stack spec the way
HybridModelProviderdoes.The configured stack spec may be a
ModuleSpecor a factory that takes no arguments or the model config. When it is unset, Bridge’s default selection applies. The local attention backend and a non-default Mamba chunk size are applied to a copy of the resolved spec.- _resolve_hybrid_stack_spec() megatron.core.transformer.ModuleSpec#
Resolve the stack spec for the configured model.
- Returns:
Stack specification used to build every stage.
- build_model(
- pg_collection: megatron.core.process_groups_config.ProcessGroupCollection,
- pre_process: bool | None = None,
- post_process: bool | None = None,
- vp_stage: int | None = None,
Build a Hybrid stage from the resolved stack spec.
- Parameters:
pg_collection – Process groups used to construct the model.
pre_process – Whether to include input processing on this stage.
post_process – Whether to include output processing on this stage.
vp_stage – Virtual pipeline stage to construct.
- Returns:
The constructed Hybrid model stage.
- bridge.models.hybrid.hybrid_builder.__all__#
[‘DEFAULT_MAMBA_CHUNK_SIZE’, ‘BridgeHybridModelBuilder’, ‘HybridModelBuilder’, ‘HybridModelConfig’, …