Repository navigation
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
NOT READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
The only compact ep_fused=2 row (token 8192, tile 128) covers recv bounds 4096-8192, i.e. tpr 1025-2048 under the bench's max_recv = 4 * tpr. Dropping it sends the compact path to the ep_fused=1 row (tile 256, APRE), the tile mori already runs there. Unit bench, S1F us/layer with the row -> without the row (same worktree): tpr 1280 410.6 -> 382.0 (-7.0%) tpr 1536 419.6 -> 401.7 (-4.3%) tpr 2048 491.4 -> 498.0 (+1.3%) MEGA-CHECK accuracy PASS at all three. Not yet measured end to end. test_compact_rows_override_only_compact now asserts that the compact lookup at token 8192 resolves to the same ep_fused=1 row as mori.
88480c1 retuned the DSR1 EP4 ep_fused=1 rows for the fused-shared-expert key (experts=65), but test_grouped_ep_fused_lookup kept the old values and failed on four checks: token row now test expected 512 32/32, 3/3 16/16, 3/3 1024 64/64, 3/3 128/128, 2/2 2048 128/128, 3/3 128/128, 2/2 compact plan align at 512: 32, expected 16 Point the expectations at the current rows; the CSV is unchanged. All 13 tests in the file pass.
…-mask selects
A select on a raw ArithValue condition takes the constant type from the
other operand, so two Python ints fail to build ('int' object has no
attribute '_CAPIPtr') on some FlyDSL 0.5.3 builds. Main wraps them; #8092
had unwrapped the cluster-mask pair.
…tile 256 OP_STORES + 3 reached 64 for hidden 7168 (56 payload + 4 scale + 1 rowmap stores per op), which tripped the "stores overflow the storecnt wait field" ValueError once a step picked the 256-row tile (EP4 tpr >= 8192). The wait immediate is 6 bits, but retire() only needs a count <= d, and a wave never has more than 63 stores outstanding, so capping the listed waits at 63 is safe.
Resolve conflicts with #8889 (s1f_ctl.py, s1f_stage1.py, dispatch_compact.py): keep the config-based S1F helpers, and redefine s1f_packed_a_fits as "one storer op's stores <= the 63 a wave can have outstanding" so hidden 7168 (61 stores/op) keeps packed A through the capped WAIT_STEPS. Fix test_compact_plan_uses_ep_fused_tile config (dispatch_token_nbytes / dispatch_scale_nbytes), broken on origin/main by #8889.
…arena Wide wire rows (hidden 7680/8192 fp4) made the stage-1 kernel raise "producer LDS 136320 B exceeds the GEMM arena 133632 B" at tile 64, on origin/main too. Record each variant's GEMM1 arena and drop a tile whose arena is smaller than the producer ring from the offered tiles, so a step that aligns to it keeps dispatch and GEMM1 separate (the existing S1F fallback) instead of failing in the JIT. Hidden 5120/7168 fit every tile, so their paths are unchanged. Add test_s1f_ring_fits.py for the packed-A store limit and the ring gate.
Drop the unit test added with the producer-ring gate; the gate itself is unchanged.
Resolve the conflict in mxfp4_preshuffle_gfx1250_tdm.py: keep this branch's VGPR-partition / preshuffled-output setup and main's split_f4_wmma (gfx1250-strict, #9058); both sit in the same prologue and are independent.
NOT READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
Summary
DeepSeek-R1 on EP4 fuses its shared expert, so the MegaMoE grouped lookup is
experts=65 topk=-1 ep_fused=1and the S1F cap check sees top-9. This PR does two things for that path:(4, 9)joins the uncapped shapes).ep_fused=1grouped rows are retuned for tokens 512, 1024, 2048 and 4096. [gfx1250] [MoE] DeepSeek-R1 EP4 MegaMoE grouped FMoE rows: ep_fused=1 buckets, tuned 8192 and 32768 #8002 is already on main and owns the other buckets.storecntwaits are capped at 63 instead of raisingValueError. Single-tray EP4s1f_s2fon hidden 7168 (DSV4-Pro style, top-6/7) now runs at tpr 8192 and 16384 (see "Packed-A storecnt cap" below).AITER_MEGA_S1F_FALLBACK=mori, S1F is faster than the mori dispatch path at every tpr from 64 to 16384 (−1.4% to −13.7% per layer). Commit 8a9752a ports the pinned EP4 prefill path from [FlyDSL] perf: integrate APRE M256 kernels into gfx1250 MegaMoE S1F #7410, turns it on by default, and keeps the mori and small-tile paths at their previous speed (see "vs mori dispatch" below).The
s1f_ctl.pychange is exactly the hunk #7332 also carries, so the two PRs merge in either order andAITER_MOE_LOC=1keeps its placed-weight launch arguments.Motivation
For this shape
max_recv = world_size * tokens_per_rank, so tpr 1536 (6144), 2048 (8192) and 4096 (16384) all stepped off S1F and ran dispatch plus GEMM1. DSV4.1 top-6/7 was already uncapped; DSR1 top-9 was not.With #8002 merged, tokens 8–256, 8192, 16384 and 32768 have
ep_fused=1rows. Token 512 is a copy of theep_fused=0row (16×256×256 / 16×512×128). Tokens 1024 and 2048 are128×256×256with 2 buffers, and 4096 had no 10-iter measurement. The S1F kernel runs its own 256×256 n/k tile; CSVtile_konly affects the unfused GEMM and GEMM2.Changes
s1f_ctl.py: add(4, 9): 1 << 30to_S1F_MAX_RECV_BY_SHAPE, with the same comment lines as [FlyDSL] [GFX1250] [MoE] Retune gfx1250 DSv4.1 EP4 a4w4 grouped MoE rows for d… #7332. Nothing else in the file changes.s1f_stage1.py: remove theOP_STORES + 3 > 63check ("an op's stores overflow the storecnt wait field") and cap theWAIT_STEPScounts at 63 (min(_STORECNT_MAX, OP_STORES + p)). Nothing else in the file changes. Why it is safe:PAY_ITERS + SC_ITERS + 1VMEM stores. For hidden 7168 fp4 that is 56 payload + 4 scale + 1 rowmap = 61, soOP_STORES + 3reached 64, one past what the 6-bits_wait_storecntimmediate can encode. Hidden 5120 and 4096 need 44 and 32 and were never affected.retire()waits for the largest listed count<= d(d= stores the wave issued after the retiring op's last store); a smaller count only over-waits.d >= 63, the retiring op is already complete andwait(63)holds either way.origin/main([FlyDSL] [gfx1250] MegaMoE S1F: packed A only where its stores fit storecnt #8889) into this branch, and later oforigin/mainat2d62557a8(one conflict inmxfp4_preshuffle_gfx1250_tdm.py: this branch's VGPR-partition setup kept with main'ssplit_f4_wmmafrom [FlyDSL] [gfx1250] Split 32x16x128 f4 WMMA into two 16x16x128 on gfx1250-strict #9058). Itss1f_packed_a_fitsrequiredop_stores + 3 <= 63, which turns packed A off for hidden 7168 (61 stores per op). This branch usesop_stores <= 63instead, with the sameWAIT_STEPScap, so hidden 7168 keeps packed A. Measured on the merged code (tpr 8192, hidden 7168, 2 layers, 10 iters, two rounds): packed A 2914–2935 µs, the [FlyDSL] [gfx1250] MegaMoE S1F: packed A only where its stores fit storecnt #8889 gate 2969–2975 µs.s1f_ctl.py:s1f_ring_fits(tile_m, wire_row). The producer's slot ring (4 slots × 8 rows × wire row + 5248 B) aliases the GEMM1 LDS arena. For hidden 7680/8192 fp4 (4096/4352 B rows, 136320/144512 B of producer LDS) tile 64 (arena 133632 B) did not fit, and the build raisedproducer LDS ... exceeds the GEMM arena. Such a tile is no longer offered, so a step that aligns to it takes the existing separate dispatch + GEMM1 path. Hidden 5120 and 7168 fit every tile, so their paths do not change.dsr1_tuned_grouped_fmoe.csv,experts=65,model_dim=7168,inter_dim=2048. The token key is the padded receive countnext_pow2(4 * tpr). Of the 72 rows, 13 change (ep_fused=1rows fortopk=-1, tokens 512–4096;cluster_mon rows withtopk=9for non-fused calls at tokens 4096–32768, and ontopk=-1rows at 16384 and 32768). The other 59 rows, including everyexperts=64row, are byte-identical toorigin/main.cluster_m2/4 → 1 on thetopk=9rows is the DSR1 (4, 9) non-fused path, which the fused S1F path does not read; see Performance.usfilled inRows for the other buckets were measured and dropped. On the same bench #8002's rows were as fast or faster there, or the ranges overlapped, so tokens 8–256, 8192, 16384 and 32768 stay as #8002 has them.
Performance (if applicable)
4× gfx1250, DeepSeek-R1 EP4, 256 routed experts plus 1 fused shared expert per rank, top-8, hidden 7168, intermediate 2048, A4W4 MXFP4, fp4 dispatch, stage-1 and stage-2 fused, uniform routing,
AITER_MEGA_QUANT_FUSE=128,AITER_MEGA_PLAN_PREFETCH=0,AITER_MOE_LOC=0. Bench isop_tests/multigpu_tests/bench_mega_moe.py --layers 8 --warmup 5 --iters 10 --profile_table 0 --acc_verify 0 --fused_shared_experts 1. The number is the median host time of one CUDA-graph replay of the 8-layer chain, averaged across the 4 ranks. Before is current main (with #8002), After is this branch.At tpr 128 and 256 the ranges do not overlap. At tpr 512 the ranges touch (2042–2069 vs 2070–2104 µs) and at tpr 1024 they overlap, so those two are within noise against main with S1F on.
AITER_MOE_LOC=1was also run on this branch merged with #7332 (S1F on, fused shared expert, uniform routing, 8 iters, single run per point):Every point runs and
acc_verify 1passes at tpr 128 and 1536 (logits diff 0.112 against tolerance 0.216 at 1536).Packed-A storecnt cap (hidden 7168, tile 256)
Cause: the grouped CSV picks the 256-row GEMM1 tile once the padded receive count reaches 32768 (EP4 tpr 8192), and S1F forces packed A (
a_preshuffled=1) at tile 256. On hidden 7168 that built an op with 61 stores, which the old check rejected. The error was not turned into a fallback, so the wholes1f_s2fconfiguration failed (err=9, fb=0) whilenone,s2fands1f_offpassed. Before this change, EP4 top-6, hidden 7168, tpr 8192 reproduced theValueErroron all 4 ranks.4× gfx1250, DEP4, A4W4 MXFP4, fp4 dispatch, stage-2 fused, uniform routing,
-e 384 -hd 7168 -id 3072 --layers 2 --iters 3 --warmup 5 --profile_table 0,--stage1_fused both(mori dispatch vs S1F in one process). The number is the median host time of one CUDA-graph replay of the 2-layer chain, averaged across the 4 ranks. Accuracy is the bench's fp32-referencelogits_diff, tolerance 0.063559, and it passes in every row.-k 6-k 6-k 6 --fused_shared_experts 1At (4, 6) tpr 16384 the S1F replays spread from 5011 to 5460 µs (min to max), more than the other rows; only 3 iterations were run, so this was not investigated. The DSR1 (4, 9) shape takes the pinned #7410 path, not packed A, and is unaffected by this change.
vs mori dispatch (commit 8a9752a)
Per-layer unit bench, not the CUDA-graph chain above:
op_tests/multigpu_tests/bench_mega_moe.py -q a4w4_mxfp4 -e 256 -k 8 -hd 7168 -id 2048 --fused_shared_experts 1 --layers 58 -tpr <tpr> --stage1_fused both --stage2_fused true --dispatch_wire fp4 --combine_quant none --warmup 5 --iters 20on 4× gfx1250, withAITER_MEGA_S1F_FALLBACK=moriand the defaultAITER_FLYDSL_EXPLICIT_VGPR_PARTITION=1. Each cell is us per layer, mean over 20 iters, one run per point. The mori column is the same run with S1F off. Accuracy passes at every point, andlogits_diffmatches commit 9caaca3 bit for bit.Up to tpr 2048 the S1F numbers are the same as before this commit, within about 1%. The 1536 and 2048 margins are smaller because the mori path got faster there, while S1F moved by 4–5 us, which is close to run-to-run noise. At tpr 4096 and above the pinned prefill path takes over:
What the commit carries:
s1f_prefill_config()(M256/N256/K256 2x2, GEMM1 3 buffers, GEMM2 4 buffers, A preshuffle, for recv ≥ 16384 on the DSR1 and Flash EP4 shapes). The stage-1 kernel gets row-major MMA reuse, paired CTAs with A multicast, an 8-slot ring, and an APRE payload for GEMM2. GEMM2 uses a 4096-worker fixed-N EP scatter. Combine uses a dense BF16 slot pitch and a 128-thread reduce, and masks dropped routes using the source topk IDs.AITER_FLYDSL_EXPLICIT_VGPR_PARTITIONnow defaults to 1 and only gates those pinned specializations. M256 4-wave tiles always take the fixed VGPR partition, as on main, and small tiles no longer take it. With the [FlyDSL] perf: integrate APRE M256 kernels into gfx1250 MegaMoE S1F #7410 global flag, tpr 256 S1F was 241 us/layer; it is 205.5 now.ksl0_fence_mmatail, and compact M variants are limited tocluster_n <= 2. Mori GEMM2 at tpr 4096 went from 300.7 to 291.5 us.cluster_m=1. Clustered kernels now form under graph capture, and at tpr 16384 the automatic 4x4 GEMM1 took 980 us vs 780 us at 1x4. This also makes mori faster than before at 8192 (1516 → 1494) and 16384 (2879 → 2779).AITER_FLYDSL_EXPLICIT_VGPR_PARTITION=0turns the pinned path off. Then tpr 4096 S1F is 820.4 (−2.9% vs mori), 8192 is 1491.2 (tie), and 16384 runs mori again. Tpr 64–2048 and every mori number stay within 0.6% of the pinned-on run.No end-to-end serving run has been done on this commit yet.
CSV
cluster_mchange, DSR1 (4, 9) (A/B againstorigin/main's CSV)Only
aiter/configs/model_configs/dsr1_tuned_grouped_fmoe.csvwas swapped; everything else is this branch. Command:run_watch.shwith-e 256 -k 8 --fused_shared_experts 1 -hd 7168 -id 2048 --layers 2 --iters 3 --profile_table 0 --dispatch_wire fp4 --stage1_fused both --stage2_fused true -tpr {4096,8192}, one run per side, 4× gfx1250. MEGA-CHECK PASS in all four runs.origin/mainCSVOne run per side, so this shows no regression beyond about 2%, not a speedup. The
_find_grouped_configlookups before and after confirm the selectedcluster_mis 1 instead of 2 or 4 on those keys.Testing
CPU tests:
test_grouped_ep_fused_lookup.py,test_grouped_gemm_launch_abi.py,test_flydsl_aot_launch.py: 72 passed, 2 skipped.test_grouped_ep_fused_lookup.py's fake compact config gainstopk,world_size,stage1_fusedand the fp4dispatch_token_nbytes/dispatch_scale_nbytesthat_compact_gemm_tilesnow reads; without themtest_compact_plan_uses_ep_fused_tilefailed onorigin/maintoo.Post-merge GPU runs (fp4 wire,
stage1_fused true,stage2_fused true, MEGA-CHECK PASS in every row): DSR1 (4, 9) pinned at tpr 4096 and 8192 (repeated 3 times at 8192, 2749–2756 µs;origin/main3464 µs on the same config); (4, 6) hidden 7168 at tpr 8192 and 16384; hidden 7680 and 8192 at tpr 1024, 8192 and 16384; Flash (5120, 2304) at tpr 4096, 8192 and 16384; fp8 wire at hidden 8192 tpr 8192. The bf16 wire is rejected by the compact dispatch (recipe.py) onorigin/maintoo. The Flash hang seen earlier is in--stage1_fused false(mori dispatch) at tpr 4096, onorigin/mainas well; the S1F run of the same shape passes.In the CUDA-graph chain benchmark, accuracy was checked only in the
AITER_MOE_LOC=1run above, at two points; the unit-bench table checks it at every tpr. No MI250X or MI300X run. Routing other than uniform, EP sizes other than 4 and top-k other than 9 (with the fused shared expert) were not swept.Documentation
The cap table is documented in
s1f_ctl.py;AITER_S1F_MAX_RECVstill overrides it.Dependencies
Breaking Changes
None. DSR1 EP4 top-9 steps wider than 4096 received tokens now run the stage-1 kernel instead of dispatch plus GEMM1, and they compile a few more plan widths.
AITER_S1F_MAX_RECVcan still impose a cap.AITER_FLYDSL_EXPLICIT_VGPR_PARTITIONnow defaults to 1, so the pinned #7410 prefill path is on for the DSR1 (7168, 2048, 65, 9, 4) and Flash (5120, 2304, 96, 6, 4) EP4 shapes once recv ≥ 16384. Set it to 0 to get the previous behaviour. Flash was not re-benchmarked on this branch.Merging with #7332:
s1f_ctl.pyis identical in the cap hunk. The only overlap is the token-512 row, which #7332 carries from #8002; keep this PR's row there.PR Self-Review
Reviewed revision
85e3b90
Behavior and intent
For DSR1 EP4 with the fused shared expert, the S1F stage-1 kernel now runs at every receive width (
(4, 9)cap1 << 30). It was failing withan op's stores overflow the storecnt wait fieldat tpr 8192 and 16384, and that is what this PR removes. The packed-A check now allows one storer op up to 63 stores, which keeps packed A for hidden 7168, where #8889'sop_stores + 3 <= 63turned it off and made S1F slower than mori. The producer ring is checked against the GEMM arena, so hidden 7680/8192 fp4 falls back to separate dispatch + GEMM1 at tile 64 instead of raising at build time. The grouped CSV retunes 13 DSR1 rows (see Changes). Why the existing behavior is insufficient: onorigin/mainthe S1F build raises for these widths, so the fused path cannot be used at all for them.Validation and unverified scope
Commands and results. CPU:
pytest op_tests/tuning_tests/test_grouped_ep_fused_lookup.py op_tests/tuning_tests/test_grouped_gemm_launch_abi.py tests/test_flydsl_aot_launch.py: 72 passed, 2 skipped. Lint with the CI-pinned black 26.10.1 and ruff 0.16.0 over tracked files: clean. GPU (4× gfx1250, fp4 wire,stage1_fused true,stage2_fused true, MEGA-CHECK PASS in every run): DSR1 (4, 9) pinned at tpr 4096 (1585 µs) and 8192 (2741 µs, repeated 3×, 2749–2756 µs); (4, 6) hidden 7168 at tpr 8192 (2916 µs) and 16384 (5032 µs); hidden 7680 at tpr 8192 (4036 µs) and 16384 (12111 µs, on the separate dispatch + GEMM1 fallback); hidden 8192 at tpr 8192 and 16384; Flash 5120/2304 at tpr 4096 (1051 µs), 8192 and 16384.origin/mainon the DSR1 tpr 8192 config: 3464 µs. The CSV A/B is in Performance above.Unverified (not run): two-node setups (the two-node failure from the original report was not reproduced); tpr ≥ 32768 (except the 32768 token key in the CSV A/B); hidden > 8192; MI250X and MI300X; routing other than uniform; more than 3 iterations per point. The retuned fused rows for tokens 512, 1024 and 2048 were measured before the merge with #8889, not re-measured after it. The Flash 5120/2304 hang in
--stage1_fused false(mori dispatch, tpr 4096) also reproduces onorigin/main; it is out of scope here and the S1F run of the same shape passes.PR-specific question
The cap was there so a wide step would not JIT a new stage-1 plan on the serving path. Those plans are compiled up front.
Changed op tests
op_tests/tuning_tests/test_grouped_ep_fused_lookup.py(the only changed op test). (1)test_ep_fused_rows_selectednow expects the retuned fused rows: 512 → tile 32, 1024 → tile 64, 2048 → tile 128 (buffers 3). These are the CSV rows this PR changes, so the old expectations would fail on them. (2) Newtest_compact_rows_override_only_compactchecks that compact and mori resolve the same row for DSR1 8192 and 16384 when no compact-only row exists, which covers the compact/mori split in_find_grouped_configthat no other test exercises. (3)test_compact_plan_uses_ep_fused_tilefake config gains the fp4 wire sizes,topk,world_sizeandstage1_fused, which_compact_gemm_tilesreads since #8889; without them the test failed onorigin/mainas well. Not redundant: none of these three cases are covered by the other tests in the directory.Made with Cursor