Skip to content

Add a8w4 kernel for Quark mix-precision#837

Open
amd-xiaoyu12 wants to merge 5 commits into
ROCm:mainfrom
amd-xiaoyu12:xiaoyu/a8w4-quark
Open

Add a8w4 kernel for Quark mix-precision#837
amd-xiaoyu12 wants to merge 5 commits into
ROCm:mainfrom
amd-xiaoyu12:xiaoyu/a8w4-quark

Conversation

@amd-xiaoyu12

Copy link
Copy Markdown

Motivation

Add a modified A8W4 preshuffle GEMM kernel (from v0.1.7) at kernels/gemm/preshuffle_gemm_a8w4.py.
Port the A8W4 kernel to the current FlyDSL kernels/gemm/ layout and kernels.mma.* imports.
Include the ragged-M OOB fix by sizing A/C buffer descriptors with exact runtime num_records_bytes, preventing out-of-bounds reads/writes for non-tile-aligned M.

Quark integration: https://gitenterprise.xilinx.com/AMDNeuralOpt/Quark/pull/5866

Test Plan

Finished end to end test on Quark diffusion model Wan2.2 mix precision - w4a4/w4a8.

Compile verification:
python -m py_compile kernels/gemm/preshuffle_gemm_a8w4.py.
GPU correctness/perf tests not run locally. Recommended follow-up: run the A8W4 ragged-M validation on gfx950 with the Quark integration test once the Quark patch is applied.

Test Result

Submission Checklist

@amd-xiaoyu12
amd-xiaoyu12 requested a review from coderfeli July 12, 2026 16:50
The a8w4 kernel referenced kernels.mma.* (old flat layout) which does not
exist in the kernels/gemm + kernels/common layout, so the module failed to
import. Point the imports at kernels.common.mma.*. Also forward the epilogue
kwarg (none/bias/bias_relu/bias_silu/bias_gelu) from compile_preshuffle_gemm_a8w4
to compile_preshuffle_gemm_a8 so Quark's fused-bias w4a8 path works.
Port the fused epilogue (none/bias/bias_relu/bias_silu/bias_gelu, tanh-approx
GELU) into launch_gemm: add arg_bias + epilogue constexpr, fold per-N bias and
activation into the C store in f32. Bit-identical to the dedicated
preshuffle_gemm_a8w4 bias path (cosine 1.0); activations match torch.

Add tests/kernels/test_a8w4_preshuffle.py covering the fp8-A path against a bf16
reference (cosine/max/min/abs/pct metrics, ragged M, 3x repeatability) and all
epilogue variants. Drop the stale 'fp8-A not yet supported' skip in
test_preshuffle_gemm.py (that test only ever launches fp4-A; a8w4 is now covered
by the new file). fp8-A works and is bit-exact vs the dedicated a8w4 kernel.

Note: tile_n=64 is a known-degraded config (cosine ~0.957 vs bf16) tracked
separately; the small-N test case relaxes its cosine floor accordingly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant