Skip to content

[FlyDSL] [gfx1250] grouped MoE GEMM1 opts into mega - #7921

Merged
junhaha666 merged 6 commits into
mainfrom
zxe/mega_update_moe
Nov 26, 2026
Merged

junhaha666 merged 6 commits into
mainfrom
zxe/mega_update_moe

Conversation

@XingerZhu

@XingerZhu XingerZhu commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Port the grouped-MoE GEMM1 prefill schedule into mega stage-1 (S1F), and land the gfx1250 grouped-MoE prefill rows that schedule depends on.

For EP4 top-6, a step whose receive bound is at least 65536 (tpr 16384 and 32768) has the stage-1 producer write M16 packed A. GEMM1 then runs the 256³ 2×2 prefill kernel: a_preshuffle, lds_soa_load_interleave, next_stage_prefetch, pinned VGPRs, and WMMA 2×4. Smaller steps keep the existing 128-tile row-major stage-1 kernel.

On DSV4.1 Flash, 4×gfx1250, 8-layer graph, the packed path is 1654 vs 1704 µs/layer at tpr 16384 (−2.9%) and 3111 vs 3258 µs/layer at tpr 32768 (−4.5%).

A follow-up commit lets mega GEMM2's persistent bf16 EP scatter defer its final TDM wait (defer_c_wait), and tunes the tpr 512 / 1024 buckets: tpr 512 goes from 217.0 to 214.7 µs/layer (−1.1%, GEMM2 57.6 → 55.2 µs), and tpr 1024 GEMM2 goes from 81.2 to 78.9 µs.

A third commit prefetches kernel code past the launch window (following #7827). A launch preloads only the first ~32 KiB of a kernel. The S1F tile-256 kernel (~46 KiB) and the stage-1 GEMM (up to ~62 KiB) start their tails cold whenever another large kernel has evicted them, which is one reason UT gains do not always show up end to end. With the prefetch, S1F tile 256 at tpr 8192 goes from 930.2 to 918.6 µs/layer (−1.2%), and a stage-1 GEMM alternating with another shape drops from 7.0K to 0.5K instruction-cache misses per dispatch. End-to-end impact is still to be measured.

Motivation

Grouped MoE prefill GEMM1 is faster once A is in the packed M16 layout, because that is what makes the TDM loads, LDS SoA interleave, and next-stage prefetch pay off together. Mega stage-1 was still producing row-major wire rows, so turning those flags on did not speed the fused kernel up. The wide DSV4.1 Flash bucket was also missing a 131072-token grouped-GEMM row, so tpr 32768 fell back to a 64-row tile.

Changes

  • S1F producer writes packed A (M/16, K/128, 4, 16, 16B) plus row-major e8m0 scales, with masked VMEM stores. Payload and scale are separate buffer resources so the masked-lane offset 0x7FFFFFFF stays out of range. One resource for the whole region is about 2.21 GB at tpr 32768 and turned every masked lane into a real system-scope store (S1F ~50 ms).
  • GEMM1 at tile 256 uses 2×2 warps and the prefill schedule in mxfp4_preshuffle_gfx1250_tdm.py. Stage-1 quant output stays row-major, which mega GEMM2 already reads. AITER_MEGA_S1F_PREFILL_RECV=0 disables the 256-tile path. AITER_MEGA_S1F_WARPS overrides the warp grid.
  • The plan alignment uses the same recv threshold, so GEMM1 and the compact plan agree.
  • Not taken from the grouped-MoE 256³ rows: num_buffers=4 (planar LDS is about 328 KB, over the 320 KB per-CU budget; S1F keeps 3) and cluster 2×2 / 4×2 (explicit_tile plus persistent workers requires both cluster dimensions to be 1).
  • DSV4.1 Flash E96 topk=-1 rows at tokens 8192, 16384, and 32768 turn on GEMM2 next_stage_prefetch and lds_soa_load_interleave. A 131072-token row with the same 128-tile is added.
  • New topk=6 grouped-MoE rows for E96 (tokens 1 through 8192, plus 16384) and the E97 shared-expert rows. DSR1 65-expert rows move into dsr1_tuned_grouped_fmoe.csv.
  • Grouped GEMM1 can split activation out into the quant/scatter kernel. Mega stage-1 keeps activation and quant fused in GEMM1.
  • GEMM2 EP scatter defer_c_wait: a persistent bf16 scatter stages its rows in the last pipeline stage and skips the tensor_wait(0) after the remote TDM gather-store. The next tile's first fence retires it, because TDM ops complete in issue order, and the persistent loop drains with tensor_wait(0) before exit. It turns on only when the rows fit that stage and the prologue does not reach it (tile_m > 32, more than 2 buffers, no planar LDS, no A-scale prologue, k_waves == 1). The kernel name gets a _dcw suffix. AITER_FLYDSL_EP_DEFER_C_WAIT=0 turns it off.
  • Instruction prefetch: prefetch_kernel_code(num_waves) in gemm_common_gfx1250.py, after [FlyDSL] [gfx1250] DSv4.1 Flash 32x32 GEMMs: tune C1024 decode, prefetch a8w8/a4w4 compute kernel code #7827. It sets MODE.SCALAR_PREFETCH_EN (bit 24) through the llvm.amdgcn.s.setreg intrinsic, not inline asm, because immediate-form inline setreg clears the VGPR MSB bits MODE[19:12]. The kernel span comes from s_getpc_b64 and .Lfunc_end0 - label. Each wave issues every num_waves-th 4 KiB s_prefetch_inst chunk up to 56 KiB, with no branches; chunks past the end repeat the last line. S1F calls it at entry and drops its old inline-asm _prefetch_cold_code, which was a no-op without MODE[24]. The a8w4 TDM GEMM (stage-1 and GEMM2) calls it at kernel entry, from gemm_task when not persistent and from the persistent wrapper otherwise, and adds an _ipf suffix to the kernel name. AITER_FLYDSL_INST_PREFETCH=0 turns it off.
  • New DSV4.1 Flash E96 topk=-1 ep_fused=1 fp4 rows (mega only): token 2048 sets persistent_workers2=512, so the tpr 512 GEMM2 is persistent and takes the deferred path. Token 4096 sets num_buffer_stage2=3. The rest of each row copies the existing blank-ep_fused row.

Performance (if applicable)

Hardware is 4× gfx1250. Workload is DSV4.1 Flash, EP4, 384 experts, top-6, hidden 5120, intermediate 2304, A4W4 MXFP4, fp4 dispatch, stage-1 and stage-2 fused, uniform routing, 8-layer CUDA graph, median per layer. Before is the same mega stage-1 without packed A (GEMM2 prefetch/SoA and the 131072 row already present).

Hardware Workload/configuration Before After Change
4× gfx1250 tpr 16384, packed A on 1704 µs/layer 1654 µs/layer −2.9%
4× gfx1250 tpr 32768, packed A on 3258 µs/layer 3111 µs/layer −4.5%
4× gfx1250 tpr 8192, packed path off 888 µs/layer 889 µs/layer flat

S1F / GEMM2 device time on those runs: tpr 16384 is 632 / 575 µs, tpr 32768 is 1160 / 1126 µs. tpr 32768 is 17894 TFLOPS across the four GPUs (90% of the 19845 TFLOPS peak used for this shape). Before the buffer split, that S1F kernel was about 50 ms and still numerically correct.

The 131072-row fix, measured earlier on the same bench before packed A, took tpr 32768 from 3783 to 3258 µs/layer. The 3111 µs number above is on top of that.

Full 16-point sweep (--layers 8 --warmup 5 --iters 5), per-layer µs, before → after: 65.07→64.67, 72.32→72.03, 83.47→82.83, 106.55→106.46, 146.59→145.34, 169.54→167.19, 182.55→181.48, 191.58→191.78, 196.28→196.05, 218.21→216.01, 283.61→283.03, 363.20→363.37, 544.48→543.87, 887.93→889.16, 1704.20→1654.11, 3257.91→3110.75. Points at tpr 8192 and below stay within 1.4%.

GEMM2 deferred scatter follow-up. Same bench, interleaved A/B, 3 runs each. A is the previous rows with AITER_FLYDSL_EP_DEFER_C_WAIT=0. B is the new rows.

Hardware Workload/configuration Before After Change
4× gfx1250 tpr 512, layer 217.0 µs (216.5/216.9/217.7) 214.7 µs (214.0/214.8/215.3) −1.1%
4× gfx1250 tpr 512, GEMM2 kernel 57.6 µs 55.2 µs −4.2%
4× gfx1250 tpr 1024, GEMM2 kernel 81.2 µs 78.9 µs −2.8%
4× gfx1250 tpr 1024, layer 282.6 µs 283.1 µs within run-to-run noise (±3 µs)

Instruction prefetch follow-up. Same bench, --layers 4 --iters 10, AITER_FLYDSL_INST_PREFETCH=0 vs 1. Counters are rocprofv3 SQC_ICACHE_MISSES, median over 8 dispatches, with the stage-1 GEMM (5120/2304) alternating with a 7168/2048 GEMM.

Hardware Workload/configuration Before After Change
4× gfx1250 tpr 8192, S1F tile 256 forced (AITER_MEGA_S1F_PREFILL_RECV=1), layer 930.2 µs 918.6 µs −1.2%
4× gfx1250 tpr 4096, default tiles, layer (earlier base) 547.8 / 546.9 µs 547.5 / 544.7 µs within noise
1× gfx1250 stage-1 GEMM alternating, I$ misses per dispatch 7.0K 0.5K −93%

The #7827 switch penalty (alternating vs back-to-back sum, threshold 1.10) is 1.00–1.065 at tokens 512 and 2048 with or without prefetch. At tokens 8192 it is 1.15 both ways, which is data-side, as #7827 also notes. The tpr 4096 row and the switch ratios were measured on the earlier base, and the other rows on this branch.

A full 16-point sweep on the new revision stays within ±1.2% of the sweep above at every tpr. Low-tpr GEMM2 tile, buffer, and persistent sweeps (tpr 4, 16, 64), and S1F tile_n / tile_k / producer / BTH sweeps at tpr 64, found nothing better than the current rows.

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Accuracy, same shape, op_tests/multigpu_tests/bench_mega_moe.py --acc_verify 1 --layers 2 on 4× gfx1250: PASS at tpr 8, 512, 1024, 8192, 16384, and 32768. Average logits diff is 0.0423 against tolerance 0.0636. tpr 512 and 1024 were re-run on the deferred-scatter revision, and logits_diff is unchanged (0.042289 / 0.042290). The instruction-prefetch revision passes MEGA-CHECK at tpr 8192 with tile 256 forced, both with and without prefetch. The ISA shows s_setreg_imm32_b32 hwreg(HW_REG_MODE, 24, 1), s_getpc_b64, and the s_prefetch_inst chunks at entry, and the stage-1 and GEMM2 kernel names carry _ipf. Kernel names confirm the gate: tpr 8192 is t128 with no apre; tpr 16384 and 32768 are apre t256.

No MI250X or MI300X run. This schedule is gfx1250. Non-uniform routing, other EP sizes, and top-k other than 6 were not swept.

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

The packed path is an internal schedule of the existing mega stage-1 launch. s1f_prefill_tile documents AITER_MEGA_S1F_PREFILL_RECV.

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None. Receive bounds below 65536 keep the previous stage-1 tile. AITER_MEGA_S1F_PREFILL_RECV=0 disables the packed 256-tile path. Instruction prefetch is on by default for every gfx1250 a8w4 TDM GEMM and S1F launch, and changes their kernel names (_ipf), so cached JIT artifacts are rebuilt once. AITER_FLYDSL_INST_PREFETCH=0 restores the previous code. Grouped-MoE rows for other (gfx, token, model_dim, inter_dim, expert, topk) keys are unchanged, except the DSR1 65-expert rows, which move to dsr1_tuned_grouped_fmoe.csv with the same lookup key.

PR Self-Review

Reviewed revision

a85897e

Behavior and intent

Mega stage-1 on a large EP4 top-6 prefill step now writes and consumes packed A and runs the grouped-MoE 256³ prefill schedule. Row-major compact A could not use those loads, so the same GEMM flags did not make S1F faster. Steps under the recv threshold are unchanged. The missing 131072 grouped-GEMM row is what was sending tpr 32768 to a 64-row tile.

Validation and unverified scope

Command: torchrun --nproc_per_node=4 op_tests/multigpu_tests/bench_mega_moe.py -tpr <tpr> --layers 8 -e 384 -k 6 -hd 5120 -id 2304 --fused_shared_experts 0 --routing uniform -q a4w4_mxfp4 --dispatch_wire fp4 --stage1_fused true --stage2_fused true --warmup 5 --iters 5 on 4× gfx1250. Accuracy used --layers 2 --acc_verify 1 at tpr 8, 8192, 16384, and 32768 and passed. Results are in the performance table.

Instruction prefetch: AITER_MEGA_S1F_PREFILL_RECV=1 AITER_FLYDSL_INST_PREFETCH={0,1} torchrun --nproc_per_node=4 op_tests/multigpu_tests/bench_mega_moe.py -q a4w4_mxfp4 -e 384 -k 6 -hd 5120 -id 2304 --layers 4 -tpr 8192 --iters 10 --stage1_fused true --stage2_fused true, plus rocprofv3 --pmc SQC_ICACHE_MISSES on standalone stage-1 GEMMs launched alternately. Not yet measured for prefetch: the end-to-end model, tpr 16384 / 32768 (where tile 256 is the default), and GEMM2 I$ counters, which read 0 under rocprofv3, so for GEMM2 only the ISA and accuracy were checked.

Not run: MI250X, MI300X, zipf routing, EP other than 4, top-k other than 6, and the standalone grouped-GEMM preshuffle rows at tokens other than the mega sweep. num_buffers=4 and GEMM1 clustering stay off.

PR-specific question

Which exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?

Grouped-GEMM CSV keys that change are gfx1250, cu 256, model_dim 5120, inter_dim 2304:

  • expert 96, topk -1, tokens 8192, 16384, 32768: GEMM2 next_stage_prefetch=1 and lds_soa_load_interleave=1 only. Tile stays 128. Mega GEMM2 selects these ep-fused rows.
  • expert 96, topk -1, token 131072: new row, same 128-tile. This is the bucket _get_padded_m uses for tpr 32768. It did not exist, so that step previously missed and kept the caller's 64-tile default.
  • expert 96, topk 6, tokens 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384: new grouped-MoE rows. a_preshuffle=1 is only on tokens 4096, 8192, and 16384.
  • expert 97, topk -1, tokens 4 through 32768: new shared-expert rows.
  • expert 96, topk -1, ep_fused=1, fp4 A, tokens 2048 and 4096: new rows. Explicit ep_fused rows win only on the EP-fused (mega) lookup, so grouped MoE still selects the blank rows.

The deferred scatter needs EP scatter, bf16 combine, and persistent GEMM2 workers. In the current CSVs only these two DSV4.1 rows and two minimax rows set persistent_workers2, and the minimax rows are tile_m2=16, which is not eligible. So the new path runs only at DSV4.1 EP4 tpr 512.

Mega stage-1 does not read the topk-6 a_preshuffle bit. Its own gate is (world_size, topk) = (4, 6) and recv bound ≥ 65536, implemented in s1f_prefill_tile. The 8-layer sweep is the evidence for everything else: tpr 8192 still launches s1f_stage1_..._t128x256x256_w1x4_b3 with no apre, and tpr 1 through 4096 stay within 1.4% of the previous mega scan. Rows for other gfx, model dimensions, expert counts, or top-k values are not in the diff, so their lookup result is unchanged. The DSR1 65-expert rows moved file but keep the same key.

Instruction prefetch reaches every launch of s1f_stage1 and of the a8w4 TDM GEMM (mxfp4_preshuffle_gfx1250_tdm.py) on gfx1250, independent of CSV keys. Kernels under ~32 KiB already fit the launch window, so the extra chunks re-touch lines that are already resident. Running the prefetch costs a handful of scalar instructions per wave at entry, and the tpr 4096 mega run (default tiles) shows no change.

Changed op tests

op_tests/flydsl_tests/test_flydsl_grouped_gemm.py: test_shared_expert_byte_accounting and test_shared_expert_routing cover fused shared experts, which the existing routed-only cases do not. One shared expert is appended with unit weight and must not be counted as another routed weight read, and it must not change the renorm of the routed weights. The byte test checks a 2-token, 8-of-64 routed plus 1 shared case (16 routed weights plus one shared weight, not 18). The routing test checks tokens 1 and 16: the shared id is last, its weight is 1, routed weights still sum to 1, and routed ids stay inside the routed expert range. No mega stage-1 op test was added; that path is the multi-GPU bench_mega_moe.py --acc_verify 1 run above.

@XingerZhu
XingerZhu requested review from a team and a balanced review from Copilot November 13, 2026 07:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@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 7921 --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.

@aiter-bot

aiter-bot commented Nov 13, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision c2b6a47b3bea · 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.

Copilot AI balanced review requested due to automatic review settings November 13, 2026 16:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 16, 2026 07:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 16, 2026 08:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 16, 2026 09:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@JiaoliangYu

Copy link
Copy Markdown
Contributor

DeepSeek-V4-Pro (hidden 7168) dies in warmup on this branch: packed A is enabled for every tile_m 256 stage-1, but its store budget depends on hidden

I picked this branch up for 455-CI, where DeepSeek-V4-Pro currently fails on the slot_width <= 128 assert that #7973 fixes. With #7973 plus this branch, V4-Pro still dies in the first warmup forward, now on a check this PR adds:

File ".../mega_moe_gfx1250/s1f_ctl.py", line 590, in _precompile
File ".../mega_moe_gfx1250/s1f_ctl.py", line 511, in _launcher
    launch = make_s1f_stage1(
File ".../mega_moe_gfx1250/s1f_stage1.py", line 667, in make_s1f_stage1
    raise ValueError("an op's stores overflow the storecnt wait field")

All 4 ranks, in _precompile, i.e. while stage-1 builds GEMM1 for the tile the CSV resolved, not on a step that the new prefill bound admitted.

Why V4-Pro hits it and DSV4.1-Flash does not. _S1F_GEMM_OPTS = {256: {"a_preshuffled": 1, ...}} is applied in _launcher for any tile_m == 256, so packed A is on whenever stage-1 builds that tile. But OP_STORES scales with hidden, which nothing in that path checks (fp4 wire, WAVE=32, R=8, computed from this branch's formula with the geometry both models log):

model hidden payload e8m0 PAY_ITERS SC_ITERS OP_STORES OP_STORES + 3
DSV4.1-Flash 5120 2560 B 160 B 40 3 44 47 (ok)
DeepSeek-V4-Pro 7168 3584 B 224 B 56 4 61 64 > 63

On an fp4 wire the cutoff is hidden <= 7040, and 7168 is the first width past it. The model this path was tuned on (hidden 5120) has a wide margin, which is why the sweeps would not show it.

AITER_MEGA_S1F_PREFILL_RECV=0 does not avoid it. I tried that (the "off" the docstring describes, and s1f_prefill_tile does return 0 for it): same ValueError, same _precompile -> _launcher -> make_s1f_stage1 frames, 171 s after launch instead of 431 s. So on this geometry there is no env escape, and _S1F_PREFILL_MIN_RECV_BY_SHAPE is not the only way in: any step whose GEMM1 tile is 256 rows picks packed A up from _S1F_GEMM_OPTS.

Suggestion. The decision to pack A is made per tile_m, but whether the storer can wait on those stores is a function of hidden (and of the wire's payload and scale bytes). Computing OP_STORES where _S1F_GEMM_OPTS is applied, and leaving a_preshuffled=0 when OP_STORES + 3 > 63, would keep the wide-hidden models on the previous schedule instead of refusing to build. If the raise stays as a backstop, it would help for it to print the numbers (OP_STORES, hidden, payload and scale bytes): as it stands it names no shape, and the traceback runs through the FlyDSL JIT, so the geometry that overflowed is not visible.

Repro. Image rocm/fw-bringup-mlperf:gfx1250-atom-ci455-20261114 (aiter b6f1ff6b7, ATOM 9fec99786) on 4x gfx1250. aiter = image + #7973 + this branch's net diff (f858b48e6..a85897e1b, with the one V4.1-Flash CSV hunk skipped, as the image predates those rows). Weights deepseek-ai/DeepSeek-V4-Pro @ b5968e91. Server command verbatim from the 455-CI recipe: EP4 + DP attention, MEGA_DISPATCH_WIRE=fp4, ATOM_MEGA_STAGE1_FUSED=1, warmup 16384 tokens/rank. MegaMoE logs hidden=7168 inter=3072 experts=384 topk=6 M=16384 dispatch=compact wire=fp4.

For context, on the same image with only #7973 (already in main) V4-Pro comes up and scores GSM8K 3-shot 0.9492 flexible / 0.9500 strict, so this PR is not what unblocks V4-Pro; it is the next thing in its way.

Boss2002n and others added 4 commits November 20, 2026 07:45
…age-1 (#7919)

* Optimize FlyDSL grouped MoE kernels

* improve test

* support a preshuffle

* add csv support

* update quant and shuffle

* update

* update mega-moe

* update

* update csv

* update

* simplify code

* fix accuracy drop

* update csv

* fix format

* fix(flydsl): align A-preshuffle guards and AOT coverage

* improve cs test

* fix ruff

* Tune conc16384 benchmark with WPT2 and cluster sync disabled

* Add standalone conc16384 GEMM1 performance reproducer

Rename the benchmark to reproduce.sh and pin the validated zero-input configuration. Include standalone activation/quantization dependencies and tests so the script does not rely on stashed implementation changes. Preserve unrelated work in stash. GPU timing was not rerun for this commit.

* Tune grouped MoE LDS scheduling and prologue initialization

Use normal WMMA order with operand B reuse and precomputed payload LDS bases. Initialize accumulators before the prologue TDM wait and select WPT1 for the conc16384 tuned configuration.

Include the local benchmark scripts and the reproducer iteration update.

* Pin FlyDSL WMMA scale registers to disjoint low VGPR slots

* update

* update

* update

* remove useless tests

* add script

* update script

* update script and wheel

* update

* update1

* update

* Fix LDS helper shadowing after GEMM task refactor

* Simplify gfx1250 prefill scheduling and add reproducible MoE benchmarks

* Keep local GPU benchmark scripts and microtests out of the branch

* Restore LDS layout controls and decouple interleaving from scheduling

* Fix strict VGPR pinning with FlyDSL 0.5.0

Resolve sched_vgpr through rocdl.experimental on FlyDSL 0.5.0 while retaining compatibility with the older public API. Keep strict placement enabled for prefill kernels.

Validated DSV4 Pro conc16384 with three const/random runs at 32 iterations. Both GEMMs have zero scratch instructions and accumulator placement at physical v512-v1023; median const GEMM1/GEMM2 is 465.77/322.86 us.

* update for ds flash v4.1

* Tune DSV4.1 Flash 8192 prefill configuration

* update for release

* add csv

* update csv

* update csv for dsr1 fused expert

* Move DSR1 grouped MoE configs into a dedicated CSV

* remove useless csv

* update csv

* [FlyDSL] Simplify prefill WMMA emission and barriers

* Tune DSR1 65-expert (64 routed + 1 shared, topk 9) grouped MoE rows for 1-1024 tokens

The single 16x256x256 four-wave as-prologue row left gemm1 at ~16 TB/s for decode-sized
batches (three workgroup rounds, extra round at 4 tokens, and a 64-row tile that doubled
weight reads at 1024 tokens). Re-swept tiles and knobs for this shape on gfx1250:
narrower gemm1 tiles (tile_n 64/128) with deeper buffering for 1-32 tokens, as-prologue
kept only at 64 and 256 tokens where it measures faster, and 128x256 tiles at 1024 tokens.

gemm1+gemm2 vs the previous rows (test_flydsl_grouped_gemm, constant + uniform init):
1 tok 1.81x, 2 1.11x, 4 1.25x, 8-256 1.12-1.16x, 512 1.08x, 1024 1.38x; >= 2048 unchanged.

* Simplify FlyDSL KSL0 fence configuration and kernel symbols

* Merge PR #5899 (zxe/mega_stage1_compact_overlap) for local benchmarking

Co-authored-by: Cursor <[email protected]>

* mega: adapt S1F/GEMM2 to the MoE prefill path, tune DSV4.1 Flash EP4 buckets

- Pin VGPRs only for the 2x2 256^3 tile; S1F's 1x4 256 variant overflowed the map.
- S1F GEMM1 warp grid per tile_m (2x2 at 256, AITER_MEGA_S1F_WARPS override)
  and pass the GEMM kernel_attrs to the S1F launch.
- DSV4.1 Flash E96 rows: GEMM2 next_stage_prefetch + lds_soa_load_interleave
  at 8192+, add the missing 131072 bucket (tpr 32768: 3783 -> 3258 us/layer).

Co-authored-by: Cursor <[email protected]>

* [FlyDSL] [gfx1250] Pack GEMM1 A inside mega stage-1 for large prefill buckets

The stage-1 producer writes the M16 packed A layout, and the 256-row GEMM1
turns on a_preshuffle, lds_soa and next_stage_prefetch together with the
grouped-MoE prefill schedule. This runs only when the recv bound is at least
65536, which for EP4 top-6 is tpr 16384 and 32768. Payload and scale use
separate buffer resources so the masked store sentinel stays out of range.

DSV4.1 Flash EP4, 8-layer graph: 1654 vs 1704 us/layer at tpr 16384 (-2.9%)
and 3111 vs 3258 at tpr 32768 (-4.5%). Smaller buckets stay on the 128-tile path.

Co-authored-by: Cursor <[email protected]>

---------

Co-authored-by: yadaish <[email protected]>
Co-authored-by: JiaoliangYu <[email protected]>
Co-authored-by: lalala-sh <[email protected]>
Co-authored-by: hyi <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: XingerZhu <[email protected]>
…EP4 buckets

A persistent bf16 EP scatter now stages its rows in the last pipeline stage
and skips the tensor_wait after the remote gather-store (defer_c_wait): the
next tile's first fence retires it and the persistent loop drains at exit.
It turns on by itself when the rows fit there (tile_m > 32, > 2 buffers, no
planar LDS / A-scale prologue / k_waves); AITER_FLYDSL_EP_DEFER_C_WAIT=0
turns it off.

DSV4.1-Flash EP4 a4w4 fp4-wire, mega S1F+S2F, uniform routing, 3x A/B:
- tpr 512 (token 2048): persistent_workers2=512 -> GEMM2 57.6 -> 55.2 us,
  layer 217.0 -> 214.7 us (-1.1%).
- tpr 1024 (token 4096): num_buffer_stage2=3 -> GEMM2 81.2 -> 78.9 us.
Accuracy (layers=2) PASS at both with an unchanged logits_diff.

Co-authored-by: Cursor <[email protected]>
…8 dwords

FP4 256x256 at 1x4 needs 160 dwords and asserts in make_rmem_slot. Gate the
explicit map on the same slot width, so that shape stays on the ordinary
allocator while 2x2 (128 dwords) keeps the pinned schedule.

Co-authored-by: Cursor <[email protected]>
A launch preloads only the first ~32 KiB of a kernel into the
instruction cache. The S1F tile-256 kernel (~46 KiB) and the stage-1
GEMM (up to ~62 KiB) ran their tails cold whenever another large kernel
had evicted them, so UT gains did not always show up end to end.

Add prefetch_kernel_code(num_waves) to gemm_common_gfx1250, following
#7827: set MODE.SCALAR_PREFETCH_EN through llvm.amdgcn.s.setreg, find
the kernel span with s_getpc_b64 and .Lfunc_end0, and have each wave
issue every num_waves-th 4 KiB s_prefetch_inst chunk up to 56 KiB,
without branches. S1F replaces its old inline-asm prefetch, which was a
no-op without MODE[24]; the a8w4 TDM GEMM calls it at kernel entry and
tags the kernel name with _ipf. AITER_FLYDSL_INST_PREFETCH=0 turns it off.

Co-authored-by: Cursor <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 20, 2026 07:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 23, 2026 09:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@zufayu
zufayu requested a review from GwilliamHu November 24, 2026 01:18
@zufayu zufayu assigned GwilliamHu and unassigned yadaish Nov 24, 2026
# Conflicts:
#	aiter/ops/flydsl/kernels/mxfp4_preshuffle_gfx1250_tdm.py
Copilot AI balanced review requested due to automatic review settings November 25, 2026 07:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@junhaha666
junhaha666 merged commit 4120f98 into main Nov 26, 2026
61 checks passed
@junhaha666
junhaha666 deleted the zxe/mega_update_moe branch November 26, 2026 09:49
coderfeli pushed a commit that referenced this pull request Dec 2, 2026
…orecnt (#8889)

#7921 widens S1F prefill to tile 256 with packed A (a_preshuffled) keyed by
(world_size, topk) only. For DeepSeek-V4-Pro (hidden 7168, fp4 wire) one
packed-A storer op issues 61 VMEM stores, 61 + 3 > 63 overflows the 6-bit
s_wait_storecnt field, make_s1f_stage1 raises in _precompile and the server
fails to start.

Gate packed A on one helper (s1f_packed_a_fits) shared by _launcher,
launch_args (scale layout), _s1f_warps, s1f_prefill_tile and the compact
plan tile alignment, so they always agree. When it does not fit,
s1f_prefill_tile returns 0 and the 256 variant runs without packed A on 1x4
warps. The prefill threshold table is now keyed by hidden size as well.

Verified on the V4-Pro MoE shape (EP2, fp4 wire, S1F): forced prefill
widening and AITER_TDM_TILE_M=256 both pass accuracy; V4.1-Flash still
builds the packed-A 2x2 tile-256 variant and passes.
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.

8 participants