Add a8w4 kernel for Quark mix-precision#837
Open
amd-xiaoyu12 wants to merge 5 commits into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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