Repository navigation
[gfx950] a4w4: route triton_preshuffle tuned rows to Triton split-K GEMM; Qwen3.8-27B rows - #6419
Closed
vorapolsiloai wants to merge 5 commits into
Closed
vorapolsiloai wants to merge 5 commits into
vorapolsiloai wants to merge 5 commits into
Conversation
gemm_a4w4 now dispatches tuned rows named
triton_preshuffle_bm{BM}_bn{BN}_bk{BK}_ks{KSPLIT}_w{WARPS}_wpe{WPE} to
gemm_afp4wfp4_preshuffle. The kernel reads the same preshuffled weight and
shuffled scale bytes as the asm kernel, so no operand is copied. The route is
taken on gfx950 for M >= 32, bf16 output, preshuffled B, K % 256 == 0 and no
bias/alpha/beta/global scales; otherwise it logs once and falls back to the
default asm heuristic, as the flydsl_ route does.
CK gen_instances skips triton_ rows like it skips _ZN and flydsl_ rows, so
build_tune_dict does not reject them.
Adds a CPU check of the triton_ rows in the a4w4 tuned CSVs (names parse,
rows meet the route's restrictions, M=17..31 has exact non-Triton rows) and
the routed shapes to test_gemm_a4w4.py.
15 tuned rows for M in 32..128 that run the Triton split-K GEMM: (5120,3072) M32/64, (5120,6144) M32/48/64, (5120,8704) M32, (5120,17408) M32..128 step 16, (7168,5120) M32, (8192,5120) M32. They replace the asm rows at the same keys. M=17..31 pads onto the M=32 row, which is now a Triton row the route does not take below M=32, so the 90 exact rows for M=17..31 of these six shapes carry the asm kernel that was tuned at M=32 (same kernelName, splitK, us). tflops/bw of the 105 rows are recomputed from us with the tuner's formula.
…56 CUs) 41 tuned rows: - flydsl_ decode rows for M 1/2/4/8/16 at (N,K) (5120,6144), (5120,17408), (14336,5120), (34816,5120) and (16384,5120) M16, replacing asm rows (CK rows at N=34816), plus new keys (16384,5120) M1/2/4/8; - shapes of the packed linear-attention in_proj (in_proj_qkvz and in_proj_ba as one GEMM): (8448,5120) and (16640,5120), flydsl_ for M 1..16 and asm for M 32/48/64. Those N only occur when the serving framework packs the two projections. The flydsl_ rows added by the FlyDSL decode change are kept as they are.
act_mul_and_mxfp4_quant took scaling_mode but always launched the kernel with SCALING_MODE=0, and the kernel did not pass SCALING_MODE on to _mxfp4_quant_op. Pass it through, map "even" -> 0 and "ceil" -> 1, and raise ValueError for anything else. The default stays "even", so existing callers get the same output. "ceil" is 2^ceil(log2(amax / 6)), the RoundUp (RCEIL) scale that per_1x32_f4_quant and the HIP quant use by default. With it the fused act+mul+quant gives the same FP4 values and scales as act-and-mul followed by per_1x32_f4_quant on the fp32 product, except that an all-zero block gets scale byte 1 instead of 0 (both dequantize to zero). A model whose GEMM input was quantized by per_1x32_f4_quant can then switch to the fused kernel and keep the same scale rounding. The fused kernel still quantizes the fp32 product, not a bf16-rounded one, so the output is not bit-identical to an unfused bf16 act-and-mul followed by per_1x32_f4_quant.
4 tasks done
…s/a4w4-triton-splitk-route-qwen38
3 of 6 tasks
4 of 9 tasks
Contributor
Author
|
Closing as superseded by #7117, as noted there: #7117 carries the same Please continue the review on #7117 (routing and rows) and #7116 ( |
This was referenced Nov 2, 2026
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.
Follow-up to #6218.
What
gemm_a4w4dispatches tuned rows namedtriton_preshuffle_bm{BM}_bn{BN}_bk{BK}_ks{KSPLIT}_w{WARPS}_wpe{WPE}togemm_afp4wfp4_preshuffle(Triton split-K), on the same preshuffled weight andshuffled scale bytes, with no copies. Taken on gfx950 for M >= 32, bf16 out,
K % 256 == 0, no bias/alpha/beta/global scales; otherwise it logs once and
falls back like the
flydsl_route.gen_instancesskipstriton_rows (as for_ZN/flydsl_).qwen38_27b_a4w4_blockscale_tuned_gemm.csv:15
triton_preshuffle_*rows (M 32..128); exact M=17..31 rows for those shapes(asm kernel tuned at M=32) so M<32 does not pad onto a Triton row; FlyDSL
decode rows (M 1..16) for (5120,6144), (5120,17408), (14336,5120), (16384,5120),
(34816,5120) and the packed GDN in_proj shapes (8448,5120)/(16640,5120).
The FlyDSL rows added by [CK] [FlyDSL] FlyDSL A4W4 decode GEMM for M<=16 on gfx950 #6218 are unchanged.
act_mul_and_mxfp4_quantnow honoursscaling_mode(previously ignored) andaccepts
"ceil", the RoundUp E8M0 scale used byper_1x32_f4_quant. Defaultstays
"even".Why
Qwen3.8-27B TP1 decode at batch 32..128: the Triton split-K kernel is faster
than the asm kernel on these shapes (down_proj M=32 29.4 -> 19.3 us,
M 40..64 about -20%).
Tests
op_tests/tuning_tests/test_a4w4_triton_route.py(CPU): names parse, rows meetthe route's restrictions, no M<32 padding onto Triton rows.
op_tests/test_gemm_a4w4.py: routed shapes added. Not yet run on this branch.op_tests/triton_tests/test_activation.py:"ceil"vsper_1x32_f4_quant(round_mode=RoundUp); invalid mode raises. Not yet run on this branch.Performance
MI355X,
amd/Qwen3.8-27B-Quark-AWQ-MXFP4on SGLang, 5 serving configs, A/Bagainst the same image without the change:
(8k/1k conc 32: +5.0%), GSM8K 0.955. TP2 neutral (-0.1%).
packed in_proj change; together +3.4% (TP1) / +3.8% (TP2).
These were measured with the same code applied as a downstream image overlay;
the GPU tests above and a re-measure on this branch are still to do, hence draft.