Skip to content

[Config] [Bugfix] Add Kimi-K3.1 gfx950 TP1 BF16 GEMM rows so PP prefill stops falling back to hipBLASLt stream-K - #8245

Merged
yifehuan merged 2 commits into
mainfrom
Jasen/kimik31-tp1-bf16-tuned
Nov 30, 2026
Merged

yifehuan merged 2 commits into
mainfrom
Jasen/kimik31-tp1-bf16-tuned

Conversation

@Jasen2201

@Jasen2201 Jasen2201 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds 124 gfx950 FlyDSL rows to kimik3_bf16_tuned_gemm.csv (and their shapes to kimik3_bf16_untuned_gemm.csv). They cover the nine BF16 GEMM shapes that Kimi-K3.1 runs unsharded on a TP1 prefill stage, at M = 1, 2, 4, …, 8192 (the gl=1 padded-M buckets); lm_head stops at M = 4096 (see Changes).

Motivation

Kimi-K3.1 P/D with a PP8 × TP1 prefill (one GPU per stage) runs every BF16 linear at TP1. The existing Kimi-K3 rows cover the TP8 shards only, so these nine shapes fall through to torch_gemm → F.linear → hipBLASLt. hipBLASLt's heuristic then picks stream-K kernels. Under P/D load one of them never finishes, and the prefill stage hangs with no error.

  • rocgdb on the hung stage shows one dispatch left: Cijk_Alik_Bljk_BBS_BH_Bias_HA_S_SAV_UserArgs_MT256x240x64_..._SK3_..., grid 64512.
  • Its last workgroups spin in label_SK_Fixup.
  • It reproduces on one node (16-layer cut, PP4 × TP1 prefill → TP4 × DCP4 decode, GSM8K C64). The run stops at 27–40 of 1319 requests.
  • TORCH_BLAS_PREFER_HIPBLASLT=0 (rocBLAS) avoids it, but that is an environment workaround and changes every untuned torch GEMM in the process.

With these rows, the stage never takes the torch path for these shapes.

Changes

  • aiter/configs/model_configs/kimik3_bf16_tuned_gemm.csv: +124 rows, all libtype=flydsl, gfx950, cu_num=256, bias=False, bf16 → bf16.
  • aiter/configs/model_configs/kimik3_bf16_untuned_gemm.csv: the same 124 shapes, plus (128, 7168, 12288).
  • (M=128, N=7168, K=12288) is already tuned in bf16_tuned_gemm.csv, so its tuned row is not repeated (no duplicate-shape key). The shape is still listed in the untuned CSV so a retune covers it.
  • No lm_head row at M = 8192. The FlyDSL epilogue computes its output offset in Int32, and gl=1 reuses an M=8192 row for every larger M. For N = 163840 that passes 2^31 output elements from M = 13108. With no M=8192 row, M > 4096 takes the torch path. In ATOM, lm_head runs only on sampled rows.
N × K Kimi-K3.1 layer at TP1
49376 × 7168 KDA in_proj (q, k, v, g + b_proj + f_a_proj)
7168 × 12288 KDA / MLA o_proj
12288 × 128 KDA f_b_proj
12288 × 7168 shared experts gate_up (2 × 3072 × 2), MLA g_proj
7168 × 6144 shared experts down
24576 × 512 MLA kv_b_proj
67584 × 7168 dense MLP gate_up (layer 0)
7168 × 33792 dense MLP down (layer 0)
163840 × 7168 lm_head

Performance (if applicable)

MI355X (gfx950, 256 CUs), rocm/atom-dev:nightly_202611171508 (aiter b9e08da).

  • Before = the default torch path (hipBLASLt heuristic), measured by the same tuner with --libtype torch.
  • After = the tuned row.
  • Sum of per-call times over the M grid:
N × K rows all M: after / before (µs) M ≥ 2048: after / before (µs) rows slower
7168 × 6144 14 1,246 / 1,343 (−7.2%) 907 / 938 (−3.2%) 0
7168 × 12288 13 2,277 / 2,355 (−3.3%) 1,717 / 1,770 (−3.0%) 1
7168 × 33792 14 6,186 / 6,329 (−2.3%) 4,681 / 4,870 (−3.9%) 4
12288 × 128 14 170 / 194 (−12.4%) 115 / 123 (−6.7%) 0
12288 × 7168 14 2,243 / 2,261 (−0.8%) 1,681 / 1,655 (+1.5%) 4
24576 × 512 14 526 / 535 (−1.5%) 398 / 387 (+2.8%) 5
49376 × 7168 14 8,889 / 9,344 (−4.9%) 6,775 / 7,294 (−7.1%) 6
67584 × 7168 14 11,837 / 12,547 (−5.7%) 9,066 / 9,712 (−6.7%) 4
163840 × 7168 13 15,291 / 16,049 (−4.7%) 9,289 / 9,831 (−5.5%) 3
all 124 48,668 / 50,957 (−4.5%) 34,629 / 36,581 (−5.3%) 27

27 rows are slower than the hipBLASLt default, mostly at mid M (16–1024). The worst are:

  • 7168 × 33792 at M = 1024: +18.5%.
  • 67584 × 7168 at M = 256: +16.8%.
  • 24576 × 512 at M = 512: +13.7%.

These rows were tuned with FlyDSL candidates limited to the 1,136 kernels that already win a gfx950 BF16 row in aiter's tables. A triton + opus pass over the 27 slower rows beat FlyDSL on 3 of them, by 1–10%. Those rows were left out, because an opus row names its kernel by catalog index. A full-catalog FlyDSL pass (~3,500 candidates per shape) was not run. I kept these rows anyway, because the alternative for these shapes is a hipBLASLt path that can hang.

Testing

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

Tested on MI355X (gfx950). Single node, Kimi-K3.1 with a 16-layer cut. Prefill PP4 × TP1 (GPUs 0–3) → decode TP4 × DCP4 (GPUs 4–7) over Mooncake. lm_eval GSM8K, 3-shot, C64, 1319 requests. Accuracy is meaningless on a 16-layer model; the runs only check the hang. ATOM main 9b2e67b7f plus the Kimi-K3.1 PP → DCP P/D PRs ROCm/ATOM#3464, ROCm/ATOM#3465 and ROCm/ATOM#3479.

Run BF16 path for the 9 TP1 shapes Result
no new rows, default torch → hipBLASLt (stream-K) hung at 27/1319; rocgdb: ..._MT256x240x64_..._SK3_... spinning in label_SK_Fixup
no new rows, TORCH_BLAS_PREFER_HIPBLASLT=0 torch → rocBLAS 1319/1319
this PR's rows (72fbf6f; e12f0a5 only drops the lm_head M=8192 row, which no K3.1 call reaches), default FlyDSL 1319/1319, AITER_LOG_LEVEL=INFO shows 0 "not found tuned config" lines on the prefill stages
  • Every row has err_ratio ≤ 0.026 against the torch reference, at the tuner's errRatio=0.05.
  • All 126 kernel names fullmatch _HGEMM_KERNEL_RE on current main. 74 of them already appear in aiter's tuned tables.

Documentation

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

Tuned-config rows only.

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None. The rows only match gfx950 / 256 CU / these nine (N, K) shapes, which had no row before.

PR Self-Review

Reviewed revision

e12f0a5

Behavior and intent

For Kimi-K3.1's TP1 shapes, get_GEMM_A16W16_config now returns a FlyDSL row instead of the torch default, so these GEMMs no longer reach hipBLASLt's stream-K kernels. No other shape changes.

Validation and unverified scope

  • Validated: the hang and the GSM8K C64 runs above, the per-row timings, and the error ratios.
  • Not verified:
    • an end-to-end throughput A/B on the full 93-layer model (the hipBLASLt baseline cannot finish a full P/D run);
    • other CU counts and gfx targets (no rows added for them);
    • a full-catalog FlyDSL search for the 27 slower rows.
  • The hipBLASLt stream-K hang itself is not fixed here; this PR keeps Kimi-K3.1's shapes off that path.

PR-specific question

Changed op tests

None.

Kimi-K3.1 served with a PP8 x TP1 prefill runs every BF16 linear
unsharded. Nine of those (N, K) shapes have no tuned row, so tgemm falls
back to torch / hipBLASLt, whose heuristic picks stream-K (SK3) kernels.
Under P/D load one of them never finishes: a workgroup spins in
label_SK_Fixup and the prefill stage hangs.

Add 125 FlyDSL rows (M = 1..8192, powers of two, for the gl=1 bucket)
for the KDA in_proj / o_proj / f_b_proj, MLA kv_b_proj, the dense
layer-0 MLP and lm_head at TP1. (M=128, 7168x12288) is already tuned in
bf16_tuned_gemm.csv and is not repeated.

Signed-off-by: Jasen2201 <[email protected]>
@Jasen2201
Jasen2201 requested review from a team and a balanced review from Copilot November 19, 2026 02:12
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
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
ci:windows Windows JIT op smoke test on the Radeon R9700 ROCm runner
ci:multi-gpu 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: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
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 8245 --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.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@aiter-bot

aiter-bot commented Nov 19, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision e12f0a5ab6c8 · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. Which exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — PR-specific question has no substantive answer
  • FAIL — validation answer must name a command, result, or evidence link
  • FAIL — validation answer must explicitly state what remains unverified (or say none with a reason)

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

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

Large padded-M inputs can trigger 32-bit output-index overflow and incorrect stores, with additional unresolved compatibility and tuning-coverage issues.

5 open issues
What changed in this PR

Adds Kimi-K3.1 TP1 BF16 GEMM tuning coverage on gfx950, directing prefill workloads to FlyDSL instead of the hipBLASLt fallback associated with hangs.

Changes:

  • Add 125 FlyDSL configurations for nine TP1 shape families across M buckets from 1 to 8192.
  • Add matching tuner inputs while reusing the existing canonical tuned entry for (128,7168,12288).
File Description
aiter/​configs/​model_configs/​kimik3_bf16_untuned_gemm.csv Adds 125 TP1 GEMM shapes to the model’s tuning inputs.
aiter/​configs/​model_configs/​kimik3_bf16_tuned_gemm.csv Adds 125 BF16 FlyDSL selections for gfx950 GPUs with 256 compute units.

Review effort: Balanced

… 7168, 12288) shape

The gfx950 FlyDSL HGEMM computes its output offset as Int32
`global_row * n + global_col`, and getPaddedM(gl=1) reuses an M=8192 row
for every larger M. For lm_head (N = 163840) that passes 2^31 output
elements from M = 13108. Keep lm_head rows to M <= 4096 so larger M takes
the torch path.

Also list (128, 7168, 12288) in the untuned shapes: its tuned row lives in
bf16_tuned_gemm.csv, but a retune reads only this list.

Signed-off-by: Jasen2201 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 02:46

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.

@yifehuan yifehuan 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

@yifehuan
yifehuan merged commit 7546609 into main Nov 30, 2026
1 check passed
@yifehuan
yifehuan deleted the Jasen/kimik31-tp1-bf16-tuned branch November 30, 2026 10:44
whx-sjtu added a commit to whx-sjtu/aiter that referenced this pull request Dec 1, 2026
Conflict: aiter/configs/model_configs/kimik3_bf16_tuned_gemm.csv, where
main (ROCm#8245) appended the Kimi-K3.1 TP1 rows and this branch appended the
merged fused_qkv_a + g_proj rows (N 3808, K 7168). Both sets kept, main's
first; no duplicate (gfx, cu_num, M, N, K, bias, dtype, outdtype, scaleAB,
bpreshuffle) key in this file or across the bf16 tuned GEMM tables.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
gbyu-amd pushed a commit that referenced this pull request Dec 3, 2026
…4098)

(cherry picked from commit b34b6b8)

Rebase onto main 12-03: kimik3_bf16_tuned_gemm.csv conflicted with main's gfx950 row updates (#8317 / #8245 / #8915). Replayed by row key: the 32 gfx1250 rows this commit adds are inserted; its 15 gfx950 edits were number formatting only (a CSV round-trip) and are left as main has them. Same rows as the PR head 3b64098.
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