Skip to content

[FlyDSL] [gfx1250] Batched mxfp8 GEMM fused-quant epilogue: quantize from the accumulators, use the tuned row - #7667

Open
yhl-amd wants to merge 7 commits into
ROCm:mainfrom
yhl-amd:hyi/gfx1250-bmm-fused-quant-acc-epilogue
Open

yhl-amd wants to merge 7 commits into
ROCm:mainfrom
yhl-amd:hyi/gfx1250-bmm-fused-quant-acc-epilogue

Conversation

@yhl-amd

@yhl-amd yhl-amd commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Two follow-ups to the fused MXFP8 epilogue of the gfx1250 batched mxfp8_32 GEMM (#7178), on main with #7673 (gfx1250 compute-kernel fused epilogue) and #8101 (gfx950 fused quant):

  1. When the warp tile holds an even number of 16-column WMMA tiles, the epilogue quantizes straight from the accumulators instead of staging the bf16 tile in LDS and re-reading it per group.
  2. batched_gemm_a8w8_mxscale_bpreshuffle_fused_quant runs the tuned row the bf16 entry uses for the same shape on gfx1250 too ([FlyDSL] [gfx950] flydsl batched mxfp8 GEMM: optional fused mxfp8 quant epilogue #8101 does it for gfx950), instead of the runner's heuristic tile.

Motivation

  1. In [FlyDSL] [gfx1250] flydsl batched mxfp8 GEMM: optional fused mxfp8 quant epilogue #7178 the epilogue writes the bf16 tile to LDS, waits on a barrier, then has each thread re-read 32 contiguous values per group. A lane already holds 8 consecutive columns of one row per 16x16 tile, so with an even wmma_n_rep a 32-column group is two adjacent tiles across lanes l and l^16 and its amax needs a single shuffle_xor(16).
  2. The fused entry passed no kernel name, so it always used the heuristic tile while the bf16 entry used the tuned table; tuned rows for the shape could never take effect on the fused path.

Changes

PR Self-Review

Reviewed revision

d4016d5

Behavior and intent

Validation and unverified scope

  • gfx1250, earlier revision of the accumulator epilogue (its math and indexing are unchanged here, only moved into its own branch): fused entry vs bf16 GEMM followed by a standalone quantize_fp8 (amax floor 1e-10, e8m0 round-up): e4m3 codes and e8m0 scales bit-identical over many M including ragged tails, three data sets (all-zero rows, saturating fp8 inputs with large scales, fp8 subnormals and half-sparse rows), CUDA graph capture and replay with new inputs, and with the tuned rows. DeepSeek-V4.1-Flash served end to end with wo_a on the fused entry; GSM8K in line with the baseline.
  • Earlier revision bd6cc9b50, offline gfx1250 compile of launch_gemm_a8w8 (flydsl 0.5.0, no GPU), final ISA compared: the bf16 path (batched and 2-D mxfp8_32, mxfp8_128, ptpc) is ISA-identical to main; the three-branch restructure is ISA-identical to the head before it. No VGPR spill, no scratch.
  • Earlier head 68071323b (on main 0d894387b, before [FlyDSL] [gfx1250] Compute GEMM: fused MXFP8 epilogue; untuned prefill-sized batched mxfp8_32 runs the compute kernel #7673), gfx1250: python op_tests/test_flydsl_batched_gemm.py exits 0. The compute kernelName cases from main pass; the pinned tiles t16x64x512 nw4 (LDS-staged) and t32x64x512 nw2 / t128x128x256 nw2 (accumulator) have 0 scale and 0 fp8 mismatches at M = 48 and M = 200; the heuristic-tile fused cases have 0 mismatches and the fused quant epilogue reports all bit-exact. python -m pytest op_tests/test_bmm_a8w8_fused_quant_tuned_row.py op_tests/test_bmm_a8w8_fused_quant_supported.py: 7 passed. Log in the PR comments.
  • This head e552b7c00 (on main 67a2084e2), offline gfx1250 compile (flydsl 0.5.0, no GPU), final ISA compared: the batched kernel's fused-quant variants (LDS-staged and accumulator tiles, including t160x128x256 and t96x128x256) are ISA-identical before and after the quant_utils.py move; the 256x256 compute kernel (batched and 2-D, fused and bf16) is ISA-identical to main; the batched and 2-D bf16 variants are ISA-identical to main. No VGPR spill, no scratch.
  • This head, gfx950: python op_tests/test_flydsl_batched_gemm.py exits 0 with the same accuracy columns and the same fused-quant mismatch counts (all 0) as main 67a2084e2; python -m pytest op_tests/test_bmm_a8w8_fused_quant_supported.py op_tests/test_bmm_a8w8_fused_quant_tuned_row.py: 10 passed. test_compute_operand_guards fails on gfx950 the same way on main (a gfx1250 test, not gated by arch).
  • Head 99d9d6d6f: the last commit changes only comments, docstrings and one test constant; the three kernel files are AST-identical to e552b7c00 once docstrings are blanked, so the ISA statements above carry over. gfx950: python op_tests/test_flydsl_batched_gemm.py output is identical to e552b7c00 (exit 0, all fused-quant mismatches 0); python -m pytest op_tests/test_bmm_a8w8_fused_quant_supported.py op_tests/test_bmm_a8w8_fused_quant_tuned_row.py: 10 passed.
  • Head dfc62154e, gfx950: python op_tests/test_flydsl_batched_gemm.py exits 0 with output identical to 99d9d6d6f (all 45 fused-quant lines 0 mismatches, fused quant epilogue all bit-exact); with the final ISA dumped, all 30 fused-quant (_fq) bmm kernels are byte-identical to 99d9d6d6f, so the helper call emits the same code. python -m pytest op_tests/test_bmm_a8w8_fused_quant_supported.py op_tests/test_bmm_a8w8_fused_quant_tuned_row.py: 10 passed.
  • Head dfc62154e, gfx1250 (FlyDSL 0.5.0): results in [FlyDSL] [gfx1250] Batched mxfp8 GEMM fused-quant epilogue: quantize from the accumulators, use the tuned row #7667 (comment). python op_tests/test_flydsl_batched_gemm.py exits 0: all nine FUSED_QUANT_TILES (two LDS-staged, seven accumulator) have 0 scale and 0 fp8 mismatches at M = 48 and 200, the 45 heuristic-tile fused lines are all 0, and the compute kernelName cases pass; the heuristic sweep at M 1025 and 2048 (B 2 and 8, the 256x256 compute kernel) also has 0 mismatches; and the public batched_gemm_a8w8_mxscale_bpreshuffle_fused_quant on eight DSv4.1 wo_a table shapes (B 8, M 2 to 608, both epilogue branches, tile from the real table lookup) is bit-identical to the bf16 entry plus quantize_fp8.
  • Head f1a3bc230 (this head; [FlyDSL] [gfx1250] Batched mxfp8 GEMM fused-quant epilogue: quantize from the accumulators, use the tuned row #7667's six commits rebased onto main 3fd42598c, only conflict a test-file one in op_tests/test_flydsl_batched_gemm.py: main's _fused_quant_k() and gfx950 ragged-K block kept): the kernel code of this PR is the same as at dfc62154e (kernels/gemm_a8w8_gfx1250.py and kernels/quant_utils.py byte-identical; the patches to gemm_a8w8_256x256_gfx1250.py, bmm_a8w8_mxscale_gfx950.py, batched_gemm_a8w8_gfx1250.py and batched_gemm_op_a8w8.py line-identical, on top of main's [FlyDSL] [gfx1250] Compute GEMMs: cluster_m as a launch argument, DSv4.1 Flash prefill rows #7868 / [FlyDSL] Fix issue 7967:mm_a8w8_mxscale_gfx950: support a K of 32 mod 64 (DeepSeek-V4.1 shared-expert down projection at TP8, K = 288) #8636). Offline gfx1250 compile (flydsl 0.5.0, null pointers, no GPU), final ISA: 15 batched-kernel configs (bf16 batched / 2-D / mxfp8_128 / ptpc and the fused LDS-staged and accumulator tiles) byte-identical to dfc62154e; the four 256x256 compute configs (bf16 and fused, batched and 2-D) byte-identical to main 3fd42598c (as they were to main 67a2084e2 at dfc62154e); no spill, no scratch. CPU (GPU-less container): test_gemm_host_dispatch_cache.py + test_bmm_a8w8_fused_quant_tuned_row.py + test_bmm_a8w8_fused_quant_supported.py 27 passed; the 10 failures (CUDA-only cases) fail the same way on main. black / ruff clean. No idle gfx950 GPU for a rerun; the gfx1250 results of dfc62154e below carry over through the identical ISA.
  • Head d4016d527: adds one comment-only commit on top of f1a3bc230 (the FUSED_QUANT_TILES header now counts two LDS-staged and seven accumulator tiles); no code changes, so every result above for f1a3bc230 carries over.
  • black and ruff clean on the changed files.
  • Unverified: CI has no gfx1250 runner for FlyDSL op tests (ci:gfx1250-ffm-triton runs only for branches in ROCm/aiter and only the Triton suite plus two FlyDSL tests), so gfx1250 coverage is the manual runs above (this head: the comment linked above).

PR-specific question

What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?

  • op_tests/test_bmm_a8w8_fused_quant_tuned_row.py: before this PR the fused entry had no tuned-row lookup (every case fails); on earlier heads of this PR the unparsable-name case fails (the entry silently fell back to the heuristic tile while the bf16 entry raises) and the compute-row case fails (the compute kernelName was passed through; before [FlyDSL] [gfx1250] Compute GEMM: fused MXFP8 epilogue; untuned prefill-sized batched mxfp8_32 runs the compute kernel #7673 the runner rejected it with y_scale_out). On main ([FlyDSL] [gfx950] flydsl batched mxfp8 GEMM: optional fused mxfp8 quant epilogue #8101) the gfx1250 flydsl-row cases fail (the lookup returns None on every arch but gfx950). No other test calls _fused_quant_tuned_kernel; test_bmm_a8w8_fused_quant_supported.py only covers the arch check.
  • op_tests/test_flydsl_batched_gemm.py (gfx1250 pinned tiles): a wrong lane pairing, group column or scale-byte index in either epilogue branch, or a branch picked for the wrong wmma_n_rep, gives e4m3 / e8m0 mismatches against quantize_fp8 of the bf16 GEMM on the same tile. The existing test_woa_fused_quant_epilogue runs only the heuristic tile, which reaches one branch at most, so it does not pin both.

Changed op tests

  • op_tests/test_flydsl_batched_gemm.py (gfx1250): test_woa_fused_quant_epilogue takes a kernel_name; the bf16 reference and the fused run use the same tile. FUSED_QUANT_TILES runs shipped DSv4.1 tiles that pin both epilogue branches: two LDS-staged tiles (t16x64x512 nw4, t32x32x512 nw2 with one group per tile row) and seven accumulator tiles (t32x64x512 nw2, t128x128x256 nw2, t64x32x512 mw4 nw1 with one group per tile row, t160x128x256 nw2 and t192x128x256 nw2 with more tile rows than threads, t128x256x256 mw1 nw4 with eight groups per tile row, t96x128x256 nw2) on the DSv4.1 wo_a N/K, at M = 200 (ragged for every tile) and M = 48 (ragged for every tile but t16x64, of which it is a whole number). The last four are tuned wo_a rows the fused entry runs. gfx950 runs only the heuristic-tile fused check ([FlyDSL] [gfx950] flydsl batched mxfp8 GEMM: optional fused mxfp8 quant epilogue #8101), in its own block in main(). Not redundant: the existing check uses only the heuristic tile, so nothing guaranteed that either branch is reached.
  • op_tests/test_bmm_a8w8_fused_quant_tuned_row.py (new, CPU): _fused_quant_tuned_kernel with lookup_mxscale_bmm_config patched to return no row, an opus row, a compute-kernel row (one of main's DSv4.1 wo_a rows), a flydsl row and an unparsable flydsl name on gfx1250, and a flydsl row (the DSv4 batched preshuffle table's row for that shape), an opus row and no row on gfx950; also checks the lookup arguments (bpreshuffle table, weight-scale block, arch, CU count; the gfx1250 fixture uses a CU count other than the gfx950 one). It is the part of this PR that runs in CI.

🤖 Generated with Claude Code

@yhl-amd
yhl-amd requested a review from a team November 9, 2026 15:08
@github-actions github-actions Bot added the FlyDSL label Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026

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 7667 --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 9, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision d4016d52769d · 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

- Branch: main `3fd42598c` (rebased from `67a2084e2`; includes #7673, #8101, #7868, #8636) (includes #7673 and #8101) plus six commits: the earlier nine squashed into one that states the final behavior (accumulator quant, three peer branches, fused entry on the tuned row with compute rows left to the runner, tests); the tuned-row CPU test extended to gfx950 rows after the merge with #8101; the accumulator group-32 quant shared with #7673's epilogue in `quant_utils.py`; two more pinned accumulator tiles; comment and test-data fixes from review (scale-row copy wording, two stale `quant_utils.py` docstrings, the gfx950 fixture row); a second review round (no compute-name import or regex on gfx950, the gfx950 bmm epilogue on the shared group-32 scale helper, two docstrings, four more pinned tuned tiles, a non-256 CU count in the tuned-row fixture).
- Before: the fused epilogue always staged the bf16 C tile in LDS and re-read 32 values per group per thread; the fused entry always ran the heuristic tile.
- After: with an even `wmma_n_rep` (for example `t32x64 nw2`, `t64x32 nw1`, `t128x128 nw2`, `t128x256 nw4`) the group amax comes from the accumulators; an odd `wmma_n_rep` (`t16x64 nw4`, `t32x32 nw2`) keeps the #7178 path. The e4m3 codes and e8m0 scales are the same as `quantize_fp8` of the bf16 output in both cases. The fused entry runs the same tuned row as the bf16 entry on gfx1250 when that row is a non-compute flydsl kernel; a compute-kernel row (main's DSv4.1 wo_a table has some) is left to the runner's own tile choice, and a flydsl row with a bad name raises instead of silently falling back. gfx950 keeps #8101's behavior (a flydsl row picks the tile, `_fused_quant_falls_back` rows run bf16 plus the same quant).
- The non-fused bf16 path is unchanged, and the 256x256 compute kernel's generated code is unchanged (its fused epilogue now calls the shared helpers). No new environment variable.

Validation and unverified scope

- gfx1250, earlier revision of the accumulator epilogue (its math and indexing are unchanged here, only moved into its own branch): fused entry vs bf16 GEMM followed by a standalone `quantize_fp8` (amax floor 1e-10, e8m0 round-up): e4m3 codes and e8m0 scales bit-identical over many M including ragged tails, three data sets (all-zero rows, saturating fp8 inputs with large scales, fp8 subnormals and half-sparse rows), CUDA graph capture and replay with new inputs, and with the tuned rows. DeepSeek-V4.1-Flash served end to end with wo_a on the fused entry; GSM8K in line with the baseline.
- Earlier revision `bd6cc9b50`, offline gfx1250 compile of `launch_gemm_a8w8` (flydsl 0.5.0, no GPU), final ISA compared: the bf16 path (batched and 2-D mxfp8_32, mxfp8_128, ptpc) is ISA-identical to main; the three-branch restructure is ISA-identical to the head before it. No VGPR spill, no scratch.
- Earlier head `68071323b` (on main `0d894387b`, before #7673), gfx1250: `python op_tests/test_flydsl_batched_gemm.py` exits 0. The compute kernelName cases from main pass; the pinned tiles `t16x64x512 nw4` (LDS-staged) and `t32x64x512 nw2` / `t128x128x256 nw2` (accumulator) have 0 scale and 0 fp8 mismatches at M = 48 and M = 200; the heuristic-tile fused cases have 0 mismatches and the fused quant epilogue reports all bit-exact. `python -m pytest op_tests/test_bmm_a8w8_fused_quant_tuned_row.py op_tests/test_bmm_a8w8_fused_quant_supported.py`: 7 passed. Log in the PR comments.
- This head `e552b7c00` (on main `67a2084e2`), offline gfx1250 compile (flydsl 0.5.0, no GPU), final ISA compared: the batched kernel's fused-quant variants (LDS-staged and accumulator tiles, including `t160x128x256` and `t96x128x256`) are ISA-identical before and after the `quant_utils.py` move; the 256x256 compute kernel (batched and 2-D, fused and bf16) is ISA-identical to main; the batched and 2-D bf16 variants are ISA-identical to main. No VGPR spill, no scratch.
- This head, gfx950: `python op_tests/test_flydsl_batched_gemm.py` exits 0 with the same accuracy columns and the same fused-quant mismatch counts (all 0) as main `67a2084e2`; `python -m pytest op_tests/test_bmm_a8w8_fused_quant_supported.py op_tests/test_bmm_a8w8_fused_quant_tuned_row.py`: 10 passed. `test_compute_operand_guards` fails on gfx950 the same way on main (a gfx1250 test, not gated by arch).
- Head `99d9d6d6f`: the last commit changes only comments, docstrings and one test constant; the three kernel files are AST-identical to `e552b7c00` once docstrings are blanked, so the ISA statements above carry over. gfx950: `python op_tests/test_flydsl_batched_gemm.py` output is identical to `e552b7c00` (exit 0, all fused-quant mismatches 0); `python -m pytest op_tests/test_bmm_a8w8_fused_quant_supported.py op_tests/test_bmm_a8w8_fused_quant_tuned_row.py`: 10 passed.
- Head `dfc62154e`, gfx950: `python op_tests/test_flydsl_batched_gemm.py` exits 0 with output identical to `99d9d6d6f` (all 45 fused-quant lines 0 mismatches, fused quant epilogue all bit-exact); with the final ISA dumped, all 30 fused-quant (`_fq`) bmm kernels are byte-identical to `99d9d6d6f`, so the helper call emits the same code. `python -m pytest op_tests/test_bmm_a8w8_fused_quant_supported.py op_tests/test_bmm_a8w8_fused_quant_tuned_row.py`: 10 passed.
- Head `dfc62154e`, gfx1250 (FlyDSL 0.5.0): results in https://github.com/ROCm/aiter/pull/7667#issuecomment-7093541653. `python op_tests/test_flydsl_batched_gemm.py` exits 0: all nine `FUSED_QUANT_TILES` (two LDS-staged, seven accumulator) have 0 scale and 0 fp8 mismatches at M = 48 and 200, the 45 heuristic-tile fused lines are all 0, and the compute kernelName cases pass; the heuristic sweep at M 1025 and 2048 (B 2 and 8, the 256x256 compute kernel) also has 0 mismatches; and the public `batched_gemm_a8w8_mxscale_bpreshuffle_fused_quant` on eight DSv4.1 wo_a table shapes (B 8, M 2 to 608, both epilogue branches, tile from the real table lookup) is bit-identical to the bf16 entry plus `quantiz

[truncated in readiness report; see the PR description for the full answer]

PR-specific question

What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?

- `op_tests/test_bmm_a8w8_fused_quant_tuned_row.py`: before this PR the fused entry had no tuned-row lookup (every case fails); on earlier heads of this PR the unparsable-name case fails (the entry silently fell back to the heuristic tile while the bf16 entry raises) and the compute-row case fails (the compute kernelName was passed through; before #7673 the runner rejected it with `y_scale_out`). On main (#8101) the gfx1250 flydsl-row cases fail (the lookup returns None on every arch but gfx950). No other test calls `_fused_quant_tuned_kernel`; `test_bmm_a8w8_fused_quant_supported.py` only covers the arch check.
- `op_tests/test_flydsl_batched_gemm.py` (gfx1250 pinned tiles): a wrong lane pairing, group column or scale-byte index in either epilogue branch, or a branch picked for the wrong `wmma_n_rep`, gives e4m3 / e8m0 mismatches against `quantize_fp8` of the bf16 GEMM on the same tile. The existing `test_woa_fused_quant_epilogue` runs only the heuristic tile, which reaches one branch at most, so it does not pin both.

Changed op tests

- `op_tests/test_flydsl_batched_gemm.py` (gfx1250): `test_woa_fused_quant_epilogue` takes a `kernel_name`; the bf16 reference and the fused run use the same tile. `FUSED_QUANT_TILES` runs shipped DSv4.1 tiles that pin both epilogue branches: two LDS-staged tiles (`t16x64x512 nw4`, `t32x32x512 nw2` with one group per tile row) and seven accumulator tiles (`t32x64x512 nw2`, `t128x128x256 nw2`, `t64x32x512 mw4 nw1` with one group per tile row, `t160x128x256 nw2` and `t192x128x256 nw2` with more tile rows than threads, `t128x256x256 mw1 nw4` with eight groups per tile row, `t96x128x256 nw2`) on the DSv4.1 wo_a N/K, at M = 200 (ragged for every tile) and M = 48 (ragged for every tile but `t16x64`, of which it is a whole number). The last four are tuned wo_a rows the fused entry runs. gfx950 runs only the heuristic-tile fused check (#8101), in its own block in `main()`. Not redundant: the existing check uses only the heuristic tile, so nothing guaranteed that either branch is reached.
- `op_tests/test_bmm_a8w8_fused_quant_tuned_row.py` (new, CPU): `_fused_quant_tuned_kernel` with `lookup_mxscale_bmm_config` patched to return no row, an opus row, a compute-kernel row (one of main's DSv4.1 wo_a rows), a flydsl row and an unparsable flydsl name on gfx1250, and a flydsl row (the DSv4 batched preshuffle table's row for that shape), an opus row and no row on gfx950; also checks the lookup arguments (bpreshuffle table, weight-scale block, arch, CU count; the gfx1250 fixture uses a CU count other than the gfx950 one). It is the part of this PR that runs in CI.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

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.

@yhl-amd

yhl-amd commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto the current head of #7178 (352446c2f, which includes efb9bbeb1). Our two commits are unchanged in content. bmm_a8w8_mxfp8_fused_quant_supported() now looks up _RUNNERS through base_gfx_arch(get_gfx()), so gfx1250-strict is folded the same way _runner does it. The new commits do not add any other raw get_gfx() table lookup; the tuned-row lookup in the fused entry goes through the same _device_arch_and_cu + lookup_mxscale_bmm_config path as the bf16 entry, which already folds gfx1250-strict. op_tests/test_bmm_a8w8_fused_quant_supported.py passes on this branch.

Thanks @karverma-amd for pointing this out.

@yhl-amd

yhl-amd commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Standard Tests (1 GPU) shard 2 failed in op_tests/test_woa_fused_quant.py with ModuleNotFoundError: No module named 'op_tests' (log). CI runs op tests as python op_tests/<file>.py, so the repo root is not on sys.path and the import of the sibling test fails before the gfx1250 check can skip. Pushed a17fb17, which prepends the repo root the same way other op tests that import a sibling test do.

@karverma-amd this file comes from #7178, so #7178 will hit the same failure once its tests run; feel free to take the same change there, and I will drop mine on the next rebase.

@yhl-amd
yhl-amd force-pushed the hyi/gfx1250-bmm-fused-quant-acc-epilogue branch from a17fb17 to 47d53cd Compare November 11, 2026 03:38
@yhl-amd

yhl-amd commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto #7178's current head (803a3cd). #7178 now carries the sys.path fix for op_tests/test_woa_fused_quant.py itself, so the duplicate commit is dropped here; the two remaining commits cherry-picked without conflicts and are unchanged. The branch merges cleanly with current main.

Checked (no GPU): py_compile / black / ruff on the changed files, the changed modules import from the branch tree, test_woa_fused_quant.py imports as a script, and op_tests/test_bmm_a8w8_fused_quant_supported.py passes.

@zufayu
zufayu removed the request for review from coderfeli November 11, 2026 06:55
@zufayu zufayu assigned aoli26 and unassigned coderfeli Nov 11, 2026
@zufayu
zufayu requested a review from coderfeli November 11, 2026 06:56
@yhl-amd
yhl-amd force-pushed the hyi/gfx1250-bmm-fused-quant-acc-epilogue branch from 47d53cd to cfc5415 Compare November 11, 2026 14:43
@yhl-amd

yhl-amd commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

The previous build_aiter_wheels failure was infrastructure: the Docker Hub pull of the build image hit 429 Too Many Requests on all five attempts, and this branch predated the mirror.gcr.io fallback (#7694). Rebased the two commits onto the current #7178 head (eba36e7d31, which already merges main), so CI picks up the fallback; patches unchanged.

@yhl-amd
yhl-amd force-pushed the hyi/gfx1250-bmm-fused-quant-acc-epilogue branch from cfc5415 to 5aa2e85 Compare November 11, 2026 15:54
@yhl-amd

yhl-amd commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main now that #7178 is merged. The #7178 commits are gone; the branch is main plus our two commits, unchanged. Removed the "Stacked on #7178" line from the description. No test files are touched here, so nothing depends on the removed test_woa_fused_quant.py.

aoli26 added a commit that referenced this pull request Nov 13, 2026
…4-1536, 2048/3072

In the model a FlyDSL compute kernel runs 10-25 us slower after another
compute specialization than it does alone, which the tuner cannot see.
Pick kernels that do not have the penalty:

- Q-B (1,32768,1280) M=576/672: compute -> bmm t192x256x256 nb2 _pl
  (needs the software-pipelined K loop from #7668, stacked on #7667)
- O-A batched (8,1024,4096) M=1024..1536 step 64: compute -> bmm
  t256x256x256 nb2 (9 rows replaced; kernelName only; the fused-quant
  entry uses the tuned row only with #7667)
- Shared down (5120,2304) M=2048/3072: new rows, bmm t256x256x256 nb2
- O-B (5120,8192) M=2048/3072: new rows, compute t256x256x128 nb2 cm1_cn1

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ Action required before merge (4)

  1. Flatten the epilogue into three peer branches and drop the dead code in the new branch. kernels/gemm_a8w8_gfx1250.py:959/1068/1079/1105: use if const_expr(not fuse_quant_out): <bf16 store, unchanged> / elif const_expr(wmma_n_rep % 2 == 0): <acc quant> / else: <#7178 LDS quant>. The bf16 path then keeps its old indentation and drops out of the diff. In the new branch, row64 (:991) and cbase_blk (:986-988) are never read (c8_off at :1049-1051 computes cbase_blk again). Move GN, v2i32_ty, n32_64, srow and sbase_blk above the fused branches so both quant paths share one copy.
  2. Fix the comment on the new path. gemm_a8w8_gfx1250.py:963 says "no LDS staging, no barrier", but the e4m3 and scale bytes are staged in LDS (:1018-1032) and there is a workgroup_barrier at :1033. Say the amax needs only one shuffle_xor(16) and the bytes still go through LDS for the TDM store.
  3. Add tests that pin each epilogue branch and the tuned-row lookup. test_woa_fused_quant_epilogue (op_tests/test_flydsl_batched_gemm.py:347) uses only the heuristic tile, so no test is guaranteed to reach a given branch. Both branches are live in the DSv4.1 table: t16x64_nw4 and t32x32_nw2 (wmma_n_rep 1) take the #7178 path, and t32x64_nw2, t64x32_nw1 and t128x128_nw2 take the new one. Add a kernel_name parameter and run one tile of each kind against quantize_fp8. Also add a CPU test of _fused_quant_tuned_kernel next to op_tests/test_bmm_a8w8_fused_quant_supported.py, with lookup_mxscale_bmm_config patched to return no row, an opus row and a flydsl row. CI has no gfx1250 runner, so this CPU test is the only part that runs in CI.
  4. Make the fused entry handle a bad row the way the bf16 entry does. batched_gemm_op_a8w8.py:515: a flydsl row whose name parse_bmm_mx32_kernel_name rejects makes the fused entry quietly use the heuristic tile, while the bf16 entry raises ValueError for that same row (run_bmm_a8w8_mxfp8_32_gfx1250). Drop the check and pass the flydsl row's kernelName through. Keep returning None only when there is no row or the row is an opus row.

Index mapping checked on CPU (lanes l and l^16 cover each 32-column group, every e4m3 and scale byte in LDS is written exactly once, and the new LDS use fits in C_STORE_B) for 156 tiles and every DSv4.1 row: probes/test_epilogue_index_model.py. CI is green (MI35X only). #7668 is stacked on this PR: it contains these two commits and changes neither the epilogue nor _fused_quant_tuned_kernel, so merge this PR first.


Reviewed at 5aa2e85.

@yhl-amd
yhl-amd force-pushed the hyi/gfx1250-bmm-fused-quant-acc-epilogue branch from 5aa2e85 to bd6cc9b Compare November 14, 2026 03:54
yhl-amd added a commit to yhl-amd/ATOM that referenced this pull request Nov 19, 2026
…ate_up tests

- recipes/DeepSeek-V4.1-Flash.md: gfx1250 needs an AITER that contains
  ROCm/aiter#7667, #7668 and #8057 (aiter main after #8057; the exact commit
  goes in once they land). The pinned AITER is noted as the gfx950 one: with
  it a gfx1250 V4.1 build fails at the shared expert's import.
- Expert.gate_up_silu_quant: the batch-size note is exact. The dequantized
  values stay within one e4m3 step, but a group's E8M0 scale, and every code
  in it, can differ when its max sits on 448 * 2**k in one chain and on the
  next bf16 value in the other.
- Tests: the fused branch hands AITER quantize_fp8's e4m3 rows and E8M0
  scales (the objects themselves); the op's fake returns e4m3 [m, inter] and
  E8M0 [m, inter / 32] on x's device, called directly and through the
  registered op under FakeTensorMode.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@yhl-amd
yhl-amd force-pushed the hyi/gfx1250-bmm-fused-quant-acc-epilogue branch from 6807132 to 305f898 Compare November 19, 2026 10:57
@yhl-amd

yhl-amd commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

@valarLip Rebased onto main e8baf0696 (which includes #7673); new head 305f898e7 (previous head kept at bak/7667-pre1119d).

Conflict resolution:

Checks on this head: gfx950, python op_tests/test_flydsl_batched_gemm.py exits 0 with accuracy columns identical to main e8baf0696; pytest op_tests/test_bmm_a8w8_fused_quant_supported.py op_tests/test_bmm_a8w8_fused_quant_tuned_row.py 7 passed; test_compute_operand_guards fails on gfx950 identically on main (gfx1250 test). black 26.10.1 / ruff clean; Self-Review updated to this head (0 issues). gfx1250 validation of this head pending.

Could you approve formally?

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ Action required before merge (2)

  1. Rebase onto main and resolve the #8101 conflict so that both arches keep their tuned rows. The PR conflicts with main in aiter/ops/batched_gemm_op_a8w8.py and op_tests/test_flydsl_batched_gemm.py, because #8101 (gfx950 fused quant) adds its own _fused_quant_tuned_kernel with if gfx != "gfx950": return None. Please watch for these traps:
    • Don't keep main's gfx950-only gate. It silently drops every gfx1250 tuned row. Keep your body (:494-519: lookup, None for a compute row, otherwise pass the name through) and main's _fused_quant_falls_back block, which is gated on gfx == "gfx950".
    • Delete the second _device_arch_and_cu import and call. Git merges it into the fused entry without a conflict marker.
    • Rewrite #8101's docstrings, which become false after the merge. In _fused_quant_tuned_kernel, "None ... on every other arch: a gfx1250 32x32 table row may name a compute kernel, which has no fused epilogue" is already false since #7673. In the fused entry, "... as does every other arch" is also false. Say that the flydsl row picks the tile on both arches, and that an opus row, a gfx1250 compute row or no row leaves the choice to the runner. Keep #8101's sentence that the fused GEMM may differ from the bf16 entry's by an fp32 rounding.
    • Test file, gfx950 branch: don't pass kernel_name to the gfx950 run_ref. It is functools.partial(..., kernel_name=tile), and a call-time None overrides tile.
    • Test file, main(): give the gfx1250 fused call its own block, e.g. if arch == "gfx950": _run_fused_quant(shapes) and if arch == "gfx1250": _run_fused_quant(shapes, pin_tiles=not custom_shape). The FUSED_QUANT_TILES names are gfx1250 kernels. A separate block also gives #7668/#8057 a safe place for _run_pipelined() / _run_gate_up_silu(). Under a shared ("gfx1250", "gfx950") gate a mechanical rebase lands them there with no conflict, and they raise on MI35X (batched_gemm_a8w8_gfx1250.py:422).
    • Expected result: checked on CPU, with that resolution, gfx950 behaves as main on all 681 gfx950 table rows, gfx1250/strict behaves as this head on all 122 rows, and both CPU test files pass (8/8).
  2. Share the accumulator group-32 quant with #7673's epilogue instead of adding a second copy. The new branch (kernels/gemm_a8w8_gfx1250.py:994-1002 _group_scale, the per-group loop after :1031, the scale-row loop and the e4m3 TDM store) is near-verbatim the fused epilogue #7673 put on main (kernels/gemm_a8w8_256x256_gfx1250.py:1642-1734): same h0/h1 amax, shuffle_xor(16), 1e-10 floor, RoundUp e8m0, emit_cvt_scalef32_pk8_fp8_f32, LDS offsets and rr scale-row store (~60 of ~100 lines identical, the rest renames). In this rebase, move the per-group step (acc pair -> e4m3 and scale bytes in LDS) and the scale-row store into kernels/quant_utils.py next to emit_mx_e8m0_scale, call it from both kernels, keep each kernel's own TDM view, and rerun the bit-exact fused check for both kernels on gfx1250.

Optional:

  • Add t64x32x512 mw4 nw1 (GN 1) and t160x128x256 nw2 (tile_m > 128, so a second scale-row pass) to FUSED_QUANT_TILES. Both are shipped accumulator-branch rows that no test pins. A CPU model of the branch is bit-exact for them.
  • Since the rebase is needed anyway, a squash message that states the final behaviour would keep 6c2a1f1's "the runner rejects it when y_scale_out is set" out of main.

Reviewed at 305f898 (deep, 3 hunters + 2 verifiers + miss pass; full diff). The kernel is byte-identical to 6807132. The accumulator epilogue is bit-exact against the LDS-staged branch and a quantize_fp8 reference on all 40 gfx1250 32x32 rows on main, and the bf16 path is unchanged. The fused and bf16 entries pick the same row on gfx1250 and strict. Already fixed: all 9 earlier asks (three peer branches, new-path comment, pinned-tile and tuned-row tests, a bad flydsl name raising, the gfx1250 run, test comments, compute rows → None, _group_scale, the _check_bmm_operands docstring). Item 2 became visible only when #7673 landed (11-19), after the 6807132 LGTM. Leaving tuned compute rows to the runner matches main's behaviour and is stated in the PR; not required. CI: 8 MI35X shards pending, nothing failed. #7668/#8057 must re-check main() after they rebase.

@yhl-amd
yhl-amd force-pushed the hyi/gfx1250-bmm-fused-quant-acc-epilogue branch from 305f898 to e552b7c Compare November 20, 2026 02:07
@yhl-amd

yhl-amd commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

@valarLip Addressed review 5979457321. Rebased onto main 67a2084e2 (includes #8101); new head e552b7c00, previous head kept at bak/7667-pre1120a. Per your squash note, the earlier nine commits are now one commit (ca4d44203) whose message states the final behavior, so the old "the runner rejects it when y_scale_out is set" text is gone.

1. #8101 conflict, both arches keep their tuned rows (ca4d44203, 53c2d443c)

  • One _fused_quant_tuned_kernel for both arches: no gfx != "gfx950" gate; lookup, None for no row / opus row / gfx1250 compute row (is_compute_wmma_kernel_name), otherwise the name is passed through. gfx950 names never match the compute-name patterns, so gfx950 gets the same result as on main.
  • Main's _fused_quant_falls_back block (gated on gfx == "gfx950") kept as is; the second _device_arch_and_cu import and call removed, and the fused call uses the kernel_name computed once.
  • Docstrings rewritten: the flydsl row picks the tile on both arches; an opus row, a gfx1250 compute row or no row leaves the choice to the runner. [FlyDSL] [gfx950] flydsl batched mxfp8 GEMM: optional fused mxfp8 quant epilogue #8101's sentence about the fp32 rounding difference vs the bf16 entry is kept.
  • Test file: the gfx950 branch of test_woa_fused_quant_epilogue keeps run_ref = partial(..., kernel_name=tile) and is not passed kernel_name. The gfx1250 branch binds kernel_name with partial for both the reference and the fused run. main() has separate blocks: if arch == "gfx950": _run_fused_quant(shapes) and if arch == "gfx1250": _run_fused_quant(shapes, pin_tiles=not custom_shape).
  • op_tests/test_bmm_a8w8_fused_quant_tuned_row.py adds gfx950 cases (flydsl row passed through; opus row and no row give None) next to the gfx1250 ones.

2. Accumulator group-32 quant shared with #7673's epilogue (085326080)

  • kernels/quant_utils.py, next to emit_mx_e8m0_scale: emit_mxfp8_group32_scale (1e-10 floor, RoundUp e8m0, f32 scale), emit_mxfp8_acc_pair_to_lds (acc pair -> round to out dtype, h0/h1 amax + shuffle_xor(16), scaled fp8 conversion, e4m3 and scale bytes into LDS) and emit_mxfp8_scale_rows_store (LDS scale rows -> row-major scale). The last two are @flyc.jit because they contain runtime branches (kgrp == 0, the row bound).
  • Both gemm_a8w8_gfx1250.py (accumulator branch; the LDS-staged branch uses emit_mxfp8_group32_scale, replacing the local _group_scale) and gemm_a8w8_256x256_gfx1250.py call them. Each kernel keeps its own e4m3 TDM view and store.
  • Offline gfx1250 compile, final ISA: the batched kernel's fused variants (two LDS-staged and six accumulator tiles, including t160x128 and t96x128) are identical before and after the move. The 256x256 kernel (batched and 2-D, fused and bf16) and the bf16 variants are identical to main, with no spill and no scratch. The gfx1250 bit-exact rerun of both kernels is pending.

Optional

  • FUSED_QUANT_TILES adds t64x32x512 mw4 nw1 and t160x128x256 nw2 nb3 (e552b7c00); M = 48 and 200 are ragged for both.
  • Squash message: done as described above.

Checks on this head:

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ Action required before merge (4)

  1. Post the gfx1250 bit-exact run for both kernels at this head. This is still open from the last review. 085326080 moved the accumulator quant into kernels/quant_utils.py:189-265: the per-group step and the scale-row store are now @flyc.jit helpers that take out_cls and the tile constants as arguments, and both gemm_a8w8_gfx1250.py and gemm_a8w8_256x256_gfx1250.py call them. The PR description and your 11-20 comment both say the gfx1250 run is pending. The only evidence for the move is an offline ISA compare. The two newly pinned tiles (t64x32x512 mw4 nw1, t160x128x256 nw2) have never run on hardware, and CI has no gfx1250 FlyDSL lane. Run python op_tests/test_flydsl_batched_gemm.py on gfx1250 and paste:
    • the scale and fp8 mismatch lines for all five FUSED_QUANT_TILES at M = 48 and 200, which should all be 0;
    • the heuristic-tile fused sweep, including M 1025 and 2048 on the 256x256 compute kernel;
    • if you can, one call of the public batched_gemm_a8w8_mxscale_bpreshuffle_fused_quant on a DSv4.1 wo_a table shape, compared bit-exact against the bf16 entry plus quantize_fp8. No test goes through the real lookup on gfx1250.
  2. Fix the gfx950 fixture name in the new CPU test. At op_tests/test_bmm_a8w8_fused_quant_tuned_row.py:22-23, flydsl_bmm_mxfp8_mfma_t16x16x256_w1x1_nb6_sk4_nt_sps is commented as "A gfx950 row of main's tuned bmm tables". It is only in the 2-D *_tuned_gemm.csv tables, not in any *batched_gemm_a8w8_blockscale_mxscale_bpreshuffle_tuned*.csv that lookup_mxscale_bmm_config(bpreshuffle=True) reads. Use flydsl_bmm_mxfp8_mfma_t64x32x512_w2x2_nb3_sk1_nt, which is the DSv4 bmm row for exactly _SHAPE_950, or fix the comment.
  3. Fix the "one row per thread" text this PR adds. The scale-row loop runs ceil(tile_m / block) passes (thread tid writes rows tid, tid + block, …). So on the shipped t160/t192/t256x128 nw2 tiles a thread writes two rows. Reword both new sites:
    • quant_utils.py:251, the emit_mxfp8_scale_rows_store docstring;
    • gemm_a8w8_gfx1250.py:1056.
      For example: "each thread copies whole scale rows (rows tid, tid + block, …); a row's GN bytes are contiguous in the row-major scale, so each row is one small store." The same comment in gemm_a8w8_256x256_gfx1250.py:1688 came from main, but sits in a hunk you edit; fix it too.
  4. Fix the squash message. ca4d44203 says the pinned tiles are "one LDS-staged, two accumulator", but FUSED_QUANT_TILES now has one LDS-staged and four accumulator tiles. Please correct it in the squash text when merging.

Pre-existing (not required here): quant_utils.py:363 refers to emit_amax_e8m0_recip, which doesn't exist. The module docstring lists mxfp6/mxint8, but _DTYPE_CFG has only fp4/fp8.


Reviewed at e552b7c (deep: 3 hunters + ecc:review-pr, 2 verifiers, miss pass, and an independent second pass; full diff). Checked on CPU and clean:

  • The three helpers are AST-identical to the inline code they replace in both kernels, and every call-site argument matches, including the batched sbase.
  • An index/LDS/bit-exact model passes on every gfx1250 table tile, including GN=1 and tile_m > block.
  • The bf16 path is unchanged.
  • _fused_quant_tuned_kernel matches main on all 680 gfx950 rows. On gfx1250 it passes 37 rows through, all accepted by the runner with y_scale_out, and the 3 compute rows go to None.

Already fixed: the #8101 rebase (one function for both arches, a single _device_arch_and_cu, rewritten docstrings, gfx950 run_ref, separate main() blocks), the helpers shared with #7673, both optional tiles, and the squash into one commit. CI: shards 0/4/5/7 of the MI35X 1-GPU Standard Tests failed with "runner lost communication" (infra), so the Test Gate needs a rerun.

@yhl-amd
yhl-amd force-pushed the hyi/gfx1250-bmm-fused-quant-acc-epilogue branch from e552b7c to 99d9d6d Compare November 20, 2026 10:23
@yhl-amd

yhl-amd commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

@valarLip thanks, addressed at head 99d9d6d6f (old head kept as bak/7667-pre1120b on the fork).

  1. gfx1250 bit-exact run for both kernels — gfx1250 run will be posted before merge. It will include everything you listed: the scale and fp8 mismatch lines of all five FUSED_QUANT_TILES at M = 48 and 200; the heuristic-tile fused sweep including M 1025 and 2048 on the 256x256 compute kernel; and one call of the public batched_gemm_a8w8_mxscale_bpreshuffle_fused_quant on a DSv4.1 wo_a table shape, compared bit-exact against the bf16 entry plus quantize_fp8. The description now says this instead of "pending".
  2. gfx950 fixture name — op_tests/test_bmm_a8w8_fused_quant_tuned_row.py now uses flydsl_bmm_mxfp8_mfma_t64x32x512_w2x2_nb3_sk1_nt, the row for exactly _SHAPE_950 in dsv4_batched_gemm_a8w8_blockscale_mxscale_bpreshuffle_tuned.csv, and the comment says so (99d9d6d6f).
  3. "one row per thread" — reworded with your text at all three sites: the emit_mxfp8_scale_rows_store docstring in quant_utils.py, gemm_a8w8_gfx1250.py and gemm_a8w8_256x256_gfx1250.py (99d9d6d6f).
  4. Squash message — the first commit's message (now 1e9deb743, was ca4d44203; tree unchanged) says "one LDS-staged, four accumulator".

Pre-existing, also fixed in 99d9d6d6f since they are docstring-only: emit_amax_e8m0_native_scale now describes what it does (max tree, one shuffle_xor(16), emit_mx_e8m0_scale, forward scale) instead of referring to the non-existent emit_amax_e8m0_recip; the module docstring no longer lists mxfp6/mxint8 and says _DTYPE_CFG defines fp4 (e2m1) and fp8 (e4m3 / e4m3fnuz) only.

The new commit touches only comments, docstrings and one test constant; the three kernel files are AST-identical to e552b7c00 with docstrings blanked, so no kernel instruction changes. gfx950 at this head: python op_tests/test_flydsl_batched_gemm.py exits 0 with output identical to e552b7c00 (all 45 fused-quant lines 0 mismatches); pytest op_tests/test_bmm_a8w8_fused_quant_supported.py op_tests/test_bmm_a8w8_fused_quant_tuned_row.py: 10 passed. black 26.10.1 and ruff clean; PR Self-Review updated to this head.

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ Action required before merge (5)

  1. Post the gfx1250 bit-exact run at this head (still open from the last review). Since the last hardware run (1631e8ebd, 3 tiles), the quant moved into the quant_utils.py helpers, and t64x32x512 mw4 nw1 and t160x128x256 nw2 were added; none of these has run on gfx1250. CI has no gfx1250 FlyDSL lane. Paste the mismatch lines for all five FUSED_QUANT_TILES at M = 48 and 200, the heuristic fused sweep including M 1025/2048, and one public fused-entry call on a DSv4.1 wo_a shape. Also include tiles that the fused entry now runs from main's tuned rows but no test pins: t192x128x256 nw2 (M 544-736, tile_m > 128 threads), t128x256x256 mw1 nw4 (M 800-896, GN = 8), t96x128x256 (M 352) and t32x32x512 (M 20, LDS branch, GN = 1). Either pin them in FUSED_QUANT_TILES or add them to the run.
  2. Keep the per-shape import and regex off gfx950. aiter/ops/batched_gemm_op_a8w8.py:528,543 now runs from .flydsl.mxfp8_bpreshuffle_gemm_gfx1250 import is_compute_wmma_kernel_name and the compute-name regex on every lru_cache miss, on gfx950 too, where no row name can match. Each new M (eager prefill on the DSv4.1 wo_a path) costs +1.2-1.3 µs: base 0.96-2.3 µs vs head 2.2-3.6 µs, two independent A/B runs on a pinned core with controls. Do not hoist the import to module level: aiter/__init__.py would then import flydsl unconditionally. Instead end the function with:
    name = cfg["kernelName"]
    if gfx == "gfx950":
        return name
    from .flydsl.mxfp8_bpreshuffle_gemm_gfx1250 import is_compute_wmma_kernel_name
    return None if is_compute_wmma_kernel_name(name) else name
    This measures the same as base on gfx950, and the new CPU test still passes.
  3. Use the new helper in the gfx950 bmm kernel too. aiter/ops/flydsl/kernels/bmm_a8w8_mxscale_gfx950.py:1179-1185 repeats emit_mxfp8_group32_scale (quant_utils.py:190-201) step for step: 1e-10 floor, RoundUp FP8_E4M3 e8m0, <<23 scale. Replace it with e8, scale = emit_mxfp8_group32_scale(amax), imported next to emit_mx_e8m0_scale at :53, and keep the gfx950 fused-quant lines at 0 mismatches. We missed this last round and filed it as pre-existing.
  4. Fix the two "bf16 C tile" sentences that the accumulator branch made untrue. In batched_gemm_a8w8_gfx1250.py:489, write e.g. "y_scale_out: when given, the epilogue writes the output group-32 MXFP8-quantized (e4m3) instead of bf16 -- ...". In gemm_a8w8_gfx1250.py:75, write e.g. "fuse_quant_out: the output is group-32 MXFP8-quantized in the epilogue instead of written as bf16, from the accumulators rounded to bf16 when wmma_n_rep is even, else from the bf16 C tile staged in LDS." You already fixed the same point in _check_bmm_operands.
  5. Give one tuned-row test fixture a CU count other than 256. In op_tests/test_bmm_a8w8_fused_quant_tuned_row.py, both _SHAPE and _SHAPE_950 use cu 256, so replacing cu_num=cu_num with a constant 256 still passes all cases. Use e.g. 80 in one of them.

Reviewed at 99d9d6d (deep, full diff: 4 hunters including ecc:review-pr, 2 verifiers, a miss pass). Checked on CPU and clean:

  • An index, LDS and numerics model of both epilogue branches and the scale-row store passes on all 44 gfx1250 table and heuristic tiles at head and current main.
  • The helper code is AST-equivalent to main's inline 256x256 code, the bf16 path is unchanged, and the semantic merge with current main is clean.
  • The runner accepts all 41 gfx1250 rows the fused entry now passes through. gfx950 routing is identical to main on 680 rows.
  • CI is green, and the new CPU test ran in shard 2.

Already fixed: the fixture row, the "one row per thread" text at all three sites, the squash tile count, and both stale quant_utils docstrings.

@yhl-amd
yhl-amd force-pushed the hyi/gfx1250-bmm-fused-quant-acc-epilogue branch from 99d9d6d to dfc6215 Compare November 21, 2026 01:51
@yhl-amd

yhl-amd commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

@valarLip thanks, addressed at head dfc62154e (old head kept as bak/7667-pre1121a on the fork).

  1. gfx1250 bit-exact run — gfx1250 run will be posted before merge, with everything listed: the mismatch lines for every FUSED_QUANT_TILES entry at M = 48 and 200, the heuristic fused sweep including M 1025/2048, and one public fused-entry call on a DSv4.1 wo_a shape against the bf16 entry plus quantize_fp8. The four tiles you named are now pinned in FUSED_QUANT_TILES, so that run covers them: t192x128x256 mw2 nw2 nb3, t128x256x256 mw1 nw4 nb3, t96x128x256 mw2 nw2 nb4 and t32x32x512 mw2 nw2 nb4 (the names of main's DSv4.1 wo_a rows). The list is now two LDS-staged and seven accumulator tiles; the test docstring and the first commit's message (801419a51, tree unchanged) say so.
  2. Per-shape import and regex off gfx950 — _fused_quant_tuned_kernel now ends with your code: gfx950 returns the name directly, and the is_compute_wmma_kernel_name import and check run only on gfx1250 (dfc62154e). The import stays function-local. The tuned-row CPU test passes.
  3. gfx950 bmm kernel on the shared helper — bmm_a8w8_mxscale_gfx950.py now calls e8, scale = emit_mxfp8_group32_scale(amax). The import replaces emit_mx_e8m0_scale and the mx_types import, since nothing else in the file uses them (ruff would flag them). This touches kernel source, so I checked the generated code on gfx950. At this head python op_tests/test_flydsl_batched_gemm.py exits 0 with output identical to 99d9d6d6f: all 45 fused-quant lines have 0 mismatches and the fused quant epilogue is all bit-exact. I also dumped the final ISA at both heads: all 30 fused-quant (_fq) bmm kernels are byte-identical, so the instructions do not change. Outside the fused kernels, 104 of 105 dumps also match. The one exception is a non-fused split-K kernel, which does not contain the changed code; its diff is only a swap of the scalar registers in one 64-bit address add.
  4. "bf16 C tile" sentences — reworded with your text in batched_gemm_a8w8_gfx1250.py (y_scale_out) and in the fuse_quant_out comment in gemm_a8w8_gfx1250.py (dfc62154e).
  5. CU count in the tuned-row fixture — _SHAPE (gfx1250) now uses cu 80, so a constant 256 in place of cu_num=cu_num fails the gfx1250 cases (dfc62154e).

Also at this head: pytest op_tests/test_bmm_a8w8_fused_quant_supported.py op_tests/test_bmm_a8w8_fused_quant_tuned_row.py gives 10 passed on gfx950; black 26.10.1 and ruff are clean; the PR Self-Review is updated to dfc62154e.

@yhl-amd

yhl-amd commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

gfx1250 run at head dfc62154e (dfc62154eb2a9e58de6eb81a19d040f0dfd02964), FlyDSL 0.5.0, one GPU. All three items @valarLip asked for in #7667 (comment) and #7667 (comment) pass with 0 mismatches.

1. FUSED_QUANT_TILES (2 LDS-staged + 7 accumulator tiles) at M = 48 and 200 — python op_tests/test_flydsl_batched_gemm.py, rc = 0:

fused quant B=8 M=48 N=1024 K=4096 tile flydsl_bmm_mxfp8_32_wmma_t16x64x512_mw1_nw4_nb4_sk1_cm1_cn1: scale mismatch 0/12288, fp8 mismatch 0/393216
fused quant B=8 M=200 N=1024 K=4096 tile flydsl_bmm_mxfp8_32_wmma_t16x64x512_mw1_nw4_nb4_sk1_cm1_cn1: scale mismatch 0/51200, fp8 mismatch 0/1638400
fused quant B=8 M=48 N=1024 K=4096 tile flydsl_bmm_mxfp8_32_wmma_t32x64x512_mw2_nw2_nb4_sk1_cm1_cn1: scale mismatch 0/12288, fp8 mismatch 0/393216
fused quant B=8 M=200 N=1024 K=4096 tile flydsl_bmm_mxfp8_32_wmma_t32x64x512_mw2_nw2_nb4_sk1_cm1_cn1: scale mismatch 0/51200, fp8 mismatch 0/1638400
fused quant B=8 M=48 N=1024 K=4096 tile flydsl_bmm_mxfp8_32_wmma_t128x128x256_mw2_nw2_nb4_sk1_cm1_cn1: scale mismatch 0/12288, fp8 mismatch 0/393216
fused quant B=8 M=200 N=1024 K=4096 tile flydsl_bmm_mxfp8_32_wmma_t128x128x256_mw2_nw2_nb4_sk1_cm1_cn1: scale mismatch 0/51200, fp8 mismatch 0/1638400
fused quant B=8 M=48 N=1024 K=4096 tile flydsl_bmm_mxfp8_32_wmma_t64x32x512_mw4_nw1_nb4_sk1_cm1_cn1: scale mismatch 0/12288, fp8 mismatch 0/393216
fused quant B=8 M=200 N=1024 K=4096 tile flydsl_bmm_mxfp8_32_wmma_t64x32x512_mw4_nw1_nb4_sk1_cm1_cn1: scale mismatch 0/51200, fp8 mismatch 0/1638400
fused quant B=8 M=48 N=1024 K=4096 tile flydsl_bmm_mxfp8_32_wmma_t160x128x256_mw2_nw2_nb3_sk1_cm1_cn1: scale mismatch 0/12288, fp8 mismatch 0/393216
fused quant B=8 M=200 N=1024 K=4096 tile flydsl_bmm_mxfp8_32_wmma_t160x128x256_mw2_nw2_nb3_sk1_cm1_cn1: scale mismatch 0/51200, fp8 mismatch 0/1638400
fused quant B=8 M=48 N=1024 K=4096 tile flydsl_bmm_mxfp8_32_wmma_t192x128x256_mw2_nw2_nb3_sk1_cm1_cn1: scale mismatch 0/12288, fp8 mismatch 0/393216
fused quant B=8 M=200 N=1024 K=4096 tile flydsl_bmm_mxfp8_32_wmma_t192x128x256_mw2_nw2_nb3_sk1_cm1_cn1: scale mismatch 0/51200, fp8 mismatch 0/1638400
fused quant B=8 M=48 N=1024 K=4096 tile flydsl_bmm_mxfp8_32_wmma_t128x256x256_mw1_nw4_nb3_sk1_cm1_cn1: scale mismatch 0/12288, fp8 mismatch 0/393216
fused quant B=8 M=200 N=1024 K=4096 tile flydsl_bmm_mxfp8_32_wmma_t128x256x256_mw1_nw4_nb3_sk1_cm1_cn1: scale mismatch 0/51200, fp8 mismatch 0/1638400
fused quant B=8 M=48 N=1024 K=4096 tile flydsl_bmm_mxfp8_32_wmma_t96x128x256_mw2_nw2_nb4_sk1_cm1_cn1: scale mismatch 0/12288, fp8 mismatch 0/393216
fused quant B=8 M=200 N=1024 K=4096 tile flydsl_bmm_mxfp8_32_wmma_t96x128x256_mw2_nw2_nb4_sk1_cm1_cn1: scale mismatch 0/51200, fp8 mismatch 0/1638400
fused quant B=8 M=48 N=1024 K=4096 tile flydsl_bmm_mxfp8_32_wmma_t32x32x512_mw2_nw2_nb4_sk1_cm1_cn1: scale mismatch 0/12288, fp8 mismatch 0/393216
fused quant B=8 M=200 N=1024 K=4096 tile flydsl_bmm_mxfp8_32_wmma_t32x32x512_mw2_nw2_nb4_sk1_cm1_cn1: scale mismatch 0/51200, fp8 mismatch 0/1638400

2. Heuristic-tile fused sweep, same run: all 45 heuristic lines (B 16/8/4/2/1 x M 1, 16, 17, 32, 48, 128, 1024, 4096, 16384) have 0 scale / 0 fp8 mismatches, and the run ends with fused quant epilogue ALL BIT-EXACT. The 5 compute kernelName cases (incl. B=1 M=768 N=32768 K=1280) pass checkAllclose with err 0, and test_compute_operand_guards passes. The default sweep on plain gfx1250 does not include M 1025 / 2048 (only the gfx1250-strict block does), so I ran them explicitly: python op_tests/test_flydsl_batched_gemm.py -s 1025,1024,4096 2048,1024,4096 -b 2 8, rc = 0:

fused quant B=2 M=1025 N=1024 K=4096 tile heuristic: scale mismatch 0/65600, fp8 mismatch 0/2099200
fused quant B=2 M=2048 N=1024 K=4096 tile heuristic: scale mismatch 0/131072, fp8 mismatch 0/4194304
fused quant B=8 M=1025 N=1024 K=4096 tile heuristic: scale mismatch 0/262400, fp8 mismatch 0/8396800
fused quant B=8 M=2048 N=1024 K=4096 tile heuristic: scale mismatch 0/524288, fp8 mismatch 0/16777216
fused quant epilogue ALL BIT-EXACT

For M > 1024 the heuristic is the 256x256 compute kernel: pick_bmm_mx32_compute_kernel_name(b, m, 1024, 4096) returns flydsl_mxfp8_32_bpreshuffle_compute_wmma_t256x256x128_mw2_nw2_nb2_sk1_cm1_cn4 for b in {1, 2, 4, 8, 16} and M in {1025, 2048, 4096, 16384}, and None at M = 1024. So M 1025, 2048, 4096 and 16384 above all ran the compute kernel's fused epilogue.

3. Public entry on DSv4.1 wo_a table shapes, real lookup path. Small script (not committed): B = 8, N = 1024, K = 4096, raw 32x32 weight scale; batched_gemm_a8w8_mxscale_bpreshuffle_fused_quant(x, wo_a, x_scale, w_scale) vs batched_gemm_a8w8_mxscale_bpreshuffle(...) (bf16 entry) followed by quantize_fp8 (the test's atom_quantize_fp8 mirror: group-32 over the flattened row, amax floor 1e-10, e8m0 round-up), compared byte for byte. The device reports cu_num 256, so lookup_mxscale_bmm_config hits the dsv41_batched_gemm_a8w8_blockscale_mxscale_bpreshuffle_tuned.csv rows; the script prints the row and the tile _fused_quant_tuned_kernel hands to the runner. rc = 0:

public fused entry B=8 M=2 N=1024 K=4096: row t16x64x512_mw1_nw4_nb4_sk1_cm1_cn1 (fused entry runs the same tile): scale mismatch 0/512, fp8 mismatch 0/16384
public fused entry B=8 M=20 N=1024 K=4096: row t32x32x512_mw2_nw2_nb4_sk1_cm1_cn1 (fused entry runs the same tile): scale mismatch 0/5120, fp8 mismatch 0/163840
public fused entry B=8 M=24 N=1024 K=4096: row t32x64x512_mw2_nw2_nb4_sk1_cm1_cn1 (fused entry runs the same tile): scale mismatch 0/6144, fp8 mismatch 0/196608
public fused entry B=8 M=36 N=1024 K=4096: row t64x32x512_mw4_nw1_nb4_sk1_cm1_cn1 (fused entry runs the same tile): scale mismatch 0/9216, fp8 mismatch 0/294912
public fused entry B=8 M=352 N=1024 K=4096: row t96x128x256_mw2_nw2_nb4_sk1_cm1_cn1 (fused entry runs the same tile): scale mismatch 0/90112, fp8 mismatch 0/2883584
public fused entry B=8 M=480 N=1024 K=4096: row t128x128x256_mw2_nw2_nb4_sk1_cm1_cn1 (fused entry runs the same tile): scale mismatch 0/122880, fp8 mismatch 0/3932160
public fused entry B=8 M=544 N=1024 K=4096: row t192x128x256_mw2_nw2_nb3_sk1_cm1_cn1 (fused entry runs the same tile): scale mismatch 0/139264, fp8 mismatch 0/4456448
public fused entry B=8 M=608 N=1024 K=4096: row t160x128x256_mw2_nw2_nb3_sk1_cm1_cn1 (fused entry runs the same tile): scale mismatch 0/155648, fp8 mismatch 0/4980736
public fused entry ALL BIT-EXACT

The shapes cover both epilogue branches through the public entry: LDS-staged (t16x64x512 nw4 at M = 2, t32x32x512 nw2 at M = 20) and accumulator (t32x64, t64x32 nw1, t96x128, t128x128, t192x128, t160x128).

The PR description's Validation section now points to this comment.

yhl-amd added a commit to yhl-amd/aiter that referenced this pull request Nov 23, 2026
A shared expert whose down projection reads MXFP8 runs the gate_up GEMM
(bf16 [M, 2I]), silu_and_mul and quantize_fp8 as three launches. The
batched mxfp8_32 gfx1250 kernel now applies the SwiGLU before its fused
group-32 MXFP8 epilogue, so the three become one GEMM.

Kernel (kernels/gemm_a8w8_gfx1250.py), new fuse_act_mul / act_limit
constexprs (batched mxfp8_32, 32x32 B scale, fuse_quant_out, no K tail):
- B is the unmodified [gate; up] weight. Each CTA gathers its tile_n B
  rows, and their scale rows, as tile_n/64 blocks of [32 gate rows, the
  matching 32 up rows] through one nested TDM view, so a wave's 64 columns
  hold gate and up of the same 32 outputs in the same lanes.
- The epilogue rounds the accumulators to bf16 and forms
  bf16(silu(bf16(min(g, L))) * clamp(u, -L, L)) as aiter silu_and_mul
  does (L = 0: no clamp), then quantizes each 32-column group with ROCm#7667's
  emit_mxfp8_acc_pair_to_lds / emit_mxfp8_scale_rows_store; only the e4m3
  TDM store stays local, shared with the accumulator-quant epilogue.
- Against the bf16 GEMM + silu_and_mul + quantize_fp8 chain, a SwiGLU
  value can sit one bf16 step from silu_and_mul's (exp/rcp rounding), so
  an e4m3 code can differ by one step; where that value is its group's
  amax at 448 * 2**k, the group's e8m0 scale moves by one instead (and so
  all 32 codes).
- The kernel name gets a _silu<limit>q suffix, so it never collides with
  the plain GEMM; fuse_act_mul defaults to off.

Host (batched_gemm_a8w8_gfx1250.py):
- run_gate_up_silu_mxfp8_32_gfx1250: the raw launch. Operand dtypes,
  strides, shapes, devices, alignment, the limit and the kernel name are
  checked before the arch check; the e8m0 x_scale / w_scale checks run
  after it. swiglu_limit is read as the f32 silu_and_mul receives.
  kernel_name=None picks the tile from the runtime row count.
- gate_up_silu_supported(n2, k): gfx1250 with the measured CU count at
  the measured [2I, K]; independent of the row count.
- gate_up_silu_kernel_for(m, n2, k): the table tile for the measured
  device and shape only, else None. A host helper for code that sees the
  real row count; not for branching in a traced forward.
- The table tiles end in _pl (the pipelined K loop).

Op (batched_gemm_op_a8w8.py): functional registered op
gate_up_silu_mxfp8_32 (mutates_args=[]) that picks the tile from the
runtime row count and returns the e4m3 / e8m0 outputs.

Tests: op_tests/test_flydsl_gate_up_silu_host.py (CPU: gating, picker,
limit and operand validation, functional op under fullgraph dynamic
shapes) and test_gate_up_silu_fused in op_tests/test_flydsl_batched_gemm.py
(gfx1250: every tile bucket, limits 10, 0 and 5.02, vs the unfused chain).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
yhl-amd added a commit to yhl-amd/aiter that referenced this pull request Nov 23, 2026
A shared expert whose down projection reads MXFP8 runs the gate_up GEMM
(bf16 [M, 2I]), silu_and_mul and quantize_fp8 as three launches. The
batched mxfp8_32 gfx1250 kernel now applies the SwiGLU before its fused
group-32 MXFP8 epilogue, so the three become one GEMM.

Kernel (kernels/gemm_a8w8_gfx1250.py), new fuse_act_mul / act_limit
constexprs (batched mxfp8_32, 32x32 B scale, fuse_quant_out, no K tail):
- B is the unmodified [gate; up] weight. Each CTA gathers its tile_n B
  rows, and their scale rows, as tile_n/64 blocks of [32 gate rows, the
  matching 32 up rows] through one nested TDM view, so a wave's 64 columns
  hold gate and up of the same 32 outputs in the same lanes.
- The epilogue rounds the accumulators to bf16 and forms
  bf16(silu(bf16(min(g, L))) * clamp(u, -L, L)) as aiter silu_and_mul
  does (L = 0: no clamp), then quantizes each 32-column group with ROCm#7667's
  emit_mxfp8_acc_pair_to_lds / emit_mxfp8_scale_rows_store; only the e4m3
  TDM store stays local, shared with the accumulator-quant epilogue.
- Against the bf16 GEMM + silu_and_mul + quantize_fp8 chain, a SwiGLU
  value can sit one bf16 step from silu_and_mul's (exp/rcp rounding), so
  an e4m3 code can differ by one step; where that value is its group's
  amax at 448 * 2**k, the group's e8m0 scale moves by one instead (and so
  all 32 codes).
- The kernel name gets a _silu<limit>q suffix, so it never collides with
  the plain GEMM; fuse_act_mul defaults to off.

Host (batched_gemm_a8w8_gfx1250.py):
- run_gate_up_silu_mxfp8_32_gfx1250: the raw launch. Operand dtypes,
  strides, shapes, devices, alignment, the limit and the kernel name are
  checked before the arch check; the e8m0 x_scale / w_scale checks run
  after it. swiglu_limit is read as the f32 silu_and_mul receives.
  kernel_name=None picks the tile from the runtime row count.
- gate_up_silu_supported(n2, k): gfx1250 with the measured CU count at
  the measured [2I, K]; independent of the row count.
- gate_up_silu_kernel_for(m, n2, k): the table tile for the measured
  device and shape only, else None. A host helper for code that sees the
  real row count; not for branching in a traced forward.
- The table tiles end in _pl (the pipelined K loop).

Op (batched_gemm_op_a8w8.py): functional registered op
gate_up_silu_mxfp8_32 (mutates_args=[]) that picks the tile from the
runtime row count and returns the e4m3 / e8m0 outputs.

Tests: op_tests/test_flydsl_gate_up_silu_host.py (CPU: gating, picker,
limit and operand validation, functional op under fullgraph dynamic
shapes) and test_gate_up_silu_fused in op_tests/test_flydsl_batched_gemm.py
(gfx1250: every tile bucket, limits 10, 0 and 5.02, vs the unfused chain).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
yhl-amd added a commit to yhl-amd/aiter that referenced this pull request Nov 23, 2026
Keeps ROCm#7667's commits as they are and takes main's changes. The only
conflict is the module docstring of op_tests/test_gemm_host_dispatch_cache.py:
main's text for the nested blockscale call (ROCm#8291) plus this branch's `_pl`
bullet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
yhl-amd and others added 6 commits November 25, 2026 23:51
…ed entry runs the tuned row

Fused MXFP8 epilogue: when the warp tile holds an even number of 16-column
WMMA tiles (even wmma_n_rep), the group-32 quant reads the accumulators
instead of staging the bf16 C tile in LDS and re-reading it per group. A lane
holds 8 consecutive columns of one row per 16x16 tile, so a 32-column group
is two adjacent tiles across lanes l and l^16 and its amax is one
shuffle_xor(16). Values are rounded to the output dtype first, exactly as the
bf16 path stores them, so the e4m3 codes and e8m0 scales are unchanged; the
e4m3 and scale bytes still go through LDS for the TDM store. An odd
wmma_n_rep keeps the LDS-staged quant. The epilogue has three peer branches
(bf16 store, accumulator quant, LDS-staged quant) with the quant setup and
the group-32 scale step shared by the two quant branches.

batched_gemm_a8w8_mxscale_bpreshuffle_fused_quant looks the shape up in the
same preshuffle table as the bf16 entry and passes a flydsl row's kernelName
to the runner, so both entries run the same tuned tile. No row, an opus row
or a compute-kernel row leaves the tile to the runner; any other name is
passed through, so a name the runner does not accept raises, as for the bf16
entry.

Tests: op_tests/test_flydsl_batched_gemm.py checks the fused quant on tuned
tiles that pin each epilogue branch (two LDS-staged, seven accumulator) at
ragged M against quantize_fp8 of the bf16 GEMM on the same tile;
op_tests/test_bmm_a8w8_fused_quant_tuned_row.py is a CPU test of the
tuned-row lookup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
After the merge with main's gfx950 fused quant, one _fused_quant_tuned_kernel
serves both arches. The CPU test now also checks a gfx950 flydsl row (passed
through) and a gfx950 opus row or no row (runner's choice).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The batched mxfp8_32 kernel's accumulator quant and the 256x256 compute
kernel's fused epilogue emitted the same per-group step (round to the output
dtype, h0/h1 amax with one shuffle_xor(16), 1e-10 floor, RoundUp e8m0,
scaled fp8 conversion, e4m3 and scale bytes into LDS) and the same scale-row
store. Both now call emit_mxfp8_acc_pair_to_lds and
emit_mxfp8_scale_rows_store in kernels/quant_utils.py, next to
emit_mx_e8m0_scale; emit_mxfp8_group32_scale (floor + RoundUp scale) is also
used by the batched kernel's LDS-staged quant. Each kernel keeps its own e4m3
TDM store. No change in the emitted code is intended.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
FUSED_QUANT_TILES adds t64x32x512 mw4 nw1 (one quant group per tile row) and
t160x128x256 nw2 (more tile rows than threads, so the scale rows take a
second pass), both shipped DSv4.1 rows on the accumulator branch that no test
pinned.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The scale-row store loops ceil(tile_m / block) times, so a thread copies
rows tid, tid + block, ...; say that in the helper docstring and at both
kernel call sites instead of "one row per thread". In quant_utils, the
native-scale helper no longer refers to a function that does not exist,
and the module docstring names the dtypes _DTYPE_CFG actually defines.
The gfx950 tuned-row test uses the DSv4 batched preshuffle table's row for
its shape. Comments and test data only; no kernel change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…red group-32 scale

_fused_quant_tuned_kernel imports the gfx1250 compute-kernel name check
only on gfx1250, after the table lookup; gfx950 returns the flydsl row's
name directly, as before the merge with the gfx1250 lookup. The gfx950 bmm
fused epilogue calls emit_mxfp8_group32_scale instead of its own copy of
the same steps (1e-10 floor, RoundUp e8m0, f32 scale). Two docstrings no
longer say the fused epilogue always quantizes the bf16 C tile.

Tests: FUSED_QUANT_TILES also pins the DSv4.1 wo_a tuned tiles the fused
entry runs (t192x128x256, t128x256x256 mw1 nw4, t96x128x256, and the
LDS-staged t32x32x512); the gfx1250 tuned-row fixture uses a CU count
other than the gfx950 one so the lookup must forward the caller's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@yhl-amd
yhl-amd force-pushed the hyi/gfx1250-bmm-fused-quant-acc-epilogue branch from dfc6215 to f1a3bc2 Compare November 25, 2026 16:06
yhl-amd added a commit to yhl-amd/aiter that referenced this pull request Nov 25, 2026
A shared expert whose down projection reads MXFP8 runs the gate_up GEMM
(bf16 [M, 2I]), silu_and_mul and quantize_fp8 as three launches. The
batched mxfp8_32 gfx1250 kernel now applies the SwiGLU before its fused
group-32 MXFP8 epilogue, so the three become one GEMM.

Kernel (kernels/gemm_a8w8_gfx1250.py), new fuse_act_mul / act_limit
constexprs (batched mxfp8_32, 32x32 B scale, fuse_quant_out, no K tail):
- B is the unmodified [gate; up] weight. Each CTA gathers its tile_n B
  rows, and their scale rows, as tile_n/64 blocks of [32 gate rows, the
  matching 32 up rows] through one nested TDM view, so a wave's 64 columns
  hold gate and up of the same 32 outputs in the same lanes.
- The epilogue rounds the accumulators to bf16 and forms
  bf16(silu(bf16(min(g, L))) * clamp(u, -L, L)) as aiter silu_and_mul
  does (L = 0: no clamp), then quantizes each 32-column group with ROCm#7667's
  emit_mxfp8_acc_pair_to_lds / emit_mxfp8_scale_rows_store; only the e4m3
  TDM store stays local, shared with the accumulator-quant epilogue.
- Against the bf16 GEMM + silu_and_mul + quantize_fp8 chain, a SwiGLU
  value can sit one bf16 step from silu_and_mul's (exp/rcp rounding), so
  an e4m3 code can differ by one step; where that value is its group's
  amax at 448 * 2**k, the group's e8m0 scale moves by one instead (and so
  all 32 codes).
- The kernel name gets a _silu<limit>q suffix, so it never collides with
  the plain GEMM; fuse_act_mul defaults to off.

Host (batched_gemm_a8w8_gfx1250.py):
- run_gate_up_silu_mxfp8_32_gfx1250: the raw launch. Operand dtypes,
  strides, shapes, devices, alignment, the limit and the kernel name are
  checked before the arch check; the e8m0 x_scale / w_scale checks run
  after it. swiglu_limit is read as the f32 silu_and_mul receives.
  kernel_name=None picks the tile from the runtime row count.
- gate_up_silu_supported(n2, k): gfx1250 with the measured CU count at
  the measured [2I, K]; independent of the row count.
- gate_up_silu_kernel_for(m, n2, k): the table tile for the measured
  device and shape only, else None. A host helper for code that sees the
  real row count; not for branching in a traced forward.
- The table tiles end in _pl (the pipelined K loop).

Op (batched_gemm_op_a8w8.py): functional registered op
gate_up_silu_mxfp8_32 (mutates_args=[]) that picks the tile from the
runtime row count and returns the e4m3 / e8m0 outputs.

Tests: op_tests/test_flydsl_gate_up_silu_host.py (CPU: gating, picker,
limit and operand validation, functional op under fullgraph dynamic
shapes) and test_gate_up_silu_fused in op_tests/test_flydsl_batched_gemm.py
(gfx1250: every tile bucket, limits 10, 0 and 5.02, vs the unfused chain).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
yhl-amd added a commit to yhl-amd/aiter that referenced this pull request Nov 25, 2026
A shared expert whose down projection reads MXFP8 runs the gate_up GEMM
(bf16 [M, 2I]), silu_and_mul and quantize_fp8 as three launches. The
batched mxfp8_32 gfx1250 kernel now applies the SwiGLU before its fused
group-32 MXFP8 epilogue, so the three become one GEMM.

Kernel (kernels/gemm_a8w8_gfx1250.py), new fuse_act_mul / act_limit
constexprs (batched mxfp8_32, 32x32 B scale, fuse_quant_out, no K tail):
- B is the unmodified [gate; up] weight. Each CTA gathers its tile_n B
  rows, and their scale rows, as tile_n/64 blocks of [32 gate rows, the
  matching 32 up rows] through one nested TDM view, so a wave's 64 columns
  hold gate and up of the same 32 outputs in the same lanes.
- The epilogue rounds the accumulators to bf16 and forms
  bf16(silu(bf16(min(g, L))) * clamp(u, -L, L)) as aiter silu_and_mul
  does (L = 0: no clamp), then quantizes each 32-column group with ROCm#7667's
  emit_mxfp8_acc_pair_to_lds / emit_mxfp8_scale_rows_store; only the e4m3
  TDM store stays local, shared with the accumulator-quant epilogue.
- Against the bf16 GEMM + silu_and_mul + quantize_fp8 chain, a SwiGLU
  value can sit one bf16 step from silu_and_mul's (exp/rcp rounding), so
  an e4m3 code can differ by one step; where that value is its group's
  amax at 448 * 2**k, the group's e8m0 scale moves by one instead (and so
  all 32 codes).
- The kernel name gets a _silu<limit>q suffix, so it never collides with
  the plain GEMM; fuse_act_mul defaults to off.

Host (batched_gemm_a8w8_gfx1250.py):
- run_gate_up_silu_mxfp8_32_gfx1250: the raw launch. Operand dtypes,
  strides, shapes, devices, alignment, the limit and the kernel name are
  checked before the arch check; the e8m0 x_scale / w_scale checks run
  after it. swiglu_limit is read as the f32 silu_and_mul receives.
  kernel_name=None picks the tile from the runtime row count.
- gate_up_silu_supported(n2, k): gfx1250 with the measured CU count at
  the measured [2I, K]; independent of the row count.
- gate_up_silu_kernel_for(m, n2, k): the table tile for the measured
  device and shape only, else None. A host helper for code that sees the
  real row count; not for branching in a traced forward.
- The table tiles end in _pl (the pipelined K loop).

Op (batched_gemm_op_a8w8.py): functional registered op
gate_up_silu_mxfp8_32 (mutates_args=[]) that picks the tile from the
runtime row count and returns the e4m3 / e8m0 outputs.

Tests: op_tests/test_flydsl_gate_up_silu_host.py (CPU: gating, picker,
limit and operand validation, functional op under fullgraph dynamic
shapes) and test_gate_up_silu_fused in op_tests/test_flydsl_batched_gemm.py
(gfx1250: every tile bucket, limits 10, 0 and 5.02, vs the unfused chain).

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

yhl-amd commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main 3fd42598c (head f1a3bc230, previous head kept as bak/7667-pre1125a). The only conflict was mechanical, in op_tests/test_flydsl_batched_gemm.py: I kept main's _fused_quant_k() and gfx950 ragged-K block. The kernel code is the same as at dfc62154e. Evidence from an offline gfx1250 compile (flydsl 0.5.0, no GPU): all 15 batched-kernel configs (bf16 and fused) give final ISA byte-identical to dfc62154e, and the four 256x256 compute configs are byte-identical to main 3fd42598c, with no spill and no scratch. So the gfx1250 results posted for dfc62154e carry over. CPU host tests pass (the CUDA-only failures match main), and black and ruff are clean. No idle gfx950 GPU was free for a rerun.

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

⚠️ Action required before merge (1)

  1. Nit: update the FUSED_QUANT_TILES header comment to the nine tiles it now lists. op_tests/test_flydsl_batched_gemm.py:180-185 still says "one LDS-staged tile and four accumulator tiles" and names only t16x64 as LDS-staged. The tuple has two LDS-staged tiles (t16x64 nw4, t32x32 nw2) and seven accumulator tiles. The module docstring (:26-27) and a38316731 already say this. For example: "Tuned DSv4.1 tiles that pin both fused-quant epilogue branches: two LDS-staged tiles and seven accumulator tiles. One 16-column WMMA tile per warp (t16x64 nw4, t32x32 nw2) keeps the LDS-staged quant; an even count quantizes from the accumulators." Keep the t64x32 / t160x128 sentences.

Everything else is done. Thanks for the gfx1250 run.

Root cause vs patch

This is a root fix. It addresses two problems: the fused epilogue staged bf16 in LDS and re-read it for each group, and the fused entry ignored the tuned tile that the bf16 entry uses. Quantizing from the accumulators, sharing one group-32 helper across all three kernels, and using the bf16 entry's tuned-row lookup solve both at the source.

Two parts look like patches but are acceptable:

  • The LDS fallback for odd wmma_n_rep is structural, because a 32-column group crosses warps.
  • Tuned gfx1250 compute rows go to None. This was accepted at 305f898. A possible follow-up: the runner accepts most fused compute names, so exposing the runner's fused-capable predicate would let the fused entry keep those rows too.

Reviewed at f1a3bc2 (deep re-review: two independent full passes; delta plus full diff). The PR's kernel and helper lines are identical to dfc6215, so the posted gfx1250 run covers this head: all 9 FUSED_QUANT_TILES at M 48/200, the heuristic sweep including M 1025/2048, and 8 public-entry DSv4.1 wo_a rows, all with 0 mismatches. The rebase resolution keeps main's _fused_quant_k() and the gfx950 ragged-K block, and merge-tree with current main is clean.

Already fixed:

  • the gfx1250 run with the 4 named tiles pinned;
  • the gfx950 early return before the function-local import (batched_gemm_op_a8w8.py:540-545);
  • the gfx950 bmm kernel now uses emit_mxfp8_group32_scale (same floor, RoundUp and <<23; ISA byte-identical);
  • both "bf16 C tile" sentences;
  • the cu 80 fixture.

CI is green and no review threads are open.

Two LDS-staged tiles (t16x64 nw4, t32x32 nw2) and seven accumulator tiles,
as the tuple and the module docstring list them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
yhl-amd added a commit to yhl-amd/aiter that referenced this pull request Nov 27, 2026
A shared expert whose down projection reads MXFP8 runs the gate_up GEMM
(bf16 [M, 2I]), silu_and_mul and quantize_fp8 as three launches. The
batched mxfp8_32 gfx1250 kernel now applies the SwiGLU before its fused
group-32 MXFP8 epilogue, so the three become one GEMM.

Kernel (kernels/gemm_a8w8_gfx1250.py), new fuse_act_mul / act_limit
constexprs (batched mxfp8_32, 32x32 B scale, fuse_quant_out, no K tail):
- B is the unmodified [gate; up] weight. Each CTA gathers its tile_n B
  rows, and their scale rows, as tile_n/64 blocks of [32 gate rows, the
  matching 32 up rows] through one nested TDM view, so a wave's 64 columns
  hold gate and up of the same 32 outputs in the same lanes.
- The epilogue rounds the accumulators to bf16 and forms
  bf16(silu(bf16(min(g, L))) * clamp(u, -L, L)) as aiter silu_and_mul
  does (L = 0: no clamp), then quantizes each 32-column group with ROCm#7667's
  emit_mxfp8_acc_pair_to_lds / emit_mxfp8_scale_rows_store; only the e4m3
  TDM store stays local, shared with the accumulator-quant epilogue.
- Against the bf16 GEMM + silu_and_mul + quantize_fp8 chain, a SwiGLU
  value can sit one bf16 step from silu_and_mul's (exp/rcp rounding), so
  an e4m3 code can differ by one step; where that value is its group's
  amax at 448 * 2**k, the group's e8m0 scale moves by one instead (and so
  all 32 codes).
- The kernel name gets a _silu<limit>q suffix, so it never collides with
  the plain GEMM; fuse_act_mul defaults to off.

Host (batched_gemm_a8w8_gfx1250.py):
- run_gate_up_silu_mxfp8_32_gfx1250: the raw launch. Operand dtypes,
  strides, shapes, devices, alignment, the limit and the kernel name are
  checked before the arch check; the e8m0 x_scale / w_scale checks run
  after it. swiglu_limit is read as the f32 silu_and_mul receives.
  kernel_name=None picks the tile from the runtime row count.
- gate_up_silu_supported(n2, k): gfx1250 with the measured CU count at
  the measured [2I, K]; independent of the row count.
- gate_up_silu_kernel_for(m, n2, k): the table tile for the measured
  device and shape only, else None. A host helper for code that sees the
  real row count; not for branching in a traced forward.
- The table tiles end in _pl (the pipelined K loop).

Op (batched_gemm_op_a8w8.py): functional registered op
gate_up_silu_mxfp8_32 (mutates_args=[]) that picks the tile from the
runtime row count and returns the e4m3 / e8m0 outputs.

Tests: op_tests/test_flydsl_gate_up_silu_host.py (CPU: gating, picker,
limit and operand validation, functional op under fullgraph dynamic
shapes) and test_gate_up_silu_fused in op_tests/test_flydsl_batched_gemm.py
(gfx1250: every tile bucket, limits 10, 0 and 5.02, vs the unfused chain).

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

yhl-amd commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

@valarLip Thanks. Fixed in d4016d527 (comment only, previous head kept as bak/7667-pre1127a). The FUSED_QUANT_TILES header now reads: two LDS-staged tiles and seven accumulator tiles; one 16-column WMMA tile per warp (t16x64 nw4, t32x32 nw2) keeps the LDS-staged quant, and an even count quantizes from the accumulators. The t64x32 / t160x128 sentences are kept. No code changed, so the gfx1250 and gfx950 results for f1a3bc230 carry over. black and ruff are clean, and Self-Review is updated to the new head.

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

Development

Successfully merging this pull request may close these issues.

5 participants