bridge.models.minimax_m3.minimax_m3_bridge#
Module Contents#
Classes#
GPT provider that preserves MiniMax-M3’s FP32 router parameters. |
|
Megatron Bridge for the MiniMax-M3 language model. |
Functions#
Keep MiniMax-M3 router parameters in FP32 for every load path. |
API#
- 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 the router hook on fresh and deserialized providers.
- class bridge.models.minimax_m3.minimax_m3_bridge.MiniMaxM3Bridge#
Bases:
megatron.bridge.models.conversion.model_bridge.MegatronModelBridgeMegatron Bridge for the MiniMax-M3 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 language model (language_model.*weights) to a Megatron-CoreGPTModel; the vision tower and multimodal projector are not yet bridged.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 not mapped; the Megatron model 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. - The vision tower, multimodal projector, and patch-merge MLP are not mapped (language model only). - 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. - Standalone Hugging Face checkpoint export is not supported. The HF checkpoint is multimodal, while this bridge maps only itslanguage_model.*tensors. In-memory HF-to-Megatron-to-HF weight verification remains supported... rubric:: Example
from megatron.bridge import AutoBridge bridge = AutoBridge.from_hf_pretrained(“MiniMaxAI/MiniMax-M3”, trust_remote_code=True) provider = bridge.to_megatron_provider()
- SUPPORTS_HF_PRETRAINED_EXPORT#
False
- 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 HuggingFace MiniMax-M3 config to a GPTModelProvider.
- abstractmethod classmethod megatron_to_hf_config(
- provider: megatron.bridge.models.gpt_provider.GPTModelProvider,
Reject standalone HF export until the full multimodal contract is mapped.
- mapping_registry() megatron.bridge.models.conversion.mapping_registry.MegatronMappingRegistry#
Return the parameter mappings for the MiniMax-M3 language model.
All HF weights live under the
language_model.prefix of the multimodal checkpoint. MoE weights use the legacyblock_sparse_moelayout with per-expertw1(gate),w3(up), andw2(down) tensors, the same on-disk format as MiniMax-M2.