Skip to content

[Config] [gfx1250] Kimi-K3 TP1 prefill: mxfp8_128 rows at M 2048-16384 (stacked on #8586) - #8601

Draft
zejunchen-zejun wants to merge 1 commit into
zejun/k3-tp1-decode-gemm-rowsfrom
zejun/k3-tp1-prefill-gemm-rows
Draft

zejunchen-zejun wants to merge 1 commit into
zejun/k3-tp1-decode-gemm-rowsfrom
zejun/k3-tp1-prefill-gemm-rows

Conversation

@zejunchen-zejun

Copy link
Copy Markdown
Contributor

Summary

Retunes the Kimi-K3 mxfp8_128 bpreshuffle rows at M 2048 / 4096 / 8192 / 16384 for the PD prefill (P) node.

Motivation

  • P runs these GEMMs unsplit at large M. It is PP8 × TP1, so the attention, shared-expert and dense-FFN GEMMs see the whole micro-batch: about 16K tokens a forward.
  • Four rows carry all of P's M. The power-of-two rows from 2048 up serve every M above 1024:
    • a row at b serves b itself;
    • it also serves the M that fall through to it (getPaddedM gl=1): 1025–2047 → 2048, 2049–4095 → 4096, 4097–8191 → 8192;
    • for N > 4096, every M above 8192 without an exact row also falls to the 8192 row, because gl=1 caps there.
  • kda_in_proj ran a generic kernel at every large M (4.1–4.6 PF/s). N = 49408 = 193 × 256 rules out every cluster along N, but a compute kernel with cluster_m 4 along M does fit.
  • kda_f_b had no row above M=1024.

Changes

aiter/configs/model_configs/kimik3_a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm.csv: 654 → 658 rows.

Rows that changed

shape rows speedup at M (ABBA) kernel
kda_in_proj 2048, 4096, 8192, 16384 1.23–1.27× compute_t256x256x128 nb2 cm4_cn1 (generic before)
dense gate_up 2048, 4096, 8192, 16384 1.08–1.12×
dense down 16384 1.25×
kda_f_b 2048, 4096, 8192, 16384 (new) 1.14–1.16× over the heuristic
mla_gate / shexp_gate_up 4096, 8192, 16384 1.04–1.11×
shexp_down 2048, 4096, 8192, 16384 1.04–1.24×
o_proj 8192, 16384 1.04–1.08×
mla_q_b 2048, 4096 1.06–1.08×
mla_qkv_a none

How a row was chosen

  1. Candidates. The full [HIP] [CK] [FlyDSL] [gfx1250] Fused split-K for the generic a8w8 GEMM; retune K3 mx128 rows #8246 space at each M (row-major A, split-K 1 or fused), every candidate fitting both ends of its gl=0 bucket. Timed in a CUDA graph with 4 calls a replay, then the top 12 re-timed interleaved with the FP32 check.

  2. The row's own M. The candidate must be at least 3% faster than today's row in an ABBA A/B on one GPU.

  3. The range the row serves. The candidate must not be slower than 0.99× at two interior points of the range the row also serves, also by ABBA:

    • 1536/1900 for the 2048 row;
    • 3072/3800 for the 4096 row;
    • 6144/7600 for the 8192 row, plus 12000/15360 when N > 4096 (the cap);
    • 12288/15360 for the 16384 row of mla_qkv_a (N ≤ 4096).

    This rule rejected 10 of the 34 candidates. For example, mla_qkv_a M8192 was 1.06× at 8192 but 0.90× at 7600.

  4. Overlap with [Config] [Perf] Tune eight Kimi K3 TP1 dense E8M0 GEMM rows on gfx1250 #8557. The dense FFN rows overlap the keys of draft [Config] [Perf] Tune eight Kimi K3 TP1 dense E8M0 GEMM rows on gfx1250 #8557.

Every candidate row: ABBA at its M and at the interior points
shape row M before kernel after kernel at M: before → after µs interior M: speedup taken
kda_in_proj 2048 t256x256x128_mw2_nw2_nb4_sk1_cm1_cn1 C_t256x256x128_mw2_nw2_nb2_sk1_cm4_cn1 340.0 → 272.7 (1.25×) M1536 1.21×, M1900 1.22× yes
kda_in_proj 4096 t256x256x128_mw2_nw2_nb4_sk1_cm1_cn1 C_t256x256x128_mw2_nw2_nb2_sk1_cm4_cn1 644.9 → 525.8 (1.23×) M3072 1.28×, M3800 1.14× yes
kda_in_proj 8192 t256x256x128_mw2_nw2_nb4_sk1_cm1_cn1 C_t256x256x128_mw2_nw2_nb2_sk1_cm4_cn1 1261.1 → 998.8 (1.26×) M6144 1.28×, M7600 1.27×, M12000 1.14×, M15360 1.25× yes
kda_in_proj 16384 t256x256x128_mw2_nw2_nb4_sk1_cm1_cn1 C_t256x256x128_mw2_nw2_nb2_sk1_cm4_cn1 2518.5 → 1981.1 (1.27×) — yes
o_proj 2048 C_t256x256x128_mw2_nw2_nb4_sk1_cm4_cn4 C_t256x256x128_mw2_nw2_nb4_sk1_cm1_cn2 69.0 → 69.4 (1.00×) M1536 1.12×, M1900 1.01× no
o_proj 4096 C_t256x256x128_mw2_nw2_nb4_sk1_cm2_cn2 C_t256x256x128_mw2_nw2_nb4_sk1_cm1_cn2_ps2 131.4 → 130.8 (1.01×) M3072 1.02×, M3800 1.00× no
o_proj 8192 C_t256x256x128_mw2_nw2_nb4_sk1_cm2_cn2 C_t256x256x128_mw2_nw2_nb4_sk1_cm2_cn4 267.3 → 255.4 (1.04×) M6144 1.03×, M7600 1.04×, M12000 1.09×, M15360 1.08× yes
o_proj 16384 C_t256x256x128_mw2_nw2_nb4_sk1_cm2_cn2 C_t256x256x128_mw2_nw2_nb2_sk1_cm4_cn2 528.4 → 491.3 (1.08×) — yes
mla_gate 2048 C_t256x256x128_mw2_nw2_nb4_sk1_cm2_cn2 C_t256x256x128_mw2_nw2_nb4_sk1_cm4_cn2 69.9 → 69.1 (1.02×) M1536 1.00×, M1900 1.04× no
mla_gate 4096 C_t256x256x128_mw2_nw2_nb4_sk1_cm4_cn2 C_t256x256x128_mw2_nw2_nb4_sk1_cm4_cn4 122.0 → 117.2 (1.04×) M3072 1.00×, M3800 1.02× yes
mla_gate 8192 C_t256x256x128_mw2_nw2_nb4_sk1_cm2_cn2 C_t256x256x128_mw2_nw2_nb4_sk1_cm4_cn4 251.9 → 226.9 (1.10×) M6144 1.03×, M7600 1.03×, M12000 1.08×, M15360 1.05× yes
mla_gate 16384 C_t256x256x128_mw2_nw2_nb4_sk1_cm2_cn2 C_t256x256x128_mw2_nw2_nb4_sk1_cm4_cn4 509.7 → 459.3 (1.11×) — yes
kda_f_b 2048 heuristic (no row) t64x256x128_mw2_nw2_nb2_sk1_cm4_cn1 8.3 → 7.1 (1.16×) M1536 1.22×, M1900 1.00× yes
kda_f_b 4096 heuristic (no row) t128x256x128_mw2_nw2_nb2_sk1_cm2_cn4 12.6 → 11.0 (1.15×) M3072 1.22×, M3800 1.17× yes
kda_f_b 8192 heuristic (no row) t256x128x128_mw4_nw1_nb2_sk1_cm1_cn4 22.4 → 19.6 (1.13×) M6144 1.19×, M7600 1.17×, M12000 1.17×, M15360 1.18× yes
kda_f_b 16384 heuristic (no row) t256x128x128_mw4_nw1_nb2_sk1_cm2_cn2 41.3 → 36.0 (1.14×) — yes
mla_qkv_a 2048 t256x128x256_mw2_nw2_nb3_sk1_cm1_cn1 t128x128x256_mw2_nw2_nb2_sk1_cm2_cn1 25.7 → 27.8 (0.93×) M1536 0.97×, M1900 0.88× no
mla_qkv_a 4096 C_t128x128x128_mw2_nw2_nb4_sk1_cm4_cn1 C_t128x128x128_mw2_nw2_nb4_sk1_cm2_cn1 42.6 → 42.5 (1.00×) M3072 0.99×, M3800 1.01× no
mla_qkv_a 8192 t256x128x256_mw2_nw2_nb3_sk1_cm1_cn1 C_t128x128x128_mw2_nw2_nb4_sk1_cm4_cn1 81.4 → 77.1 (1.06×) M6144 0.91×, M7600 0.90× no
mla_q_b 2048 C_t256x256x128_mw2_nw2_nb4_sk1_cm2_cn2 C_t256x256x128_mw2_nw2_nb4_sk1_cm1_cn4 33.4 → 30.9 (1.08×) M1536 1.03×, M1900 1.07× yes
mla_q_b 4096 C_t256x256x128_mw2_nw2_nb4_sk1_cm4_cn2 C_t256x256x128_mw2_nw2_nb4_sk1_cm2_cn4 56.3 → 53.0 (1.06×) M3072 1.03×, M3800 1.04× yes
mla_q_b 8192 C_t256x256x128_mw2_nw2_nb4_sk1_cm4_cn4 C_t256x256x128_mw2_nw2_nb4_sk1_cm2_cn4_ps2 102.2 → 101.4 (1.01×) M6144 0.99×, M7600 0.98×, M12000 1.05×, M15360 1.03× no
mla_q_b 16384 C_t256x256x128_mw2_nw2_nb2_sk1_cm4_cn4_ps2 C_t256x256x128_mw2_nw2_nb2_sk1_cm2_cn2_ps2 176.2 → 173.6 (1.01×) — no
shexp_down 2048 C_t256x256x128_mw2_nw2_nb4_sk1_cm4_cn4 C_t256x256x128_mw2_nw2_nb4_sk1_cm4_cn2 40.2 → 37.7 (1.05×) M1536 1.13×, M1900 1.02× yes
shexp_down 4096 C_t256x256x128_mw2_nw2_nb4_sk1_cm2_cn2 C_t256x256x128_mw2_nw2_nb4_sk1_cm1_cn2_ps2 71.9 → 69.5 (1.04×) M3072 1.03×, M3800 1.02× yes
shexp_down 8192 C_t256x256x128_mw2_nw2_nb4_sk1_cm2_cn2 C_t256x256x128_mw2_nw2_nb4_sk1_cm4_cn4 139.7 → 124.5 (1.12×) M6144 1.01×, M7600 1.03×, M12000 1.06×, M15360 1.04× yes
shexp_down 16384 C_t256x256x128_mw2_nw2_nb4_sk1_cm2_cn2 C_t256x256x128_mw2_nw2_nb4_sk1_cm4_cn4 284.5 → 230.5 (1.24×) — yes
ffn_gate_up 2048 C_t256x256x128_mw2_nw2_nb4_sk1_cm2_cn2 C_t256x256x128_mw2_nw2_nb4_sk1_cm2_cn4 361.6 → 336.8 (1.07×) M1536 1.07×, M1900 1.08× yes
ffn_gate_up 4096 C_t256x256x128_mw2_nw2_nb4_sk1_cm2_cn2 C_t256x256x128_mw2_nw2_nb4_sk1_cm2_cn4 693.8 → 629.9 (1.10×) M3072 1.08×, M3800 1.11× yes
ffn_gate_up 8192 C_t256x256x128_mw2_nw2_nb4_sk1_cm2_cn2 C_t256x256x128_mw2_nw2_nb4_sk1_cm4_cn4 1351.4 → 1208.2 (1.12×) M6144 1.07×, M7600 1.07×, M12000 1.11×, M15360 1.08× yes
ffn_gate_up 16384 C_t256x256x128_mw2_nw2_nb4_sk1_cm2_cn2 C_t256x256x128_mw2_nw2_nb4_sk1_cm4_cn4 2709.6 → 2433.1 (1.11×) — yes
ffn_down 4096 C_t256x256x128_mw2_nw2_nb4_sk1_cm4_cn2_ps2 C_t256x256x128_mw2_nw2_nb2_sk1_cm2_cn4 368.8 → 362.9 (1.02×) M3072 0.97×, M3800 0.98× no
ffn_down 8192 C_t256x256x128_mw2_nw2_nb2_sk2_cm4_cn4 C_t256x256x128_mw2_nw2_nb4_sk2_cm2_cn4_fsk 756.0 → 739.2 (1.02×) M6144 1.04×, M7600 0.99×, M12000 1.07×, M15360 1.03× no
ffn_down 16384 C_t256x256x128_mw2_nw2_nb4_sk1_cm4_cn2 C_t256x256x128_mw2_nw2_nb2_sk1_cm4_cn4 1657.2 → 1321.2 (1.25×) — yes

Performance

Setup

  • gfx1250, 256 CUs, one 4-GPU tray.
  • Image rocm/fw-bringup:gfx1250-atom-k3-20261120, with its aiter switched to this branch. FlyDSL 0.5.0.

Prefill proxy

  • What it measures: all TP1 dense A8W8 GEMMs of one K3 forward at M tokens, in one CUDA graph.
    • 68 KDA layers: in_proj, f_b, o_proj.
    • 24 MLA layers: qkv_a, q_b, gate, o_proj.
    • The shared expert of all 92 MoE layers.
    • The dense FFN of layer 1.
  • Every layer has its own weights (48 GB).
  • The before and after tables are replayed in a shuffled order.
  • Each figure is the median over 4 GPUs.
Hardware Workload Before After Change
gfx1250 K3 prefill TP1 GEMMs per forward, M=16384 324.2 ms 282.4 ms -12.9%
gfx1250 same, M=8192 163.5 ms 143.7 ms -12.4%
gfx1250 same, M=4096 84.0 ms 75.0 ms -10.8%

#578 measured the dense FFN on P's stage 0 at about 140 TFLOP/s in the model. This table does not explain that: with today's rows, those two GEMMs run at 5.0–5.8 PF/s on their own at M 12K–16K. The gap more likely comes from sharing CUs with the PP send/recv kernels.

Testing

Note on the reference: hipBLASLt's FP32 GEMM faulted on two shapes, M=20000 × N=49408 and, in one process, M=2048 × N=49408. So the reference is computed in 1024-row blocks.

🤖 Generated with Claude Code

The PD prefill node (PP8 x TP1) runs these GEMMs at about 16K tokens a forward.
The power-of-two rows from 2048 up serve every M above 1024 (getPaddedM gl=1;
for N > 4096 every M above 8192 without an exact row lands on the 8192 row).

20 rows replaced and 4 added (kda_f_b had none above 1024), each >= 3% faster at
its M in an ABBA A/B and not below 0.99x at two interior points of the range the
row serves. kda_in_proj moves from the generic kernel to compute t256x256 with
cluster_m 4 (1.23-1.27x).

Prefill proxy (all TP1 GEMMs of one forward, per-layer weights): -12.9% at
M=16384, -12.4% at 8192, -10.8% at 4096. Large-M correctness: 9 shapes x 24
M points, 0 failures.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ZLkanyo009 added a commit to ZLkanyo009/aiter that referenced this pull request Nov 25, 2026
Port the tuning by zejunchen-zejun from ROCm#8586, ROCm#8601 and ROCm#8634,
with the required ROCm#8246 implementation and two inherited qkv_a rows.
Resolve overlapping dense/f_b choices in favor of the peer workload
coverage; retain our remaining dense, DSpark and PTPC contributions.
Preserve the dev underfilled-compute guard, fallback policy, existing
ROCm#8348 latent rows, and unrelated architecture rows. GPU validation of
the combined dev revision is still pending.

Source-PR: ROCm#85868311172
Source-PR: ROCm#86010d0c8d7
Source-PR: ROCm#86341f962ee
Dependency-PR: ROCm#8246ccc4270
Signed-off-by: Ling Zhang <[email protected]>
aoli26 added a commit that referenced this pull request Nov 26, 2026
… TP1 table

Table only. This branch's prefill rows are kept (in_proj and q_a+kv_a use the N
tail compute tiles, which the PR does not have) except 6 rows the PR measured
faster here: dense gate_up M2048/4096/8192 (3-pass isolated A/B, 1.08-1.09x) and
the M8192 rows of o_proj, gate / shared gate_up and shared down, which are faster
inside the K3 prefill step at the M above 8192 they also serve.
gbyu-amd pushed a commit that referenced this pull request Dec 1, 2026
#8978)

* K3 TP1 a8w8 GEMM: compute N tail, underfilled tiles, aligned A-scale loads, retuned rows (#8778 @ ea7a5d8)

#8778 (aoli26; base main; open) applied to k3-455-dev as its net change on its 19 files at head
ea7a5d8 (2026-11-26T14:47:07Z), 3-way against the PR's main base adbb6ac. The 8 files k3-455-dev had
changed (all only by #8246 @ 15808c7) take the PR's version, so all 19 files equal the PR head. It
carries the newer #8246 (ccc4270), the table PRs #8579 / #8586 / #8601 and main's #8566 (its compute
guard, which #8778 replaces); no other main change rides in.

Validated in the K3 1P1D integration branch (aiter zejun/k3-455-dev 627e1eb) on 16 MI455X
(wuhuikx/LLM-Booster#578). The PR head has moved on since (204ce9d: merges of #8246 @ 0d6cf15 and of
main, which brings #8737); those can follow when #8778 lands.

Co-authored-by: zejunchen-zejun <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Update K3 FP8 kernels to c997 and add exact-M tuning

Preserve the existing dev wrappers and bucket tables. Add 162 accepted retuned exact configurations and 3 c997-default compatibility records, with CPU dispatch coverage for all 675 measured points. Backport the three kernel files from c99781c without merging main history. Integrated-head GPU validation remains outstanding.

---------

Co-authored-by: aoli26 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Zhang <[email protected]>
gbyu-amd pushed a commit that referenced this pull request Dec 3, 2026
#8978)

* K3 TP1 a8w8 GEMM: compute N tail, underfilled tiles, aligned A-scale loads, retuned rows (#8778 @ ea7a5d8)

#8778 (aoli26; base main; open) applied to k3-455-dev as its net change on its 19 files at head
ea7a5d8 (2026-11-26T14:47:07Z), 3-way against the PR's main base adbb6ac. The 8 files k3-455-dev had
changed (all only by #8246 @ 15808c7) take the PR's version, so all 19 files equal the PR head. It
carries the newer #8246 (ccc4270), the table PRs #8579 / #8586 / #8601 and main's #8566 (its compute
guard, which #8778 replaces); no other main change rides in.

Validated in the K3 1P1D integration branch (aiter zejun/k3-455-dev 627e1eb) on 16 MI455X
(wuhuikx/LLM-Booster#578). The PR head has moved on since (204ce9d: merges of #8246 @ 0d6cf15 and of
main, which brings #8737); those can follow when #8778 lands.

Co-authored-by: zejunchen-zejun <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Update K3 FP8 kernels to c997 and add exact-M tuning

Preserve the existing dev wrappers and bucket tables. Add 162 accepted retuned exact configurations and 3 c997-default compatibility records, with CPU dispatch coverage for all 675 measured points. Backport the three kernel files from c99781c without merging main history. Integrated-head GPU validation remains outstanding.

---------

Co-authored-by: aoli26 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Zhang <[email protected]>
(cherry picked from commit 1cc9d02)

Rebase onto main 12-03: the 19 files keep this commit's content; only main's later changes are added: the AOT launcher factories of #8678 (mxfp8 / batched wrappers launch gemm_a8w8_launcher.lazy(), _gemm_a8w8_compute_bound_launcher.lazy(), splitk_reduce_launcher.lazy(); _lazy_import keeps _data_ptr), #7449's deferred split-K entry points and #8636's ragged-K fallback. gemm_a8w8_gfx1250.py: this commit's rank0 split-K epilogue and flush_addr (it already carries #8737's flush). gemm_op_a8w8.py: main's #8566 guard in get_mxscale_bpreshuffle_config (no padded row below a compute kernel's M tile) is removed, as on the #8778 head, because the c997 compute kernel serves underfilled tiles; test_gemm_host_dispatch_cache.py takes #8778's test_mxscale_compute_row_serves_underfilled_m_tile in place of main's two guard tests. kimik3 mxscale tuned CSV: this commit's rows (626 changed or added) replayed by key; the result equals this commit's table.

Rebase onto main 12-03: main #7449 moved the bpreshuffle row lookup into _bpreshuffle_config(XQ, WQ); this commit's Kimi-K3 exact-row lookup there needs x_scale, w_scale and Y, so _bpreshuffle_config takes them (the deferred split-K path passes a meta tensor of the output's shape and dtype, so it picks the same row as gemm_a8w8_bpreshuffle).

Rebase onto main 12-03: op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py counts reduce launches through splitk_reduce_launcher.lazy (main #8678 replaced _compile_splitk_reduce).

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