Skip to content

feat: support opt-in multi-adapter MoE LoRA waves - #1139

Merged
bradhilton merged 15 commits into
mainfrom
stark/fused-moe-pr
Oct 22, 2026
Merged

bradhilton merged 15 commits into
mainfrom
stark/fused-moe-pr

Conversation

@bradhilton

@bradhilton bradhilton commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Agent: Shazeer

Problem. #1135 lets dense canonical adapters share one decoder forward and backward, but it rejects routed experts. MoE, where many small adapters gain the most from fusion, stayed on one pass per adapter. A naive fused MoE pass failed the same-state gradient gate. The combined batch changed:

  • router aux/z losses and capacity;
  • TE row geometry;
  • FLASH mask tile origins;
  • the reduction tree of FLA's batch-autotuned gate cumsum.

Behavior. New explicit installers and scopes let several adapters share one MoE decoder pass, while each adapter keeps its native per-adapter numerics:

  • The router runs once per adapter, preserving aux/z losses, capacity and padding.
  • Dispatched expert rows carry adapter IDs, so each adapter's own LoRA factors use the native grouped or shared-outer kernels.
  • TE norms and projections, and attention, run per root with native row geometry and tile origins.
  • FLA's scalar chunk-local cumsum runs per root while the recurrence stays batched. The scope survives activation recompute.
  • execution(None, numerical_policy="native", deterministic_native=True) scopes PyTorch determinism. FLASH forward is kept, and backward uses deterministic Triton. If execution falls out of compilation, it now raises rather than silently using the eager path.

Nothing changes unless a caller installs these and enters the scopes, with one exception: callers that already enable PyTorch determinism with FLASH now get the Triton backward. On main, strict mode raises NotImplementedError for masked FLASH, and warn-only runs the nondeterministic FLASH backward. Determinism-off behavior is unchanged. OpenPipe/caladan will enable MoE waves only behind STARK_FUSED_WAVES=1, under a versioned native-moe-wave-v1 policy (separate PR).

This PR carries the native-repeat lane's whole deterministic attention change: d17408e0, with 355fccef, 3b4517ec and e23d0482 cherry-picked. That lane doesn't need its own ART PR.

Validation.

  • Exact-head GPT-6.1 Sol reviews:
    • The first, at a0bd182a, was NOT CLEAR. Its one P2: deterministic FLASH could silently fall back to eager attention after Dynamo's recompile limit. It also raised a P3 on test portability.
    • The three cherry-picks fix both. The second review, at f47f793c, is CLEAR-WITH-NOTES.
    • CI then failed because three new unit-test files import Megatron, which the backend test step lacks. fab384ed runs them in the Megatron step instead. A third review, at this head fab384ed, is also CLEAR-WITH-NOTES.
  • 95 CPU unit tests pass, including the real-MCore router, the expert plan, the GDN scope and contexts, and the deterministic lowering and cache guard. Ruff and format pass.
  • The lanes passed these GPU tests on H200: 16 TE/attention/expert, 4 GDN and the deterministic attention suite.
  • Full-model Qwen3.6-35B-A3B qualification ran on one H200 (Torch 2.11, TE 2.11, FLA 0.5.0, MCore 0.17). All 24 cells pass: LoRA rank 1/8/32 × 2/4/8/16 adapters × 1K tokens each or 64K bulk. Each ran three continued AdamW steps, and every output, gradient and optimizer delta is bitwise equal across three serial controls and the fused run. At rank 1 with 1K tokens per adapter, a full step is 2.17× faster with 16 adapters and 2.09× with 64.

Limitations.

  • Single rank only (TP/CP/EP/PP 1), with no expert bias or global aux loss, qualified on H200.
  • The full-model matrix used uniform 1,024- and 2,048-token roots. Unequal roots are covered only by component tests: TE and attention at 257/129 tokens. The GDN tests use equal roots.
  • The policy matches its own serial execution, not default native gradients, which still differ.
  • The GPU matrix ran before the three cherry-picks and wasn't rerun. They add a guard and tests only.
  • Raising on compilation escape could stop a long-lived deterministic trainer with a very diverse compile history. The review found this plausible but not demonstrated. Recompile-limit tuning or monitoring is a follow-up.
  • The earlier 7–10× spike estimates used a coalesced proxy, and this PR doesn't reproduce them.

🤖 Generated with Claude Code

bradhilton and others added 15 commits October 21, 2026 18:47
Keep independent adapter ownership through canonical root slicing and
checkpoint recomputation. Reject segmented routed experts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Capture grouped-backward opt-in at forward, preserve main stride failures by default, and route empty segmented FC1 dependencies through the owning slots. Align expert rejection assertions with the production guard and cover gated/non-gated and conflicting-context boundaries on CPU.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Retain original slot ownership through native EP1 dispatch and recomputation. Keep TE row geometry and router aux/z/capacity computations per adapter; reuse compact expert kernels and leave ordinary forwards unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Run each independent root through the existing attention backend with cached root-local masks. The full-model trace localizes the remaining forward drift to layer 3 attention with exact Q/K/V inputs. Preserve native execution outside an explicit segmented scope.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	src/art/megatron/lora.py
Reuse native-repeat d17408e0 lowering and regression tests verbatim. Add an explicit native execution scope that enables the standard determinism opt-in without changing root geometry. Native controls and ART defaults retain their existing execution.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Capture independent-root reduction scope on FLA autograd contexts. Keep recurrent GEMMs batched while using batch-one scalar cumsum geometry in forward and backward.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Use the existing LoRA checkpoint context capture to carry the opt-in GDN reduction scope onto autograd worker threads. Add thread and real recurrence checkpoint regressions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contexts created before the explicit installer retain native reductions. Flagged MoE contexts follow the identical captured-scope path qualified in 8d8b173.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merge ART main 922cbf5 without rewriting the frozen qualification source.
Only inference hooks and their tests change; Megatron training math remains
byte-identical to the measured 4bba0bf source.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Include the dense fixture GQA geometry and 65-token tail, with and without LSE gradients. Scope the FLASH-specific regression to SM90 because Blackwell already selects Triton.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 355fccefcec8c5827a2a7be74a65df5724de4f79)
Reset Dynamo between independent model geometries and reject its unfused debug fallback. Shared test specialization history exhausted the compile cache, changed LSE conventions and violated the unchanged FP64 gate; do not widen that tolerance.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 3b4517eca0179058fac520ac19ee425c148a9142)
Keep the deterministic opt-in on its compiled backward lowering when Dynamo exhausts specialization capacity. Preserve default eager behavior and cover the cache transition with a failing-first CPU regression.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit e23d04821f29e4ac9f03f07d9e4bc4f1b709855d)
The router, expert-plan and GDN capture tests import Megatron, which the backend unit-test environment lacks. Run those three files with the other Megatron lightweight tests and exclude them from the backend run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bradhilton
bradhilton merged commit 5f0c1fb into main Oct 22, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant