Skip to content

[Perf] [NVIDIA] kimi-k3: Route draft/dense bf16 GEMMs to TGV and narrow the MLA output gate vector - #46468

Merged
kpham-sgl merged 1 commit into
sgl-project:mainfrom
kpham-sgl:kpham/k3-tgv-shapes-output-gate
Oct 26, 2026
Merged

kpham-sgl merged 1 commit into
sgl-project:mainfrom
kpham-sgl:kpham/k3-tgv-shapes-output-gate

Conversation

@kpham-sgl

@kpham-sgl kpham-sgl commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

A per-kernel comparison of Kimi-K3 NVFP4 target verify (bs=1, 8 tokens, TP8 per-rank shapes) found three small-M bf16 GEMMs still on cuBLAS where TGV is faster, and an MLA output gate launch with too few CTAs for its [8, 12, 128] tile.

Modifications

  • cutedsl_bf16_gemm.py: add (7168, 1792) DSpark draft down, (7168, 512) draft o_proj and (8448, 7168) dense gate_up to _K3_TGV_WIN_SHAPES. The table only applies at M <= 8, so this affects decode and verify.
  • mla_output_gate.cuh: 4 bf16 per thread instead of 8, doubling the CTA count. Output is bit-exact.

Accuracy Tests

  • mla_output_gate: bit-exact against the torch reference for T in {1, 2, 5, 8, 16, 128, 1024}.
  • TGV vs cuBLAS on the three shapes: identical output (max abs diff 0.0).
  • On this branch: test_mla_output_gate.py OK and test_cutedsl_bf16_gemm.py 462 passed on both SM107 and GB300 (SM103).

Speed Tests and Profiling

CUDA-graph us per call with cold weights (rotated past L2). M=7 for the draft shapes, M=8 otherwise.

op SM100 before SM100 after SM107 before SM107 after
draft down_proj 7168x1792 5.64 4.77 6.23 3.90
draft o_proj 7168x512 3.07 2.53 3.00 1.92
dense gate_up 8448x7168 19.47 18.95 14.07 13.70
mla_output_gate 1.29 1.07 1.28 1.02

About 25 us per decode step in total; end to end it is within run-to-run noise (SM107 TP8, bs=1, 8k in / 1k out: 645.6 vs 647.7 / 651.7 tok/s single runs), with the trace confirming the new kernel selection.

Checklist

  • Format your code according to pre-commit.
  • Add unit tests (existing test_mla_output_gate.py and test_cutedsl_bf16_gemm.py cover both changes).
  • Update documentation.
  • Provide accuracy and speed benchmark results.

🤖 Generated with Claude Code

… vector (sgl-project#36)

Route three more Kimi-K3 TP8 per-rank bf16 GEMM shapes (M <= 8) to the
CuTe DSL TGV kernel instead of cuBLAS: DSpark draft down_proj (7168x1792),
draft o_proj (7168x512) and the dense-layer gate_up (8448x7168). Draft
down_proj was the one kernel measurably slower on Rubin than on B200.

Halve the MLA output-gate vector width (8 -> 4 bf16 per thread), doubling
the CTA count for the [8, 12, 128] verify tile. Output stays bit-exact.

CUDA-graph us/call, cold weights, M=7 (draft) / 8:

| op                        | SM107 before | SM107 after | SM100 before | SM100 after |
|---------------------------|--------------|-------------|--------------|-------------|
| draft down_proj 7168x1792 | 6.23         | 3.90        | 5.64         | 4.77        |
| draft o_proj 7168x512     | 3.00         | 1.92        | 3.07         | 2.53        |
| dense gate_up 8448x7168   | 14.07        | 13.70       | 19.47        | 18.95       |
| mla_output_gate           | 1.28         | 1.02        | 1.29         | 1.07        |

End to end on Rubin TP8 (2x4 SM107, NVFP4 + fp8 KV, DSpark, bs1,
8k in / 1k out): 645.6 -> 647.7 / 651.7 output tok/s, ITL 1.55 -> 1.53 ms
(single runs; ~25 us/step expected on an 8.5 ms step).

Co-authored-by: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 33d6cea13e5552359803374096907df7206c5b64)
@kpham-sgl

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_mla_output_gate.py test_cutedsl_bf16_gemm.py

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

🚀 4-gpu-b200 (2 tests): ✅ View workflow run

cd test/ && python3 registered/kernels/ops/elementwise/test_mla_output_gate.py
cd test/ && python3 registered/kernels/ops/gemm/test_cutedsl_bf16_gemm.py

@kpham-sgl
kpham-sgl merged commit a0618d5 into sgl-project:main Oct 26, 2026
111 of 126 checks passed
@nvpohanh

Copy link
Copy Markdown
Collaborator

cc @leejnau

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants