Repository navigation
[FlyDSL] [gfx1250] flydsl batched mxfp8 GEMM: optional fused mxfp8 quant epilogue - #7178
Conversation
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).
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
WAITING ON AUTHORPR Self-ReviewRevision 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
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
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]>
Co-authored-by: Cursor <[email protected]>
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]>
aoli26
left a comment
There was a problem hiding this comment.
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.
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
left a comment
There was a problem hiding this comment.
LGTM now, thanks for the fix.
|
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]>
…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]>
…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]>
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).
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_outon the gfx1250 flydsl batched mxfp8_32 kernel. Disabled, the bf16 store is the previous code.batched_gemm_a8w8_mxscale_bpreshuffle_fused_quantandbatched_gemm_a8w8_mxscale_bpreshuffle_fused_quant_supported. Unsupported arch or scale layout raisesNotImplementedErrorso the caller can fall back.Performance (if applicable)
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
gfx1250 only. MI250X (gfx90a) and MI300X (gfx942) do not have this epilogue;
batched_gemm_a8w8_mxscale_bpreshuffle_fused_quant_supportedreturns false there and the bf16 entry is unchanged.Documentation
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
Breaking Changes
None. The bf16
batched_gemm_a8w8_mxscale_bpreshufflepath 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_outstill get the bf16 store.batched_gemm_a8w8_mxscale_bpreshuffle_fused_quant_supportedlets a caller pick the fused entry once instead of discovering the limitation fromNotImplementedError.Validation and unverified scope
op_tests/test_woa_fused_quant.pyon gfx1250 compares one fused launch against the unfused bf16 GEMM followed by a torch mirror of ATOMquantize_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.pyfails 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 noy_scale_outpath, 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.pyis 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 drivesy_scale_outorbatched_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.