Skip to content

[CK] [Bugfix] Fix gfx1250 grouped MoE tuning and re-tune 6 A8W4 and A4W4 rows - #6356

Open
jhinpan wants to merge 3 commits into
mainfrom
jhinpan/gfx1250-grouped-moe-a8w4-retune
Open

jhinpan wants to merge 3 commits into
mainfrom
jhinpan/gfx1250-grouped-moe-a8w4-retune

Conversation

@jhinpan

@jhinpan jhinpan commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #6346.

Merged main at 0f6cb2f. Since the measurements below, #6709 changed the gfx1250 grouped MoE kernel (A-preshuffle, new scheduling defaults) and replaced the tiles of main's 7168 x 3072 (96 experts) rows without timing them again: their us is still the old value. This PR now keeps main's 7168 x 3072 rows and replaces only the 6 rows of 7168 x 768 (384 experts): T = 2048, 4096 and 8192, A8W4 and A4W4. The 7168 x 3072 rows in the tables below are no longer part of this PR. The tuner fix is still needed: on main, _find_grouped_config is still cached on the shape only, and the tuner still runs a8w4 candidates with FP4 activations.

@yadaish, could you tune the 7168 x 3072 rows again on current main with this tuner fix?

The tables below were measured before #6269; the re-timing against main with #6269 is in this comment.

Tuner

On gfx1250, GroupedFmoeTuner timed every candidate of an A8W4 shape with the default tiles and FP4 activations, so its pick did not depend on the candidates:

  • fused_moe quantizes the activations to FP4 on gfx1250 unless the caller asks for FP8 (quant_dtype_a, or AITER_FORCE_A8W4=1). The a8w4 candidate ran as A4W4, its row (q_dtype_a = torch.float8_e4m3fn) never matched, and the default tiles ran. The tuner now passes quant_dtype_a from the row.
  • _find_grouped_config is an lru_cache keyed on the shape, not on the CSV path, so after the first candidate every lookup returned the first result. The tuner now clears it together with _GROUPED_CONFIG_CACHE.

One shape (7168 x 768, 384 experts, top-k 6, T = 4096) with AITER_GROUPED_DEBUG=1:

main This PR
Row lookups 1 for 4 candidates, key q_dtype_a = torch.float4_e2m1fn_x2, no match; all 24 calls on the default tiles 4, each candidate on its own torch.float8_e4m3fn row
Tuner time for tile_m = 16 / 32 / 64 / 128 (µs) 306.8 / 305.0 / 303.4 / 305.0 573.2 / 404.7 / 303.4 / 374.1

A8W4 rows

With the fixed tuner I re-tuned the A8W4 rows for 7168 x 768 (384 experts) and 7168 x 3072 (96 experts), top-k 6, T = 8 to 8192 (22 rows). Then I timed the old and the new CSV through fused_moe(..., quant_dtype_a=fp8), with AITER_CONFIG_GROUPED_FMOE naming the CSV, in one process on the same inputs: gfx1250 (MI450-class, 256 CUs), random routing (each token picks 6 distinct experts), median of 15 interleaved samples of the whole call. A copy of the old CSV, timed the same way, gives the noise: 0.975 to 1.009 of the old time. Old and new rows give bit-identical outputs on all 22 shapes.

This PR replaces the 9 rows that are at least 3% faster (the tuner's --min_improvement_pct default):

Shape T Old row: tile_m/n/k, stage 2 New row: tile_m/n/k Old (µs) New (µs) New / old
7168 x 768, 384 experts 2048 16/256/256, 16/512/128 32/256/256 408.45 319.04 0.781
4096 16/256/256, 16/512/128 64/256/256 736.24 400.39 0.544
8192 16/256/256, 16/512/128 128/256/256 1265.18 679.44 0.537
7168 x 3072, 96 experts 8 64/512/256, 64/512/256 32/256/256 126.33 101.36 0.802
16 64/512/256, 64/512/256 32/256/256 169.66 156.93 0.925
256 16/256/128, 16/256/512 32/256/256 246.57 205.39 0.833
2048 128/512/256, 128/256/128 128/256/256 697.59 534.34 0.766
4096 128/512/256, 128/256/128 128/256/256 1114.47 859.78 0.771
8192 128/512/256, 128/256/128 128/256/256 1932.95 1527.08 0.790

The other 13 rows stay as they are. Their new / old ratio is 0.979 to 1.032, except T = 512 on 7168 x 3072, where the tuner's pick is 1.162: the tuner spreads the tokens evenly over the experts, and with random routing the current row is faster.

The new rows leave the stage-2 and TDM cells blank, as the tuner timed them, so the kernel uses its defaults (stage 2 reuses the stage-1 tiles). The exception is the columns that have no blank cell in the merged grouped configs (split_k1, split_k2, tdm_as_in_prologue, cluster_n, waves_per_tensor_tdm, next_stage_prefetch, lds_soa_load_interleave). There the rows carry the value that a blank cell means, because one blank cell makes pandas write the whole column as floats when AITER merges the config files, and the AOT build then fails on split_k1 = "1.0". The us of the new rows is the tuner's.

A4W4 rows

The cache bug also hit the A4W4 rows of the same two shapes (q_dtype_a = torch.float4_e2m1fn_x2). Most of them have the same us, 468.05. I re-tuned these 22 rows and timed them as above, with FP4 activations (the gfx1250 default). The noise is 0.973 to 1.015. This PR replaces the 9 rows where the whole call is at least 3% faster and the GEMMs are not slower. Old and new rows give bit-identical outputs on these shapes:

Shape T Old row: tile_m/n/k, stage 2 New row: tile_m/n/k Old (µs) New (µs) New / old
7168 x 768, 384 experts 2048 16/256/256, 16/512/128 64/256/256 421.46 270.35 0.641
4096 16/256/256, 16/512/128 64/256/256 727.88 365.78 0.503
8192 16/256/256, 16/512/128 128/256/256 1236.98 549.80 0.444
7168 x 3072, 96 experts 32 16/512/128, 16/512/128 16/256/256 202.88 186.42 0.919
64 16/512/128, 16/512/128 16/256/256 214.60 201.90 0.941
128 16/512/128, 16/512/128 16/256/256 220.25 202.59 0.920
2048 64/512/128, 64/512/128 128/256/256 513.87 410.03 0.798
4096 64/512/128, 64/512/128 128/256/256 851.16 678.92 0.798
8192 256/256/256, 256/256/256 128/256/256 1257.11 1174.03 0.934

After #6269, the T = 8192 row on 7168 x 3072 runs as fast as main's row (kernels 0.996 of its time), so this PR no longer changes it.

The other 13 rows stay as they are. Their new / old ratio is 0.983 to 1.031, with three exceptions on 7168 x 3072. At T = 8 and 256 the tuner's pick is slower (1.092 and 1.076). At T = 512 the call is 0.960, but the GEMMs are 4% slower, so the gain does not come from the new row.

Write-back

I put the rows in place with a script rather than through result_to_csv, which does not write them correctly into this CSV:

  • The tuner keys on gate_mode, which tuned_grouped_fmoe.csv does not have, so it appends the new row next to the old one instead of replacing it. The lookup then takes the row with the lower us.
  • The rewrite turns the integer cells of other rows into floats (16 becomes 16.0).

This PR does not change either one; #6395 fixes both.

Default config files (not changed here)

With AITER_CONFIG_GROUPED_FMOE unset, the lookup reads the file that update_config_files merges with pandas, and there every numeric column that has a blank cell comes out as floats. Since #6425, _as_int on main reads those cells; #6360 also makes the lookup match an ep_fused written as 1.0 and parses the cells exactly.

@zufayu, could you help review this?

PR Self-Review

Reviewed revision

955281d

Behavior and intent

Two fixes to GroupedFmoeTuner on gfx1250. It passes quant_dtype_a from the row, so an a8w4 candidate runs with FP8 activations instead of FP4. It also clears the lru_cache of _find_grouped_config between candidates, so each candidate runs with its own row instead of the first one. Without them the tuner timed every candidate on the same tiles, so its picks did not depend on the candidates. Both bugs are still on main at 0f6cb2f. With the fixed tuner, 6 rows of tuned_grouped_fmoe.csv change: 7168 x 768, 384 experts, top-k 6, T = 2048, 4096 and 8192, A8W4 and A4W4.

Validation and unverified scope

  • Tuner behavior and row timing: see Tuner, A8W4 rows and A4W4 rows above (gfx1250 MI450-class, 256 CUs, fused_moe median of 15 interleaved samples, bit-identical outputs).
  • This revision merges main 0f6cb2f. The 6 rows keep their tiles and us, and get main's new a_preshuffle column as 0, the value main has on these rows.
  • On a CPU-only container, python3 -m pytest on test_csv_validation, test_config_shape_collision, test_grouped_ep_fused_lookup, test_grouped_gemm_launch_abi, test_tuner_infra and test_fast_tuning gave the same results as on main: 149 passed, and the same 13 cases failed because they need a GPU.
  • Unverified: the 6 rows were timed before [FlyDSL] Add gfx1250 grouped MoE A-preshuffle and tuned CSV validation #6709 changed the kernel's scheduling defaults, and the fixed tuner was not run again on current main.

PR-specific question

The tuner change runs only in GroupedFmoeTuner._run_candidate, the gfx1250 grouped FlyDSL tuner. quant_dtype_a is FP8 only when _data_format returns a8w4 for the row's q_dtype_a; otherwise it stays FP4, the previous gfx1250 default. No kernel source changes. The 6 CSV rows apply only to gfx1250 with 256 CUs, BF16, SiLU, per_1x32, 7168 x 768 with 384 experts and top-k 6, at T = 2048, 4096 and 8192. _find_grouped_config matches every key column, so other shapes keep their rows.

Changed op tests

None

@jhinpan
jhinpan requested review from a team and zufayu October 10, 2026 04:26
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
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: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: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 6356 --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.

@github-actions github-actions Bot changed the title [Bugfix] Fix gfx1250 grouped MoE tuning of A8W4 rows and re-tune 9 rows [CK] [Bugfix] Fix gfx1250 grouped MoE tuning of A8W4 rows and re-tune 9 rows Oct 10, 2026
@github-actions github-actions Bot added the CK label Oct 10, 2026
@jhinpan jhinpan changed the title [CK] [Bugfix] Fix gfx1250 grouped MoE tuning of A8W4 rows and re-tune 9 rows [CK] [Bugfix] Fix gfx1250 grouped MoE tuning and re-tune 18 A8W4 and A4W4 rows Oct 11, 2026
@zufayu
zufayu requested review from coderfeli and yadaish and removed request for zufayu October 12, 2026 05:47
@zufayu

zufayu commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

@coderfeli this PR fixes two tuner bugs and replaces 18 gfx1250 FlyDSL grouped-MoE rows—not CK1—with author-measured 5.9–55.6% gains; please confirm the target shapes and tuning results from the gfx1250 side.

@jhinpan
jhinpan force-pushed the jhinpan/gfx1250-grouped-moe-a8w4-retune branch from 0b64f4d to 07ec5a1 Compare October 13, 2026 04:58
@jhinpan

jhinpan commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

@coderfeli @yadaish Rebased on main after #6269, which rewrote tuned_grouped_fmoe.csv: it dropped max_m, grouped_persistent_m and wave_specialized_tdm and added rolled_drain and persistent_workers2. The runtime did not read the dropped columns before #6269 either; they come from the tuner's candidate rows. So each row now starts from main's row, including #6269's defaults, and takes only the cells this PR changes.

#6269 also changed the gfx1250 grouped GEMM kernel, so I re-timed the rows against main on gfx1250 (MI450-class, 256 CUs) with the protocol of the description: fused_moe with AITER_CONFIG_GROUPED_FMOE naming each CSV, random routing, median of 15 interleaved samples, and a copy of the old CSV for the noise. On this box the whole call carries about 800 µs of host time per call, whatever the row, so I also took the GPU time of the call's kernels from the profiler (median of 5 interleaved rounds):

Data Rows Kernels, new / old GEMMs, new / old Whole call, new / old
A8W4 9 0.472 to 0.943 0.423 to 0.930 0.667 to 1.006
A4W4 8 0.400 to 0.930 0.348 to 0.926 0.605 to 1.003

The noise is 0.979 to 1.019 for the kernels and 0.983 to 1.006 for the whole call. Old and new rows give bit-identical outputs on every shape.

One row no longer qualifies: A4W4, 7168 x 3072, 96 experts, T = 8192. With #6269 its kernels take 0.996 of the time of main's row (GEMMs 0.992), so this PR now leaves that row as main has it and replaces 17 rows: 9 A8W4 and 8 A4W4.

Per row
Data Shape T Old row New row Kernels old / new (µs) New / old GEMMs new / old Whole call new / old
A8W4 7168 x 768, 384 experts 2048 16/256/256 32/256/256 364.3 / 303.4 0.833 0.810 0.929
A8W4 7168 x 768, 384 experts 4096 16/256/256 64/256/256 622.7 / 351.4 0.564 0.518 0.791
A8W4 7168 x 768, 384 experts 8192 16/256/256 128/256/256 1199.9 / 566.3 0.472 0.423 0.667
A8W4 7168 x 3072, 96 experts 8 64/512/256 32/256/256 108.7 / 102.5 0.943 0.930 1.006
A8W4 7168 x 3072, 96 experts 16 64/512/256 32/256/256 149.5 / 133.4 0.892 0.884 1.002
A8W4 7168 x 3072, 96 experts 256 16/256/128 32/256/256 235.9 / 208.5 0.884 0.874 1.002
A8W4 7168 x 3072, 96 experts 2048 128/512/256 128/256/256 633.4 / 435.0 0.687 0.667 0.836
A8W4 7168 x 3072, 96 experts 4096 128/512/256 128/256/256 1086.1 / 764.3 0.704 0.685 0.786
A8W4 7168 x 3072, 96 experts 8192 128/512/256 128/256/256 1901.6 / 1437.6 0.756 0.738 0.783
A4W4 7168 x 768, 384 experts 2048 16/256/256 64/256/256 373.5 / 250.4 0.671 0.631 0.885
A4W4 7168 x 768, 384 experts 4096 16/256/256 64/256/256 633.4 / 334.4 0.528 0.481 0.763
A4W4 7168 x 768, 384 experts 8192 16/256/256 128/256/256 1187.7 / 475.3 0.400 0.348 0.605
A4W4 7168 x 3072, 96 experts 32 16/512/128 16/256/256 202.2 / 183.7 0.909 0.903 1.003
A4W4 7168 x 3072, 96 experts 64 16/512/128 16/256/256 213.8 / 196.3 0.918 0.915 0.995
A4W4 7168 x 3072, 96 experts 128 16/512/128 16/256/256 215.2 / 200.1 0.930 0.926 0.998
A4W4 7168 x 3072, 96 experts 2048 64/512/128 128/256/256 430.5 / 350.2 0.813 0.794 0.928
A4W4 7168 x 3072, 96 experts 4096 64/512/128 128/256/256 775.2 / 578.9 0.747 0.729 0.873
A4W4 7168 x 3072, 96 experts 8192 256/256/256 not changed (main's row) 1158.4 / 1153.3 0.996 0.992 0.969

Tiles are tile_m/tile_n/tile_k; the new rows leave the stage-2 cells blank, so stage 2 reuses the stage-1 tiles.

@github-actions

Copy link
Copy Markdown
Contributor

No activity for 15 days, so this is now labelled stale. A push or a comment clears it; keep-open exempts it. Nothing is closed automatically.

@github-actions github-actions Bot added the stale The PR hasn't been updated in 2 weeks label Oct 29, 2026
@zufayu
zufayu requested review from yzhou103 and removed request for coderfeli November 11, 2026 05:47
@github-actions github-actions Bot removed the stale The PR hasn't been updated in 2 weeks label Nov 12, 2026
tuned_grouped_fmoe.csv: keep main's rows for the 11 7168x3072 E96 keys that
#6709 re-tuned, and apply this branch's values only to the 6 7168x768 E384
keys that main left unchanged (a_preshuffle stays 0).
@aiter-bot

aiter-bot commented Nov 14, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 955281d14655 · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

Two fixes to `GroupedFmoeTuner` on gfx1250. It passes `quant_dtype_a` from the row, so an a8w4 candidate runs with FP8 activations instead of FP4. It also clears the `lru_cache` of `_find_grouped_config` between candidates, so each candidate runs with its own row instead of the first one. Without them the tuner timed every candidate on the same tiles, so its picks did not depend on the candidates. Both bugs are still on main at 0f6cb2f. With the fixed tuner, 6 rows of `tuned_grouped_fmoe.csv` change: 7168 x 768, 384 experts, top-k 6, T = 2048, 4096 and 8192, A8W4 and A4W4.

Validation and unverified scope

- Tuner behavior and row timing: see Tuner, A8W4 rows and A4W4 rows above (gfx1250 MI450-class, 256 CUs, `fused_moe` median of 15 interleaved samples, bit-identical outputs).
- This revision merges main 0f6cb2f. The 6 rows keep their tiles and `us`, and get main's new `a_preshuffle` column as 0, the value main has on these rows.
- On a CPU-only container, `python3 -m pytest` on `test_csv_validation`, `test_config_shape_collision`, `test_grouped_ep_fused_lookup`, `test_grouped_gemm_launch_abi`, `test_tuner_infra` and `test_fast_tuning` gave the same results as on main: 149 passed, and the same 13 cases failed because they need a GPU.
- Unverified: the 6 rows were timed before #6709 changed the kernel's scheduling defaults, and the fixed tuner was not run again on current main.

PR-specific question

The tuner change runs only in `GroupedFmoeTuner._run_candidate`, the gfx1250 grouped FlyDSL tuner. `quant_dtype_a` is FP8 only when `_data_format` returns `a8w4` for the row's `q_dtype_a`; otherwise it stays FP4, the previous gfx1250 default. No kernel source changes. The 6 CSV rows apply only to gfx1250 with 256 CUs, BF16, SiLU, `per_1x32`, 7168 x 768 with 384 experts and top-k 6, at T = 2048, 4096 and 8192. `_find_grouped_config` matches every key column, so other shapes keep their rows.

Changed op tests

None

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

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

@jhinpan

jhinpan commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

@yadaish @coderfeli Please review this PR. The last reviewer comment was on Oct 12.

  • State: Aiter Test Gate is green at 955281d. The PR has no conflicts with main.
  • Scope: the PR now replaces only the 6 rows for 7168 x 768. It does not change the 7168 x 3072 rows.
  • Question for yadaish: can you tune the 7168 x 3072 rows again on main with this tuner fix?

@jhinpan jhinpan changed the title [CK] [Bugfix] Fix gfx1250 grouped MoE tuning and re-tune 18 A8W4 and A4W4 rows [CK] [Bugfix] Fix gfx1250 grouped MoE tuning and re-tune 6 A8W4 and A4W4 rows Nov 23, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

4 participants