perf(moe): add frozen grouped GEMM for adapter training - #3
Open
taufeeque9 wants to merge 9 commits into
Open
Conversation
…ding Re-entrant activation checkpointing only attaches a grad_fn when some tensor input requires grad. Under adapter-only training the embedding is frozen, so every checkpointed chunk output carried no grad_fn and the adapters inside the chunks received no gradient. Detach and re-enable grad on the block input before the chunk loop. The rest of the source commits added a MambaStack checkpointed forward, which upstream has since absorbed: MambaStack moved to megatron/core/models/hybrid/hybrid_block.py and routes full-granularity recompute through megatron/core/recompute.py::checkpointed_forward. Signed-off-by: Taufeeque <taufeeque@far.ai> (cherry picked from commit 91c8b41) (cherry picked from commit abd235c) (cherry picked from commit 8d9ad06) Signed-off-by: Taufeeque <taufeeque@far.ai>
Signed-off-by: Taufeeque <taufeeque@far.ai>
Signed-off-by: Taufeeque <taufeeque@far.ai>
Signed-off-by: Taufeeque <taufeeque@far.ai>
Signed-off-by: Taufeeque <taufeeque@far.ai>
Signed-off-by: Taufeeque <taufeeque@far.ai>
taufeeque9
marked this pull request as ready for review
August 26, 2026 03:49
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.
Written by Codex.
Why this change
Nemotron-3 Super LoRA freezes the 128 local expert base weights. On B200, the pinned Transformer Engine grouped path launched roughly one small GEMM per expert, leaving substantial launch overhead.
torch._grouped_mmexecutes the frozen base branch as one SM100 grouped CUTLASS kernel while the ordinary Bridge LoRA branch remains unchanged.This path reduced the measured logprob-plus-update cycle from 21.640 s to 14.684 s on the production-shaped benchmark: 32.1% less time and 47.4% more throughput, with the same peak allocated memory.
B200 throughput evidence
The comparison used the same
gb215node, step-75 checkpoint, fixed production-mixed token batch, and TP4/PP1/EP4/ETP1 topology. Both arms used BF16 LoRA, ordinary all-to-all dispatch, a 32k dynamic token cap, and 121,088 input tokens per iteration.torch._grouped_mmArtifacts:
102251,tf-super-deepep-ab-v1-a4e9b214c0/super-topology-benchmark.json,tp4-alltoallarm.102265,tf-super-torch-gmm-v1-a518a324d7/super-topology-benchmark.json.102277,tf-super-torch-gmm-profile-v1-a518a324d7.The parity gate reported zero relative-L2 and max-absolute error for both forward output and input gradient, including experts with zero assigned tokens. The runtime packed 80 grouped FC1/FC2 modules and relocated 52.5 GiB of frozen weights without adding checkpoint entries.
Why existing behavior remains safe
transformer_engineremains the default. No model uses the new path unless its config explicitly selectsmoe_expert_gemm_backend="torch".Parameterobjects and state-dict keys are preserved. Each expert parameter becomes a view into one non-persistent contiguous buffer.Full-recompute correctness
The PR also carries the small frozen-input guard needed by PP1 adapter-only full recompute. Re-entrant checkpointing otherwise sees a frozen embedding output with
requires_grad=Falseand can detach every checkpointed chunk from the adapters inside it.A direct regression now freezes the block and input, installs a trainable low-rank adapter inside a fully checkpointed hybrid layer, runs backward, and requires nonzero gradients on every adapter parameter. The production 32k and 48k NeMo-RL runs use this full-recompute path; their recorded gradients are nonzero and their losses move.
Scope deliberately omitted
expert_fc1_actrecompute was faster than whole-MoE recompute at short context, but the 32k selective arm OOMed because it did not cover the 40 Mamba mixers. The tested 32k and 48k recipes use full recompute instead.Validation status
git diff --checkpass.113785, which uses this exact Core head withmoe_expert_gemm_backend: torch, PP1 full recompute, and ordinary LoRA. It migrated the step-75 adapter checkpoint and completed optimizer steps through at least step 31; W&B run as6tqeze records nonzero gradient norms and changing rewards. The isolated pytest job113381timed out while building its SIF and produced no test result, so it is not counted as evidence.Commit signing
All commits carry DCO sign-off. Cryptographic signing was unavailable because this machine has no configured GPG or SSH signing identity.