bridge.models.glm_moe_dsa.glm5_provider#
Hybrid model provider for the GLM-5 DSA family.
Module Contents#
Classes#
Construct GLM as DSA/dense/MoE Hybrid layers with MLA configuration. |
Functions#
Build an architecture-preserving pattern from HF block counts. |
|
Place PP boundaries without splitting attention/MLP pairs. |
|
Split ordered layer groups into contiguous stages that minimize the largest stage. |
|
Return the main layer pattern with the pipeline boundaries that |
|
Check GLM’s physical layout and training settings without changing the config. |
|
Keep each DSA sharing group within one pipeline stage and derive GLM’s layer settings. |
Data#
API#
- bridge.models.glm_moe_dsa.glm5_provider.glm_hybrid_pattern(
- *,
- num_layers: int,
- first_k_dense_replace: int,
Build an architecture-preserving pattern from HF block counts.
- bridge.models.glm_moe_dsa.glm5_provider.split_glm_pattern(pattern: str, block_counts: list[int]) str#
Place PP boundaries without splitting attention/MLP pairs.
- bridge.models.glm_moe_dsa.glm5_provider._partition_layer_groups(
- group_sizes: list[int],
- num_stages: int,
Split ordered layer groups into contiguous stages that minimize the largest stage.
- Parameters:
group_sizes – Number of layers in each group, in layer order.
num_stages – Number of stages; must not exceed the number of groups.
- Returns:
Number of layers in each stage. Every stage receives at least one whole group.
- bridge.models.glm_moe_dsa.glm5_provider._dsa_aligned_hybrid_pattern(config: Any) str#
Return the main layer pattern with the pipeline boundaries that
finalize_glm_hybrid_pattern()sets.A pattern without
|is split intopipeline_model_parallel_sizestages, each starting on a layer that computes its own DSA top-k indices. A pattern with|is returned as given. The config is not changed.- Raises:
ValueError – If PP exceeds the number of DSA top-k sharing groups.
- bridge.models.glm_moe_dsa.glm5_provider.validate_glm_hybrid_pattern(config: Any) None#
Check GLM’s physical layout and training settings without changing the config.
GLM5ModelProviderandGLM5ModelConfigrun this beforefinalize_glm_hybrid_pattern(). The pipeline checks apply to the pattern as finalization sets it, so a pattern without|is valid for PP > 1: finalization places DSA-aligned boundaries.- Parameters:
config – GLM-5 provider or model config to check.
- Raises:
ValueError – If the pattern, pipeline topology or training settings are unsupported.
- bridge.models.glm_moe_dsa.glm5_provider.finalize_glm_hybrid_pattern(config: Any) None#
Keep each DSA sharing group within one pipeline stage and derive GLM’s layer settings.
GLM5ModelProviderandGLM5ModelConfigrun this aftervalidate_glm_hybrid_pattern()and before their Hybrid finalization. It places DSA-aligned pipeline boundaries, enables sequence parallelism for TP > 1, and derivesnum_layers, the MTP pattern and the MoE layer schedule fromhybrid_layer_pattern.- Parameters:
config – GLM-5 provider or model config to update in place.
- class bridge.models.glm_moe_dsa.glm5_provider.GLM5ModelProvider#
Bases:
megatron.bridge.models.hybrid.hybrid_provider.HybridModelProvider,megatron.bridge.models.transformer_config.MLATransformerConfigConstruct GLM as DSA/dense/MoE Hybrid layers with MLA configuration.
- property post_wrap_hook: Callable[[list[megatron.core.transformer.module.MegatronModule]], list[megatron.core.transformer.module.MegatronModule]] | None#
Include DSA metric setup after distributed construction binds the process groups.
- _resolve_hybrid_stack_spec() megatron.core.transformer.spec_utils.ModuleSpec#
- finalize() None#
Validate physical layout and preserve DSA sharing within each stage.
- bridge.models.glm_moe_dsa.glm5_provider.__all__#
[‘GLM5ModelProvider’, ‘finalize_glm_hybrid_pattern’, ‘validate_glm_hybrid_pattern’]