Skip to content

[FlyDSL] [DSV41] MegaMoE improvements for DEP8 - #8186

Closed
heachary wants to merge 5 commits into
ROCm:mainfrom
heachary:heachary/dsv41flash/megamoe-improvements
Closed

heachary wants to merge 5 commits into
ROCm:mainfrom
heachary:heachary/dsv41flash/megamoe-improvements

Conversation

@heachary

@heachary heachary commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

MegaMoE's fixed-slot path for DeepSeek-V4.1-Flash EP8 A4W4 leaves time on the table:

  • No overlap between dispatch and GEMM1. Tokens claim rows in their destination expert with remote atomics, so a destination cannot know how many tokens an expert will receive until every source has finished sending. Each rank waits on that all-rank sync before it builds the plan, even though most experts' rows are already there.
  • No overlap between GEMM1 and GEMM2. Stage2 is a separate launch, so GEMM2 and the combine scatter wait for every GEMM1 tile on the rank.
  • Kernel selection. A4W4 ran the generic fixed-slot and compact configs (32 x 128 GEMM1 tiles, 32-row GEMM2 blocks), which stream each expert's weights more than once at decode sizes.

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) and forward(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 of Stage1Config / Stage2Config, set by the tuned config, so they are part of the bundle and AOT kernel identity.

  • MXFP4 combine (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. auto never selects it.
  • Tuned V4.1-Flash EP8 A4W4 configs: searched decode (fixed-slot, MTPR 512), prefill (compact, MTPR 4096) and draft rules. The fixed-slot runtime now also admits 16 experts per rank, so the drafter decodes fixed-slot.
  • Recipe for the decode instance: V4.1-Flash EP8 A4W4, fixed-slot at MTPR 512 (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):
    • Dispatch/GEMM1 overlap (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 (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.
    • GEMM1/GEMM2 overlap (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_config keeps it only for fixed-slot A4W4 at 48 experts per rank with the MXFP4 combine and 4-wave Stage1 CTAs, and MegaMoEConfig rejects it without the MXFP4 combine.
    • Resident grid (resident_grid): Stage1 launches num_cu * grid_mult CTAs. 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.
    • Tuned GEMM1 (buckets 128/256 config, 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.
    • Tuned GEMM2 (buckets 128/256 config, Stage2Config.wide_scatter): 64-row GEMM2 blocks, so each expert's W2 is read once, and an MXFP4 scatter that keeps every lane busy.
  • Kernel code on main's helpers: the FP4 combine epilogue and the fused GEMM2 use main's Stage2 helpers (Stage2Meta, _fp8_scale_e8m0, store_peer, the warp reductions); the GEMM2 tile is a Stage2Unit that Stage2 and the fused Stage1 share. The L1 invalidate uses comm_ops.invalidate_l1(); the PR adds no raw MLIR or inline asm.

Recipe settings: AITER_MEGA_FIXED_SLOT_MAX_MTPR=1023 and stage2_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

image

After

image

Figures above show a breakdown at 224 tokens / rank. Theres a good improvement from 261us -> 204us.

Results

Measured on revision 11b1cc53a, where the Stage1/Stage2 options were environment switches (all on in the test arm). The current revision is within 1.5% of 11b1cc53a with bitwise-equal outputs at the MoE-layer sizes below (see Validation); the end-to-end numbers will be refreshed on it.

MoE layer

DeepSeek-V4.1-Flash MoE layer (vLLM DeepseekV4AiterMegaMoEExperts, EP8, A4W4, MXFP4 combine) on 8x MI355X, vLLM nightly 7c3a9302, CUDA-graph replay, slowest rank. Outputs are bitwise identical to the baseline at every size.

Tokens per rank Phase Baseline (µs) This PR (µs) Improvement
160 decode 247.0 209.7 15.1%
192 decode 260.3 212.3 18.4%
224 decode 284.8 213.9 24.9%
1024 prefill 519.8 507.0 2.5%
2048 prefill 848.6 728.0 14.2%
4096 prefill 1246.9 1249.7 −0.2%

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 and AITER_MEGA_FIXED_SLOT_MAX_MTPR=1023; the test arm also sets the Stage1/Stage2 options above. Image vllm/vllm-openai-rocm:nightly-rocm100-7c3a9302f5ac2441ad199134129e973d22a46797 with this PR, the vLLM PR and FlyDSL 0.5.0. Full server and benchmark commands are in vllm-project/vllm#68385.

Metric Baseline This PR Delta
Output token throughput (tok/s) 32,397 39,605 +22.2%
Total token throughput (tok/s) 36,447 44,556 +22.2%
Benchmark duration (s) 258.9 211.8 -18.2%
Mean TTFT (ms) 3,797.6 1,151.4 -69.7%
Median TTFT (ms) 154.4 152.1 -1.5%
P99 TTFT (ms) 17,025.7 14,788.1 -13.1%
Mean TPOT (ms) 6.29 5.61 -10.8%
Median TPOT (ms) 4.79 4.91 +2.4%
P90 TPOT (ms) 10.95 8.58 -21.6%
P99 TPOT (ms) 13.80 10.58 -23.3%
Median ITL (ms) 25.05 23.92 -4.5%
Mean E2EL (ms) 55,287 47,073 -14.9%
P99 E2EL (ms) 120,438 87,497 -27.4%
Spec decode acceptance length 6.19 6.22

Accuracy, GSM8K 5-shot through lm_eval against the same servers:

GSM8K (5-shot) Baseline This PR Delta
strict-match 0.9712 ± 0.0046 0.9765 ± 0.0042 +0.0053
flexible-extract 0.9704 ± 0.0047 0.9757 ± 0.0042 +0.0053

AgentX, concurrency 256

InferenceX AgentX, DeepSeek-V4.1-Flash, 8x MI355X, DEP8, the override_dep8_c256 recipe 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 nightly 7c3a9302. The baseline is the stock image, which runs MegaMoE A8W4 with the auto combine 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=1023 and 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.

Metric Baseline This PR Change
Successful requests 37,129 39,179 +5.5%
Total throughput per GPU (tok/s) 184,676 199,134 +7.8%
Output throughput per GPU (tok/s) 1,296 1,374 +6.0%
Interactivity, median (tok/s per user) 159.9 192.2 +20.2%
Interactivity, p90 (tok/s per user) 106 148 +39.7%
TPOT, median / p95 (ms) 6.25 / 11.4 5.20 / 7.99 −17% / −30%
TTFT, median / p90 (s) 1.87 / 3.81 1.53 / 2.97 −18% / −22%
End-to-end latency, median (s) 5.2 4.2 −19%

PR Self-Review

Reviewed revision

697332913 (merge of origin/main into 11b1cc53a, 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:

  1. It adds an MXFP4 combine (stage2_p2p_quant="fp4_blockwise_1x32"), used only when the caller requests it. auto never 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.
  2. It adds tuned A4W4 configs for the v41_flash_ep8 profile and a new v41_flash_draft_ep8 profile, and lets the fixed-slot runtime take 16 experts per rank as well as 48.
  3. It adds Stage1/Stage2 config fields (early_tiles, light_release, resident_grid, unroll_k, g1_split_tail, fused_g2, wide_scatter), all default False. Only the V4.1-Flash EP8 A4W4 fixed-slot MTPR-512 instance with the MXFP4 combine sets them, in every bucket: early_tiles and light_release change what ranks exchange, so the buckets of an instance must agree. fused_g2 is 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 and forward(max_tokens=...) always takes it. With p2p_quant left on auto, 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.

  • Parity of this revision with 11b1cc53a (recipe switches on), with the new timing test, three runs against three runs of 11b1cc53a on the same machine:
    cd op_tests/multigpu_tests
    torchrun --nproc-per-node 8 test_mega_moe_v41_flash_a4w4_timing.py --reference prev_run1.json prev_run2.json prev_run3.json --tolerance 0.03 --compare-outputs prev_outputs/
    
    Outputs are bitwise equal at every size, and the slowest-rank time is within 1.5%: decode 160/192/224 at 207.2/210.5/212.6 µs (was 207.9/210.6/212.7), prefill 1024/2048/4096 at 497/700/1241 µs (was 501/709/1231). The extra decode sizes 1/16/64/128/300/400/512 are within 1.3%, and the draft shape (--shape draft) at 160/192/224 within 0.8%, all bitwise equal.
  • The routed A4W4 instance, with the routes suite now accepting --quant a4w4:
    AITER_MEGA_FIXED_SLOT_MAX_MTPR=1023 torchrun --nproc-per-node 8 test_mega_moe_v2.py --suite routes --network v41_flash --quant a4w4 --stage2-p2p-quant fp4_blockwise_1x32 --check-time-acc
    
    All pass: uneven, idle, padded and masked-slot cases against the fp32 reference (relL2 0.239) and bitwise against the pinned staged route, 600 layer rebinds over 61 slots with interleaved calls, and CUDA-graph replay against eager. The A8W4 routes suite (--network v41_flash --check-time-acc) also passes on this revision.
  • Against 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.
  • MXFP4 combine accuracy: relL2 against the BF16 reference is 0.210 with the BF16 combine, 0.211 with FP8 and 0.239 with FP4, where 0.21 is A4W4's own rounding. Per-size timings are in the commit message of 1f9ee68.
  • Tuned configs: each tuned candidate's output matched its base config bitwise on the same inputs. The before and after tables for decode, prefill and draft are in the commit message of 8819c04, and the Stage1/Stage2 options' A/B table in that of cf67db6.
  • CPU: tests/test_mega_moe_gfx950_route_plan.py passes (100 tests).

Unverified or remaining:

  • Only gfx950 / MI355X at EP8 on a single node was tested. MI300X, other world sizes and multi-node are not tested.
  • The prefill rules at MTPR 4096 do not depend on the combine format. With the 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.
  • In the compact-dispatch search, 40 or more dispatch CUs deadlocked at 3072 and 4096 tokens per rank. Bucket 4096 therefore keeps 32 dispatch CUs, and the deadlock has not been root-caused.
  • Fixed-slot dispatch at 16 experts per rank is validated only at the V4.1-Flash draft dimensions (5120 / 2304).
  • R1, Kimi-K3 and V4.1-Flash EP2/EP4 were not re-benchmarked; that their selection is unchanged comes from the code gating described below.
  • tests/test_mega_moe_gfx1250_recipe.py::test_layout fails in this environment on origin/main as well; this PR does not touch gfx1250 code.
  • The ci:multi-gpu label has not been run on this revision yet.

PR-specific question

Network profiles are matched by _match_network on 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 when world_size == 8 and A4W4 (apply_fp4):
    • Fixed-slot at MTPR 512 (reached only with 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.
    • Compact at MTPR 4096, buckets 1024, 2048 and 4096.
    • Every other A4W4 bucket or MTPR returns the base config, as before. The A8W4 branch of _tune_v41_flash_ep8 is unchanged: the new code sits entirely under if ctx.apply_fp4:, and A8W4 previously returned at the same point.
  • v41_flash_draft_ep8, a new key (16, 5120, 2304), only when world_size == 8, A4W4, fixed-slot and MTPR 512, buckets 128 and 256.
  • Runtime selection: FIXED_SLOT_EXPERTS_PER_RANK = (48, 16) replaces == 48 in select_mega_moe_config and build_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.
  • The combine format: auto still resolves to BF16 or FP8 as before. The aligned-pair override fires only when fp4_blockwise_1x32 or none is requested explicitly; none at the 8192 bucket used to raise "conflicts with aligned-pair Stage2" and now takes the plain Stage2 (11b1cc5).
  • V4-Pro shares 48 experts per rank but never takes the options: only _tune_v41_flash_ep8 sets them, and fused_g2 is 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, bucket and, for the options, the combine format. The new config fields default to False, and the fused-config digests in tests/test_mega_moe_gfx950_route_plan.py are 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; --reference gates slowdowns against earlier runs and --compare-outputs checks outputs bitwise.
  • op_tests/multigpu_tests/test_mega_moe_v2.py: --suite routes accepts --quant a4w4 (V4.1-Flash; staged route only, default MTPR 512, the small-input epoch-wrap check skipped), and --stage2-p2p-quant is shared by both suites and accepts fp4_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; MegaMoEConfig rejects fused_g2 without the MXFP4 combine. The new config fields enter the fused-config digest tables only when set, so the pinned digests hold.

Mehmet Aslan and others added 3 commits November 18, 2026 10:12
…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]>
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter standard tests on MI35X
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the Radeon R9700 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 8186 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@heachary heachary changed the title [FlyDSL] [Perf] MegaMoE: dispatch/GEMM1 and GEMM1/GEMM2 overlap, MXFP4 combine and tuned tiles for DeepSeek-V4.1-Flash EP8 A4W4 [DSV41] MegaMoE improvements for DEP8 Nov 18, 2026
@heachary
heachary marked this pull request as ready for review November 18, 2026 12:00
@heachary
heachary requested a review from a team November 18, 2026 12:00
@github-actions github-actions Bot changed the title [DSV41] MegaMoE improvements for DEP8 [FlyDSL] [DSV41] MegaMoE improvements for DEP8 Nov 18, 2026
@aiter-bot

aiter-bot commented Nov 18, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 6973329138f7 · mode shadow

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

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. Which exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

…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 coderfeli left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 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=...))?
  2. 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]>
@heachary

Copy link
Copy Markdown
Contributor Author
  • 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.

Merged main and refactored the implementation:

  • Unified interface. Merged main and adapted the branch to the routed interface (routed=True + forward(max_tokens=...)). A4W4 takes the staged route of the route plan, since the small and large routes are A8W4-only.
  • Env vars and raw MLIR.
    envs.py and all its AITER_MEGA_* switches are removed. They are now fields on Stage1Config/Stage2Config (early_tiles, light_release, resident_grid, unroll_k, g1_split_tail, fused_g2, wide_scatter). _tune_v41_flash_ep8 sets them for the V4.1-Flash EP8 A4W4 MTPR-512 layout with the MXFP4 combine. select_mega_moe_config / MegaMoEConfig reject fused_g2 anywhere else.
  • The inline-asm invalidate_l1 in dispatch.py is replaced by comm_ops.invalidate_l1(). The FP4 combine epilogue and the fused GEMM2 are rebuilt on main's Stage2 helpers (Stage2Meta, store_peer, _fp8_scale_e8m0, fx.coop.warp_max). No inline asm, llvm.* or _mlir is added.

The timing results at different tokens / rank are very close to what they were before the refactor:
image

@heachary

Copy link
Copy Markdown
Contributor Author

Closing the PR, overlaps with : #8623

@heachary heachary closed this Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants