Skip to content

[FlyDSL] [gfx1250] flydsl batched mxfp8 GEMM: optional fused mxfp8 quant epilogue - #7178

Merged
valarLip merged 11 commits into
ROCm:mainfrom
karverma-amd:karverma/gfx1250-woa-fused-mxfp8-quant
Nov 11, 2026
Merged

valarLip merged 11 commits into
ROCm:mainfrom
karverma-amd:karverma/gfx1250-woa-fused-mxfp8-quant

Conversation

@karverma-amd

@karverma-amd karverma-amd commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Add an opt-in fused quantization epilogue to the FlyDSL batched mxfp8_32 A8W8 GEMM on gfx1250. When enabled, the kernel quantizes its bf16 C tile to e4m3 values + e8m0 group scales in-kernel (group-of-32, lane-local, no cross-lane reduction) and writes the mxfp8 output directly, instead of storing bf16 and running a separate quantize_fp8 launch afterwards.

This targets the DeepSeek-V4.1 attention wo_a -> wo_b seam, where the standalone quantize_fp8 between the two GEMMs can be removed. The bf16 store path is unchanged and is still the default; the fused path is gated and selected via the new public entry
batched_gemm_a8w8_mxscale_bpreshuffle_fused_quant (+ _supported helper).

  • kernels/gemm_a8w8_gfx1250.py: group-32 mxfp8 quant epilogue under fuse_quant_out (bf16 path preserved verbatim when disabled).
  • flydsl/batched_gemm_a8w8_gfx1250.py, flydsl/batched_gemm_a8w8.py: thread y_scale_out through host + dispatch.
  • ops/batched_gemm_op_a8w8.py: public fused entry + _supported.
  • op_tests/test_woa_fused_quant.py: bit-exactness vs bf16-GEMM-then-quantize_fp8 (0 mismatch across M=1..512 incl ragged).

Summary

gfx1250 callers of the batched mxfp8_32 GEMM can now ask for an mxfp8 output in the same launch. The existing bf16 store path is unchanged.

Motivation

DeepSeek-V4.1 attention does wo_a (bf16) then a separate quantize_fp8 before wo_b. That extra launch is the whole gap. The GEMM already holds the bf16 tile in registers, so quantizing it in the epilogue removes the round trip. Callers that want bf16 keep the old entry.

Changes

  • fuse_quant_out / y_scale_out on the gfx1250 flydsl batched mxfp8_32 kernel. Disabled, the bf16 store is the previous code.
  • Public batched_gemm_a8w8_mxscale_bpreshuffle_fused_quant and batched_gemm_a8w8_mxscale_bpreshuffle_fused_quant_supported. Unsupported arch or scale layout raises NotImplementedError so the caller can fall back.

Performance (if applicable)

Hardware Workload/configuration Before After Change
gfx1250 DSV4.1-Flash EP4+DPA, bf16 KV, fp4 index, concurrency 128, fused wo_a quant vs standalone quantize_fp8 baseline fused epilogue about +1.1% throughput

The machine has been down for the last 3 days, so this is the concurrency-128 result we already had, not a fresh rerun.

Testing

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

gfx1250 only. MI250X (gfx90a) and MI300X (gfx942) do not have this epilogue; batched_gemm_a8w8_mxscale_bpreshuffle_fused_quant_supported returns false there and the bf16 entry is unchanged.

Documentation

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

The new public functions document the return layout, the bit-exact claim, and the fallback. No user-guide change: this is an opt-in kernel entry, and the bf16 API is unchanged.

Dependencies

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

Breaking Changes

None. The bf16 batched_gemm_a8w8_mxscale_bpreshuffle path is unchanged. The fused entry is new.

PR Self-Review

Reviewed revision

c9723a0

Behavior and intent

The batched mxfp8_32 GEMM on gfx1250 always stored a bf16 C tile. DeepSeek-V4.1 then launched quantize_fp8 (group-32, amax floored at 1e-10, code = ceil_pow2(amax/448)) before wo_b. That second launch is unnecessary when the next consumer wants mxfp8: the epilogue can quantize the tile in-register and write e4m3 values plus e8m0 scales. Existing callers that pass no y_scale_out still get the bf16 store. batched_gemm_a8w8_mxscale_bpreshuffle_fused_quant_supported lets a caller pick the fused entry once instead of discovering the limitation from NotImplementedError.

Validation and unverified scope

op_tests/test_woa_fused_quant.py on gfx1250 compares one fused launch against the unfused bf16 GEMM followed by a torch mirror of ATOM quantize_fp8. Recorded result: 0 scale mismatches and 0 fp8 mismatches across M=1..512, including ragged M. Command: python op_tests/test_woa_fused_quant.py. The same fusion in DSV4.1-Flash serving (EP4+DPA, bf16 KV, fp4 index, concurrency 128) was about a 1.1% throughput uplift.

What remains unverified: a fresh rerun. The system has been down for the last 3 days, so there is no new isolated-kernel timing and no new end-to-end number beyond that concurrency-128 result. Also unverified: arches other than gfx1250 (the epilogue is refused there), scale layouts other than 32x32, and GEMM shapes outside the wo_a family this test covers. Those stay on the existing bf16 entry.

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_woa_fused_quant.py fails if the fused epilogue's e4m3 bytes or e8m0 group scales differ from quantize_fp8 of the unfused bf16 GEMM. Before this PR there is no y_scale_out path, so the test cannot pass. The existing batched-mxfp8 tests check the bf16 GEMM result. They never compare an in-kernel group-32 quant (floor 1e-10, ceil_pow2(amax/448), no cross-lane reduction) with ATOM's quantize_fp8, which is the bug this epilogue can introduce.

Changed op tests

op_tests/test_woa_fused_quant.py is new. It covers byte-identity of the fused (y_fp8, y_scale) pair against quantize_fp8 of the bf16 GEMM, including ragged M. It is not redundant: no existing op test drives y_scale_out or batched_gemm_a8w8_mxscale_bpreshuffle_fused_quant, and the canonical batched GEMM tests stop at the bf16 output. A wrong scale rounding or a lane reduction in the epilogue would still pass those tests and fail this one.

Add an opt-in fused quantization epilogue to the FlyDSL batched mxfp8_32
A8W8 GEMM on gfx1250. When enabled, the kernel quantizes its bf16 C tile
to e4m3 values + e8m0 group scales in-kernel (group-of-32, lane-local, no
cross-lane reduction) and writes the mxfp8 output directly, instead of
storing bf16 and running a separate quantize_fp8 launch afterwards.

This targets the DeepSeek-V4.1 attention wo_a -> wo_b seam, where the
standalone quantize_fp8 between the two GEMMs can be removed. The bf16
store path is unchanged and is still the default; the fused path is gated
and selected via the new public entry
batched_gemm_a8w8_mxscale_bpreshuffle_fused_quant (+ _supported helper).

- kernels/gemm_a8w8_gfx1250.py: group-32 mxfp8 quant epilogue under
  fuse_quant_out (bf16 path preserved verbatim when disabled).
- flydsl/batched_gemm_a8w8_gfx1250.py, flydsl/batched_gemm_a8w8.py:
  thread y_scale_out through host + dispatch.
- ops/batched_gemm_op_a8w8.py: public fused entry + _supported.
- op_tests/test_woa_fused_quant.py: bit-exactness vs bf16-GEMM-then-
  quantize_fp8 (0 mismatch across M=1..512 incl ragged).
@karverma-amd
karverma-amd requested a review from a team October 29, 2026 23:38
@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:windows Windows JIT op smoke test on the gfx1201 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 7178 --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 [gfx1250] flydsl batched mxfp8 GEMM: optional fused mxfp8 quant epilogue [FlyDSL] [gfx1250] flydsl batched mxfp8 GEMM: optional fused mxfp8 quant epilogue Oct 29, 2026
@aiter-bot

aiter-bot commented Oct 29, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision eba36e7d31fb · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. 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?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_bmm_a8w8_fused_quant_supported.py
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_flydsl_batched_gemm.py

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

karverma-amd and others added 3 commits November 1, 2026 20:07
Black reformats the new call sites, ruff wants __all__ sorted, and the unused unpacked total in the op test is renamed.

Co-authored-by: Cursor <[email protected]>
Existing non-fused kernels omit arg_scale_out. A None default is not a
JitArgument, so FlyDSL cannot derive a cache signature and the wheel
build fails those kernels.

Co-authored-by: Cursor <[email protected]>
@zufayu
zufayu requested a review from aoli26 November 3, 2026 06:34
karverma-amd and others added 2 commits November 9, 2026 21:41
supported() indexed _RUNNERS with the raw get_gfx(), so gfx1250-strict missed the mxfp8_32 row and callers logged an unsupported shape. Use base_gfx_arch, the same mapping _runner uses.

Co-authored-by: Cursor <[email protected]>
yhl-amd added a commit to yhl-amd/aiter that referenced this pull request Nov 10, 2026

@aoli26 aoli26 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The fusion approach makes sense, but preserving tuned dispatch is important for realizing the performance benefit. the fused public entry uses the heuristic configuration while the BF16 entry consults the tuned table.
#7667 adds the compatible FlyDSL tuned-row lookup, and #7668 inherits that fix. That addresses this concern for generic WMMA rows. #7673 also adds fused-quant output to the 256×256 compute GEMM path for non-persistent configurations, keeping the interface consistent. So there is no need to duplicate the implementation here.

Comment thread op_tests/test_woa_fused_quant.py Resolved
karverma-amd and others added 2 commits November 10, 2026 15:59
CI runs op tests as `python op_tests/<file>.py`, which puts op_tests/ on
sys.path, so the sibling import fails before the gfx1250 skip.

Co-authored-by: Cursor <[email protected]>
A mismatched shape used to print and still exit 0. Return 1 so CI fails
the run. Fold the arch with base_gfx_arch, the same map supported() uses,
so gfx1250-strict runs the numerical test instead of skipping.

Co-authored-by: Cursor <[email protected]>
aoli26
aoli26 previously approved these changes Nov 11, 2026

@aoli26 aoli26 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM now, thanks for the fix.

zufayu
zufayu previously approved these changes Nov 11, 2026
@zufayu

zufayu commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

could we merge new op test into old op test?

The byte compare of y_scale_out against quantize_fp8 now runs from test_flydsl_batched_gemm.py, including on gfx1250-strict. A mismatch still exits 1.

Co-authored-by: Cursor <[email protected]>
@karverma-amd
karverma-amd dismissed stale reviews from zufayu and aoli26 via a218260 November 11, 2026 03:33
yhl-amd added a commit to yhl-amd/aiter that referenced this pull request Nov 11, 2026
@karverma-amd
karverma-amd requested a review from zufayu November 11, 2026 04:39
@zufayu
zufayu requested review from aoli26 and removed request for coderfeli November 11, 2026 06:53
@zufayu zufayu assigned aoli26 and unassigned coderfeli Nov 11, 2026
@zufayu
zufayu requested a review from coderfeli November 11, 2026 06:53
@valarLip
valarLip merged commit ef7ab2b into ROCm:main Nov 11, 2026
vpietila-amd pushed a commit that referenced this pull request Nov 12, 2026
…ant epilogue (#7178)

* [gfx1250] flydsl batched mxfp8 GEMM: optional fused mxfp8 quant epilogue

Add an opt-in fused quantization epilogue to the FlyDSL batched mxfp8_32
A8W8 GEMM on gfx1250. When enabled, the kernel quantizes its bf16 C tile
to e4m3 values + e8m0 group scales in-kernel (group-of-32, lane-local, no
cross-lane reduction) and writes the mxfp8 output directly, instead of
storing bf16 and running a separate quantize_fp8 launch afterwards.

This targets the DeepSeek-V4.1 attention wo_a -> wo_b seam, where the
standalone quantize_fp8 between the two GEMMs can be removed. The bf16
store path is unchanged and is still the default; the fused path is gated
and selected via the new public entry
batched_gemm_a8w8_mxscale_bpreshuffle_fused_quant (+ _supported helper).

- kernels/gemm_a8w8_gfx1250.py: group-32 mxfp8 quant epilogue under
  fuse_quant_out (bf16 path preserved verbatim when disabled).
- flydsl/batched_gemm_a8w8_gfx1250.py, flydsl/batched_gemm_a8w8.py:
  thread y_scale_out through host + dispatch.
- ops/batched_gemm_op_a8w8.py: public fused entry + _supported.
- op_tests/test_woa_fused_quant.py: bit-exactness vs bf16-GEMM-then-
  quantize_fp8 (0 mismatch across M=1..512 incl ragged).

* style: satisfy black and ruff on the fused mxfp8 epilogue

Black reformats the new call sites, ruff wants __all__ sorted, and the unused unpacked total in the op test is renamed.

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

* fix: default the shared GEMM scale pointer so AOT can sign it

Existing non-fused kernels omit arg_scale_out. A None default is not a
JitArgument, so FlyDSL cannot derive a cache signature and the wheel
build fails those kernels.

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

* fix: fold gfx1250-strict in the fused mxfp8 supported() lookup

supported() indexed _RUNNERS with the raw get_gfx(), so gfx1250-strict missed the mxfp8_32 row and callers logged an unsupported shape. Use base_gfx_arch, the same mapping _runner uses.

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

* op_tests: make test_woa_fused_quant importable when run as a script

CI runs op tests as `python op_tests/<file>.py`, which puts op_tests/ on
sys.path, so the sibling import fails before the gfx1250 skip.

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

* op_tests: fail the fused-quant check, and run it on gfx1250-strict

A mismatched shape used to print and still exit 0. Return 1 so CI fails
the run. Fold the arch with base_gfx_arch, the same map supported() uses,
so gfx1250-strict runs the numerical test instead of skipping.

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

* op_tests: fold the fused-quant check into the batched GEMM test

The byte compare of y_scale_out against quantize_fp8 now runs from test_flydsl_batched_gemm.py, including on gfx1250-strict. A mismatch still exits 1.

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

---------

Co-authored-by: karverma-amd <[email protected]>
Co-authored-by: Cursor <[email protected]>
coderfeli pushed a commit that referenced this pull request Nov 13, 2026
…8 launch (#7920)

* [FlyDSL] [gfx1250] Pass arg_scale_out on every cached launch_gemm_a8w8 launch

#7178 appended the defaulted runtime pointer arg_scale_out to
launch_gemm_a8w8. Only the first launch of a specialization goes through
flyc.compile, which applies signature defaults; later launches call the
cached CompiledFunction positionally, and it reads each runtime argument
by its signature index. The dense mxfp8_128 / mxfp8_32, ptpc and batched
mxfp8_128 wrappers stop before arg_scale_out, so their second launch
raised IndexError: tuple index out of range (DeepSeek-V4-Pro wqkv_a
during CUDA graph capture).

Pass the trailing b_scale_32x32 / k_tail constexprs and arg_scale_out
explicitly, as the batched mxfp8_32 wrapper already does, and cover each
wrapper's cached second launch in test_gemm_host_dispatch_cache.py.

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

* Drop the redundant op test and shorten the arg_scale_out comments

test_gemm_a8w8_mxfp8_bpreshuffle.py and test_flydsl_batched_gemm.py already
fail on gfx1250 without the fix.

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

---------

Co-authored-by: Cursor <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants