Skip to content

[Config] [FlyDSL] [gfx1250] Kimi-K3 TP1 decode mx128 rows (on #8246) - #8579

Draft
zejunchen-zejun wants to merge 2 commits into
gfx1250/k3-flydsl-fp8-gemmfrom
zejun/k3-tp1-decode-mx128-rows
Draft

zejunchen-zejun wants to merge 2 commits into
gfx1250/k3-flydsl-fp8-gemmfrom
zejun/k3-tp1-decode-mx128-rows

Conversation

@zejunchen-zejun

Copy link
Copy Markdown
Contributor

Summary

Kimi-K3 mx128 (E8M0 1x128 / 128x128, (16,16)-preshuffled W) rows for the decode M range of the TP1 GEMMs that the DP8EP8 decode node runs: there, attention runs at TP1 (DP attention), so every rank reads the full N x K weights. Stacked on #8246 (base branch gfx1250/k3-flydsl-fp8-gemm at ccc4270): the rows use its fused split-K, runtime cluster_m and opt-in (_qe / _nlb) kernels. The diff is the K3 table only.

  • 4577577: seven TP1-only shapes (kda_in_proj, o_proj, mla_gate / shexp_gate_up, kda_f_b, shexp_down, dense FFN gate_up / down). 81 rows added, 12 replaced.
  • 84a741a: mla_qkv_a 2176x7168 and mla_q_b 18432x1536. These N/K are the same at TP8, so this commit also changes [HIP] [CK] [FlyDSL] [gfx1250] Fused split-K for the generic a8w8 GEMM; retune K3 mx128 rows #8246's TP8 decode picks of those two shapes. It is kept separate so it can be dropped or re-checked on its own. 11 rows added, 13 replaced.

Motivation

The table had only power-of-two M rows for the large TP1 shapes, so the padded-M lookup sent M = 257..512 to the M = 512 row and M = 513..1024 to the M = 1024 row. K3 runs decode at M = 300..315 per rank at c512 and ~640 at c1024. kda_f_b_proj (12288x128) had no row at all and ran the untuned fallback. In the 1124 c512 decode breakdown the dense A8W8 GEMMs take 10.2 ms of the ~67 ms step; kda_in_proj and o_proj are 87 % of that.

Changes

aiter/configs/model_configs/kimik3_a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm.csv only.

Method:

  1. Sweep.
    • Space: every candidate of [HIP] [CK] [FlyDSL] [gfx1250] Fused split-K for the generic a8w8 GEMM; retune K3 mx128 rows #8246's kernels_list that fits, i.e. split_k 1 or fused, row-major A, which is 1.1k–7.5k per (shape, M).
    • Validity: a candidate must also fit the bucket's lowest M (padded-M buckets: 16-aligned up to 256, 32-aligned up to 1024). No row runs a compute kernel below its tile_m, or a cluster_m that the dispatcher would silently drop.
    • Anchors: M = 64, 128, 192, 256, 320, 384, 448, 512, 640 for all nine shapes, plus M = 1..32 for kda_f_b.
  2. Timing.
    • Cold weights: rotating copies totalling ≥ 2 GB. Warm activations, as in the model.
    • Each candidate is captured as ≥ 16 back-to-back calls in one CUDA graph, the way decode runs.
  3. Decision.
    • Over a multi-minute sweep the same kernel drifts by up to ~9 % (power/thermal), so rows are not decided on sweep times.
    • Instead, the top-8 of each anchor, and of the two neighbouring anchors for the in-between buckets, are re-timed against the kernel the runtime picks today in 7 interleaved rounds (paired).
    • A row is written only when the median paired ratio is ≤ 0.97 and every round is faster.
    • The us column is the CUDA-graph per-call time.

Performance

gfx1250 (256 CU), 1120 K3 image, cold weights, CUDA graph, µs per call. Today's pick → this PR; unchanged where only one number is shown. The paired median ratio of 7 rounds decided each changed cell.

shape (N x K) M=16 M=32 M=64 M=128 M=160 M=192 M=256 M=288 M=320 M=384 M=448 M=512 M=640
kda_in_proj (49408x7168) — — 27.4 → 26.3 30.3 42.1 42.8 45.0 85.6 → 65.2 85.5 → 68.6 84.3 → 71.2 86.7 → 74.4 91.3 → 75.0 139.5 → 112.9
o_proj (7168x12288) — — 12.4 → 10.0 13.9 18.5 → 17.2 18.9 → 17.5 22.9 → 18.2 26.4 → 24.4 26.3 → 24.7 25.9 → 24.8 27.0 26.5 34.4
mla_gate (12288x7168) — — 12.0 → 9.8 14.4 16.0 15.7 16.2 21.3 21.7 22.5 21.8 22.8 30.0 → 27.1
kda_f_b (12288x128) 2.0 → 1.4 2.3 → 1.4 2.8 → 1.5 2.6 → 1.6 2.8 → 2.0 2.6 → 1.9 2.7 → 1.9 2.9 → 2.3 2.8 → 2.3 2.8 → 2.3 2.9 → 2.5 3.0 → 2.5 3.2 → 2.8
mla_qkv_a (2176x7168) — — 6.3 → 5.5 6.9 → 6.1 7.5 → 6.4 8.1 → 6.3 8.3 → 8.0 10.9 → 8.7 9.5 → 8.7 9.5 → 8.7 11.2 → 9.4 11.5 → 10.9 11.8
mla_q_b (18432x1536) — — 4.6 → 4.5 5.4 — 7.0 → 6.6 7.3 → 6.8 — 7.9 8.2 8.9 9.2 11.3
shexp_down (7168x6144) — — 8.0 → 7.1 10.0 → 8.7 12.1 → 11.1 12.1 → 11.3 13.2 → 11.6 14.2 13.8 13.9 14.1 14.2 18.7
ffn_gate_up (67584x7168) — — 42.4 → 38.4 54.0 → 47.7 65.0 65.7 67.4 93.2 91.1 93.8 93.5 95.6 134.2 → 129.8
ffn_down (7168x33792) — — 22.6 → 21.2 26.9 32.3 33.1 35.4 47.9 49.3 52.0 53.2 55.5 → 53.4 85.9 → 78.2

Decode-step proxy. This replays the main-stream dense GEMMs of one K3 decode step: 24 MLA layers (qkv_a, q_b, gate, o_proj) and 68 KDA layers (in_proj, f_b, o_proj). Each layer has its own weights, all calls go in one CUDA graph, and the old and new tables are run alternately twice.

Hardware Workload Before After Change
gfx1250 K3 decode-step dense GEMMs, M=160 (c256) 6.96 ms 6.44 ms −7.5 %
gfx1250 same, M=288 10.22 ms 8.23 ms −19.4 %
gfx1250 same, M=315 (c512, in-model M) 10.76 ms 9.26 ms −14.0 %
gfx1250 same, M=640 (c1024) 15.39 ms 13.36 ms −13.2 %

At M=315, kda_in_proj goes from 6.41 to 5.03 ms/step, o_proj from 2.83 to 2.21 ms/step and kda_f_b from 0.24 to 0.18 ms/step. The shared-expert pair on the side stream is unchanged at M=315.

Testing

  • Ragged M: public entry gemm_a8w8_blockscale_bpreshuffle, every M = 1..1024 for all nine shapes on the new table, 9,216 cases.
    • Against an FP32 reference of the dequantized operands (rtol = atol = 1e-2): 0 failures, worst errRatio 0.017.
    • CUDA-graph replay over a NaN-poisoned output is bitwise equal to eager.
  • Unit tests: op_tests/tuning_tests/test_config_shape_collision.py and test_csv_validation.py: 52 passed.
  • Merge: no key collides with another *_a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm.csv.
  • Static launch check: simulated lookup and resolve_cluster_m for every M = 1..1024. The new rows add no launch that kernel_fits_shape would refuse.
  • Not tested: MI250X / MI300X (gfx1250-only rows), and an in-model c512 decode breakdown (needs a DP8EP8 node; to follow).

Notes for review

🤖 Generated with Claude Code

zejunchen-zejun and others added 2 commits November 24, 2026 13:55
… f_b

Kimi-K3 runs its attention at TP1 on the DP8EP8 decode node (DP attention),
so every rank reads the full N x K weights. The tuned table only held the
power-of-two M rows of these shapes, so M = 315 ran the M = 512 tile,
M = 640 the M = 1024 tile, and f_b (12288 x 128) had no row at all.

Rows for the decode buckets M <= 640 of seven TP1-only shapes:
kda_in_proj 49408x7168, o_proj 7168x12288, mla_gate / shexp_gate_up
12288x7168, kda_f_b 12288x128, shexp_down 7168x6144, dense FFN
67584x7168 and 7168x33792. 81 rows added, 12 replaced.

Every candidate of the #8246 space that launches over the whole bucket was
timed with cold weights (rotating copies >= 2 GB) as CUDA-graph replays.
The top candidates were then re-timed against the kernel the runtime picks
today in 7 interleaved rounds. A row is written only when its median paired
ratio is <= 0.97 and every round is faster.

Public entry, M = 1..1024 on all nine K3 TP1 shapes: errRatio <= 0.017 vs
the FP32 reference and graph replay bitwise equal to eager.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
mla_qkv_a 2176x7168 and mla_q_b 18432x1536 have the same N and K at TP1 and
TP8, so these rows also change the TP8 decode picks of #8246's retune.
They come from the same cold-weight CUDA-graph sweep and paired re-timing as
the previous commit. 11 rows added, 13 replaced; most qkv_a gains are
8-22 %.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
aoli26 added a commit that referenced this pull request Nov 26, 2026
Conflict in the K3 mxfp8_128 table only. Both sides tuned the same decode buckets,
so the resolution keeps this branch's row unless the PR's row was measured faster
inside the K3 decode step (all GEMMs of a step in one CUDA graph, per-layer
weights, 4 serial runs agreeing): 3 rows of the PR are taken as they are
(f_b M384, mla_qkv_a M112, mla_q_b M256).
aoli26 added a commit that referenced this pull request Nov 26, 2026
… slower inside the step

In the K3 decode step (all GEMMs of a step in one CUDA graph, per-layer weights)
11 rows of this branch's table lose although they won the isolated back-to-back
A/B. Ten go back to the kernel their bucket ran before this branch (f_b
M80/112/128, mla_gate M192/208/240, mla_q_b M448/576/832/864); mla_q_b M208 (a
new bucket) takes the kernel PR #8579 serves it from its M256 row. 4 serial runs
agree, 1.8-14 us per call; rows written by the repo tuner.
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