Repository navigation
Conversation
…kwise_1x32")
Stage2's epilogue writes each weighted partial row to its peer as packed E2M1
(two values a byte) plus one E8M0 scale per 32 values (ceil_pow2(amax / 6), the
rounding AITER's MXFP4 quant uses), and the intranode combine's Stage 3
dequantizes, sums the top-k partials in f32 and writes BF16. A row is
hidden/2 + hidden/32 bytes, against 2 * hidden for BF16 and hidden + hidden/32
for "fp8_blockwise_1x32". "auto" never selects it. An FP4 request turns off the
aligned-pair Stage2, whose kernel writes FP8 rows only.
DeepSeek-V4.1-Flash target MoE (hidden 5120, inter 2304, 48 experts per rank,
top-6), A4W4, 8x MI355X, whole call (test_mega_moe_v2.py, 30 graph replays), ms:
fixed-slot, max_tok_per_rank 512 BF16 FP4
48 tokens per rank 0.221 0.227
224 0.288 0.293
336 0.384 0.394
512 0.440 0.435
compact, max_tok_per_rank 4096 BF16 FP8 FP4
196 0.405 0.413 0.406
1024 0.653 0.617 0.595
4096 1.691 1.432 1.325
relL2 against the BF16 reference: 0.210 with a BF16 combine, 0.211 with FP8 and
0.239 with FP4 (0.21 is A4W4's own rounding).
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Hemanth Acharya <[email protected]>
… and draft configs
v41_flash_ep8 tuned only A8W4, so A4W4 ran the base rules. These are the best of
two rounds of coordinate search (plus a joint grid) over the Stage1 and Stage2
launch knobs that leave the dispatch wire protocol alone, timed as CUDA-graph
replays of the whole call (quant, Stage1, Stage2, combine) on 8x MI355X with the
MXFP4 combine; slowest rank's median per call. Every tuned candidate's output
matched its base config's bitwise on the same inputs.
Target MoE decode, fixed-slot at MTPR 512 (AITER_MEGA_FIXED_SLOT_MAX_MTPR=1023), us:
tokens per rank base tuned
128 241.2 205.2 bucket 128
160 248.6 211.6
192 255.6 236.0 bucket 256
224 291.6 236.9
Target MoE on steps that carry a prefill chunk (compact runtime at MTPR 4096), us.
From 40 dispatch CUs up the compact dispatch deadlocked at 3072 and 4096 tokens,
so bucket 4096 keeps 32:
tokens per rank base tuned
768 528.9 513.4 bucket 1024
1024 602.9 580.7
1536 789.1 708.1 bucket 2048
2048 930.9 876.8
3072 1136.0 1108.1 bucket 4096
4096 1331.0 1310.4
DSpark draft MoE (128 experts, 16 per rank). Fixed-slot dispatch was limited to
48 experts per rank, so the drafter's decode ran the compact runtime. The
fixed-slot kernels take the expert count as a parameter (the finalize handles
1..64 per rank), so FIXED_SLOT_EXPERTS_PER_RANK now admits 16 too (other widths
stay compact); its output equals the compact runtime's bitwise. Tuned as
v41_flash_draft_ep8, us:
tokens per rank compact fixed-slot base fixed-slot tuned
128 243.2 178.6 133.2 bucket 128
160 264.5 203.9 154.2
192 267.5 227.3 181.0 bucket 256
224 278.2 238.1 195.0
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Hemanth Acharya <[email protected]>
…lot Stage1 (V4.1-Flash EP8 A4W4 decode)
For the DeepSeek-V4.1-Flash EP8 target MoE (48 experts per rank) on the
fixed-slot A4W4 runtime with the MXFP4 combine, Stage1 also runs GEMM2 and the
combine scatter, GEMM1 starts on rows as they land, and both GEMMs take the
fused-MoE recipe's tuned tiles. Every option is off by default and limited to
that 48-expert layout, so the DSpark draft MoE (16 experts per rank) and every
other model keep their kernels. Options (envs.py):
AITER_MEGA_S1_FIXED_FUSED_STAGE2 once a consumer CTA finds no GEMM1 work it
takes GEMM2 output tiles, each as soon as its M tile's GEMM1 items are
done, and scatters them to the peers; the Stage2 launch is skipped.
AITER_MEGA_S1_FIXED_EARLY_TILES sources send per-expert route counts ahead
of the payload, so the plan is built early and a GEMM1 tile starts once
its expert's rows have landed rather than after the whole dispatch.
AITER_MEGA_S1_FIXED_LIGHT_RELEASE on mori's uncached heap, producers publish
their counts and done flags after their stores drain instead of a system
release (an L2 writeback under the running GEMM).
AITER_MEGA_S1_FIXED_RESIDENT_GRID num_cu * grid_mult CTAs, the owner and
producers being the first resident ones, which run GEMM work after their
role.
AITER_MEGA_S1_FIXED_TUNED_GEMM1 (_WIDE, _V2) GEMM1 on the fused-MoE kernel's
64 x 256 workgroup tile, two consumer CTAs per CU, K loop unrolled; with
_V2 the partial last round of items is split into 64 x 128 halves.
AITER_MEGA_S2_FIXED_TUNED_GEMM2 (_V2) GEMM2 on 64-row blocks (one W2 read per
expert); with _V2 the MXFP4 scatter keeps every lane busy.
With AITER_MEGA_FIXED_SLOT_MAX_MTPR=1023 the MTPR 512 buckets 128 and 256 take
256-thread Stage1 configs these options need; without them the existing
v41_flash_ep8 configs apply.
8x MI355X, MegaMoEV2 at MTPR 512, A4W4, MXFP4 combine, random routing,
CUDA-graph replay, every option above on: outputs bitwise equal to the options
off at 1/16/64/128/160/192/224/300/400/512 tokens per rank (384 experts, top-6),
and for the draft shape (128 experts, top-3) at 160/192/224. Whole call,
slowest rank, us:
tokens per rank 1 16 64 128 160 192 224 300 400 512
options off 77.2 210.0 222.6 204.6 208.9 239.6 241.1 253.2 386.3 436.1
options on 68.3 177.1 192.3 204.2 208.7 212.3 213.9 224.1 363.1 419.9
Co-authored-by: Cursor <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
WAITING ON AUTHORPR Self-ReviewRevision Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision. Questions to answer in the PR description
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
…et 8192 The aligned-pair Stage2 writes FP8 combine rows only. An explicit stage2_p2p_quant="none" on a runtime whose plan holds the 8192 bucket (MTPR >= 8192) raised "p2p_quant='none' conflicts with aligned-pair Stage2" whenever the network's tuner left aligned-pair on: V4.1-Flash A4W4, V4.1-Flash with the fused shared expert (49 experts per rank), V4-Pro A8W4 and Kimi-K3. BF16 now takes the plain Stage2 there, as the FP4 combine already did. Configs that loaded before are unchanged. Co-authored-by: Cursor <[email protected]>
coderfeli
left a comment
There was a problem hiding this comment.
- Could you please align with the unified MegaMoE interface on main: aiter main has landed and unified MegaMoE onto the fully-fused interface (one route plan per call: staged / small / large). This PR is still based on the old two-stage path and no longer merges cleanly. Could you rebase onto main and adapt it to the fused interface (routed=True + forward(max_tokens=...))?
- Env vars and raw MLIR: Please consolidate the ~10 new AITER_MEGA_* switches into per-layout config in mega_moe_config. Please also replace the raw MLIR / inline asm (e.g. llvm.InlineAsmOp in dispatch.py) with high-level FlyDSL APIs, per the kernel-code-cleanup skill.
…face Adapts the V4.1-Flash EP8 A4W4 decode work to the routed MegaMoEV2 interface (routed=True + forward(max_tokens=...)); A4W4 always takes the staged route. - The AITER_MEGA_S1/S2_* switches (envs.py) become Stage1Config/Stage2Config fields (early_tiles, light_release, resident_grid, unroll_k, g1_split_tail, fused_g2, wide_scatter), set by the V4.1-Flash EP8 A4W4 MTPR-512 config with the MXFP4 combine; select_mega_moe_config clears fused_g2 elsewhere and MegaMoEConfig rejects it without the fp4_blockwise_1x32 combine. - The FP4 combine epilogue and the fused GEMM2 are rebuilt on main's Stage2 helpers (Stage2Unit, shared by Stage2 and the fused Stage1); dispatch uses comm_ops.invalidate_l1 instead of inline asm. - MegaMoEV2 sizes the fused Stage1 from the bundle plan, puts the GEMM1 output on the symmetric heap and skips the Stage2 launch when fused_g2 is set. - Tests: CPU route-plan tests for routed A4W4, --suite routes --quant a4w4, and test_mega_moe_v41_flash_a4w4_timing.py for the PR timing table. Timing matches the pre-merge branch within 1.5% at 160/192/224 and 1024/2048/4096 tokens per rank, with bitwise-equal outputs. Co-authored-by: Cursor <[email protected]>
|
Closing the PR, overlaps with : #8623 |

Motivation
MegaMoE's fixed-slot path for DeepSeek-V4.1-Flash EP8 A4W4 leaves time on the table:
This is work done in collaboration with @maslan-coop26
Summary of changes
The PR fits the routed MegaMoE interface from #7788: A4W4 is served through
MegaMoEV2(routed=True)andforward(max_tokens=...). The fused small-input and large-input routes are A8W4 only, so every A4W4 call takes the staged route, and this PR's work is that route's V4.1-Flash EP8 A4W4 recipe. There are no new environment switches: the Stage1/Stage2 options are fields ofStage1Config/Stage2Config, set by the tuned config, so they are part of the bundle and AOT kernel identity.stage2_p2p_quant="fp4_blockwise_1x32"): Stage2 sends each partial row as packed E2M1 plus one E8M0 scale per 32 values, and the combine dequantizes and sums in f32. That is about a quarter of the BF16 bytes.autonever selects it.AITER_MEGA_FIXED_SLOT_MAX_MTPR=1023) with the MXFP4 combine. Every bucket of that instance takes the options below; nothing else does (other networks, A8W4, the BF16/FP8 combines, other MTPRs and the 16-experts-per-rank draft keep their kernels):Stage1Config.early_tiles): ranks first do a handshake in which every source sends each destination its per-expert token counts. Each destination then knows how many rows each expert will receive from every rank and builds the plan before the payload arrives. Producers count published rows per (expert, source), and a GEMM1 tile starts as soon as its expert's rows have landed, so compute begins before dispatch completes.light_release): on mori's uncached heap (MORI_SHMEM_HEAP_TYPE, read once at import), producers publish their counts and done flags once their stores drain. This replaces a system release, whose L2 writeback stalls the GEMM running alongside.fused_g2): Stage1 also runs GEMM2 and the combine scatter. A consumer CTA with no GEMM1 work left takes GEMM2 tiles, each as soon as its M tile's GEMM1 items are done, and the separate Stage2 launch is skipped.select_mega_moe_configkeeps it only for fixed-slot A4W4 at 48 experts per rank with the MXFP4 combine and 4-wave Stage1 CTAs, andMegaMoEConfigrejects it without the MXFP4 combine.resident_grid): Stage1 launchesnum_cu * grid_multCTAs. The owner and producers are the first resident CTAs and switch to GEMM work after their role, so no consumer waits for a producer to exit before it becomes resident.unroll_k,g1_split_tail): the fused-MoE kernel's 64 x 256 tile, two CTAs per CU, with the K loop unrolled; the partial last round of tiles is split in half so it spreads over every CTA.Stage2Config.wide_scatter): 64-row GEMM2 blocks, so each expert's W2 is read once, and an MXFP4 scatter that keeps every lane busy.Stage2Meta,_fp8_scale_e8m0,store_peer, the warp reductions); the GEMM2 tile is aStage2Unitthat Stage2 and the fused Stage1 share. The L1 invalidate usescomm_ops.invalidate_l1(); the PR adds no raw MLIR or inline asm.Recipe settings:
AITER_MEGA_FIXED_SLOT_MAX_MTPR=1023andstage2_p2p_quant="fp4_blockwise_1x32"on the V4.1-Flash EP8 A4W4 instance; the options apply on their own.Companion vLLM PR: vllm-project/vllm#68385
Timing
Before
After
Figures above show a breakdown at 224 tokens / rank. Theres a good improvement from 261us -> 204us.
Results
MoE layer
DeepSeek-V4.1-Flash MoE layer (vLLM
DeepseekV4AiterMegaMoEExperts, EP8, A4W4, MXFP4 combine) on 8x MI355X, vLLM nightly7c3a9302, CUDA-graph replay, slowest rank. Outputs are bitwise identical to the baseline at every size.End to end (vLLM)
Fixed length
DeepSeek-V4.1-Flash, 8x MI355X, DEP8, 1k in / 8k out, concurrency 256, DSpark k=6,
max_num_batched_tokens=4096. Both arms run A4W4 MegaMoE with the MXFP4 combine andAITER_MEGA_FIXED_SLOT_MAX_MTPR=1023; the test arm also sets the Stage1/Stage2 options above. Imagevllm/vllm-openai-rocm:nightly-rocm100-7c3a9302f5ac2441ad199134129e973d22a46797with this PR, the vLLM PR and FlyDSL 0.5.0. Full server and benchmark commands are in vllm-project/vllm#68385.Accuracy, GSM8K 5-shot through
lm_evalagainst the same servers:AgentX, concurrency 256
InferenceX AgentX, DeepSeek-V4.1-Flash, 8x MI355X, DEP8, the
override_dep8_c256recipe from SemiAnalysisAI/InferenceX#5056 (DSpark K5, synthetic acceptance length 3.51,max_num_batched_tokens=32768), both arms on the same machine with vLLM ROCm nightly7c3a9302. The baseline is the stock image, which runs MegaMoE A8W4 with theautocombine and reproduces the c-256 DEP8 numbers from that InferenceX PR. The test arm adds this PR and the vLLM PR, and sets A4W4, the MXFP4 combine,AITER_MEGA_FIXED_SLOT_MAX_MTPR=1023and the Stage1/Stage2 options above. Unlike the fixed-length run, this delta includes the A8W4 to A4W4 switch and the MXFP4 combine as well as the kernel changes.PR Self-Review
Reviewed revision
697332913(merge oforigin/maininto11b1cc53a, adapting the PR to the routed interface)Behavior and intent
On DeepSeek-V4.1-Flash EP8 with A4W4, MegaMoE runs dispatch, GEMM1 and GEMM2 back to back. Every rank waits for the all-rank dispatch sync before it builds its plan, Stage2 waits for every GEMM1 tile on the rank, and A4W4 used the generic configs, which stream each expert's weights twice at decode sizes. The combine could only send BF16 or FP8 rows. At 160-224 tokens per rank the layer took 247-285 µs, and most of that was serialization rather than compute.
This PR changes three things:
stage2_p2p_quant="fp4_blockwise_1x32"), used only when the caller requests it.autonever picks it. An explicit FP4 or BF16 (none) request turns off the aligned-pair Stage2, whose kernel writes FP8 rows only; BF16 previously raised there.v41_flash_ep8profile and a newv41_flash_draft_ep8profile, and lets the fixed-slot runtime take 16 experts per rank as well as 48.early_tiles,light_release,resident_grid,unroll_k,g1_split_tail,fused_g2,wide_scatter), all defaultFalse. Only the V4.1-Flash EP8 A4W4 fixed-slot MTPR-512 instance with the MXFP4 combine sets them, in every bucket:early_tilesandlight_releasechange what ranks exchange, so the buckets of an instance must agree.fused_g2is cleared everywhere else, so the draft MoE keeps its separate Stage2 launch.The routed interface needs no A4W4-specific code: A4W4 is not a fused layout (
fused_layout_supported), so a routed A4W4 instance builds the staged route only andforward(max_tokens=...)always takes it. Withp2p_quantleft onauto, kernels and launch configs do not change for any model except the V4.1-Flash A4W4 rules and fixed-slot dispatch at 16 experts per rank, both listed under the PR-specific question below.Validation and unverified scope
Hardware: 8x MI355X (gfx950), image
vllm/vllm-openai-rocm:nightly-rocm100-7c3a9302, FlyDSL 0.5.0, amd_mori 1.2.3.post1, EP8.11b1cc53a(recipe switches on), with the new timing test, three runs against three runs of11b1cc53aon the same machine:--shape draft) at 160/192/224 within 0.8%, all bitwise equal.--quant a4w4:--network v41_flash --check-time-acc) also passes on this revision.origin/main, the size suite at A8W4 V4-Pro (--bs-list 1,64,128,512,2048) and A4W4 V4.1-Flash (--bs-list 1,128,1024,4096) gives the same relL2 to six digits at every size, and the same stage times except as noted below.1f9ee68.8819c04, and the Stage1/Stage2 options' A/B table in that ofcf67db6.tests/test_mega_moe_gfx950_route_plan.pypasses (100 tests).Unverified or remaining:
auto(FP8) combine, bucket 4096 is ~3% slower than main (e2e 1.383 vs 1.342 ms in the size suite; GEMM2 block_m 128 vs 64); the rules were searched with the MXFP4 combine.tests/test_mega_moe_gfx1250_recipe.py::test_layoutfails in this environment onorigin/mainas well; this PR does not touch gfx1250 code.ci:multi-gpulabel has not been run on this revision yet.PR-specific question
Network profiles are matched by
_match_networkon the exact (experts_per_rank, model_dim, inter_dim) triple, so only these keys see new configs:v41_flash_ep8, key (48, 5120, 2304), only whenworld_size == 8and A4W4 (apply_fp4):AITER_MEGA_FIXED_SLOT_MAX_MTPR=1023, since the default limit is 255). With the MXFP4 combine, every bucket takes the Stage1/Stage2 options, and buckets 128 and 256 the 256-thread Stage1 configs the fused path needs. With the BF16 or FP8 combine, buckets 128 and 256 get the searched base configs and no options._tune_v41_flash_ep8is unchanged: the new code sits entirely underif ctx.apply_fp4:, and A8W4 previously returned at the same point.v41_flash_draft_ep8, a new key (16, 5120, 2304), only whenworld_size == 8, A4W4, fixed-slot and MTPR 512, buckets 128 and 256.FIXED_SLOT_EXPERTS_PER_RANK = (48, 16)replaces== 48inselect_mega_moe_configandbuild_mega_moe_bundle_plan. As a result, any EP8 layout with 16 experts per rank and MTPR within the fixed-slot limit now uses fixed-slot instead of compact. No other registered network has 16 experts per rank (R1 has 32, V4-Pro 48 with EPLB 52/56, Kimi-K3 112 and V4.1-Flash EP2 192). For the draft MoE, the fixed-slot output equals the compact output bitwise.autostill resolves to BF16 or FP8 as before. The aligned-pair override fires only whenfp4_blockwise_1x32ornoneis requested explicitly;noneat the 8192 bucket used to raise "conflicts with aligned-pair Stage2" and now takes the plain Stage2 (11b1cc5)._tune_v41_flash_ep8sets them, andfused_g2is cleared outside the gate above.Evidence that unrelated shapes keep their previous selection: every new rule is gated on the profile key above plus
world_size,apply_fp4,fixed_slot,mtpr,bucketand, for the options, the combine format. The new config fields default toFalse, and the fused-config digests intests/test_mega_moe_gfx950_route_plan.pyare unchanged.Changed op tests
op_tests/multigpu_tests/test_mega_moe_v41_flash_a4w4_timing.py(new): times the V4.1-Flash EP8 A4W4 layer with the MXFP4 combine at the PR's sizes (decode MTPR 512: 160/192/224, prefill MTPR 4096: 1024/2048/4096, or--sizes), target or draft shape, through the routed interface;--referencegates slowdowns against earlier runs and--compare-outputschecks outputs bitwise.op_tests/multigpu_tests/test_mega_moe_v2.py:--suite routesaccepts--quant a4w4(V4.1-Flash; staged route only, default MTPR 512, the small-input epoch-wrap check skipped), and--stage2-p2p-quantis shared by both suites and acceptsfp4_blockwise_1x32.tests/test_mega_moe_gfx950_route_plan.py: routed A4W4 is staged only; the V4.1-Flash EP8 A4W4 MTPR-512 buckets share one protocol with the MXFP4 combine; the options stay off with the BF16/FP8/auto combines, A8W4, the draft, MTPR 256 and without fixed-slot;MegaMoEConfigrejectsfused_g2without the MXFP4 combine. The new config fields enter the fused-config digest tables only when set, so the pinned digests hold.