Skip to content

[FlyDSL] [gfx1250][MegaMoE] EP8 and EP16 mega tuning + stage1-fused flag-tile fix - #8189

Merged
XingerZhu merged 18 commits into
mainfrom
zxe/tune_mega_ep8_ep16
Dec 1, 2026
Merged

XingerZhu merged 18 commits into
mainfrom
zxe/tune_mega_ep8_ep16

Conversation

@XingerZhu

@XingerZhu XingerZhu commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Tune the gfx1250 MegaMoE grouped-fmoe config for two EP8 (expert=48, ep_fused=1, fp4/fp4, per_1x32) workloads and for DSV4.1 Flash at EP16 (expert=24), allow the both-fused path at world size 16, fix the stage-1-fused flag-tile handling for tile_m not divisible by FLAG_M, and make the bench driver usable for 61-layer both-fused runs on HIP's classic graph path.

Motivation

  • The EP8 and EP16 shapes had no tuned rows, so they fell back to the default tile (tile_m=64, stage1 64x256x128, stage2 64x256x128). Tuning gives a measurable gain on the EP8 shapes and on DSV4.1 Flash EP16 at every decode tpr except 256.
  • Stage-1 fusion refused world_size > 8, because the per-tile source mask (tile_src) was 8 bits wide. EP16 could only run with stage-1 fusion off.
  • s1f_flag_m returned min(tile_m, FLAG_M), which is wrong for tile_m values FLAG_M does not divide (e.g. 96). This patch falls back to FLAG_M_SMALL=32 (96 = 3 x 32).
  • The 61-layer both-fused bench segfaults in libkineto::RoctracerActivityApi::processActivities during the torch profiler stopTrace, once the classic-graph profile pass holds a few dozen stage1-fused layers. The profile pass now captures at most AITER_BENCH_PROFILE_LAYERS (default 8) layers, and its per-layer numbers are scaled back to the full chain. The timing pass and accuracy check still run all layers.

Changes

  • aiter/configs/tuned_grouped_fmoe.csv: 3 rows, hidden=7168, inter=3072, expert=48, topk=-1, ep_fused=1, tokens 1024 / 2048 / 4096 (EP8 tpr 128 / 256 / 512).
  • aiter/configs/model_configs/dsv41_flash_tuned_grouped_fmoe.csv:
    • EP8: 13 rows, hidden=5120, inter=2304, expert=48, topk=-1, ep_fused=1. Tokens 8-512 (decode tpr 1-64) set tile_m=tile_m2=16 and tdm_b_th=1. Tokens 1024 / 2048 (tpr 128 / 256) keep their earlier rows. Token 4096 (tpr 512) is the default tile plus tile_k2=256. The token 8192 (prefill tpr 1024) row is the default tile plus tile_k2=256. Tokens 16384 / 32768 (prefill tpr 2048 / 4096) add tile_n2=512 to that. Wider steps fall back to the token 32768 row, which keeps them off the token 2048 row (tdm_b_th=1, about 8% slower there) and is within noise of the token 8192 row at tpr 8192 / 16384.
    • EP16: 13 rows, same dims, expert=24. Tokens 16-512 (tpr 1-32) set tile_m=tile_m2=16 and tdm_b_th=1. Tokens 1024 / 2048 (tpr 64 / 128) set tdm_b_th=1. Token 8192 (tpr 512) sets tile_k=256 and tile_k2=256. Tokens 16384-131072 (prefill tpr 1024-8192) are the default tile plus tile_k2=256 and tile_n2=512; wider steps fall back to the token 131072 row. Token 4096 (tpr 256) is intentionally left on the default: no candidate beat it by more than 0.3%.
  • aiter/ops/flydsl/kernels/mega_moe_gfx1250/compact_plan.py, s1f_ctl.py, s1f_stage1.py: widen tile_src to a 16-bit source mask for npes > 8. The tile word becomes srcmask[15:0] | expert[23:16] | rows[31:24] (rows <= 127), the stage-1 epilogue loads one b128 per four sources, and blocking_reasons now rejects only world_size > 16. The npes <= 8 layout is unchanged.
  • aiter/ops/flydsl/kernels/mega_moe_gfx1250/s1f_ctl.py: _S1F_MAX_RECV_BY_SHAPE[(8, 6)] and [(16, 6)] are 1 << 30, as for EP2 / EP4, so EP8 and EP16 top-6 steps run stage-1 fused at every width instead of falling back to dispatch + GEMM1 above the default 4096 receive cap.
  • aiter/ops/flydsl/kernels/mega_moe_gfx1250/s1f_stage1.py: s1f_flag_m plus the FLAG_M_SMALL constant.
  • op_tests/multigpu_tests/bench_mega_moe.py: profile-pass layer cap (AITER_BENCH_PROFILE_LAYERS, default 8) and the matching per-layer rescale.

Performance (if applicable)

EP8

Two nodes x 4 GPUs (g13-06 + g13-08, 8 ranks), gfx1250, a4w4_mxfp4, dispatch_wire=fp4, 61 layers, 10 timed replays. Before is stage1_fused=false and stage2_fused=false (mori dispatch + mori combine, default tiles). After is both stages fused with the tuned CSV. Median per-layer time:

Hardware Workload tpr Unfused (µs/layer) Tuned fused (µs/layer) Change
gfx1250 x8 hidden 7168 / inter 3072 / E 384 / top6 (EP8) 128 236.1 185.7 -21.3%
gfx1250 x8 same 256 254.1 205.3 -19.2%
gfx1250 x8 same 512 317.4 263.7 -16.9%

Accuracy is PASS on every completed run (logits tol 0.712). The DSV4.1 Flash unfused baseline (hidden 5120 / inter 2304) did not finish: both tpr 128 and tpr 256 hung with the GPUs busy and no result after 7 minutes, so that shape is not in this table. Its tuned-fused times, measured separately, are 130.2 µs/layer at tpr 128 and 143.2 at tpr 256.

EP8 decode (DSV4.1 Flash)

Two nodes x 4 GPUs (g13-06 + g13-08, 8 ranks), same recipe, 8 layers, 10 timed iterations, both stages fused (AITER_S1F_MAX_RECV=0 so every width runs fused). 15 candidates interleaved with 16 default-tile reference runs; each candidate is compared with the reference run next to it. Per-layer time:

Hardware tpr (recv tokens) Default tile (µs/layer) Tuned row (µs/layer) Change
gfx1250 x8 1 (8) 78.3 69.4 (tile_m=16, tdm_b_th=1) -11.4%
gfx1250 x8 2 (16) 81.3 74.1 (same) -8.8%
gfx1250 x8 4 (32) 92.7 83.7 (same) -9.7%
gfx1250 x8 8 (64) 115.2 103.7 (same) -10.0%
gfx1250 x8 16 (128) 132.0 122.7 (same) -7.0%
gfx1250 x8 32 (256) 137.2 126.9 (same) -7.5%
gfx1250 x8 64 (512) 140.4 127.9 (same) -8.9%
gfx1250 x8 512 (4096) 184.8 178.6 (tile_k2=256) -3.3%
gfx1250 x8 1024 (8192) 271.8 (unfused, 4096 cap) 248.9 (fused, existing tile_k2=256 row) -8.4%

At tpr 512, two further samples of the same config gave -2.4% / -2.6% (the CSV us column records the 179.5 mean of the three). At tpr 1024 the fused default tile gives 254.4 and the unfused path 271.8 / 274.9, one of the reasons the EP8 cap is dropped. With the committed CSV and no env override, a profiled run confirms tpr 1-1024 run stage 1 fused with the new tiles (tpr 1 / 8 / 64 / 512 / 1024: 73.2 / 106.1 / 131.8 / 181.0 / 251.4 µs/layer on the profiling path, about 3% above the timed numbers). Every candidate's output matched the reference exactly (rel diff 0).

EP8 prefill (DSV4.1 Flash)

Two nodes x 4 GPUs (g13-06 + g13-08, 8 ranks), same recipe, 8 layers, 10 timed iterations, stage-1 fusion forced on for every width with AITER_S1F_MAX_RECV=0 (by default EP8 caps it at a 4096 receive bound). Per-layer time:

Hardware tpr (recv tokens) Default tile (µs/layer) Tuned row (µs/layer) Change
gfx1250 x8 1024 (8192) 255.5 250.5 (tile_k2=256) -2.0%

Mean of two interleaved repeats.

Without the cap, tpr 2048 / 4096 also run stage-1 fused. Compared with the previous path (at the time an 8192 cap, so dispatch + GEMM1 unfused, token 8192 row), interleaved on the same two nodes with no env override for the baseline:

Hardware tpr (recv tokens) Previous path, unfused (µs/layer) Fused + tile_k2=256 + tile_n2=512 (µs/layer) Change
gfx1250 x8 2048 (16384) 406.7 361.0 -11.2%
gfx1250 x8 4096 (32768) 667.8 576.5 -13.7%

Mean of three repeats (-11.0 / -11.2 / -11.5% and -13.5 / -13.7 / -13.8%). Fused with only tile_k2=256 gives -9.6% to -10.6% and -12.5% to -12.9%, so tile_n2=512 adds about 1%. Fused default tile gives -7.9% / -12.5%. The best unfused candidate (tile_m 128, tile_k=256, tile_k2=256) gives -8.5% / -9.4%. Fused tile_m=32 at these widths gave a wrong result (rel diff inf) and is not used; the token 1024 row's tile_m=32 was checked at its own width (rel diff 0). Wider steps fall back to the token 32768 row; unfused there it is within noise of the token 8192 row, and fused it is within 1% of the default tile (see below).

In the forced-fused sweep, tpr 8192 and 16384 had no candidate beyond the noise (within 0.6% of the default). Larger tiles (tile_m 96 / 128 / 256) are 7-31% slower: with 8 ranks the stage-1 kernel only takes tile_m <= 64, so those steps run dispatch + GEMM1 unfused. tile_k=256, num_buffers=3 and tile_n2=512 gave no stable gain.

EP16 (DSV4.1 Flash)

Four nodes x 4 GPUs (g13-04, 05, 06, 08; 16 ranks), gfx1250, hidden 5120 / inter 2304 / E 384 / top6, uniform routing, a4w4_mxfp4, dispatch_wire=fp4, stage1_fused and stage2_fused both requested, default stage-1 receive cap (4096), 8 layers, 10 timed iterations. tpr 1-256 run both stages fused. tpr 512 has an 8192 receive bound: its default-tile baseline is the pre-PR path (dispatch + GEMM1 unfused at the 4096 cap), and its tuned number is the stage-1-fused path this PR enables. The baseline is the default tile. There is no fully unfused EP16 baseline. Per-layer time:

Hardware tpr (token) Default tile (µs/layer) Tuned row (µs/layer) Change
gfx1250 x16 1 (16) 77.0 69.2 (tile_m=16, tdm_b_th=1) -10.0%
gfx1250 x16 2 (32) 80.0 71.8 (same) -10.3%
gfx1250 x16 4 (64) 87.5 78.8 (same) -10.0%
gfx1250 x16 8 (128) 96.3 86.8 (same) -9.9%
gfx1250 x16 16 (256) 108.7 97.8 (same) -10.0%
gfx1250 x16 32 (512) 109.5 99.8 (same) -8.9%
gfx1250 x16 64 (1024) 112.5 106.9 (tdm_b_th=1) -4.9%
gfx1250 x16 128 (2048) 120.5 114.1 (tdm_b_th=1) -5.3%
gfx1250 x16 256 (4096) 138.4 default 0%
gfx1250 x16 512 (8192) 202.0 (unfused) 175.0 (fused, tile_k=256, tile_k2=256) -13.4%

Sweep scope: tpr 1, 2, 4, 8, 16, 32, 64, 128, 256 and 512, with 12 candidates over tile_m (16 / 32 / 64), tile_n, tile_n2, tile_k, tile_k2, tdm_b_th and num_buffers. At tpr 1-32, tile_m=16 alone gives -2% to -5% and tdm_b_th=1 alone -4% to -7.5%; together they give -9% to -10%. From tpr 64 up, tile_m=16 is slower (+5% at tpr 64, +15% at tpr 128, +29% at tpr 256). tdm_b_th=1 at tpr 128 was measured at -4.8% in a separate earlier run. A confirmation run repeated the tpr 512 candidates twice: tile_k=256 alone gave -4.3% / -3.6%, tile_k2=256 alone -2.5% / -2.8%, both together -7.9% / -8.4%, and tdm_b_th=1 +6.7% / +5.4%. Fused at tpr 512, the same row gives 175.7 / 174.3 against 187.1 / 184.5 unfused (interleaved), and only tile_k2 matters there: the stage-1 kernel runs its own 256 K tile, so tile_k2=256 alone gives the same 174.2 / 175.9. With an 8192 cap and no override, the row gives 175.2 / 174.0. Other fused candidates did not help: tile_m 32 / 16 +10% / +40%, tdm_b_th=1 +7%, tile_n2=512, num_buffers=3 and AITER_S1F_GROUP_M 4 / 16 within 1%. tile_n=128 is rejected at tpr 512 by the stage-1 quant check (stage1 quant requires complete four-WMMA N groups). Every candidate's output matched the first reference run exactly (rel diff 0).

Candidate tiles were compared in-process with interleaved reference runs, because in-process timing drifts by about 5% across a sweep.

Stage-1 fusion without a receive cap (EP8 / EP16 prefill)

Each step compares the committed row run fused (no env, no cap) with the same row on the previous capped path (AITER_S1F_MAX_RECV set to the old cap, so dispatch + GEMM1 unfused), interleaved with default-tile references, two repeats each. EP8: g13-06 + g13-08, EP8 rows (token 32768 row at these widths). EP16: g13-04, 05, 06, 08, EP16 token 8192 row. Per-layer time, mean of the two repeats:

Hardware tpr (recv tokens) Previous cap, unfused (µs/layer) No cap, fused (µs/layer) Change
gfx1250 x8 8192 (65536) 1206.7 1014.0 -16.0%
gfx1250 x8 16384 (131072) 2267.0 1935.6 -14.6%
gfx1250 x16 1024 (16384) 280.0 256.4 -8.4%
gfx1250 x16 2048 (32768) 439.3 384.3 -12.5%
gfx1250 x16 4096 (65536) 742.2 623.6 -16.0%
gfx1250 x16 8192 (131072) 1405.0 1174.1 -16.4%

Fused, the committed rows are within 1% of the fused default tile at these widths (EP8 -0.8% / -0.9%; EP16 -1.0% to +1.1%, the EP16 token 8192 row's tile_k=256 / tile_k2=256 being +0.4% to +1.1% at tpr 4096 / 8192). Fallbacks (recv_bound ... > cap) appear only for the old-cap candidates. Every output matched the reference exactly (rel diff 0). The EP16 token 8192 row used here is replaced at these widths by the prefill rows below.

EP16 prefill (DSV4.1 Flash)

Four nodes x 4 GPUs (g13-04, 05, 06, 08), same recipe, stage 1 fused at every width (no cap), 8 layers, 10 timed iterations, 14 candidates interleaved with fused default-tile references. Per-layer time, mean of two repeats of the chosen row:

Hardware tpr (recv tokens) Fused default tile (µs/layer) tile_k2=256 + tile_n2=512 (µs/layer) Change
gfx1250 x16 1024 (16384) 258.4 255.6 -1.1%
gfx1250 x16 2048 (32768) 386.4 377.3 -2.4%
gfx1250 x16 4096 (65536) 620.7 607.7 -2.1%
gfx1250 x16 8192 (131072) 1163.6 1140.0 -2.0%

Repeats: -0.9 / -1.2%, -2.3 / -2.5%, -2.2 / -2.0%, -1.9 / -2.1%. At tpr 1024 the gain is within the run-to-run spread (a repeated default-tile candidate gave +0.1 / -1.4%). tile_n2=512 alone gives -0.7% to -1.8% and tile_k2=256 alone -1.2% to +1.2%. The token 8192 row (tile_k=256, tile_k2=256) these widths fell back to gives 0.0% to +0.9%. Slower: tdm_b_th=1 +5% to +9%, tile_m2=128 +11% to +16%, tile_n2=128 +2% to +7%; num_buffers=3 and num_buffer_stage2=3 within 1.2%. Every output matched the reference exactly (rel diff 0).

Testing

  • Unit tests added or updated: none. The config-shape collision test op_tests/tuning_tests/test_config_shape_collision.py passes (33 OK) on this tree, including the new rows.
  • Performance benchmarks run: yes, the tables above.
  • Tested on MI250X: no.
  • Tested on MI300X: no.
  • Tested on gfx1250 (2 nodes x 4 GPUs for EP8, 4 nodes x 4 GPUs for EP16): yes, with lab copies of the bench and stage-1 files. See unverified scope below.

Documentation

  • No documentation change is needed. The bench driver's behavior change is explained in its docstring/comment at the constant definition, and the 16-bit tile word layout is documented in the compile_tdm_compact_plan docstring.

Dependencies

  • No new third-party dependencies added.

Breaking Changes

  • None. The new CSV rows only match the EP8 (expert=48) and EP16 (expert=24) ep_fused=1 fp4/fp4 keys. The 16-bit tile word is used only when npes > 8, which stage-1 fusion previously refused. EP8 and EP16 top-6 steps with a receive bound above 4096 now run stage-1 fused at every width (up to 131072 measured); their output is identical to the unfused path in the runs above. AITER_S1F_MAX_RECV still restores a cap. The bench's profile-pass cap only affects the kernel-breakdown table when --stage1_fused is on and the chain is longer than 8 layers.

PR Self-Review

Reviewed revision

c2fc7e8

Behavior and intent

The PR changes four things: (1) new EP8 and EP16 grouped-fmoe rows that select tuned tiles, (2) stage-1 fusion now works at world size 9-16 through a 16-bit source mask, and EP8 / EP16 top-6 keep it on at every width, (3) s1f_flag_m handles tile_m values that FLAG_M does not divide, and (4) the bench driver caps its profile pass. The existing behavior is insufficient because the unfused path is 17-21% slower than tuned both-fused on the 7168 EP8 shape, EP16 could not run both-fused at all, the default tile is 5-10% slower than the tuned rows at DSV4.1 Flash EP16 decode (every tpr except 256), EP8 prefill steps fell back to a decode row that is about 8% slower than the default there, the flag function gave a wrong flag-tile size for tile_m=96, and the 61-layer both-fused bench crashed in the torch profiler.

Validation and unverified scope

Validated: the gfx1250 runs in the tables above, the config collision test, and compile checks. Unverified:

  • The exact committed files were not re-run on hardware. The GPU runs used the same CSV rows, with the bench driver, s1f_stage1.py and s1f_ctl.py from the lab working copy. Those lab copies contain extra experimental env hooks that this PR does not include. The world-size-16 logic in compact_plan.py is the same as the lab copy; only its docstring differs.
  • The EP8 prefill numbers were taken with stage-1 fusion forced on (AITER_S1F_MAX_RECV=0). With no cap, that is now the default path. Widths past 131072 receive tokens (EP8 tpr > 16384, EP16 tpr > 8192) were not run fused.
  • The GPU image's aiter maps tokens in [32768, 131072) to the 32768 bucket, while this branch and main use plain powers of two. The sweeps keyed candidate rows at the image's bucket; on this branch the same steps look up the plain power of two, and the committed row there has the same config (EP8 tpr 8192 falls back to the token 32768 row; EP16 tpr 4096 uses the token 65536 row).
  • The flag-tile fix is not exercised by these rows (tile_m is 16, 32 or 64, where old and new behavior agree).
  • Not tested: MI250X, MI300X, world sizes between 9 and 15, and tile_m=96 at runtime.

PR-specific question

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

The new rows match only on gfx1250, cu_num 256, expert=48 or 24, topk=-1, ep_fused=1, fp4 activation / fp4 weight, Silu, per_1x32, and the listed model_dim/inter_dim/token. Existing rows for expert 48 in these files use fp8 activation with ep_fused blank, and existing rows for other expert counts and dims are untouched, so they keep their previous selection. Evidence: in the run logs, grouped CSV config selected appears only for the target shape and token; other tokens of the same shape (for example EP16 token 4096) still print grouped CSV config miss and use the defaults. A CPU-only lookup of EP16 tokens 16-131072 against the committed CSV returns the intended row for each token and no row for 4096 (262144 falls back to the token 131072 row); for EP8 tokens 8-32768 it returns the intended row, and wider tokens fall back to the token 32768 row.

Changed op tests

  • op_tests/multigpu_tests/bench_mega_moe.py is the multi-GPU MegaMoE benchmark driver, not a unit test. It is the only tool that runs the 61-layer both-fused chain and reports the accuracy check used for the EP8 table. The change is needed because the profile pass otherwise crashes at 61 layers. No other test covers this path, so it is not redundant.

- tuned_grouped_fmoe.csv: EP8 (expert=48, ep_fused=1, fp4/fp4) rows for the
  hidden=7168 inter=3072 E=384 top6 shape at token 1024/2048/4096 (tpr 128/256/512).
- model_configs/dsv41_flash_tuned_grouped_fmoe.csv: EP8 rows for DSV4.1 Flash
  (hidden=5120 inter=2304) at tpr 128/256; tpr 512 keeps the default (no gain).
- s1f_stage1: s1f_flag_m handles tile_m not divisible by FLAG_M (e.g. 96) by
  falling back to FLAG_M_SMALL=32 instead of min(tile_m, FLAG_M).
- bench_mega_moe: cap the torch-profiler pass at AITER_BENCH_PROFILE_LAYERS
  (default 8) layers and scale its per-layer numbers back to the full chain;
  works around a kineto/roctracer SIGSEGV in stopTrace on the HIP classic graph
  path with a large fused chain.

Co-authored-by: Cursor <[email protected]>
@XingerZhu
XingerZhu requested review from a team and a balanced review from Copilot November 18, 2026 12:13

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 8189 --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.

@github-actions github-actions Bot changed the title [gfx1250][MegaMoE] EP8 and EP16 mega tuning + stage1-fused flag-tile fix [FlyDSL] [gfx1250][MegaMoE] EP8 and EP16 mega tuning + stage1-fused flag-tile fix Nov 18, 2026
@aiter-bot

aiter-bot commented Nov 18, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 952ee0a9c8e8 · 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
  • FAIL — changed op test not explained in Changed op tests: op_tests/tuning_tests/test_grouped_ep_fused_lookup.py

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

EP16 (expert=24) missed the fused fp4 table and fell back to the default
tile. The 4-node sweep is faster with tdm_b_th=1 at tpr 128 and with
stage2 tile_k=256 at tpr 512; tpr 256 stays on the default.
Copilot AI balanced review requested due to automatic review settings November 18, 2026 12:47

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.

tile_src was an 8-bit source mask, so both-fused MegaMoE refused npes>8.
Widen it to 16 bits: npes>8 packs srcmask in the low half and rows in the
top byte, and the epilogue loads one b128 per four sources.
Copilot AI balanced review requested due to automatic review settings November 18, 2026 13:13

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.

With stage1_fused and stage2_fused both on, stage1 tile_k=256 together
with stage2 tile_k2=256 is about 8% faster than the default tile at tpr
512 (185 vs 202 us/layer over two interleaved repeats). The previous row
had only tile_k2=256, which is about 2.6% faster. The tpr 128 row stays
on tdm_b_th=1: every candidate there is within 0.6% of the default.
Copilot AI balanced review requested due to automatic review settings November 19, 2026 09:14

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.

With stage1_fused and stage2_fused both on, EP16 (expert=24) tpr 1-32
(tokens 16-512) are about 9-10% faster with tile_m=tile_m2=16 and
tdm_b_th=1, and tpr 64 (token 1024) about 5% faster with tdm_b_th=1 on
the default 64-row tile. tpr 256 (token 4096) stays on the default: no
candidate beat it by more than 0.3%.
Copilot AI balanced review requested due to automatic review settings November 19, 2026 09:31

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.

EP8 (expert=48) prefill steps larger than the largest tuned token fell
back to the token 2048 row, whose tdm_b_th=1 and num_buffers=3 are 7.5-8.6%
slower than the default tile at tpr 1024 and tpr 8192. Add a token 8192 row
with the default tile plus tile_k2=256: 1.5-2.5% faster at tpr 1024, and
level with the default at tpr 2048-16384, so wider steps fall back to it.
Measured on 2 nodes x 4 GPUs with stage-1 fusion forced on
(AITER_S1F_MAX_RECV=0).
Copilot AI balanced review requested due to automatic review settings November 19, 2026 10:10

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.

… bound

At 512 tokens/rank EP16 has an 8192 receive bound, which the default
4096 cap sent down the dispatch + GEMM1 path. Fused, the same tuned row
runs 175 vs 186 us/layer on DSV4.1 Flash (4 nodes x 4 GPUs), with
identical output. Wider EP16 steps keep the default cap: they are not
measured.
Copilot AI balanced review requested due to automatic review settings November 19, 2026 10:55

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.

gbyu-amd pushed a commit that referenced this pull request Nov 26, 2026
…P8 bucket-4096 rows (#8189 @ 1e974a9, head 2026-11-26T08:13:42Z)

#8189's commits after c2fc7e8 (k3-455-dev has #8189 up to it):
c1d1fe5 black formatting in s1f_stage1.py; 6f5b68b run stage-1 fused with
tile_m 128 on EP5..EP8; d029b0f tune the Kimi-K3 EP8 bucket-4096
grouped-fmoe row; 1e974a9 split that row at 3072 tokens.
gbyu-amd pushed a commit that referenced this pull request Nov 26, 2026
…ath (TP8EP8) (#8259 @ 9a2194a, head 2026-11-19T05:04:37Z)

Kimi-K3 served as TP8 attention with the MoE expert-parallel over the same 8
GPUs (ATOM --enable-expert-parallel, DP 1) calls fused_moe with an expert
mask: 112 local experts of 896, inter_dim 3072, SiTUv2, A4W4 MXFP4 per_1x32,
GUGU weights. The grouped lookup keys that call as expert=112, topk=-1,
ep_fused=0, so it shares the kimik3 rows with the MegaMoE stage-2 scatter
(ep_fused=1); token buckets 1, 2 and 4 had no row at all.

Add 14 rows with ep_fused=0 for token buckets 1..8192. Rows that name
ep_fused win the lookup for that path only, so the MegaMoE path keeps the
existing rows. Buckets 16384 and 32768 keep the existing rows: no swept tile
beat them beyond run-to-run noise.

Swept with the production call (fused_moe with expert_mask, SiTUv2 beta 4 /
linear 25, GateMode.INTERLEAVE, moe_shuffle_weight / moe_shuffle_scale,
random top-16 routing over 896 experts); every candidate's output is
bit-identical to the existing row's. MoE kernel time per call (sum of the
device kernels of one fused_moe, median of 7 interleaved rounds, one GPU):

  token  existing us -> new us
      1     29.1 ->  24.5  (1.19x, existing: no row)
      2     28.2 ->  23.1  (1.22x, existing: no row)
      4     35.0 ->  24.2  (1.45x, existing: no row)
      8     36.1 ->  30.3  (1.19x)
     16     55.4 ->  47.0  (1.18x)
     32     74.6 ->  65.1  (1.15x)
     64     98.4 ->  90.1  (1.09x)
    128    132.4 -> 122.3  (1.08x)
    256    142.1 -> 131.0  (1.08x)
    512    146.4 -> 140.7  (1.04x)
   1024    157.3 -> 147.3  (1.07x)
   2048    175.3 -> 170.0  (1.03x)
   4096    242.0 -> 235.7  (1.03x)
   8192    387.8 -> 353.0  (1.10x)

Measured on MI455X (gfx1250, 256 CU) in rocm/fw-bringup:gfx1250-atom-k3-20261116
(aiter 69d86f590, FlyDSL 0.5.0).

Conflict: kept both new rows of the Kimi-K3 CSV (#8189's 3072 row, this 2048 ep_fused=0 row).
…uckets 2048/8192

- The grouped-fmoe row's tdm_b_th now reaches the stage-1 fused kernel's
  embedded GEMM1 (it was hard-coded to 0 in s1f_stage1.py). The launcher
  and precompile keys carry it, so each (tile, act, wmma rep, tdm_b_th)
  gets its own launcher.
- Kimi-K3 EP8 grouped-fmoe CSV:
  - token 3072 row: tdm_b_th 0 -> 1.
  - token 2048 row (Situv2): tile_m 32 (g1 32/256/256, g2 32/512/128).
  - token 8192 row (Situv2): tile_m 128 (g1 128/256/256 2x4 b3,
    g2 128/512/256 1x8 b2).
- S1F EP8 top-16 cap raised from 4096 to 8192 so bucket 8192 runs
  stage-1 fused.

Two-tray EP8 (node 0 + node 1, Silu, fp4 dispatch, bf16 combine), per-layer
us, MEGA-CHECK PASS on every row:
- tpr 160 (bound 1280, bucket 2048): 212.2 -> 205.8.
- tpr 640 (bound 5120, bucket 8192): 370.8 -> 291.6 (was falling back to
  the non-fused path because 5120 > 4096).
- tpr 1024 (bound 8192, prefill-sized receive bound): 472.5 -> 406.1.

Startup cost: the tile-128 stage-1 variant at bucket 8192 is compiled
once more on first use; wall time for the tpr 1024 run grew by about 24 s.

Not re-measured with this change: tpr 320 (bound 2560) and EP16.
Copilot AI balanced review requested due to automatic review settings November 27, 2026 08:12

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.

yanboshao added a commit that referenced this pull request Nov 29, 2026
The megakernel admitted only a hidden size that is a multiple of 1024 and only
Silu / Swiglu, which kept Kimi-K3 (hidden 3584, inter 3072, SiTUv2) on the
staged path.

- hidden: the sender quant gives each lane ceil(H / 32 / 32) 32-column groups;
  on a partial last slab (NGL < 32 groups, 16 at 3584) its idle lanes reread a
  group of the previous slab and store nothing, and only NGL / 4 lanes store
  the e8m0 dwords. A hidden that is a multiple of 1024 builds the same code
  as before. The admission now asks for a multiple of 512 (the reduce chunk).
- SiTUv2: stage-1 act 3, the builder's, with beta and linear_beta as kernel
  arguments; MegaMoE reads them once as floats.

Kimi-K3, EP4 simulating EP16 (-e 224 --sim_ep 16), SiTUv2, 8 layers, steady
state, uniform routing, us/layer with the bench's glue, against the staged S1F
of the K3 image tuned for EP16 (#8189 166c128 + its K3 rows,
AITER_S1F_MAX_RECV=0): 128 tokens 165.8 / 155.6, 320 192.7 / 209.8,
384 196.8 / 218.8, 448 216.7 / 245.3, 512 243.3 / 274.3. Accuracy passes at
every point.

Co-Authored-By: Claude <[email protected]>
yanboshao added a commit that referenced this pull request Nov 29, 2026
Kimi-K3 has many experts a rank (56 at EP16, 112 at EP8) and few rows each,
so compact's 128-row tile runs mostly empty well past the default 256-token
switch to it. Slots now serves K3 steps up to a 768-token per-rank bound, as
it does Flash.

K3, SiTUv2, EP4 simulating EP8 / EP16, steady state, uniform routing, us/layer
with the bench's glue, slots / compact by per-rank bound: 512 138.8 / 165.8,
640 216.8 / 252.3, 768 150.0 / 171.4 (EP16) and 230.7 / 256.0 (EP8),
896 274.1 / 273.6, 1024 187.1 / 178.1 (EP16) and 314.6 / 281.8 (EP8).

Against the K3 image's S1F tuned for EP16 / EP8 (#8189 166c128 +
its K3 rows): EP16 128 tokens 138.9 / 155.6, 192 150.1 / 171.1, 256 179.8 /
179.3; EP8 320 216.8 / 229.7, 384 231.2 / 243.8, 448 274.8 / 270.8.

Co-Authored-By: Claude <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 30, 2026 07:50

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 30, 2026 08:39

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.

yanboshao added a commit that referenced this pull request Nov 30, 2026
Needs the previous commit: at EP16 the stage-1 kernel did not take tile 128
before it.

- S1F cap for (world 16, topk 16): 8192 -> 16384 (tpr 1024, the widest bound
  measured).
- Expert-56 rows, ep_fused=1 (MegaMoE only; the non-fused path keeps its
  rows):
  - token 3584 (splits bucket 4096, receive bounds 2049..3584 = tpr
    129..224): the bucket-4096 row on tile 64/64.
  - token 6144 (bounds 4097..6144 = tpr 257..384): tile 64/64 -> 128/128,
    tile_k2 stays 128.
  - token 8192 (bounds 6145..8192 = tpr 385..512): the bucket-8192 row on
    tile 128/128.
  - Buckets 4096 and 16384 keep their tile-128 rows, which the stage-1
    kernel now takes at EP16.

EP4 emulating EP16 (bench_mega_moe --sim_ep 16 -e 224, SiTUv2, a4w4, fp4
dispatch, bf16 combine, AITER_S1F_WIDE_TILE_INFO=1, AITER_S1F_MAX_RECV=the
cap), us/layer, MEGA-CHECK PASS:

  tpr   before (#8189)          this
  160   S1F off (t128)  ~174    160.1  (64/64)
  192   S1F off (t128)  ~182    164.3  (64/64)
  256   S1F off (t128)  ~216    179.4  (128)
  320   S1F off         236.7   192.5  (128)
  512   S1F off         296.7   250.5  (128)
  768   S1F off         344.0   298.8  (128)
  1024  S1F off         436.0   383.2  (128)

The "before" figures for tpr 160-256 are S1F off on tile 64/64. Those rows
ran tile 128, which the stage-1 kernel rejected at EP16. tpr <= 128
(bounds <= 2048) keep the existing rows: under S1F they won against S1F off
and against tile 32/64 (tpr 32 131 vs 138, 64 136 vs 151, 128 154 vs 167).

Also swept on top of these, with no gain past noise: tile_n2 512 (alone or
with n_warp2 8), tdm_b_th 0/1/3, num_buffer_stage2 3. num_buffer_stage2 4
was 12-18% slower.

Co-Authored-By: Claude <[email protected]>
@XingerZhu
XingerZhu merged commit e18203b into main Dec 1, 2026
61 checks passed
@XingerZhu
XingerZhu deleted the zxe/tune_mega_ep8_ep16 branch December 1, 2026 03:52
yhl-amd added a commit to yhl-amd/aiter that referenced this pull request Dec 2, 2026
One FP4 EP row (topk -1) in dsv41_flash_tuned_grouped_fmoe.csv:

- e32 token 8192: the DSpark draft MoE (32 experts) had no row and ran the
  default 64-row tile; use the e96 8192 configuration (tile_m 128).

Through main's bucket lookup (ROCm#8189), e32 receive bounds above 4096 now
pick this row; no other selection changes. Tile 128 is one of the stage-1
fused (S1F) kernel's variants, so those steps stay eligible for it.
Outputs are bit identical to the previous tile (tile_m does not change the
K accumulation order; padding rows are skipped).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
yhl-amd pushed a commit that referenced this pull request Dec 2, 2026
…GEMM1


The S1F stage-1 kernel embedded GEMM1 with tdm_b_th and tdm_as_in_prologue
hardcoded to 0, so the grouped CSV rows that tune them had no effect on the
MegaMoE fused dispatch path. Pass both through from the GEMM1 launch.

The A-scale prologue loads the tile's full A-scale range up front, but under
S1F those rows arrive from the same launch's dispatch. Move the a_ready gate
ahead of that load (and drop it from the mainloop) instead of rejecting the
combination. With defer_c_wait the next tile's prologue now lands while the
deferred C store is in flight, so assert that the C staging stays below the
resident A-scale region rather than forbidding the prologue outright.

The resident A-scale region grows the arena. A variant whose CTAs would no
longer share the CU (or whose layout asserts reject the prologue) keeps the
rotating A-scale stages, decided at build time outside the jit body.

Rebased onto main after #8189, which already passes the CSV B TDM hint per
compact step (g1_tdm_b_th). The A-scale prologue now rides the same way:
_compact_gemm_tiles also returns the row's tdm_as_in_prologue (after
AITER_GROUPED_GEMM_AS_PROLOGUE, as fused_moe applies it), the step keeps it
as g1_tdm_as_in_prologue, and the launcher / precompile keys carry it. Main
moved the C staging to the arena tail (C_OFF), so the defer_c_wait check is
now that C_OFF clears the resident A-scale region; where it does not,
_g1_asprol keeps the rotating A-scale stages.
yhl-amd pushed a commit that referenced this pull request Dec 2, 2026
The DSv4.1 EP4 a4w4 4096-token row tunes GEMM1 to tile_m 96, which the
stage-1 kernel rejected: an m-tile has to be whole 64-row flag tiles, so
every step at that alignment fell back to dispatch + a separate GEMM1.

Pick the flag tile per variant instead. tile_m 96 runs on 32-row flag tiles
(three per m-tile, polled as one b128 per flag tile like the other
multi-flag variants, so it keeps the at-most-4-ranks limit); the others keep
64 rows. The compact plan already pads experts to a non-power-of-two
alignment over a smaller plan tile, and the flag, tile_src and control
buffers are sized for 16-row tiles, so only the plan tile and the kernel's
flag geometry change. The variant sits between 64 and 128 rows: three
buffers, two CTAs per CU.

Rebased onto main: #8189 already has FLAG_M_SMALL and the 96-row flag tile
in s1f_flag_m, so this adds only the 96 entry of _S1F_VARIANTS.
zejunchen-zejun added a commit that referenced this pull request Dec 2, 2026
…DSpark draft head BF16 tuning, empty-row GEMM fix (#9096)

* MegaMoE gfx1250: decode megakernel (dispatch, GEMM1, GEMM2 and combine in one launch), Kimi-K3 shapes (#7345 @ a559927, head 2026-12-01T13:13:28Z)

Opt-in with AITER_MEGAKERNEL=1. Each step chooses by its receive bound:
- "slots" (fixed per-expert slots) for bounds up to SLOTS_RECV (2048; with
  IOD-placed weights, 3072 for Kimi-K3's 3584 x 3072);
- "compact" up to COMPACT_MAX_TOKENS per rank;
- otherwise the staged path.
Off by default, so nothing changes unless the variable is set. The PR's
tests show the output bitwise equal to the staged path.

Ported onto k3-455-dev as the squashed PR diff (merge base ce334d0). Four
files conflicted:
- s1f_ctl.py: kept k3-455-dev's receive caps (_S1F_MAX_RECV 4096 plus
  #8189's _S1F_MAX_RECV_BY_SHAPE) and its s1f_max_recv(); the PR's base had
  no cap. Both __init__ fields are kept (#8483's _plan_lds, the PR's
  _packed_sc).
- s1f_stage1.py: added the PR's s1f_apre_* helpers. The stage-1 launch keeps
  #8483's SiTUv2 arguments and adds the PR's value_attrs.
- gemm_common_gfx1250.py: kept k3-455-dev's prefetch_kernel_code(max_bytes=...),
  a superset of the PR's.
- dsr1_tuned_grouped_fmoe.csv: kept k3-455-dev's DeepSeek-R1 rows and dropped
  the PR's two DSR1 rows (not Kimi-K3).
Placement is detected from the GEMM builder's signature (BUILDER_LOC), so
without IOD placement the placed paths stay off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* MegaMoE gfx1250 compact plan: re-seal the hist row head from each issuing wave before its TDM store (#8880 @ 4214819, head 2026-11-28T16:07:47Z)

Fixes the intermittent S1F spin trap (HSA_STATUS_ERROR_EXCEPTION 0x1016):
the TDM that sends a hist row to rank w is issued by wave w and could read the
row head before wave 0's LDS tag was visible to it. Every sending wave now
re-seals the tag before its store. Kimi-K3's D runs this compact plan
(dispatch=compact).

(cherry picked from commit 4214819)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* bench_mega_moe: SiTUv2, a model-sized instance and a simulated EP size, for Kimi-K3's A/Bs

--act situv2 (with --situ_beta / --situ_linear_beta), --max_tpr / --recv_bound
and --sim_ep N (a rank of an EP-N group on fewer GPUs, e.g. EP8 on one tray
with -e 448 --sim_ep 8), all opt-in. Same commit as on the IOD branch
(zejun/k3-455-dev-1201-iod); here it is merged with #7345's bench: #7345's
routing checks stay, and the step bounds come from resolve_step_bounds, which
equals #7345's inline logic without --sim_ep.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [Config] Kimi-K3 gfx1250 LM head and DSpark draft head BF16 rows (N 163840, K 7168), M 1-256

Neither head had a gfx1250 row, so both ran the default bandwidth-bound
gemm_a16w16 at 3.4-4.3 TB/s (one D decode step at c192: 546-603 us for the
target head, ~360-600 us for the draft head). A FlyDSL hgemm whose M tile
covers every row reads the 2.35 GB weight once: per M bucket (32 / 64 / 96 /
128 / 160 / 192 / 256 rows) the best block_n / block_k / stages / waves of a
tdm or ft sweep, measured with 2 weight copies alternated in a CUDA graph on
one MI455X (bf16 error 3e-3, fp32 3e-6 against an f32 matmul):

  rows      bf16 out          fp32 out
  1-32      1.04-1.16x        1.0-1.12x (rows <= 8 keep production)
  33-64     1.25-1.37x        1.31-1.35x
  65-128    1.43-1.62x        1.53-1.63x
  129-160   2.04-2.44x        2.10-2.43x   (c192's verify / draft rows)
  161-192   2.33-2.49x        2.42-2.66x
  193-256   2.10-2.72x        2.17-2.77x

At c192 (133-175 rows) that is ~300-500 us a head, ~0.6 ms a D step.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* tuned_gemm: an empty-row FlyDSL GEMM returns the empty product instead of launching

An idle DP rank's dummy step runs its GEMMs with M = 0, and the lookup pads
M = 0 into a tuned row: with a FlyDSL row there (Kimi-K3's head rows, the
commit before) validate_gemm_gfx1250_config refused the empty dimension and
the engine died at its first prefill ("dimensions, tiles, stages, wave counts
and WMMA sizes must be positive integers"; DP4 one-tray D, 12-02). Return the
[0, N] result (or the caller's buffer) without a launch, as the default
kernel effectively did.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Honglie Yi <[email protected]>
lirui927 pushed a commit that referenced this pull request Dec 3, 2026
At npes > 4 the S1F GEMM1 epilogue's pre-check (pre_load -> flag_load ->
ready_of) loaded one b128 of tile flags (sources 0..3) but indexed it up to
npes - 1, so building the kernel for EP8 failed with "vector index 4 out of
range for numel 4". Load a second b128 (sources 4..7) when npes > 4, as
upstream #8189 (e18203b) does; npes <= 4 keeps one load.

Host compile-only (gfx1250): world 8 / 16 local experts now builds; world 4
/ 32 local experts ISA is byte-identical for tile_m 64 / 128 / 256.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
gbyu-amd pushed a commit that referenced this pull request Dec 3, 2026
…nas and run SiTUv2 in the stage-1 kernel (#8483 @ 45fbfb7, head 2026-11-23T06:55:24Z)

Snapshot of #8483. The stage-1 compact
plan sizes its per-m-tile LDS table by the S1F receive cap instead of the
arena (Kimi-K3 EP8 at 16384 tokens a rank: 569 KiB -> 73 KiB, limit
320 KiB), and SiTUv2 runs in the stage-1 kernel with its betas. Validated
with #8189 on two MI455X trays: K3 DP8EP8 serving with
AITER_MEGA_S1F=1, every decode step on s1f_stage1, GSM8K unchanged
(wuhuikx/LLM-Booster#722 comment 7121412936).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 7ecc055)

Rebase onto main 12-03: main now has #8189's final head (the k3 copy of #8189 is dropped). Two textual conflicts, both sides kept: s1f_ctl.py _Stage1Fusion.__init__ sets main's _packed_sc and this PR's _plan_lds; s1f_stage1.py launch passes this PR's f32_situ_beta / f32_situ_linear_beta before main's value_attrs keyword (the PR head's order). Multi-GPU MegaMoE not run on the rebased tree.

Updated 12-03 to the PR head #8483 @ 21120ee: folds in the PR's later commits de043bb bench_mega_moe: --max_tokens_per_rank, the step's receive bound, and SiTUv2; 21120ee mega_moe gfx1250 S1F: address review of the stage-1 plan LDS bound.
gbyu-amd pushed a commit that referenced this pull request Dec 3, 2026
…ath (TP8EP8) (#8259 @ 9a2194a, head 2026-11-19T05:04:37Z)

Kimi-K3 served as TP8 attention with the MoE expert-parallel over the same 8
GPUs (ATOM --enable-expert-parallel, DP 1) calls fused_moe with an expert
mask: 112 local experts of 896, inter_dim 3072, SiTUv2, A4W4 MXFP4 per_1x32,
GUGU weights. The grouped lookup keys that call as expert=112, topk=-1,
ep_fused=0, so it shares the kimik3 rows with the MegaMoE stage-2 scatter
(ep_fused=1); token buckets 1, 2 and 4 had no row at all.

Add 14 rows with ep_fused=0 for token buckets 1..8192. Rows that name
ep_fused win the lookup for that path only, so the MegaMoE path keeps the
existing rows. Buckets 16384 and 32768 keep the existing rows: no swept tile
beat them beyond run-to-run noise.

Swept with the production call (fused_moe with expert_mask, SiTUv2 beta 4 /
linear 25, GateMode.INTERLEAVE, moe_shuffle_weight / moe_shuffle_scale,
random top-16 routing over 896 experts); every candidate's output is
bit-identical to the existing row's. MoE kernel time per call (sum of the
device kernels of one fused_moe, median of 7 interleaved rounds, one GPU):

  token  existing us -> new us
      1     29.1 ->  24.5  (1.19x, existing: no row)
      2     28.2 ->  23.1  (1.22x, existing: no row)
      4     35.0 ->  24.2  (1.45x, existing: no row)
      8     36.1 ->  30.3  (1.19x)
     16     55.4 ->  47.0  (1.18x)
     32     74.6 ->  65.1  (1.15x)
     64     98.4 ->  90.1  (1.09x)
    128    132.4 -> 122.3  (1.08x)
    256    142.1 -> 131.0  (1.08x)
    512    146.4 -> 140.7  (1.04x)
   1024    157.3 -> 147.3  (1.07x)
   2048    175.3 -> 170.0  (1.03x)
   4096    242.0 -> 235.7  (1.03x)
   8192    387.8 -> 353.0  (1.10x)

Measured on MI455X (gfx1250, 256 CU) in rocm/fw-bringup:gfx1250-atom-k3-20261116
(aiter 69d86f590, FlyDSL 0.5.0).

Conflict: kept both new rows of the Kimi-K3 CSV (#8189's 3072 row, this 2048 ep_fused=0 row).
(cherry picked from commit 8dc3601)

Rebase onto main 12-03: kimik3_gfx1250_tuned_grouped_fmoe.csv conflicted with main's #8189 final (its expert-112 rows with a blank ep_fused). Replayed by row key: this commit's 14 ep_fused=0 rows (non-fused EP path) are inserted; main's blank-ep_fused rows stay as main has them.
gbyu-amd pushed a commit that referenced this pull request Dec 3, 2026
…DSpark draft head BF16 tuning, empty-row GEMM fix (#9096)

* MegaMoE gfx1250: decode megakernel (dispatch, GEMM1, GEMM2 and combine in one launch), Kimi-K3 shapes (#7345 @ a559927, head 2026-12-01T13:13:28Z)

Opt-in with AITER_MEGAKERNEL=1. Each step chooses by its receive bound:
- "slots" (fixed per-expert slots) for bounds up to SLOTS_RECV (2048; with
  IOD-placed weights, 3072 for Kimi-K3's 3584 x 3072);
- "compact" up to COMPACT_MAX_TOKENS per rank;
- otherwise the staged path.
Off by default, so nothing changes unless the variable is set. The PR's
tests show the output bitwise equal to the staged path.

Ported onto k3-455-dev as the squashed PR diff (merge base ce334d0). Four
files conflicted:
- s1f_ctl.py: kept k3-455-dev's receive caps (_S1F_MAX_RECV 4096 plus
  #8189's _S1F_MAX_RECV_BY_SHAPE) and its s1f_max_recv(); the PR's base had
  no cap. Both __init__ fields are kept (#8483's _plan_lds, the PR's
  _packed_sc).
- s1f_stage1.py: added the PR's s1f_apre_* helpers. The stage-1 launch keeps
  #8483's SiTUv2 arguments and adds the PR's value_attrs.
- gemm_common_gfx1250.py: kept k3-455-dev's prefetch_kernel_code(max_bytes=...),
  a superset of the PR's.
- dsr1_tuned_grouped_fmoe.csv: kept k3-455-dev's DeepSeek-R1 rows and dropped
  the PR's two DSR1 rows (not Kimi-K3).
Placement is detected from the GEMM builder's signature (BUILDER_LOC), so
without IOD placement the placed paths stay off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* MegaMoE gfx1250 compact plan: re-seal the hist row head from each issuing wave before its TDM store (#8880 @ 4214819, head 2026-11-28T16:07:47Z)

Fixes the intermittent S1F spin trap (HSA_STATUS_ERROR_EXCEPTION 0x1016):
the TDM that sends a hist row to rank w is issued by wave w and could read the
row head before wave 0's LDS tag was visible to it. Every sending wave now
re-seals the tag before its store. Kimi-K3's D runs this compact plan
(dispatch=compact).

(cherry picked from commit 4214819)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* bench_mega_moe: SiTUv2, a model-sized instance and a simulated EP size, for Kimi-K3's A/Bs

--act situv2 (with --situ_beta / --situ_linear_beta), --max_tpr / --recv_bound
and --sim_ep N (a rank of an EP-N group on fewer GPUs, e.g. EP8 on one tray
with -e 448 --sim_ep 8), all opt-in. Same commit as on the IOD branch
(zejun/k3-455-dev-1201-iod); here it is merged with #7345's bench: #7345's
routing checks stay, and the step bounds come from resolve_step_bounds, which
equals #7345's inline logic without --sim_ep.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [Config] Kimi-K3 gfx1250 LM head and DSpark draft head BF16 rows (N 163840, K 7168), M 1-256

Neither head had a gfx1250 row, so both ran the default bandwidth-bound
gemm_a16w16 at 3.4-4.3 TB/s (one D decode step at c192: 546-603 us for the
target head, ~360-600 us for the draft head). A FlyDSL hgemm whose M tile
covers every row reads the 2.35 GB weight once: per M bucket (32 / 64 / 96 /
128 / 160 / 192 / 256 rows) the best block_n / block_k / stages / waves of a
tdm or ft sweep, measured with 2 weight copies alternated in a CUDA graph on
one MI455X (bf16 error 3e-3, fp32 3e-6 against an f32 matmul):

  rows      bf16 out          fp32 out
  1-32      1.04-1.16x        1.0-1.12x (rows <= 8 keep production)
  33-64     1.25-1.37x        1.31-1.35x
  65-128    1.43-1.62x        1.53-1.63x
  129-160   2.04-2.44x        2.10-2.43x   (c192's verify / draft rows)
  161-192   2.33-2.49x        2.42-2.66x
  193-256   2.10-2.72x        2.17-2.77x

At c192 (133-175 rows) that is ~300-500 us a head, ~0.6 ms a D step.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* tuned_gemm: an empty-row FlyDSL GEMM returns the empty product instead of launching

An idle DP rank's dummy step runs its GEMMs with M = 0, and the lookup pads
M = 0 into a tuned row: with a FlyDSL row there (Kimi-K3's head rows, the
commit before) validate_gemm_gfx1250_config refused the empty dimension and
the engine died at its first prefill ("dimensions, tiles, stages, wave counts
and WMMA sizes must be positive integers"; DP4 one-tray D, 12-02). Return the
[0, N] result (or the caller's buffer) without a launch, as the default
kernel effectively did.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Honglie Yi <[email protected]>
(cherry picked from commit 4c4e333)

Rebase onto main 12-03: main since has #8189's final head, #8889 (packed A only where its stores fit storecnt, tdm_b_th from the tuned row) and #8737 (LDS-to-TDM flush, C staged at the arena tail). Resolved: s1f_ctl.py keeps main's _s1f_gemm_opts / _s1f_packed_a_ok / s1f_prefill_tile(config, ...) / _s1f_warps(config, ...) (this commit's same-purpose _gemm_opts method and (world_size, topk) helpers are dropped) and adds this commit's IOD placement next to main's tdm_b_th: _launcher / _precompile take both, the launcher key and the precompile keys carry (tdm_b_th, placed), make_s1f_stage1 gets tdm_b_th, b_placed, loc_group. s1f_stage1.py: the producer role is this commit's s1f_produce(_PCtx(...)) (its body is main's inline producer, packed A and WAIT_STEPS included); OP_STORES / the storecnt check use main's s1f_packed_a_op_stores / s1f_packed_a_fits (R is 8 there); make_s1f_stage1 takes tdm_b_th and b_placed / loc_group; imports both. dispatch_compact.py: main's 4-tuple _compact_gemm_tiles. mxfp4_preshuffle_gfx1250_tdm.py: main's single C_OFF staging (arena tail, flush scratch at the head) is kept; this commit's a/c cache modifiers, scatter cache policy and defer_ep_wait are added, defer_ep_wait moving C_OFF past the input stages (and growing the arena) instead of this commit's C_EP_OFF / C_Q_OFF; the kernel name carries both suffixes. kimik3_bf16_tuned_gemm.csv: the 504 LM / draft head rows replayed by key. Multi-GPU MegaMoE / megakernel not run on the rebased tree.

Rebase onto main 12-03: after #8483 was updated to its PR head 21120ee (which adds its own bench_mega_moe flags --max_tokens_per_rank / --activation / --situ_beta), op_tests/multigpu_tests/bench_mega_moe.py keeps this commit's version (--max_tpr / --recv_bound / --act / --situ_beta / --sim_ep cover the same knobs); taking both would define --situ_beta twice.
yhl-amd added a commit to yhl-amd/aiter that referenced this pull request Dec 4, 2026
One FP4 EP row (topk -1) in dsv41_flash_tuned_grouped_fmoe.csv:

- e32 token 8192: the DSpark draft MoE (128 routed experts, 32 per rank
  at EP4) had no row and ran the default 64-row tile; use the e96 8192
  configuration (tile_m 128).

Through main's bucket lookup (ROCm#8189), e32 receive bounds above 4096 now
pick this row; no other selection changes. Tile 128 is one of the stage-1
fused (S1F) kernel's variants, so those steps stay eligible for it.
Outputs are bit identical to the previous tile (tile_m does not change the
K accumulation order; padding rows are skipped).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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