Skip to content

perf(kda): rebalance MTP verify precompute and state synchronization - #42683

Merged
BBuf merged 3 commits into
sgl-project:mainfrom
zcnrex:perf/kda-mtp-rebalance
Oct 10, 2026
Merged

BBuf merged 3 commits into
sgl-project:mainfrom
zcnrex:perf/kda-mtp-rebalance

Conversation

@zcnrex

@zcnrex zcnrex commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

The Kimi-K3 KDA MTP verify kernel (fused_kda_decode_mtp_dspark) spends much of its time on precompute dependencies and state synchronization. Rebalancing that work cuts kernel latency by up to 1.37× on B300, and outputs stay bitwise identical.

Modifications

All changes are in python/sglang/kernels/ops/attention/kda_decode_mtp.py:

  • Keep convolution weights in producer registers, removing their shared-memory staging and the initial CTA barrier.
  • Reorder independent convolution/gate work and prefetch output-normalization inputs using spare producer capacity.
  • Use warp-level synchronization for warp-local state transfers, and overlap resident-state loads with precompute while keeping the cross-warp barriers.
  • Public wrapper, launch dispatch, persistent AOT cache, ReplaySSM, padding, output normalization and caller-owned output buffers are unchanged.

Accuracy Tests

B300 (SM103), CUDA 13.0, PyTorch 2.13, CuTe DSL 4.6.2:

  • test/registered/kernels/ops/attention/test_kda_decode_mtp.py and test/registered/unit/layers/test_kda_decode_mtp_slot_stride.py: pass on both main and this PR.
  • Bitwise identical to main: 56 configurations (N ∈ {1, 2, 4, 8, 16, 32, 64}, H=12, num_spec ∈ {3, 7}, ReplaySSM ring on/off, fused output norm on/off). All 420 output tensors were compared (output, intermediate SSM/conv states, ReplaySSM rings, recurrent state), with 0 differences.
  • compute-sanitizer --tool racecheck: 0 hazards across 4 shapes covering ring/full-snapshot and norm on/off.

Speed Tests and Profiling

B300, H=12, K=V=128, same process. Warm = per-call time from a CUDA graph of 50 back-to-back calls (median of 11 replays). Cold = in-graph [512 MiB L2 flush, kernel] × 20 minus a flush-only graph (median of 21).

Speedup range (main → PR) across N = 1…64:

Mode num_spec Warm speedup Cold speedup
ReplaySSM ring + output norm 3 1.22–1.29× 1.22–1.35×
ReplaySSM ring + output norm 7 1.22–1.33× 1.26–1.37×
ReplaySSM ring 3 1.08–1.20× 1.06–1.20×
ReplaySSM ring 7 1.13–1.22× 1.15–1.22×
Full snapshots + output norm 3 1.10–1.15× 1.10–1.24×
Full snapshots + output norm 7 1.07–1.09× 1.07–1.14×
Full snapshots 3 0.98–1.04× 0.98–1.04×
Full snapshots 7 1.02–1.04× 1.02–1.04×
Per-shape timings (µs)
N num_spec ring onorm warm main → PR cold main → PR
1 3 1 1 6.145 → 4.957 10.246 → 8.195
8 3 1 1 6.636 → 5.448 11.368 → 9.326
64 3 1 1 28.467 → 22.626 41.830 → 31.890
1 7 1 1 9.544 → 7.701 14.854 → 10.954
8 7 1 1 9.951 → 8.028 15.658 → 12.083
64 7 1 1 47.864 → 36.065 59.347 → 45.515
1 7 1 0 8.767 → 7.701 12.898 → 10.856
64 7 1 0 43.233 → 36.394 56.371 → 47.266
1 7 0 1 17.080 → 15.692 21.405 → 18.843
64 7 0 1 98.303 → 91.483 101.325 → 94.934
1 3 0 0 9.216 → 9.052 12.184 → 12.288
8 3 0 0 9.705 → 9.872 13.107 → 13.270
1 7 0 0 16.671 → 16.138 19.970 → 19.130
64 7 0 0 93.554 → 91.459 97.227 → 95.179

The full-snapshot, no-norm path is roughly neutral (worst case 0.98× at N ≤ 8 with num_spec = 3, within run-to-run noise). The production ReplaySSM path gains 1.06–1.37×. On Vera Rubin (SM107) the production case (N=1, num_spec=7) drops from 13.2 µs to 9.7 µs.

Checklist

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): 🚫 Run #37892740875
Latest PR Test (Extra): ❌ Run #37892740714
Latest PR Test (AMD ROCm 10): ❌ Run #37892740907

@BBuf BBuf added the run-ci CI: run the baseline test suite on this PR label Oct 9, 2026

@BBuf BBuf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The earlier review points are addressed: output norm on/off and num_spec=0 streaming are covered in the existing test, and the dead prefetch branch is removed. The main update leaves these two PR files unchanged. LGTM; CI is running.

@BBuf

BBuf commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

/rerun-test test/registered/kernels/ops/attention/test_kda_decode_mtp.py test/registered/unit/layers/test_kda_decode_mtp_slot_stride.py

Targeted validation for c15c686.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

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

cd test/ && python3 registered/kernels/ops/attention/test_kda_decode_mtp.py

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

cd test/ && python3 registered/unit/layers/test_kda_decode_mtp_slot_stride.py

@BBuf
BBuf merged commit 7821819 into sgl-project:main Oct 10, 2026
154 of 181 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jit-kernel run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants