[Feature] Integrate MoonEP dispatcher for FSDP expert-parallel training - #2056
Open
jayhenry wants to merge 3 commits into
Open
[Feature] Integrate MoonEP dispatcher for FSDP expert-parallel training#2056jayhenry wants to merge 3 commits into
jayhenry wants to merge 3 commits into
Conversation
jayhenry
force-pushed
the
moonep
branch
2 times, most recently
from
August 31, 2026 09:49
06d5929 to
84b40b4
Compare
Collaborator
Author
|
@claude review |
jayhenry
commented
Sep 2, 2026
jayhenry
commented
Sep 2, 2026
jayhenry
commented
Sep 2, 2026
jayhenry
commented
Sep 2, 2026
jayhenry
commented
Sep 2, 2026
jayhenry
commented
Sep 2, 2026
jayhenry
commented
Sep 2, 2026
jayhenry
commented
Sep 2, 2026
jayhenry
commented
Sep 2, 2026
jayhenry
commented
Sep 2, 2026
jayhenry
commented
Sep 2, 2026
jayhenry
commented
Sep 2, 2026
jayhenry
commented
Sep 2, 2026
jayhenry
force-pushed
the
moonep
branch
5 times, most recently
from
September 7, 2026 06:43
2f97f37 to
abce37c
Compare
…norm On PyTorch 2.12 the FSDP2 + EP nested-shard bookkeeping placement is _StridedShard, which is no longer a Shard subclass, so cal_total_norm rejected it and grad-norm computation raised on FSDP2 + EP4. Route the placement check through RuntimeLayout.is_sharded_placement so both Shard and _StridedShard contribute their all-reduce.
Add an optional dispatcher="moonep" path for node-local BF16 MoE training. Native FSDP2 stays the sole owner of expert parameters, optimizer state, and checkpoint identity; MoonEP owns only the communication/VMM execution workspace. - Model-scoped MoonEP runtime adapted to the six-stage dispatcher API, with a versioned backend capability check and lazy import. - FSDP all-gathered BF16 expert weights land directly into MoonEP VMM aliases; the private VMM workspace owns the physical expert layout. - Dispatch activations and weights, reuse the existing grouped GEMM path (extended for dynamic expert gradients), and return duplicated expert gradients in BF16 before FSDP reduce-scatter, joined once per layer. - Support MTP (shared/unshared), Domino intra-layer micro-batching, sequence parallelism, activation recompute, and torch.compile. - Unify the EP dispatcher weight/routing contracts; keep routing counts on device via torch.histc. - Integrate DCP/HF persistence, activation/router offload, optimizer swap, Muon, and explicit runtime teardown.
Reproducible 20-step DeepEP/MoonEP comparison for the formal Qwen3.5-35B-A3B FSDP2 + EP4 workload, with a config-lock test and a throughput/curve comparator. XTUNER_USE_FA3 and XTUNER_DETERMINISTIC are overridable.
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.
Summary
This PR adds an optional
dispatcher="moonep"path for node-local BF16 MoE training. Native FSDP2 remains the sole owner of expert parameters, optimizer state, and checkpoint identity; MoonEP owns only the communication/VMM execution workspace.torch.compile.torch.histc.tests/acceptance/)._StridedShardrecognition in distributed grad-norm calculation.flowchart LR A["FSDP all-gather: complete BF16 experts"] --> B["MoonEP VMM direct landing"] B --> C["Dispatch + grouped GEMM + combine"] C --> D["BF16 duplicated-gradient return"] D --> E["FSDP reduce-scatter"] E --> F["FP32 shard gradient + optimizer state"]Branch status
Rebased onto
mainand organized as three commits:[Fix]route the grad-norm placement check throughRuntimeLayout.is_sharded_placementso FSDP2 + EP_StridedShardbookkeeping placements (no longer aShardsubclass on PyTorch 2.12) contribute their all-reduce.[Feature]the MoonEP integration.[Test]the acceptance gate.Design notes and the full per-run validation report are kept out of the PR and maintained separately.
Design
MoonEP is imported lazily only when selected. The integration validates a versioned backend capability before allocating resources, so DeepEP, All2All, AGRS, and non-EP configurations do not acquire a MoonEP dependency.
The hot path is ordered with CUDA events and GPU-side EP barriers. The profiler regression gate verifies:
FSDP post-all-gather hooks install the VMM landing tensors while preserving the original DTensor parameters. The backward path returns BF16 home gradients to those parameter edges; existing FSDP communication then reduce-scatters them and produces FP32 sharded gradients for the FP32 optimizer update.
Supported scope
2.12.1+cu132.Not claimed in this first version: Expert TP, FP8 experts, cross-node MoonEP, FSDP
no_sync, pipeline parallelism, or decoding.External MoonEP dependency
This XTuner branch expects MoonEP XTuner integration API v3. The validated companion implementation is commit
d4494473fb0932dcc35f3a44a0e3b31827f5e282on the MoonEPxtuner-integrationbranch.The companion MoonEP patch still needs to be published separately before this PR can be merged or reproduced outside the development environment. The XTuner package does not add MoonEP as a mandatory dependency.
Validation
Acceptance harness
tests/acceptance/(config-locked bytests/engine/test_moonep_acceptance.py, compared byxtuner/_testing/moonep_acceptance.py) runs Qwen3.5-35B-A3B on one node with 8 H200 GPUs, FSDP2 + EP4, BF16 parameters/reduction, Direct VMM landing, Triton grouped GEMM, and 20 training steps, changing only the dispatcher between the DeepEP and MoonEP legs. Default attention is FlexAttention + deterministic mode;XTUNER_USE_FA3andXTUNER_DETERMINISTICare overridable.Validated behaviour (calibrated FlexAttention + deterministic gate)
On the functionally-equivalent pre-rebase implementation, MoonEP matches DeepEP on every loss and grad-norm curve (cosine similarity >= 0.99, mean relative difference < 1%) and reaches 100-112% of DeepEP steady-state throughput at MTP disabled and MTP1. GPU regression suites (MoonEP forward / MTP / Domino / SP / compile; DCP / HF / offload / optimizer / lifecycle; dispatcher and grouped-GEMM; FSDP2 + EP4 nested-shard grad norm on PyTorch 2.12 and 2.9) passed.
Post-rebase verification on this branch
The formal FlexAttention + deterministic GPU gate has not yet been re-executed on the rebased branch; the acceptance harness is unchanged and runs it directly.
Result
The first-version objective is met for single-node BF16 FSDP2 + EP training: MoonEP matches DeepEP numerically, preserves FSDP parameter/checkpoint ownership and a host-sync-free communication hot path, and is throughput-neutral in the calibrated acceptance configuration.