feat(model): add MiniMax M3 language-model bridge and recipes - #4652
Merged
Conversation
Add Megatron-Bridge support for the MiniMax-M3 text backbone (MiniMaxM3SparseForConditionalGeneration checkpoints): - MiniMaxM3Bridge: HF <-> Megatron conversion for the language_model weights of the multimodal checkpoint. Covers mixed dense/MoE layers (first 3 dense), 128 routed experts (top-4, sigmoid scoring with expert-bias correction and routed scaling), one shared expert, per-head QK RMSNorm, Gemma-style zero-centered RMSNorm, partial RoPE, and the clamped SwiGLU-OAI activation (quick-GELU gate with clamp and +1 linear offset, same mechanism as GPT-OSS). - Pretrain and SFT recipes under recipes/minimax (TP=2, PP=4, EP=32 baseline for H100). - AutoBridge registration matrix coverage and unit tests. - Docs page under docs/models/minimax and the fern mirror. Known limitations (documented): vision tower, lightning-indexer block-sparse attention branch, and MTP modules are not mapped; the Megatron model runs full causal attention, which matches the sparse kernel exactly up to index_topk_blocks * index_block_size tokens. Related to NVIDIA-NeMo#4585 Signed-off-by: khazic <khazzz1c@gmail.com>
yaoyu-33
reviewed
Jul 5, 2026
| load_weights=False | ||
| ) | ||
|
|
||
| _apply_minimax_m3_model_settings(cfg) |
Contributor
There was a problem hiding this comment.
dont need this extra layer of function, just flatten it here.
Contributor
Author
There was a problem hiding this comment.
Done, flattened into both recipe functions in ad3eda0.
yaoyu-33
reviewed
Jul 5, 2026
| return cfg | ||
|
|
||
|
|
||
| def minimax_m3_sft_128gpu_h100_bf16_config() -> ConfigContainer: |
Contributor
There was a problem hiding this comment.
sft better just provide thd.
Contributor
Author
There was a problem hiding this comment.
Done, switched the SFT dataset to packed THD in ad3eda0.
…HD for SFT Address review feedback: inline the shared model settings into each recipe function and switch the SFT dataset to packed (THD) sequences. Signed-off-by: khazic <khazzz1c@gmail.com>
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
yaoyu-33
previously approved these changes
Jul 6, 2026
Contributor
|
/ok to test 471d942 |
Signed-off-by: khazic <khazzz1c@gmail.com>
Contributor
|
/ok to test 3e4bd01 |
upstream/main removed src/megatron/bridge/models/hf_pretrained/vlm.py and PreTrainedVLM; VLM bridges now type their HF handle as PreTrainedCausalLM (the wrapper only reads .config here, which PreTrainedCausalLM exposes). The stale PreTrainedVLM import broke conftest collection (ModuleNotFoundError) and failed every unit-test job. Merge upstream/main and switch the import. Signed-off-by: khazic <khazzz1c@gmail.com>
Contributor
|
/ok to test f1fe523 |
…bridges The SUPPORTS_HF_PRETRAINED_EXPORT capability gate resolved self._model_bridge unconditionally at the top of save_hf_pretrained, before the config-only branch. Resolving the bridge requires a concrete, registered architecture, so a config-only save from a bare PretrainedConfig (no architectures, or an auto_map pointing at an unregistered class) raised ValueError / NotImplementedError from bridge resolution instead of writing config.json. This broke the pre-existing test_save_hf_pretrained_config_only* tests. Treat an unresolvable bridge as "nothing to gate" and fall through to the normal path; still raise NotImplementedError when a bridge resolves and reports it cannot export (e.g. the MiniMax M3 LM-only bridge), so the export-rejection contract is preserved. Signed-off-by: khazic <khazzz1c@gmail.com>
Contributor
|
/ok to test 9370b6a |
L0_Launch_training_finetune failed only on test_lora_finetune_with_packed_sequences with a NCCL/NET-MLX5 SIGSEGV during init; unrelated to this MiniMax-M3 change. Re-running. Signed-off-by: khazic <khazzz1c@gmail.com>
chochowski
pushed a commit
to chochowski/Megatron-Bridge
that referenced
this pull request
Jul 21, 2026
…-NeMo#4652) Signed-off-by: khazic <khazzz1c@gmail.com> Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com> Co-authored-by: yaoyu-33 <yaoyu.094@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do ?
Add Megatron-Bridge support for the MiniMax M3 language model (
MiniMaxAI/MiniMax-M3): HF to Megatron bridge, pretraining and SFT recipes, AutoBridge registration matrix coverage, unit tests, and a docs page. First implementation step for #4585.Changelog
MiniMaxM3Bridge(src/megatron/bridge/models/minimax_m3/), registered forMiniMaxM3SparseForConditionalGeneration. It converts thelanguage_model.*weights of the multimodal checkpoint to a Megatron-CoreGPTModel:moe_layer_freq), 128 routed experts with top-4 routing, sigmoid scoring with expert-bias correction androuted_scaling_factoron the normalized top-k weights (DeepSeek-V3-style), plus one shared expert.activation_func=quick_geluwithactivation_func_clamp_valueandglu_linear_offset(same mechanism as GPT-OSS; M3 expert weights are non-interleaved and the on-disk layout is per-expertw1/w3/w2under the legacyblock_sparse_moeprefix, as in MiniMax-M2).x * (1 + w)) vialayernorm_zero_centered_gamma, per-head QK RMSNorm via stockqk_layernorm, partial RoPE (rotary_dim / head_dim), GQA with 4 KV heads.MiniMaxM3VLForCausalLMwithfull_attentionlayer types).src/megatron/bridge/recipes/minimax/(h100 namespace, TP=2 / PP=4 / EP=32 baseline; 60 layers split evenly across 4 stages).MiniMaxM3SparseForConditionalGenerationto the AutoBridge registration matrix (string registration).tests/unit_tests/models/minimax_m3/covering provider config mapping (FFN size split, MoE routing flags, activation, norms, rotary percent, MTP disable,mlp_layer_typesfallback), mapping registry contents andlanguage_model.prefixing, and text-only export config.docs/models/minimax/minimax-m3.mdplus the fern mirror and nav entries.Known limitations (documented in the model page and bridge docstring)
self_attn.index_*) is not mapped; the Megatron model runs full causal attention on every layer. Block selection keepsindex_topk_blocks * index_block_size(2048) key tokens per query, so full attention is mathematically identical up to that sequence length and an approximation beyond it.num_nextn_predict_layersbut ships nomtp.*weights), somtp_num_layersis forced to None.GitHub Actions CI
See the CI section in the Contributing doc for how to trigger the CI. A Nvidia developer will need to approve and trigger the CI for external contributors.
Before your PR is "Ready for review"
Pre checks:
Additional Information