bridge.models.minimax_m3.minimax_m3_bridge#
Module Contents#
Classes#
MiniMax-M3 router that computes its projection in the weight dtype. |
|
GPT provider that preserves MiniMax-M3’s FP32 router parameters. |
|
Provider for the complete MiniMax-M3 vision-language model. |
|
Megatron Bridge for the complete MiniMax-M3 vision-language model. |
Functions#
Build a GPT block spec that uses MiniMax-M3’s FP32 router projection. |
|
Keep MiniMax-M3 router parameters in FP32 for every load path. |
|
Read a value from either a Hugging Face config object or a dictionary. |
|
Return a detached dictionary representation of an HF config. |
API#
- class bridge.models.minimax_m3.minimax_m3_bridge.MiniMaxM3TopKRouter#
Bases:
megatron.core.transformer.moe.router.TopKRouterMiniMax-M3 router that computes its projection in the weight dtype.
- gating(input: torch.Tensor) torch.Tensor#
Match HF by widening router inputs to the FP32 router weight dtype.
- bridge.models.minimax_m3.minimax_m3_bridge.minimax_m3_block_spec(
- config: megatron.core.transformer.transformer_config.TransformerConfig,
- use_transformer_engine: bool = True,
- normalization: str | None = None,
- qk_l2_norm: bool | None = False,
- vp_stage: int | None = None,
- pp_rank: int | None = None,
- **kwargs: object,
Build a GPT block spec that uses MiniMax-M3’s FP32 router projection.
- bridge.models.minimax_m3.minimax_m3_bridge._promote_router_weights_to_float32(
- model: list[torch.nn.Module],
Keep MiniMax-M3 router parameters in FP32 for every load path.
Megatron initializes router parameters in
params_dtypeeven whenmoe_router_dtype="fp32". Promoting them immediately after construction prevents truncation when loading either HF weights or a native Megatron checkpoint.
- class bridge.models.minimax_m3.minimax_m3_bridge.MiniMaxM3ModelProvider#
Bases:
megatron.bridge.models.gpt_provider.GPTModelProviderGPT provider that preserves MiniMax-M3’s FP32 router parameters.
- __post_init__() None#
Install MiniMax-M3 router behavior on fresh and deserialized providers.
- bridge.models.minimax_m3.minimax_m3_bridge._config_value(
- config: Any,
- name: str,
- default: Any = None,
Read a value from either a Hugging Face config object or a dictionary.
- bridge.models.minimax_m3.minimax_m3_bridge._config_to_dict(config: Any) dict[str, Any]#
Return a detached dictionary representation of an HF config.
- class bridge.models.minimax_m3.minimax_m3_bridge.MiniMaxM3VLModelProvider#
Bases:
bridge.models.minimax_m3.minimax_m3_bridge.MiniMaxM3ModelProviderProvider for the complete MiniMax-M3 vision-language model.
- scatter_embedding_sequence_parallel: bool#
False
- vision_config: Any#
None
- hf_config_dict: dict[str, Any]#
‘field(…)’
- image_token_id: int#
200025
- video_token_id: int#
200026
6144
- multimodal_projector_bias: bool#
True
- spatial_merge_size: int#
2
- temporal_patch_size: int#
2
- lightning_indexer_layers: list[int]#
‘field(…)’
- index_n_heads: int#
4
- index_head_dim: int#
128
- freeze_language_model: bool#
False
- freeze_vision_model: bool#
False
- freeze_vision_projection: bool#
False
- property special_token_ids: dict[str, int]#
Return the token IDs used by multimodal data pipelines.
- provide(
- pre_process=None,
- post_process=None,
- vp_stage=None,
Construct the complete MiniMax-M3 VLM.
- provide_language_model(
- pre_process=None,
- post_process=None,
- vp_stage=None,
Construct only the Megatron text component used inside the VLM.
- to_text_provider() bridge.models.minimax_m3.minimax_m3_bridge.MiniMaxM3ModelProvider#
Return the equivalent text-only provider.
This preserves the lightweight model shape and native checkpoint keys used by the existing text pretraining and SFT recipes.
- class bridge.models.minimax_m3.minimax_m3_bridge.MiniMaxM3Bridge#
Bases:
megatron.bridge.models.conversion.model_bridge.MegatronModelBridgeMegatron Bridge for the complete MiniMax-M3 vision-language model.
MiniMax-M3 ships as a natively multimodal checkpoint (
MiniMaxM3SparseForConditionalGeneration): a CLIP-style vision tower plus a sparse-MoE text backbone. This bridge converts the vision tower, both multimodal projector MLPs, and the language model into aMiniMaxM3VLModel. The vision stack is replicated across TP ranks while the language model retains Megatron TP/PP/EP sharding.Text backbone architecture: - Mixed dense/MoE decoder: the first layers are dense (
dense_intermediate_sizeMLP), the rest use 128 routed experts (top-4) plus one shared expert. - Sigmoid router scoring with expert-bias correction androuted_scaling_factorapplied to the normalized top-k weights (same routing math as DeepSeek-V3). - SwiGLU-OAI expert/MLP activation: clamped gate/up projections with a+1linear offset (same as GPT-OSS), expressed viaactivation_func_clamp_valueandglu_linear_offset. - Gemma-style RMSNorm (x * (1 + w)) on every norm, expressed vialayernorm_zero_centered_gamma. - GQA attention with per-head QK RMSNorm and partial RoPE (rotary_dimofhead_dimchannels rotated).Known limitations: - The lightning-indexer block-sparse attention branch (
self_attn.index_{q,k}_{proj,norm}) is stored as frozen model state but is not executed; Megatron runs full causal attention on every layer. Selection happens atindex_block_sizegranularity withindex_topk_blockskept per query, so full attention is mathematically identical for sequences up toindex_topk_blocks * index_block_sizetokens (2048 for the released checkpoint) and an approximation beyond that. - MTP (Multi-Token Prediction) modules are not mapped. The released checkpoint advertisesnum_nextn_predict_layersin its config but ships nomtp.*weights, somtp_num_layersis forced to None. - The vision forward matches the native Transformers implementation, which concatenates multiple image/video patch grids into one bidirectional attention sequence. Segmented multi-image/video attention remains future work... rubric:: Example
from megatron.bridge import AutoBridge bridge = AutoBridge.from_hf_pretrained(“MiniMaxAI/MiniMax-M3”, trust_remote_code=True) provider = bridge.to_megatron_provider()
- classmethod hf_to_megatron_activation(hidden_act: str)#
Convert HF activation name to Megatron activation function.
The released MiniMax-M3 checkpoint declares
hidden_act="swigluoai", which is not a standard ACT2FN key (transformers normalizes it tosiluand computes the gate inline fromswiglu_alpha/swiglu_limit). Map it toquick_gelu— the SwiGLU-OAI gate isgate * sigmoid(1.702 * gate), i.e. exactly quick-GELU; the clamp and+1offset are carried by separate provider fields.
- provider_bridge(
- hf_pretrained: megatron.bridge.models.hf_pretrained.causal_lm.PreTrainedCausalLM,
Convert the Hugging Face MiniMax-M3 config to a full VLM provider.
- classmethod megatron_to_hf_config(
- provider: megatron.bridge.models.gpt_provider.GPTModelProvider,
Build the nested MiniMax-M3 VLM config used for Hugging Face export.
- mapping_registry() megatron.bridge.models.conversion.mapping_registry.MegatronMappingRegistry#
Return parameter mappings for the MiniMax-M3 VLM.
Text mappings target the nested
language_model. Vision and projector modules intentionally preserve the legacy checkpoint names, so their mappings are replicated identity mappings.