bridge.models.deepseek.deepseek_v4_hybrid_provider#
Provider for DeepSeek-V4 expressed as a Megatron-Core HybridModel.
DeepSeek-V4 is a Multi-Latent-Attention (MLA) model, so it needs every MLA
configuration field (q_lora_rank, output_projection_groups,
v_head_dim, rope_type / YaRN parameters, …). Those live on
- class:
MLAModelProvider. It is also a hybrid model: each logical DeepSeek-V4 block is expressed as two Megatron hybrid layers — an attention-only layer (W/C/Hsymbol) and a MoE-only layer (Esymbol) — driven byhybrid_layer_patternand built by MCore’s standard hybrid stack. The hybridprovide()/finalize()logic lives on :class:HybridModelProvider.
This provider combines both. :class:HybridModelProvider is listed first so its
provide() (which instantiates :class:~megatron.core.models.hybrid.hybrid_model.HybridModel)
and finalize() (which derives num_layers from hybrid_layer_pattern)
win over the GPT-model versions inherited via :class:MLAModelProvider, while
issubclass(DeepSeekV4HybridModelProvider, MLAModelProvider) stays True so
- meth:
MegatronModelBridge.provider_bridgekeeps mapping the HF config through the direct MLA field names.
Module Contents#
Classes#
MLA-capable :class: |
Functions#
Rebuild a DeepSeek-V4 config’s native pattern and layout for a new PP/VPP topology. |
|
Require one |
API#
- bridge.models.deepseek.deepseek_v4_hybrid_provider.rebuild_deepseek_v4_pipeline_layout(
- config: Any,
- pipeline_model_parallel_size: int,
- virtual_pipeline_model_parallel_size: int | None,
Rebuild a DeepSeek-V4 config’s native pattern and layout for a new PP/VPP topology.
The recipe runner calls this through
_pipeline_model_parallel_layout_builderafter command-line PP or VPP overrides. It mutateshybrid_layer_patternas well as the PP/VP fields andpipeline_model_parallel_layout. Existing pipe separators, including a recipe’s uneven stage allocation, are replaced by the default split of- Func:
~megatron.bridge.models.deepseek.deepseek_v4_bridge.set_deepseek_v4_pipeline_model_parallel_layout; the MTP suffix is preserved. The runner skips this hook when the command line supplies a layout, so that caller must also supply matching native pattern segments.- Parameters:
config – DeepSeek-V4 provider or builder-backed model config to update in place.
pipeline_model_parallel_size – Requested pipeline-parallel size.
virtual_pipeline_model_parallel_size – Requested virtual pipeline size, or
None.
- Returns:
The rebuilt
pipeline_model_parallel_layout.
- bridge.models.deepseek.deepseek_v4_hybrid_provider.validate_deepseek_v4_pipeline_segments(config: Any) None#
Require one
|segment per PP/VP stage, matching any explicit layout.MCore picks segment
vp_stage * PP + pp_rankand only checks that the segment count is divisible by PP, so segments left over from an earlier topology can build only part of the decoder without an error: a PP4 pattern used at PP1 builds only its first segment. A pattern without|keeps MCore’s even split by PP. When VP is unset, an explicit layout supplies it, as MCore’s finalization infers it from the layout. The check does not changeconfig.- Parameters:
config – DeepSeek-V4 provider or builder-backed model config.
- Raises:
ValueError – If the segments do not match PP x VP, or the layout places a different number of decoder layers on a stage than the matching segment holds.
- class bridge.models.deepseek.deepseek_v4_hybrid_provider.DeepSeekV4HybridModelProvider#
Bases:
megatron.bridge.models.hybrid.hybrid_provider.HybridModelProvider,megatron.bridge.models.mla_provider.MLAModelProviderMLA-capable :class:
HybridModelProviderfor DeepSeek-V4.All configuration is supplied by :class:
DeepSeekV4Bridge.provider_bridge; this class combines the MLA config and hybrid builder and keeps native pipeline segments aligned with public runner topology overrides. It also registers DSA metric setup after model wrapping, as- Class:
~megatron.bridge.models.deepseek.deepseek_v4_config.DeepSeekV4ModelConfigdoes.
- _pipeline_model_parallel_layout_builder(
- pipeline_model_parallel_size: int,
- virtual_pipeline_model_parallel_size: int | None,
Rebuild this provider’s pattern and layout after runner PP/VPP overrides.
- finalize() None#
Finalize the hybrid provider and reject stale native pipeline segments.
- 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.