Skip to content

[Config] [gfx1250] Kimi-K3 TP1 decode: BF16 MoE router and latent GEMM rows for every M bucket up to 1024 - #8634

Draft
zejunchen-zejun wants to merge 1 commit into
mainfrom
zejun/k3-tp1-decode-bf16-moe-rows
Draft

zejunchen-zejun wants to merge 1 commit into
mainfrom
zejun/k3-tp1-decode-bf16-moe-rows

Conversation

@zejunchen-zejun

Copy link
Copy Markdown
Contributor

Summary

Fills kimik3_bf16_tuned_gemm.csv on gfx1250 (256 CUs) for the three BF16 GEMMs of Kimi-K3's latent MoE. Every decode M bucket up to 1024 gets an explicit row. The three GEMMs are the router (896×7168), the latent down projection (3584×7168) and the latent up projection (7168×3584).

Motivation

  • The PD decode (D) node runs these GEMMs at TP1. The D node is DP8EP8 with --enable-dp-attention. With DSpark k=4 every request adds 5 tokens a step, so M per rank is a multiple of 5, about 5 × concurrency / 8: 120 to 960 for c192 to c1536.
    • In a c512 trace the ranks ran M = 300 to 315.
  • There were only power-of-two rows. On main the router had rows only at powers of two, and latent down and up had no gfx1250 rows at all ([Config] [gfx1250] Kimi-K3 latent-MoE BF16 GEMM rows for 256 CUs #8348 adds powers of two). With those rows, M = 315 runs the M = 512 rows.
  • In the c512 trace these three GEMMs take 79 µs per MoE layer, which is 7.3 ms per step on the main stream:
    • router: 15.7 µs, FlyDSL FT
    • latent down: 44.3 µs, TDM split-K 2
    • latent up: 19.2 µs, OPUS

Changes

aiter/configs/model_configs/kimik3_bf16_tuned_gemm.csv: 1069 → 1200 rows.

GEMM N × K rows replaced rows added gfx1250 rows after
router 896 × 7168 7 (M 16–1024 powers of two) 33 48
latent down 3584 × 7168 – 49 49
latent up 7168 × 3584 – 49 49

Of the 120 decode-bucket rows:

  • 73 are FlyDSL TDM or FT/HT.
  • 40 are OPUS, where no FlyDSL candidate beat them inside the step:
    • latent down at M 577–1024
    • latent up at M 81–128, 257–544 and 577–1024
  • 7 are the Triton default:
    • router at M 241–256
    • latent down at M ≤ 16 and 289–320 (c512)
    • latent up at M ≤ 48 and 65–80

How a row was chosen

  1. Sweep. The candidates were:

    It was coarse to fine. One representative of each TDM tile family was timed first, then every member of the 30 best families. This ran at 16 anchor M from 16 to 1024 and then at every bucket on the union of their best candidates. The top 12 were re-timed interleaved and checked against the FP32 reference.

  2. First pass. A row changed when it was at least 3% faster than today's launch in an ABBA A/B at the bucket top M.

  3. Re-selection inside the decode step. The first pass measured at the bucket top, but decode M is a multiple of 5 and almost never the bucket top. Several top-M winners were 2–4% slower than a neighbour bucket's kernel at the M inside the bucket. One example: the router's M864 winner t96x128x128 is +2.3% on the step at M 835–860 against t64x128x128. So every bucket up to 1024 was re-selected in the decode-step proxy (below) at every multiple of 5 in the bucket.

    • Candidates: the first-pass pick, today's pick, the pick the lookup makes without the bucket's row, the picks of the two buckets on each side, and the sweep's top 3.
    • Score: the median over the bucket's M of the paired step delta.
    • A new kernel needs to gain at least 0.3% and lose at most 1.5% at any M. Two graphs of the same kernel differ by up to 0.5% at a single M.
  4. Explicit rows. Every bucket up to 1024 gets its own row, so no decode M depends on a power-of-two fallthrough.

Performance

Setup

Decode-step proxy

  • What it measures: the BF16 MoE GEMMs of one decode step, 92 layers × (router, latent down, latent up). Every layer has its own weights (10.6 GB). Each table is one CUDA graph.
  • The tables are replayed in a shuffled order each round. A null control (the same table twice) has mean −0.01%, range −1.3% to +2.1%.
  • Measured at every multiple of 5 from M 100 to 960 (173 M) on 4 GPUs. Each concurrency row is the mean over the M a rank sees, 0.8× to 1.0× of 5c/8.
Hardware Workload Before After Change
gfx1250 K3 D-node BF16 MoE GEMMs per step, c192 (M 100–120) 2.80 ms 2.67 ms −4.3%
gfx1250 same, c256 (M 130–160) 3.82 ms 3.39 ms −11.4%
gfx1250 same, c384 (M 195–240) 4.31 ms 4.15 ms −3.6%
gfx1250 same, c512 (M 260–320) 5.36 ms 4.98 ms −7.0%
gfx1250 same, c768 (M 385–480) 5.84 ms 5.59 ms −4.2%
gfx1250 same, c1024 (M 515–640) 7.09 ms 6.43 ms −9.2%
gfx1250 same, c1536 (M 770–960) 7.73 ms 7.65 ms −1.1%
  • Over all 173 M the mean change is −4.6% and the worst is +0.6%.
  • The first pass alone (bucket-top picks) gave −3.4% on average, but up to +6.0% at some M (12 M above +0.5%). The re-selection removes those regressions.
Per kernel at decode M: µs per call (cold weights), and the bandwidth and FLOP rate of the new kernel
GEMM M before kernel after kernel before µs after µs speedup after TB/s after PF/s
router 896×7168 120 opus splitk_clusterlaunch_tdm t32x64x256x6_ks4_w2x4x1_gm0_ptdm 7.8 5.9 1.33 2.53 0.26
router 896×7168 160 t64x64x128x5_ks4_w4x2x1_gm0_pht t32x64x128x4_ks7_w2x2x1_gm0_ptdm 9.0 6.5 1.39 2.38 0.32
router 896×7168 240 t64x64x128x5_ks4_w4x2x1_gm0_pht t32x64x256x3_ks4_w2x4x1_gm0_ptdm 8.8 7.7 1.15 2.18 0.40
router 896×7168 315 t64x64x128x4_ks4_w4x2x1_gm0_pft t64x64x128x3_ks7_w2x2x1_gm0_ptdm 11.8 9.7 1.21 1.84 0.42
router 896×7168 480 t64x64x128x4_ks4_w4x2x1_gm0_pft t64x64x128x4_ks4_w4x2x1_gm0_pht 10.6 10.3 1.03 2.00 0.60
router 896×7168 640 opus 4wave_wl_co_128x64x64x256 t64x64x128x3_ks4_w2x4x1_gm0_ptdm 17.0 13.0 1.31 1.78 0.63
router 896×7168 960 opus 4wave_wl_co_128x64x64x256 t64x128x128x3_ks4_w2x4x1_gm0_ptdm 17.6 15.0 1.17 1.89 0.82
latent down 3584×7168 120 t64x64x128x4_ks4_w2x2x1_gm0_ptdm t64x64x128x3_ks4_w2x4x1_gm0_ptdm 12.9 12.8 1.01 4.23 0.48
latent down 3584×7168 160 t64x128x128x3_ks4_w2x4x1_gm0_ptdm t64x64x128x3_ks4_w2x2x1_gm0_ptdm 15.8 14.8 1.07 3.69 0.55
latent down 3584×7168 240 t64x128x128x3_ks4_w2x4x1_gm0_ptdm unchanged 20.8 20.6 1.01 2.75 0.60
latent down 3584×7168 315 t128x128x128x3_ks2_w4x4x1_gm0_ptdm Triton default 24.9 23.4 1.07 2.49 0.69
latent down 3584×7168 480 t128x128x128x3_ks2_w4x4x1_gm0_ptdm t64x128x128x3_ks2_w2x4x1_gm0_ptdm 28.5 27.8 1.03 2.22 0.89
latent down 3584×7168 640 opus 4wave_co_128x128x128x128 unchanged 33.5 33.4 1.00 1.95 0.98
latent down 3584×7168 960 opus 4wave_co_128x128x128x128 unchanged 36.5 36.8 0.99 1.96 1.34
latent up 7168×3584 120 opus 4wave_wl_co_128x64x64x256 unchanged 10.3 10.3 1.00 5.26 0.60
latent up 7168×3584 160 t64x128x128x6_ks1_w2x2x1_gm0_pft t64x128x128x3_ks2_w2x4x1_gm0_ptdm 14.7 14.2 1.03 3.85 0.58
latent up 7168×3584 240 t64x128x128x6_ks1_w2x2x1_gm0_pft t64x128x128x5_ks1_w2x2x1_gm0_pft 15.8 15.5 1.02 3.65 0.80
latent up 7168×3584 315 opus 4wave_wl_co_128x128x128x128 unchanged 19.1 19.2 1.00 3.03 0.84
latent up 7168×3584 480 opus 4wave_wl_co_128x128x128x128 unchanged 20.6 20.8 0.99 2.97 1.19
latent up 7168×3584 640 opus 4wave_wl_co_128x128x256x128 unchanged 24.6 24.7 1.00 2.64 1.33
latent up 7168×3584 960 opus 4wave_wl_co_128x128x256x128 unchanged 29.7 30.3 0.98 2.38 1.63

The same kernel measures within about 2% of itself between the two columns. Bytes counted are A + W + C in BF16.

What limits these shapes

  • At decode M the router reaches 1.8–2.5 TB/s and latent down/up 1.9–5.3 TB/s, at 0.3–1.6 PF/s. That is neither HBM- nor compute-bound for gfx1250. It is the best kernel the available candidates (TDM, FT/HT, OPUS, Triton) provide.
  • At prefill M (8K–16K) the latent GEMMs run 2.1–2.2 PF/s (rows unchanged).

Caveat: the shared expert overlaps the main stream in the model

  • In the model, the router and latent down overlap the shared expert's FP8 GEMMs on the alt stream. In the c512 trace, latent down takes 44.3 µs; it takes 24.9 µs alone.
  • The proxy above is single-stream.
  • I also tried a two-stream proxy (shared-expert FP8 GEMMs forked on a second stream, a spacer for the routed experts) at M = 315. Its graphs settle into one of two overlap patterns from one build to the next. In both, the new table is faster: −2% (−0.3 ms) in one, −5% (−1 ms) in the other.
  • An in-model D-node run is still pending.

Testing

  • Every decode M has a row: every M from 1 to 1024 of the three shapes resolves to a tuned row through get_GEMM_A16W16_config.
  • Correctness from 1 to 1024: tgemm.mm at every M from 1 to 1024 for the three shapes (3072 calls) against an FP32 reference (errRatio ≤ 0.05), plus CUDA-graph replay bit-exact against eager: 0 failures.
  • Correctness at large M: M 1100–32768, 8 points × 3 shapes, against an FP64 CPU reference on sampled rows (first and last 16 rows plus 96 random), plus graph replay bit-exact: 0 failures.
  • Names: every flydsl_hgemm_* name in the file (654) parses and rebuilds to itself with [FlyDSL] [gfx1250] TDM HGEMM: FP32 cluster split-K, and DSV4.1 BF16 rows where TDM measures faster #8031's get_flydsl_hgemm_kernel_params / flydsl_hgemm_kernel_name, which is the check in test_a16w16_tuned_config_lookup.py.
  • No collisions: no other bf16 table on main has gfx1250 rows for these three shapes, so the runtime merge has nothing to collide with.
  • In-model D-node run (DP8EP8 decode, c192–c1536) and GSM8K.

🤖 Generated with Claude Code

…M rows for every M bucket up to 1024

Rows for the router (896x7168), latent down (3584x7168) and latent up
(7168x3584) GEMMs of Kimi-K3's latent MoE on gfx1250 / 256 CUs: one row for
every decode M bucket up to 1024 (16-aligned to 256, 32-aligned to 1024), so
no decode M falls through to a power-of-two row.

Each bucket was picked inside a decode-step proxy (92 layers x the three
GEMMs, per-layer weights, CUDA graph) at every multiple of 5 in the bucket,
since DP8EP8 decode with DSpark k=4 gives M = 5 x requests per rank. Step
proxy, every multiple of 5 from M 100 to 960: -4.6% on average, worst +0.6%;
c256 -11.4%, c512 -7.0%, c1024 -9.2%.

The latent rows at M 1/2/4/8 and 2048-32768 are #8348's, with the _i0_ptdm /
_i1_ptdm names written as _ptdm / _ptdmi. The TDM rows need #8031's kernel.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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 8634 --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.

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]>

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