feat(moe+ssm): expert-LoRA GEMM stack and hybrid-recompute guard on the d12f6c8c base - #1
Closed
taufeeque9 wants to merge 9 commits into
Closed
feat(moe+ssm): expert-LoRA GEMM stack and hybrid-recompute guard on the d12f6c8c base#1taufeeque9 wants to merge 9 commits into
taufeeque9 wants to merge 9 commits into
Conversation
Signed-off-by: Taufeeque <taufeeque@far.ai> (cherry picked from commit 193d5fe)
Signed-off-by: Taufeeque <taufeeque@far.ai> (cherry picked from commit ecd9ca9)
Signed-off-by: Taufeeque <taufeeque@far.ai> (cherry picked from commit f2a9b74)
Signed-off-by: Taufeeque <taufeeque@far.ai> (cherry picked from commit 9316580)
Signed-off-by: Taufeeque <taufeeque@far.ai> (cherry picked from commit 2a529bc)
Signed-off-by: Taufeeque <taufeeque@far.ai> (cherry picked from commit a9c866b)
Signed-off-by: Taufeeque <taufeeque@far.ai> (cherry picked from commit b64bdd8)
…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)
… stack The fork commits were written against an older checkout and predate this repo's black profile (line length 100, --skip-magic-trailing-comma) and its pylint docstring gate on megatron/core. Signed-off-by: Taufeeque <taufeeque@far.ai>
Collaborator
Author
The fork-base scaffolding (manifest, tooling, CI prune) is in #2, which should merge first. Once it's in, this PR's merge ref will carry the manifest and the |
Collaborator
Author
|
Written by Codex. Superseded by #3, which keeps only the validated frozen grouped-GEMM backend and the full-recompute frozen-input correctness guard. The fused expert-LoRA and expert_fc1_act selective-recompute patches were intentionally pruned. |
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.
Why this PR exists
NeMo-RL's
farai/mainno longer carries a standalone Megatron-LM submodule: after the upstream sync, megatron-core flows in through the Megatron-Bridge fork's nested submodule pin, currently upstreamd12f6c8c(Aug 2026). Our fork's features — which every Nemotron-3-Super hackable-env RL run depends on — lived only as feature branches on top of a February 2026 upstream base, so they silently fell out of the stack that main consumes. Concretely, on main today:moe_expert_gemm_backend: torch) doesn't exist — the run configs are refused by a guard in nemo-rl (AlignmentResearch/nemo-rl#60);expert_fc1_actselective recompute doesn't exist — mcore rejects it at config validation;requires_gradguard, so adapter-only (LoRA) training would silently receive zero gradients: re-entrant checkpointing only attaches agrad_fnwhen a tensor input requires grad, and a frozen embedding provides none.This PR ports the full stack onto exactly the base the Bridge pins, so the features re-enter main's supply chain with a minimal delta.
What's in it
Nine commits, each carrying
(cherry picked from ...)provenance to the original fork commits:perf(moe): add frozen torch grouped GEMM backend— runs frozen expert base weights throughtorch._grouped_mmoutside TE autograd (memory/perf for frozen-base + expert-LoRA).2–3. weight-view validation + zero-token grouped-split test contracts.
perf(moe): checkpoint expert FC1 activation(expert_fc1_act) — restructured around upstream's new offload managers; the non-recompute branch is upstream's code verbatim.perf(moe): fuse shared expert LoRA projection.6–7. grouped-offsets dtype + BF16 fused-input-rounding test fixups.
fix(recompute): keep chunk outputs differentiable with a frozen embedding— the two original SSM commits collapsed to just this guard; upstream had absorbed the rest (hybrid full recompute now lives inmodels/hybrid/hybrid_block.py→core/recompute.py).Two guards added beyond the originals, both preventing silent no-ops on paths that didn't exist at the old base:
expert_fc1_actis rejected underuse_transformer_engine_op_fuser, andmoe_expert_gemm_backend='torch'is rejected withmoe_single_grouped_weight=True(explicit error instead of anAttributeError; supporting that combination needs TE ≥ 2.14 work).Gating
Do not merge before GPU validation (the port is statically verified only). Named items: the FC1-recompute parity/call-count test, the torch grouped-GEMM path end-to-end (SM100+), the deeper-nested activation-offload branch, FP8 + frozen-embedding interaction with the guard. Plan: nemo-rl topology benchmark (selective + full arms, 16k/32k) on the B200 reservation.
Chain
This PR → AlignmentResearch/megatron-bridge-contrib#4 (bumps the nested pin to this branch) → one-line Bridge-pin bump in nemo-rl, after which the guards in nemo-rl#60 pass instead of refusing.
Note:
farai/mainwas created for this PR atd12f6c8c— the exact upstream commit the Bridge pin consumes — establishing the fork's internal integration branch per our convention (the fork'smainstays a pure upstream mirror).🤖 Generated with Claude Code