Repository navigation
[ROCm][Perf][DSv4.1] Run aiter_mega_moe layers on AITER FusedEPMoE for small batches - #68998
Draft
Fangzhou-Ai wants to merge 2 commits into
Draft
Fangzhou-Ai wants to merge 2 commits into
Fangzhou-Ai wants to merge 2 commits into
Conversation
…r small batches With --moe-backend aiter_mega_moe and VLLM_ROCM_USE_AITER_FUSED_EP_MOE=1, DeepseekV4AiterMegaMoEExperts runs a layer that AITER's FusedEPMoE supports (DeepSeek-V4.1-Flash: hidden 5120, intermediate 2304, top 6, 2/4/8 EP ranks, no fused shared expert, gfx950 with 256 CUs) as one persistent launch per rank when the DP-group max tokens per rank is at most 768 (512 when MegaMoEV2 has its large-input route), and on MegaMoEV2 otherwise. The decision comes from the DP-group max, so every EP rank takes the same collective path, also under CUDA graph capture. FusedEPMoE reads the shuffled MXFP4 tensors MegaMoEV2 is built with (no copy). One instance serves every layer; it is created and prepared (compiles all tile tiers) once in finalize_weights, before graph capture. The unfused shared expert runs serially while FusedEPMoE is selected, since the kernel must not share the GPU. The op comes from ROCm/aiter#8368 and is imported lazily; without it (or for other shapes) every layer keeps MegaMoEV2. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Fangzhou Ai <fangzhou.ai@amd.com>
- V4.1 decoder: keep the FFN seam's mHC gates off the aux stream when the MoE runs FusedEPMoE, so nothing runs beside its persistent workgroups (FULL graphs, <= 128 tokens). The attention seam still overlaps. - Decide the DP-group max once per layer in DeepseekV4MoE and pass it to the experts; pass it to FusedEPMoE as rows_hint, so eager steps with uneven DP batches size the tiles as a padded graph would. - Drop the 512-token cutoff tied to MegaMoEV2's unmerged large-input route; catch any import failure of the AITER op and fall back. - Tests: drop the CPU tests built on a fake AITER module; the 2-GPU test now runs under real DP/EP parallel state and forward contexts with uneven per-rank counts (one rank with no tokens) and the 768 / 769 cutoff; the ROCm decoder overlap test covers the FusedEPMoE case. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Fangzhou Ai <fangzhou.ai@amd.com>
This branch has not been deployed
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.
Overview
Adds an opt-in call site for AITER's
FusedEPMoE(ROCm/aiter#8368, dependency, not merged yet) toDeepseekV4AiterMegaMoEExperts(--moe-backend aiter_mega_moe). For DeepSeek-V4.1-Flash, a whole routed-expert layer (MXFP8 quant, dispatch, GEMM1 + clamp-SwiGLU + requant, GEMM2, combine) then runs as one persistent launch per rank for decode-sized batches; everything else stays on MegaMoEV2.Claims
VLLM_ROCM_USE_AITER_FUSED_EP_MOE=1(default off) runs a layer onFusedEPMoEwhen the DP-group max tokens per rank is at most 768, and on MegaMoEV2 otherwise. Every EP rank decides from the same DP max, also under CUDA graph capture.FusedEPMoEruns, nothing else is scheduled beside it by this model: the unfused shared expert runs after it, and in FULL CUDA graphs the V4.1 decoder keeps the FFN seam's mHC gate projection on the main stream (the attention seam still overlaps).Validation
All runs on 8x MI355X (gfx950, 256 CUs), FlyDSL 0.5.0, AITER = ROCm/aiter main 9569fb31a + ROCm/aiter#8368 @ 54a95a7d2, MoRI from the ROCm vLLM image. The vLLM tree is this branch at 6748ef8; its Python sources were run on top of the compiled extensions of an installed ROCm vLLM build (0.34.0rc1.dev897), since only Python files change here. vLLM upstream main has not touched these files since the branch point, and ROCm/aiter main has no MegaMoEV2 change since 9569fb31a, so the baseline is current.
Tests
tests/models/test_deepseek_v4_aiter_mega_moe.py(existing file,(MI355) DeepSeek V4 MoE Integrationstep):multi_gpu_test(num_gpus=2), skipped when the op is missing): real vLLM DP=2 / EP parallel state with the MoRI all2all (parallel_launch_with_config), two realDeepseekV4AiterMegaMoEExpertslayers on the same checkpoint-layout weights, one with the flag. Each step runs insideset_forward_contextwith the per-rank token counts[1, 1],[37, 300],[0, 37](a rank with no tokens),[768, 1]and[769, 1]: up to 768 the flag layer matches the MegaMoEV2 layer (cosine > 0.999), at 769 both take the same MegaMoEV2 runtime and match bitwise. CUDA-graph replay with new inputs is bitwise equal to eager at 1 / 37 / 300 tokens.FusedEPMoEis selected.tests/kernels/mhc/test_mhc_kernels.py::test_deepseek_v41_rocm_decoder_overlap_matches_serial((MI355) mHC Kernelsstep): newfused_ep_moecase, where the FFN seam must not split onto the aux stream inside a FULL graph capture and the replayed layer still matches the serial one. It fails without the model change (assert [True] == [], 8 failed) and passes with it.Why the 0.999 bound: both paths quantize the input and the activation to MXFP8, but they do not round identically. Against the fp32 dequant reference of ROCm/aiter#8368's test (2 ranks, random inputs of the test's shapes),
FusedEPMoEreached cosine 0.999996-0.9999995 and MegaMoEV2 0.99963-0.99965 at 1 / 37 / 300 tokens per rank, so the two paths agree to ~0.99964 with each other. A wrong weight layout or expert numbering gives a cosine near 0.Call-site timing (
DeepseekV4AiterMegaMoEExperts.forwardwith the flag off / on; real vLLM DP + EP parallel state, one process per GPU; MegaMoEV2 built as vLLM builds it withmax_num_batched_tokens=8192: a 128-token fixed-slot runtime plus an 8192 compact one, i.e. the staged route; uniform routing, top 6, 48 experts per rank, bf16 tokens; 20 distinct calls captured in one CUDA graph inside a forward context carrying the per-rank counts; us per call = max over ranks, best of 5 replays x 2 in A B B A order. Script and commands below.)EP8 (384 experts, DeepSeek-V4.1-Flash):
EP8 with uneven per-rank counts (the eager DP case; each rank captures its own size).
FusedEPMoEgetsrows_hint= DP max, so its tiles are sized as in a graph padded to the busiest rank; the last column calls the op without it (tiles sized from the local count):The hint is a wash (+7 % / -5 % / +2 %); it is kept because it makes eager and graph steps of the same DP max pick the same tiles. Outputs are correct either way (covered by the
[37, 300]/[0, 37]/[768, 1]test cases).EP2 / EP4 (48 experts per rank;
FusedEPMoEaccepts 2/4/8 ranks with at most 63 experts per rank, so DeepSeek-V4.1-Flash's 384 experts only qualify on EP8; uniform routing only):Call-site benchmark script and commands
Run from the vLLM source root with ROCm/aiter#8368 and FlyDSL 0.5.0 importable:
Raw output (EP8 run):
These match the kernel-level numbers in ROCm/aiter#8368 (same machine,
op_tests/multigpu_tests/bench_fused_ep_moe.py, us per call, max over ranks; "main" = MegaMoEV2 staged route as built above):(zipf: Zipf 1.2 expert popularity; hot: every route to rank 0's experts.) At 1024 the kernel is 5 % slower than main under Zipf routing, hence the 768 cutoff. Per ROCm/aiter#8368's roofline analysis, up to ~192 tokens per rank the kernel streams the expert weights at 87-97 % of the measured HBM ceiling in its GEMM loops, and from ~384 it is bound by the GEMM2 return stores over xGMI.
End-to-end: DeepSeek-V4.1-Flash DEP8 AgentX results are pending.
Details
vllm/models/deepseek_v4/amd/mega_moe.py,DeepseekV4MoE._forward_mega_moe(stream decision), the V4.1 ROCm decoder layer (FFN-seam overlap), and the env var.prepare()ofFusedEPMoEare collectives over the EP CPU (gloo) group, done once infinalize_weights(all ranks finalize the same layers in the same order, like the MegaMoEV2 runtimes). Every input to "use it at all" (flag, op import, shape, arch/CU count) is identical on all ranks. Per call, the choice uses the same DP-group max (num_tokens_across_dp_cpu) thatselect_runtimealready uses;DeepseekV4MoEcomputes it once per layer and passes it to the experts, so there is one forward-context lookup per layer as on main. Under CUDA-graph capture this is the padded captured size, so the branch is baked into each graph consistently. No new host-device sync.FusedEPMoEWeightswraps the shuffledw13/w2tensors MegaMoEV2 is built with (shuffle_weight_a16w4/shuffle_scale_a16w4); no copy, no extra weight memory. OneFusedEPMoEinstance serves every layer (weights are a forward argument), keyed like the MegaMoEV2 runtime cache. Extra memory: ~230 MiB per rank (IPC pool + scratch).FusedEPMoEis persistent, occupies every CU and spins on its peers. Work that waits on it must never share the GPU (it would not get a CU); any other work beside it only slows it down. So while it is selected, the unfused shared expert runs after it on the main stream, and in FULL graphs (<= 128 tokens, where the V4.1 decoder forks the mHC gate projection onto the aux stream) the FFN seam's gates run on the main stream before it; the attention seam keeps its overlap, which is joined before the FFN starts.aiter.ops.flydsl.fused_ep_moe(not onlyImportError, e.g. a mismatched AITER / FlyDSL) is logged once and falls back to MegaMoEV2; all ranks share the environment, so they agree.fused_ep_moe_supported).attach_mxfp8_input) is not fed to the kernel yet (the op accepts MXFP8 + E8M0 input; not wired or measured here).FusedEPMoEruns; its cost in a full decode step is part of the pending end-to-end measurement.FusedEPMoEpath has no CI coverage yet. Once the op ships in the ROCm image, the plan is to move this test to a 2-GPU MI355 step. Validation outside CI is above.FusedEPMoE,fused_ep_moe,aiter_mega_moe,MegaMoE DeepSeek-V4.1-Flash. Related but different: [ROCm][DSv4] MegaMoE: pick small/large/staged route from the DP-group max rows #67584 (MegaMoEV2 small/large/staged route hint, needs [FlyDSL] [CI] MegaMoEV2: one route plan for every path, shared arenas, and the DeepSeek-V4.1-Flash EP2 / EP4 / EP8 fused routes ROCm/aiter#7788), [ROCm][DSv41] MegaMoE improvements for DEP8 #68385 (MegaMoEV2 A4W4 / P2P quant knobs), [ROCm][MoE] Move AITER MegaMoEV2 To Oracle #63229 (moves MegaMoEV2 to the MoE oracle), Rocm dsv41f single kernel megamoe #68131 (closed; MegaMoEV2 small-M single kernel via a patched AITER 0.1.29). None callsFusedEPMoE. On the AITER side, [FlyDSL] MegaMoE small-M: DeepSeek-V4.1-Flash, any experts per rank / top-k, fused shared-expert slots ROCm/aiter#8358 opens MegaMoEV2's small-M kernel to V4.1-Flash; per [FlyDSL] Fused expert-parallel MoE in one launch per rank for DeepSeek-V4.1-Flash EP8 a8w4 (gfx950) ROCm/aiter#8368 the fused kernel is 1.07-1.58x faster than it at 1-512 tokens per rank.AI assistance (Claude Code) was used to write this change; Fangzhou Ai is the human owner and will review/defend it end-to-end.
Pull Request Checklist
I used vLLM's
/pr-checklistskill. (Mandatory for agents, optional for humans).AI assistance was used during the creation of this PR.
Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.
Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.
Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.
Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide. (End-to-end serving results pending.)
🤖 Generated with Claude Code