Support NemotronH hybrid Mamba+Attention+MoE training (e.g. Nemotron Nano-30B-A3B)#2211
Open
HelloWorldLTY wants to merge 1 commit into
Open
Support NemotronH hybrid Mamba+Attention+MoE training (e.g. Nemotron Nano-30B-A3B)#2211HelloWorldLTY wants to merge 1 commit into
HelloWorldLTY wants to merge 1 commit into
Conversation
…Nano-30B-A3B) slime always builds a GPTModel (pure transformer), so hybrid Mamba-attention-MoE models like NVIDIA NemotronH produce param names (input_layernorm, no mixer.*) that do not match a Megatron-core NemotronH checkpoint, and the training forward crashes on the loss_mask kwarg that mcore MambaModel.forward does not accept. - model_provider: when --hybrid-override-pattern is set, build megatron.core.models.mamba.MambaModel with mamba_stack_spec, yielding decoder.layers.N.mixer.* + GroupedMLP experts + final_norm that match a Megatron-core NemotronH checkpoint (critic role keeps LinearForLastLayer). - megatron_utils/model.py: drop the loss_mask kwarg by signature check before calling the model; loss masking already happens in slime's own loss function, so GPT-family behavior is unchanged. - scripts/models/nemotron-nano-30B-A3B.sh: Megatron MODEL_ARGS for Nano-30B-A3B (52 layers, pattern MEMEM*E..., 128 experts topk6, mamba 64 heads). Validated end-to-end with single-node 8-GPU GRPO on Nemotron-3 Nano-30B-A3B (SFT checkpoint, colocate mode, actor TP2/EP8, 2x TP4 SGLang engines, --megatron-to-hf-mode bridge for weight sync): 2 full iterations of rollout -> reward -> update -> weight sync; train-vs-rollout logprob abs diff ~0.017. Co-authored-by: Wang Yuchen <yw.yy953e@alibaba-inc.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YPhWWrF2GjHDDehtKaMoh7
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.
Motivation
slime currently always builds a
GPTModel(pure transformer). Hybrid Mamba-Attention-MoE models such as NVIDIA NemotronH (e.g. Nemotron Nano-30B-A3B: Mamba2 + attention + MoE, patternMEMEM*E...) therefore get param names that don't match a Megatron-core NemotronH checkpoint (input_layernorminstead ofmixer.*), and the training forward crashes because mcoreMambaModel.forward()does not accept theloss_maskkwarg thatGPTModeldoes.This PR adds NemotronH (hybrid mamba arch) training support.
Modifications
slime/backends/megatron_utils/model_provider.py: when--hybrid-override-patternis set, buildmegatron.core.models.mamba.MambaModelwithmamba_stack_specinstead ofGPTModel. Param names (decoder.layers.N.mixer.*, GroupedMLPexperts.experts,final_norm) then match a Megatron-core NemotronH checkpoint. The critic role still swaps inLinearForLastLayer.slime/backends/megatron_utils/model.py: drop theloss_maskkwarg via a signature check before calling the model. Loss masking already happens in slime's own loss function, so behavior is unchanged for GPT-family models.scripts/models/nemotron-nano-30B-A3B.sh: MegatronMODEL_ARGSfor Nemotron Nano-30B-A3B (52 layers, hybrid patternMEMEM*E..., 128 experts top-k 6, mamba 64 heads / state 128 / 8 groups, squared-ReLU).Usage notes
--megatron-to-hf-mode bridge(megatron-bridge ships a NemotronH bridge; the raw converters don't covernemotron_h). SGLang servesnemotron_hnatively.--finetune --no-load-optim --no-load-rngexplicitly (optimizer state saved under a different TP layout cannot be resharded).mamba-ssmandcausal-conv1d.Validation
Single-node 8-GPU GRPO on Nemotron-3 Nano-30B-A3B (from an SFT checkpoint; colocate mode, actor TP2/PP1/EP8 + sequence parallel, 2× TP4 SGLang engines, CPU-offloaded Adam, selective
moe moe_actrecompute): two full iterations of rollout → reward → GRPO update → weight sync completed cleanly.grad_norm0.34/0.14, train-vs-rollout logprob abs diff ≈ 0.017 (weight sync consistent with the training model).