Repository navigation
[Config] Tune a8w8 bpreshuffle for Kimi-K3's KDA gate at tp4 - #5783
Merged
Merged
Conversation
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>
Contributor
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
PR title tags & labels: |
gbyu-amd
marked this pull request as draft
September 24, 2026 06:37
1 task
gbyu-amd
marked this pull request as ready for review
September 29, 2026 13:41
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds the 62 missing
N=3072, K=128rows toa8w8_bpreshuffle_tuned_gemm_kimik3.csv, plus the matching shapes in the untuned CSV.Why
Kimi-K3's KDA gate projection
f_b_projis[M, 128] x [128, 128 * heads/tp]. K is the KDA head dim, 128 at any tp; N isnum_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_bpreshufflefalls through togemm_a8w8_bpreshuffle_ck, whoserowwise_heuristic_dispatchhas branches only forK >= 512andK >= 192 && K % 64 == 0. K=128 hits:so the process raises on its first token. Tuning confirms there is no CK kernel for this shape at all: every
ckcandidate reportedThis GEMM is not supported!, and every winner is cktile or flydsl.How
Same M grid the
N=1536rows carry (64-step between 1024 and 4096), so padded-M lookups behave the same at both widths.62 shapes, zero failures. 5 pick cktile at small M, 57 flydsl above -- the same split
N=1536has.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_bpreshuffledirectly:M=1..16384 N=1536 K=128M=1..16384 N=3072 K=128Unsupported K for heuristic dispatch: 128End-to-end: Kimi-K3 at
--pipeline-parallel-size 2 --tensor-parallel-size 4on 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 rangerecipes/Kimi-K3.mdrecords for this model (0.9591-0.9659 / 0.9591-0.9666).