Skip to content

[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
jograner/decode-gemm-mxfp4-SILOTIGER-1219from
vassavas/a4w4-triton-splitk-route-qwen38
Closed

vorapolsiloai wants to merge 5 commits into
jograner/decode-gemm-mxfp4-SILOTIGER-1219from
vassavas/a4w4-triton-splitk-route-qwen38

Conversation

@vorapolsiloai

Copy link
Copy Markdown
Contributor

Follow-up to #6218.

What

  • gemm_a4w4 dispatches tuned rows named
    triton_preshuffle_bm{BM}_bn{BN}_bk{BK}_ks{KSPLIT}_w{WARPS}_wpe{WPE} to
    gemm_afp4wfp4_preshuffle (Triton split-K), on the same preshuffled weight and
    shuffled 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.
  • CK gen_instances skips triton_ rows (as for _ZN / flydsl_).
  • Qwen3.8-27B rows (gfx950, 256 CUs) in 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_quant now honours scaling_mode (previously ignored) and
    accepts "ceil", the RoundUp E8M0 scale used by per_1x32_f4_quant. Default
    stays "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 meet
    the 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" vs
    per_1x32_f4_quant(round_mode=RoundUp); invalid mode raises. Not yet run on this branch.

Performance

MI355X, amd/Qwen3.8-27B-Quark-AWQ-MXFP4 on SGLang, 5 serving configs, A/B
against the same image without the change:

  • Triton route + rows: TP1 output throughput +2.2% geomean, TPOT -2.1%
    (8k/1k conc 32: +5.0%), GSM8K 0.955. TP2 neutral (-0.1%).
  • FlyDSL decode rows: TP1 throughput +6.5%, TPOT -6.7%.
  • Packed in_proj rows (8448,5120)/(16640,5120): only take effect with the SGLang
    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.

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.
@vorapolsiloai

Copy link
Copy Markdown
Contributor Author

Closing as superseded by #7117, as noted there: #7117 carries the same triton_preshuffle routing change and Qwen3.8-27B rows, rebased onto #6218, plus 48 packed in_proj rows for M 72..256. The act_mul_and_mxfp4_quant scaling_mode fix that was in this PR is in #7116. Nothing from this branch needs to be carried over.

Please continue the review on #7117 (routing and rows) and #7116 (scaling_mode).

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