Skip to content

[Kimi K3] Fix CUDA graph stream explosion - #40640

Merged
kpham-sgl merged 3 commits into
sgl-project:mainfrom
kpham-sgl:fix/kimi-k3-cuda-graph-stream-explosion
Sep 22, 2026
Merged

kpham-sgl merged 3 commits into
sgl-project:mainfrom
kpham-sgl:fix/kimi-k3-cuda-graph-stream-explosion

Conversation

@kpham-sgl

@kpham-sgl kpham-sgl commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Kimi K3 target CUDA graph replay expands to 96 streams on B300. Repeated attention forks move subsequent layers onto new replay streams. Record the main attention branches before their auxiliary kernels to fix this stream explosion: the same workload now uses 4 target streams on all eight TP ranks.

Modifications

  • Record the KDA main projection before the side-stream gate GEMVs.
  • Fork the MLA output gate before attention, then record its kernel at the output-projection boundary after the attention core. Keep the original fork/join dependencies so the GPU work can still overlap, and close skipped gate branches.
  • Extend changed-input CUDA graph correctness coverage.

Accuracy Tests

python test/registered/unit/models/test_kimi_k3_bfa_overlap.py: 5 tests passed on B300. Overlap unit CI and B300 end-to-end CI also passed on the current PR head; both Kimi K3 B300 end-to-end files passed two tests each.

KDA bitwise parity covers token counts 1, 4, and 12, both defer_f_b settings, and three changed-input replays. MLA checks an in-graph input producer and changed-input parity, including eager and breakable-graph fallback selection. Full-model traces retain identical kernel-name/count multisets: 1,950 target kernels per replay on every rank.

Speed Tests and Profiling

In TP8/DCP1 traces, target replay streams fall from 96 to 4 on all eight TP ranks, with stable assignments across 16 profiled replays and identical kernel-name/count multisets. This is reproduced with both real and dummy weights.

Separate N=5 unprofiled runs per variant and batch size, using dummy MXFP4 target and dummy draft weights: 8× B300, CUDA 13.0, TP8, 60k input / 1k output, DSpark block 7, simulated acceptance 5.5, FP8 E4M3 KV, FP32 SSM, CuTe DSL MLA, FlashInfer MXFP4 MoE, connections=8.

TP8/DCP1:

Batch size Before, tok/s (mean ± SD) After, tok/s (mean ± SD) Change in mean
1 493.06 ± 2.41 498.12 ± 2.14 +1.03%
16 3139.65 ± 252.29 3249.41 ± 15.07 +3.50%

BS1 improves in all five matched pairs (+0.77% to +1.14%). The BS16 mean is distorted by one slow baseline sample (2689.09 tok/s), retained in the results. The other four matched pairs differ by −0.10% to −0.15%; these results do not establish a BS16 speedup. Full-batch steady-state throughput gives the same interpretation.

Order: baseline (3 samples), patched (3), patched (2), baseline (2), each with a fresh server and a full-shape warmup pair excluded in advance. Client/server seeds are 42; actual acceptance lengths match in every corresponding pair. All requests generated the requested tokens. Measurements share two server launches per variant, so N=5 is limited evidence. Dummy weights and simulated acceptance do not test model accuracy.

TP8/DCP8, same N=5 design and workload, with fi_a2a and replicated Q projection:

Batch size Before, tok/s (mean ± SD) After, tok/s (mean ± SD) Change in mean
1 470.94 ± 2.23 474.87 ± 2.26 +0.83%
16 3060.60 ± 14.24 3060.26 ± 13.92 −0.01%

Every BS1 matched pair improves (+0.72% to +0.88%); BS16 decode is unchanged (paired changes −0.028% to +0.001%). Acceptance matches in every pair. All samples are retained and all requests complete their requested output length with a valid full-batch decode window.

BS16 mean total latency is 44.845 → 45.105 s (+0.58%), driven by last-TTFT/prefill time (39.617 → 39.876 s), including one slower patched prefill sample. N=5 does not establish whether the small prefill difference is noise; the flat decode result is not a claim about all end-to-end timings.

The DCP benchmark uses --skip-token-capacity-check because the client guard reads physical capacity while DCP exposes eight times the logical capacity; server memory settings are unchanged. Both repeated comparisons use baseline 0f6761b54 with the PR patch applied for the patched runs. DCP8 was not profiled in this timing experiment.

Profile

Before
Screenshot 2026-09-21 at 5 46 00 PM

After
Screenshot 2026-09-21 at 5 46 44 PM

Checklist

  • Pre-commit checks pass for all changed files.
  • Registered CUDA unit tests extended and run.
  • Correctness and full-model profiling results provided above.

CI States

Latest PR Test (Base): ❌ Run #35662490950
Latest PR Test (Extra): ❌ Run #35662490698
Latest PR Test (AMD ROCm 10): ❌ Run #35662491074

@kpham-sgl

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_kimi_k3_bfa_overlap.py test_kimi_k3_b300.py test_kimi_k3_b300_low_latency.py

@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test_kimi_k3_bfa_overlap.py test_kimi_k3_b300.py test_kimi_k3_b300_low_latency.py:

🚀 1-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/unit/models/test_kimi_k3_bfa_overlap.py

🚀 8-gpu-b300 (2 tests): ✅ View workflow run

cd test/ && python3 registered/e2e/models/test_kimi_k3_b300.py
cd test/ && python3 registered/e2e/models/test_kimi_k3_b300_low_latency.py

@kpham-sgl

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_kimi_k3_bfa_overlap.py test_kimi_k3_b300.py test_kimi_k3_b300_low_latency.py

@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test_kimi_k3_bfa_overlap.py test_kimi_k3_b300.py test_kimi_k3_b300_low_latency.py:

🚀 1-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/unit/models/test_kimi_k3_bfa_overlap.py

🚀 8-gpu-b300 (2 tests): ✅ View workflow run

cd test/ && python3 registered/e2e/models/test_kimi_k3_b300.py
cd test/ && python3 registered/e2e/models/test_kimi_k3_b300_low_latency.py

@kpham-sgl
kpham-sgl merged commit c4d3770 into sgl-project:main Sep 22, 2026
94 of 110 checks passed
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