Skip to content

[Config] [gfx950] Add GLM-5.3-Flash TP4 fused KDA in-proj bf16 GEMM tunings - #5982

Merged
yzhou103 merged 3 commits into
ROCm:mainfrom
Jacob0226:jacob/glm53-flash-kda-fused-gemm-tp4
Oct 12, 2026
Merged

yzhou103 merged 3 commits into
ROCm:mainfrom
Jacob0226:jacob/glm53-flash-kda-fused-gemm-tp4

Conversation

@Jacob0226

@Jacob0226 Jacob0226 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

GLM-5.3-Flash's KDA attention computes q/k/v, beta and the f/g gate inputs with one fused bf16 GEMM, run in each of its 34 KDA layers per decode step. At TP4 that GEMM is N=6416, K=4096 (3 × 2048 + 16 + 2 × 128). At decode batch 1–16 it takes 17.5–18.5 us; a tuned kernel takes 11.2–11.9 us. glm53_flash_bf16_tuned_gemm.csv only has the TP8 shape (N=3336), so N=6416 falls through to the torch default (F.linear). This PR adds 57 rows, one per SGLang decode graph batch size up to M=512. No row is hipblaslt; no other shape changes.

Test Plan

MI355X (gfx950, 256 CUs), ROCm 10.0.0, rocm/sgl-dev:v0.5.20-rocm10-mi35x-20260928.

Step 1 — gemm_a16w16_tune.py produces the rows. Default backends, no --with-hipblaslt:

python3 csrc/gemm_a16w16/gemm_a16w16_tune.py --input_file glm53_flash_kda_tp4_untuned.csv \
    --tuned_file glm53_flash_kda_tp4_tuned.csv --mp 4

Rows that lost to stock in Step 2 were re-tuned with --libtype torch.

Step 2 — a tgemm.mm harness A/Bs the rows through the call SGLang makes. AITER_CONFIG_GEMM_BF16 lists the image's stock tuned CSVs, with and without the new rows. Each point is a HIP graph of 34 calls over 34 rotating weights, so weights miss L2; median of 8 runs. Correctness: relative L2 against fp32 F.linear. End to end: SGLang bench_serving with sgl-project/sglang#41870, which emits this GEMM; only the CSV differs, two runs per arm on swapped GPUs.

Step 2 harness
# python3 bench_kda_tgemm.py stock|tuned M1,M2,... [new_rows.csv]
import glob, importlib.util, os, sys
arm, ms = sys.argv[1], [int(m) for m in sys.argv[2].split(",")]
root = os.path.dirname(importlib.util.find_spec("aiter").submodule_search_locations[0])
files = [f"{root}/aiter/configs/bf16_tuned_gemm.csv"] + sorted(
    p for p in glob.glob(f"{root}/aiter/configs/model_configs/*bf16_tuned_gemm*.csv")
    if "untuned" not in os.path.basename(p))
if arm == "tuned":
    files.append(sys.argv[3])
os.environ["AITER_CONFIG_GEMM_BF16"] = ":".join(files)

import torch
from aiter.tuned_gemm import tgemm

N, K, LAYERS, REPLAYS = 6416, 4096, 34, 200
ws = [torch.randn(N, K, dtype=torch.bfloat16, device="cuda") * 0.02 for _ in range(LAYERS)]
for m in ms:
    x = torch.randn(m, K, dtype=torch.bfloat16, device="cuda")
    ref = torch.nn.functional.linear(x.float(), ws[0].float())
    rel_l2 = ((tgemm.mm(x, ws[0], otype=torch.bfloat16).float() - ref).norm() / ref.norm()).item()
    for _ in range(3):
        for w in ws:
            tgemm.mm(x, w, otype=torch.bfloat16)
    torch.cuda.synchronize()
    g = torch.cuda.CUDAGraph()
    with torch.cuda.graph(g):
        for w in ws:
            tgemm.mm(x, w, otype=torch.bfloat16)
    for _ in range(20):
        g.replay()
    times = []
    for _ in range(5):
        s, e = torch.cuda.Event(enable_timing=True), torch.cuda.Event(enable_timing=True)
        s.record()
        for _ in range(REPLAYS):
            g.replay()
        e.record()
        e.synchronize()
        times.append(s.elapsed_time(e) * 1e3 / (REPLAYS * LAYERS))
    print(arm, m, sorted(times)[2], f"{rel_l2:.2e}")

Test Result

Kernel, us/call, M ≤ 64 (Step 2):

M stock tuned change tuned pick rel L2 stock → tuned
1 17.53 11.30 -35.5% FlyDSL 1.65e-03 → 1.65e-03
2 17.64 11.18 -36.7% FlyDSL 1.67e-03 → 1.67e-03
3 17.71 11.19 -36.8% FlyDSL 1.63e-03 → 1.63e-03
4 17.77 11.46 -35.5% FlyDSL 1.67e-03 → 1.67e-03
5 17.86 11.24 -37.0% FlyDSL 1.65e-03 → 1.65e-03
6 17.90 11.27 -37.0% FlyDSL 1.66e-03 → 1.66e-03
7 17.95 11.31 -37.0% FlyDSL 1.66e-03 → 1.66e-03
8 18.02 11.36 -37.0% FlyDSL 1.67e-03 → 1.67e-03
12 18.36 11.63 -36.7% Triton 1.65e-03 → 1.65e-03
16 18.48 11.88 -35.7% Triton 1.66e-03 → 1.66e-03
20 14.77 13.27 -10.1% FlyDSL split-K 4 1.66e-03 → 3.16e-03
24 14.88 13.62 -8.4% FlyDSL split-K 4 1.66e-03 → 3.16e-03
32 15.02 13.89 -7.5% FlyDSL split-K 4 1.66e-03 → 3.16e-03
40 18.83 14.66 -22.1% FlyDSL split-K 2 1.66e-03 → 2.46e-03
48 18.89 15.47 -18.1% FlyDSL split-K 2 1.66e-03 → 2.45e-03
56 17.20 16.13 -6.2% FlyDSL split-K 2 1.66e-03 → 2.45e-03
64 17.22 16.98 -1.4% FlyDSL split-K 2 1.66e-03 → 2.45e-03

Split-K rows raise rel L2 to at most 3.2e-3, still bf16 rounding.

M = 72–512, same harness. At M=96, 112, 352, 368, 384, 464, 480 and 496 FlyDSL lost to stock (up to +17%), so those rows are torch: F.linear, the same path as no row, which also stops the M padding onto a neighbour's row.

M stock tuned change tuned pick
72 20.16 18.36 -8.9% FlyDSL split-K 2
80 19.85 19.05 -4.0% FlyDSL split-K 2
88 19.63 19.13 -2.5% FlyDSL
96 19.69 19.70 +0.1% torch (= stock)
104 20.78 20.30 -2.3% FlyDSL
112 20.87 20.86 -0.0% torch (= stock)
120 20.91 20.92 +0.0% torch (= stock)
128 20.80 20.81 +0.0% torch (= stock)
136 24.95 22.49 -9.9% FlyDSL
144 24.99 22.79 -8.8% FlyDSL
152 25.03 23.19 -7.4% FlyDSL
160 22.91 22.88 -0.1% torch (= stock)
168 27.27 24.56 -9.9% FlyDSL
176 27.30 25.36 -7.1% FlyDSL
184 27.34 25.48 -6.8% FlyDSL
192 27.16 25.63 -5.6% FlyDSL
200 29.66 25.94 -12.5% FlyDSL
208 30.16 26.24 -13.0% FlyDSL
216 30.46 26.74 -12.2% FlyDSL
224 30.39 27.24 -10.3% FlyDSL
232 32.98 27.56 -16.4% FlyDSL
240 33.16 28.12 -15.2% FlyDSL
248 33.90 28.24 -16.7% FlyDSL
256 29.29 29.05 -0.8% FlyDSL
272 34.30 30.59 -10.8% FlyDSL
288 34.42 31.52 -8.4% FlyDSL
304 34.72 33.55 -3.4% FlyDSL
320 34.28 33.08 -3.5% FlyDSL
336 39.56 33.85 -14.4% FlyDSL
352 30.80 30.91 +0.4% torch (= stock)
368 31.17 31.21 +0.1% torch (= stock)
384 31.12 31.31 +0.6% torch (= stock)
400 32.36 32.41 +0.1% torch (= stock)
416 42.03 38.89 -7.5% FlyDSL
432 42.28 39.06 -7.6% FlyDSL
448 41.75 39.22 -6.1% FlyDSL
464 39.34 39.34 +0.0% torch (= stock)
480 39.20 39.27 +0.2% torch (= stock)
496 38.98 38.87 -0.3% torch (= stock)
512 38.72 38.92 +0.5% torch (= stock)

44 of 57 M are faster; the 13 torch rows match stock within 0.6%.

End to end, GLM-5.3-Flash-Quark-MXFP4, TP4, input 8192 / output 1024, mean of two runs per arm:

concurrency mean TPOT stock (ms) mean TPOT tuned (ms) median ITL stock (ms) median ITL tuned (ms) output stock (tok/s) output tuned (tok/s)
4 7.97 7.88 (−1.1%) 7.43 7.36 (−1.0%) 467 473 (+1.3%)
64 24.03 23.81 (−0.9%) 12.98 12.82 (−1.2%) 2448 2469 (+0.8%)

GSM8K: 96.82% / 96.97% stock, 97.04% / 96.97% tuned.

…=6416, K=4096)

When a GLM-5.3-Flash checkpoint leaves the KDA projections unquantized, SGLang
fuses q/k/v, beta, f_a and g_a into one bf16 GEMM (fused_qkvbfg_a_proj). At TP4
that is N=6416, K=4096, run once in each of the 34 KDA layers per decode step.

glm53_flash_bf16_tuned_gemm.csv only has the TP8 shape (N=3336), so at TP4
tuned_gemm has no entry and hipBLASLt's default pick takes 17.6 us per call at
decode batch 4, against 11.6 us for the tuned kernel.

The rows cover the decode graph batch sizes M=1-8, 12, 16, 20, 24, 32, 40, 48,
56 and 64 on 256-CU gfx950. err_ratio is 0 everywhere except the split-K
FlyDSL picks at M=32/40/56 (at most 1.2%).
@Jacob0226
Jacob0226 requested review from a team and a balanced review from Copilot September 30, 2026 07:45
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
multigpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 5982 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@github-actions github-actions Bot changed the title [gfx950] Add GLM-5.3-Flash TP4 fused KDA in-proj bf16 GEMM tunings (N… [Config] [gfx950] Add GLM-5.3-Flash TP4 fused KDA in-proj bf16 GEMM tunings (N… Sep 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Hardware-specific performance and numerical behavior require final human validation on the stated gfx950 environment.

Review effort: Balanced
Findings: None

What changed in this PR

Adds gfx950 TP4 BF16 GEMM tuning data for GLM-5.3-Flash’s fused KDA projection.

Changes:

  • Adds 17 untuned shapes for N=6416, K=4096, M=1–64.
  • Adds matching hipBLASLt, FlyDSL, and Triton selections.
File Description
aiter/​configs/​model_configs/​glm53_flash_bf16_untuned_gemm.csv Adds TP4 tuning inputs.
aiter/​configs/​model_configs/​glm53_flash_bf16_tuned_gemm.csv Adds gfx950 tuned configurations.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Forty M>64 rows contradict the documented M=1–64 scope and lack corresponding validation.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)

The first 17 rows stop at M=64, so a decode batch above 64 (concurrency
72 and up) still falls through to hipBLASLt's default pick for
N=6416, K=4096.

Add 38 rows for the SGLang decode graph batch sizes M=72-256 step 8 and
272-512 step 16, from gemm_a16w16_tune.py --with-hipblaslt on 256-CU
gfx950, checked against the default pick through tgemm.mm in a HIP
graph over 34 rotating weights:

- M=96, 112 and 160: the tuner's pick is 2-4% slower than the default
  hipBLASLt solution, and falling through to the next row is slower
  still, so these rows pin the default solution (solidx 18601, 18580,
  18640).
- M=120 and 200 have no row: their tuned picks were 2% slower, while
  falling through to the M=128 and M=208 rows matches or beats the
  default.

None of the rows is split-K and err_ratio is 0 on every row.
Copilot AI balanced review requested due to automatic review settings October 1, 2026 02:19
@Jacob0226
Jacob0226 force-pushed the jacob/glm53-flash-kda-fused-gemm-tp4 branch from 66015e3 to c0a562f Compare October 1, 2026 02:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Thirty-eight unvalidated M>64 rows contradict the documented 17-row scope and change runtime dispatch.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)

@Jacob0226 Jacob0226 changed the title [Config] [gfx950] Add GLM-5.3-Flash TP4 fused KDA in-proj bf16 GEMM tunings (N… [Config] [gfx950] Add GLM-5.3-Flash TP4 fused KDA in-proj bf16 GEMM tunings Oct 6, 2026
@zufayu
zufayu requested a review from demonsan October 9, 2026 08:23
@zufayu zufayu assigned demonsan and unassigned yzhou103 Oct 9, 2026
Jacob0226 added a commit to Jacob0226/AgentSkill that referenced this pull request Oct 12, 2026
A hipblaslt row stores a solution index that only exists in the
hipBLASLt build it was tuned on, so it can error in another docker.
Maintainers asked for these rows to be removed in ROCm/aiter#5982.

Tune gemm_a16w16_tune.py without --with-hipblaslt, and use a torch
row (F.linear, no index) where only hipBLASLt beat the default or
where a shape needs to stay pinned to stock.
A hipblaslt row stores a solution index that only exists in the
hipBLASLt build it was tuned on, so it can error in another docker.
Re-run gemm_a16w16_tune.py without --with-hipblaslt over all 57
SGLang decode graph batch sizes (M=1-8, 12-64, 72-256 step 8,
272-512 step 16) for N=6416, K=4096.

Checked through tgemm.mm in a HIP graph over 34 rotating weights,
8 runs per arm. The tuner's pick was slower than the default at
M=96, 112, 352, 368, 384, 464, 480 and 496 (up to +17%), so those
rows are torch rows from --libtype torch: F.linear, the same path
as with no row, which keeps the M from padding onto a neighbour's
row. Rows: 42 FlyDSL, 2 Triton, 13 torch, 0 hipblaslt.
Copilot AI balanced review requested due to automatic review settings October 12, 2026 03:39
@Jacob0226
Jacob0226 requested a review from yzhou103 October 12, 2026 03:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The shipped 57-row configuration does not match the documented and validated 55-row backend selections.

1 open finding
2 resolved since last review

🧠 Review effort: Balanced

@demonsan demonsan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yzhou103
yzhou103 merged commit 2e0d03b into ROCm:main Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants