Skip to content

[Config] Tune a8w8 bpreshuffle for Kimi-K3's KDA gate at tp4 - #5783

Merged
yifehuan merged 3 commits into
mainfrom
guanbao/k3-a8w8-bpreshuffle-n3072
Sep 30, 2026
Merged

yifehuan merged 3 commits into
mainfrom
guanbao/k3-a8w8-bpreshuffle-n3072

Conversation

@XiaobingSuper

Copy link
Copy Markdown
Contributor

What

Adds the 62 missing N=3072, K=128 rows to a8w8_bpreshuffle_tuned_gemm_kimik3.csv, plus the matching shapes in the untuned CSV.

Why

Kimi-K3's KDA gate projection f_b_proj is [M, 128] x [128, 128 * heads/tp]. K is the KDA head dim, 128 at any tp; N is num_local_heads * 128, so the 96 KDA heads give N=1536 at tp8 and N=3072 at tp4. Only 1536 was tuned, so tp4 misses the table on every token.

A miss here is not a slower kernel. gemm_a8w8_bpreshuffle falls through to gemm_a8w8_bpreshuffle_ck, whose rowwise_heuristic_dispatch has branches only for K >= 512 and K >= 192 && K % 64 == 0. K=128 hits:

TORCH_CHECK(false, "Unsupported K for heuristic dispatch: 128. Supported K greater than 192 and K % 64 == 0.")

so the process raises on its first token. Tuning confirms there is no CK kernel for this shape at all: every ck candidate reported This GEMM is not supported!, and every winner is cktile or flydsl.

How

Same M grid the N=1536 rows carry (64-step between 1024 and 4096), so padded-M lookups behave the same at both widths.

python3 csrc/ck_gemm_a8w8_bpreshuffle/gemm_a8w8_bpreshuffle_tune.py \
  -i aiter/configs/model_configs/a8w8_bpreshuffle_untuned_gemm_kimik3.csv \
  -o aiter/configs/model_configs/a8w8_bpreshuffle_tuned_gemm_kimik3.csv \
  --mp 8 --errRatio 0.01

62 shapes, zero failures. 5 pick cktile at small M, 57 flydsl above -- the same split N=1536 has.

The rows are inserted in the file's existing (N, M, K) order rather than letting the tuner re-sort the whole file, so the diff is 62 additions and no deletions.

Verification

gfx950 / 256 CU, via gemm_a8w8_bpreshuffle directly:

shape before after
tp8 M=1..16384 N=1536 K=128 OK OK
tp4 M=1..16384 N=3072 K=128 FAIL Unsupported K for heuristic dispatch: 128 OK

End-to-end: Kimi-K3 at --pipeline-parallel-size 2 --tensor-parallel-size 4 on MI355X x8 now serves with no framework-side GEMM override, GSM8K 5-shot over the full 1319 questions at 0.9598 flexible-extract / 0.9606 strict-match, inside the range recipes/Kimi-K3.md records for this model (0.9591-0.9659 / 0.9591-0.9666).

K3's KDA gate projection `f_b_proj` is `[M, 128] x [128, 128 * heads/tp]`.
K is the KDA head dim, 128 at any tp; N is `num_local_heads * 128`, so the
96 KDA heads give N=1536 at tp8 and N=3072 at tp4. Only 1536 was tuned, so
tp4 misses the table on every token.

A miss here is not a slower kernel. `gemm_a8w8_bpreshuffle` falls through
to `gemm_a8w8_bpreshuffle_ck`, whose `rowwise_heuristic_dispatch` has
branches only for `K >= 512` and `K >= 192 && K % 64 == 0`, so K=128 hits

    TORCH_CHECK(false, "Unsupported K for heuristic dispatch: 128.
                        Supported K greater than 192 and K % 64 == 0.")

and the process raises on its first token. Tuning confirms there is no CK
kernel for this shape at all: every `ck` candidate reported "This GEMM is
not supported!", and the winners are all cktile or flydsl.

Same M grid the N=1536 rows carry (64-step between 1024 and 4096), so the
padded-M lookups behave the same at both widths. 62 shapes, no failures;
5 pick cktile at small M and 57 flydsl above, which is the split N=1536
has. Measured on gfx950 / 256 CU:

    tp8  M=1..16384  N=1536  K=128  ->  OK    (before and after)
    tp4  M=1..16384  N=3072  K=128  ->  FAIL  before, OK after

The untuned CSV gets the same 62 shapes so the rows can be regenerated.

Co-authored-by: Cursor <cursoragent@cursor.com>
@XiaobingSuper
XiaobingSuper requested review from a team and a lite review from Copilot September 23, 2026 06:52

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 was unable to review this pull request because the user who requested the review has reached their quota limit.

@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; main branch always runs both MI35X and MI300X
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 5783 --add-label <label>

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 opt this PR out.

@github-actions github-actions Bot changed the title Tune a8w8 bpreshuffle for Kimi-K3's KDA gate at tp4 [Config] Tune a8w8 bpreshuffle for Kimi-K3's KDA gate at tp4 Sep 23, 2026
@zufayu
zufayu requested a review from yifehuan September 24, 2026 01:46
@gbyu-amd
gbyu-amd marked this pull request as draft September 24, 2026 06:37
@zufayu
zufayu removed the request for review from yifehuan September 25, 2026 00:29
@gbyu-amd
gbyu-amd marked this pull request as ready for review September 29, 2026 13:41
@zufayu
zufayu requested a review from yifehuan September 30, 2026 00:34

@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 d0c104d into main Sep 30, 2026
71 of 84 checks passed
@yifehuan
yifehuan deleted the guanbao/k3-a8w8-bpreshuffle-n3072 branch September 30, 2026 11:51
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