Skip to content

[Triton/Gluon] [Config] a4w4: dispatch triton_preshuffle tuned rows, tune Qwen3.8-27B decode GEMMs on gfx950 - #7117

Draft
vorapolsiloai wants to merge 5 commits into
ROCm:jograner/decode-gemm-mxfp4-SILOTIGER-1219from
vorapolsiloai:perf/qwen35-a4w4-decode-gemm-rows
Draft

vorapolsiloai wants to merge 5 commits into
ROCm:jograner/decode-gemm-mxfp4-SILOTIGER-1219from
vorapolsiloai:perf/qwen35-a4w4-decode-gemm-rows

Conversation

@vorapolsiloai

@vorapolsiloai vorapolsiloai commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Depends on #6218 (open): stacked on it (FlyDSL A4W4 decode GEMM); the diff shows only this PR's 5 commits. Retargets to main once #6218 merges.

Supersedes #6419 (closed).

Summary

gemm_a4w4 dispatches tuned triton_preshuffle_* rows to the Triton split-K GEMM, and the Qwen3.8-27B MXFP4 table gains decode rows (914 to 1072) including packed in_proj rows for M 72..256.

MI355X, Qwen3.8-27B MXFP4 TP1, SGLang, 8k/1k, vs #6218 alone: c16 median TPOT -15.0%, output tok/s +15.3%; c64 -1.7% / +0.8%; c256 -2.1% / +1.4%. Not claimed: the packed in_proj rows only apply when the framework packs the two projections; bandwidth and roofline are not measured.

Full description and stack note

Supersedes #6419: the same routing change and Qwen3.8-27B rows, rebased onto #6218, plus 48 packed in_proj rows for M 72..256. #6419 can be closed once this is reviewed.

Stacked on #6218 (FlyDSL A4W4 decode GEMM). The base branch is #6218's branch, so the diff shows only this PR's 5 commits (bd0c36d3..1e7a1038). Once #6218 merges, this PR retargets to main. The act_mul_and_mxfp4_quant scaling_mode fix that was in earlier revisions of this PR now lives in its own PR (#7116).

Motivation

At M 32..128 the Triton split-K preshuffle GEMM beats every asm tile on several shapes, and the packed in_proj had no tuned rows (about 2x slower than the best tile at M = 256).

Details

Qwen3.8-27B MXFP4 decode on gfx950 (256 CUs) runs its GEMMs at M <= 256. The a4w4 path has two gaps there:

  • At M 32..128 the Triton split-K preshuffle GEMM beats every asm tile on several of the model's shapes. gemm_a4w4 cannot use it, because it only dispatches asm, CK and flydsl_ rows.
  • The packed linear-attention in_proj has no tuned rows. This is in_proj_qkvz and in_proj_ba run as one GEMM, N = 16640 at TP1 and N = 8448 at TP2. CUDA-graph decode runs it up to M = 256 on the default asm heuristic, which is about 2x slower than the best tile at M = 256.

Changes

Triton route in gemm_a4w4 (gfx950, M >= 32, K % 256 == 0, falls back to asm), CK gen_instances.py skips triton_ rows, and rows added to qwen38_27b_a4w4_blockscale_tuned_gemm.csv (914 to 1072).

Route restrictions, row list
  • gemm_a4w4 dispatches rows named triton_preshuffle_bm{BM}_bn{BN}_bk{BK}_ks{KSPLIT}_w{WARPS}_wpe{WPE} to gemm_afp4wfp4_preshuffle.
    • The Triton kernel reads the asm kernel's preshuffled weight and shuffled scales unchanged, so no operand is copied.
    • The route applies only on gfx950 with M >= 32, bf16 output, preshuffled B, K % 256 == 0, and no bias, alpha, beta or global scales.
    • Otherwise it logs once and falls back to the default asm heuristic, the same way the flydsl_ route does.
  • CK gen_instances.py skips triton_ rows, as it already does for _ZN and flydsl_ rows, so build_tune_dict does not reject them.
  • qwen38_27b_a4w4_blockscale_tuned_gemm.csv (gfx950, 256 CUs) goes from 914 to 1072 rows:
    • 14 triton_preshuffle_* rows at M 32..128 for (5120, 3072), (5120, 6144), (5120, 17408), (7168, 5120) and (8192, 5120).
    • Exact asm rows at M 17..31 for those shapes, so that no lookup with M < 32 pads onto a Triton row.
    • flydsl_ decode rows for M <= 16 on (5120, 6144), (5120, 17408), (14336, 5120), (16384, 5120) and (34816, 5120). The rows added by [CK] [FlyDSL] FlyDSL A4W4 decode GEMM for M<=16 on gfx950 #6218 are unchanged.
    • Packed in_proj (8448, 5120) and (16640, 5120): flydsl_ rows for M <= 16, and asm rows for M 32..256 at every CUDA-graph batch size (step 8 above 64). Each asm row is the fastest candidate whose output is bit-identical to the current dispatch.
    • (32, 5120, 8704) stays on its existing asm row.
  • The Triton rows come from a separate Triton preshuffle sweep, not from gemm_a4w4_blockscale_tune.py, which has no Triton libtype. Re-running that tuner on these shapes would replace them.

Performance (if applicable)

Kernel times, decode traces, end-to-end tables, setup

Kernel times on gfx950, measured as HIP-graph-captured back-to-back calls over rotated weight copies:

Shape (M, N, K) Before After
(32, 5120, 3072) 8.15 us (asm) 7.14 us (Triton)
(32, 7168, 5120) 11.91 us (asm) 10.07 us (Triton)
(32, 8192, 5120) 12.02 us (asm) 10.88 us (Triton)
(72..256, 8448, 5120) 16.6-20.5 us (default heuristic) 11.2-16.1 us
(72..256, 16640, 5120) 19.9-47.2 us (default heuristic) 16.5-24.5 us

MI355X, Qwen3.8-27B MXFP4, TP1, 8k input / 1k output, from decode traces:

End-to-end decode, SGLang, Qwen3.8-27B MXFP4, TP1 on MI355X, 8k input / 1k output tokens. With vs without this PR (#6218 in both):

Concurrent requests Median TPOT without → with Output tok/s without → with
16 9.42 → 8.00 ms (-15.0%) 1,417 → 1,633 (+15.3%)
64 19.08 → 18.75 ms (-1.7%) 2,524 → 2,544 (+0.8%)
256 58.05 → 56.83 ms (-2.1%) 3,106 → 3,151 (+1.4%)

Without this PR, #6218 alone does not change these numbers (within 1%): its FlyDSL decode GEMM is selected for the Qwen3.8-27B shapes by the rows added here. The default merged table goes from 20 to 30 FlyDSL rows for the Qwen3.8-27B decode shapes at M ≤ 16, plus 14 Triton rows for M 32-128 and the packed in_proj rows for M 72-256.

Test configuration: MI355X (gfx950, 256 CUs), Qwen3.8-27B MXFP4, SGLang TP1 with --attention-backend aiter, FP8 KV cache, --enable-amd-monokernel and chunked prefill 16384. "With vs without" is the full stack (SGLang and AITER with this PR and the PRs it builds on) vs the same build without this PR, on the same GPU, averaged over 2 GPUs. Decode is bench_serving random, 64 / 128 / 256 prompts at 16 / 64 / 256 concurrent requests. Repeat noise of the full stack on one GPU: TTFT 0.1-0.8%; TPOT 0.1-0.8%, except 2.4% at 16 concurrent requests on one GPU TPOT (2.4% at 16 requests on one GPU).

The packed in_proj rows only take effect when the serving framework packs the two projections into one GEMM.

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

test_a4w4_triton_route.py + test_csv_validation.py: 22 passed on MI355X; test_decode_gemm_mxfp4.py: 32 passed.

Test details
  • op_tests/tuning_tests/test_a4w4_triton_route.py (new, CPU only) checks three things:

    • every triton_ name parses with the dispatcher's own regex;
    • every row meets the route's restrictions;
    • every Triton M = 32 row has exact non-Triton rows for M 17..31.

    It passes, and so does test_csv_validation.py. The merged default table has no duplicate keys.

  • op_tests/test_gemm_a4w4.py gains the routed shapes, an odd M that pads onto a Triton row (33 -> 48), and M 17..31 shapes that must stay on asm.

  • Results on MI355X: op_tests/test_gemm_a4w4.py on the 24 Qwen3.8-27B shapes this PR tunes (M 1-256; N 3,072-17,408, including the packed GDN input projection N 8,448 / 16,640): all pass checkAllclose (atol/rtol 0.01), error 0. op_tests/tuning_tests/test_a4w4_triton_route.py + test_csv_validation.py: 22 passed. op_tests/flydsl_tests/test_decode_gemm_mxfp4.py: 32 passed.

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Dispatch route and tuned rows only.

Dependencies

  • No new third-party dependencies added

Depends on #6218 (open), see the banner.

Breaking Changes

None.

PR Self-Review

Self-review

Not written yet for the current head; to be completed (reviewed revision, behavior and intent, validation and unverified scope, changed op tests) before this PR is marked ready for review.

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.
The packed linear-attention in_proj shapes, (8448, 5120) at TP2 and
(16640, 5120) at TP1, had tuned rows only up to M = 64. CUDA-graph decode
runs the packed GEMM up to M = 256, so larger batches fell back to the
default asm heuristic. 48 rows at M = 72..256, step 8 (every captured
graph batch size), all asm f4gemm:
- (8448, 5120): 32x128, 96x128 and 64x128 tiles;
- (16640, 5120): 96x128, 128x128, 160x128, 64x256 and 96x256 tiles.

Each row is the fastest candidate whose output is identical to the
current dispatch, out of 40 preshuffled asm tile/splitK combinations and
240 Triton preshuffle configs, timed on MI350X as HIP-graph-captured
back-to-back calls over weight copies rotated through >= 640 MB. Against
the default heuristic: (8448, 5120) 16.6-20.5 us -> 11.2-16.1 us,
(16640, 5120) 19.9-47.2 us -> 16.5-24.5 us.

(32, 5120, 8704), the TP2 down_proj at M = 32, goes back to the asm row
it had before the Triton rows commit, so this series leaves that pick
unchanged. In the same MI350X sweep the Triton config there takes
16.13 us against 17.11 us for the asm tile; it can come back once a TP2
serving run shows the gain.
Covers the 14 triton_preshuffle rows of
qwen38_27b_a4w4_blockscale_tuned_gemm.csv, an odd M that pads onto one of
them (33 -> 48), and M = 17..31 shapes that must stay on asm.
…6 CUs)

The packed GDN in_proj GEMM (N = 16384 + 256 padded in_proj_ba rows = 16640,
K = 5120) had rows only up to M = 256, so at prefill sizes gemm_a4w4 fell
back to its default kernel: 1596 us at M = 16384 on MI355X vs 646 us for
the 256x256 tile, 726 vs 318 us at M = 8192.

Each new row sits at a getPaddedM gl=1 bucket and serves every M in it, so
it holds the tile that is best across the bucket, from cold-weight timings
of every BpreShuffle tile at 21 batch sizes from 272 to 16384: 160x384 for
512 ... 4096 (one wave up to M = 800, within 1.3% of the best at 2048 and
4096), 256x256 for 8192 and 16384 (also reached by every M above 8192).
@vorapolsiloai
vorapolsiloai force-pushed the perf/qwen35-a4w4-decode-gemm-rows branch from b81750d to 37a6260 Compare November 24, 2026 08:37

This branch has not been deployed

No deployments
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