Skip to content

[Kimi] Support DCP + DSpark (ported from kimi-k3 branch) - #32828

Merged
kpham-sgl merged 6 commits into
sgl-project:mainfrom
kpham-sgl:kpham/test-kimi-linear-dcp-dspark
Aug 1, 2026
Merged

kpham-sgl merged 6 commits into
sgl-project:mainfrom
kpham-sgl:kpham/test-kimi-linear-dcp-dspark

Conversation

@kpham-sgl

@kpham-sgl kpham-sgl commented Jul 29, 2026 •

Copy link
Copy Markdown
Collaborator

Port the Kimi Linear DCP + DSPARK feature from the kimi-k3 branch, and add its test coverage.

main had the DCP half (#32612) but not the DSPARK half for a hybrid linear-attention target: the target's KDA/mamba recurrent state was never committed to the accepted length after verify, so it drifted from the accepted token sequence every step.

Changes

  • speculative/dspark_components/dspark_worker_v2.py — commit the last accepted verify step's recurrent state (gated on a mambaish target whose backend exposes update_mamba_state_after_mtp_verify; chain layout only).
  • layers/attention/tokenspeed_mla_backend.py — size the TokenSpeed workspace for the DCP-gathered head count and the real speculative width.
  • mem_cache/kv_cache_configurator.py — size replicated draft pools for the DCP virtual loc space.
  • model_executor/pool_configurator.py — budget the replicated draft pool at dcp_size x in the memory solve.

The last four are no-ops at dcp_size == 1.

Tests

  • dcp/test_tokenspeed_mla_dcp_metadata.py — global vs per-rank KV lengths in the TokenSpeed CUDA-graph metadata.
  • dcp/test_kimi_linear_dcp_dspark4.py — 4xBlackwell GSM8K acceptance, with and without --dcp-replicate-q-proj.

CI States

Latest PR Test (Base): ✅ Run #30669840663
Latest PR Test (Extra): ❌ Run #30669840509

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@kpham-sgl
kpham-sgl marked this pull request as ready for review July 29, 2026 23:53
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@kpham-sgl
kpham-sgl force-pushed the kpham/test-kimi-linear-dcp-dspark branch from c576713 to b8bf4c3 Compare July 30, 2026 00:05
@kpham-sgl kpham-sgl changed the title test: cover Kimi Linear DCP + DSPARK target verify [Kimi] Fix DCP + DSPARK draft KV pool OOB and add static-verify coverage Jul 30, 2026
@kpham-sgl
kpham-sgl marked this pull request as draft July 30, 2026 00:08
@kpham-sgl
kpham-sgl force-pushed the kpham/test-kimi-linear-dcp-dspark branch from b8bf4c3 to ddac145 Compare July 30, 2026 00:16
@kpham-sgl
kpham-sgl marked this pull request as ready for review July 30, 2026 00:20
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@kpham-sgl

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/dcp/test_kimi_linear_dcp_dspark4.py test/registered/dcp/test_tokenspeed_mla_dcp_metadata.py

@github-actions

github-actions Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/dcp/test_kimi_linear_dcp_dspark4.py test/registered/dcp/test_tokenspeed_mla_dcp_metadata.py:

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

cd test/ && python3 registered/dcp/test_kimi_linear_dcp_dspark4.py
cd test/ && python3 registered/dcp/test_tokenspeed_mla_dcp_metadata.py

@kpham-sgl
kpham-sgl marked this pull request as draft July 30, 2026 00:21
@kpham-sgl
kpham-sgl marked this pull request as ready for review July 30, 2026 00:22
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@kpham-sgl kpham-sgl added run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci) bypass-fastfail high priority labels Jul 30, 2026
sgl-project#32612 landed DCP for Kimi Linear with its test diff trimmed to
test_kimi_linear_dcp4.py, leaving the speculative-decoding path uncovered.
No test on main combines Kimi Linear with DSPARK.

- dcp/test_tokenspeed_mla_dcp_metadata.py: pins global_seq_lens_k (the
  global causal boundary) against seq_lens_k (rank-owned pages) in the
  TokenSpeed CUDA-graph metadata, so conflating them fails at unit level
  instead of as a silent accuracy drop.
- dcp/test_kimi_linear_dcp_dspark4.py: 4xBlackwell GSM8K acceptance for
  static verify, with and without --dcp-replicate-q-proj.
DSPARK on a hybrid linear-attention target (Kimi Linear) never committed the
target's KDA/mamba recurrent state to the accepted length after verify, so
the state drifted from the accepted token sequence every step. The server
stays healthy and output degrades to noise: GSM8K 0.02 on tp4/dcp4 and 0.015
on tp1 with no DCP, while the same model without speculation scores 0.905.

Pure-MLA targets have no recurrent state to commit, which is why the
existing DSPARK tests (DSV4 / model-agnostic) do not catch this.

Arm the track buffers before the verify forward and commit the last accepted
step's state afterwards, gated on a mambaish target whose backend exposes
update_mamba_state_after_mtp_verify. Chain layout only (topk == 1).

Ported from the kimi-k3 branch.
@kpham-sgl
kpham-sgl force-pushed the kpham/test-kimi-linear-dcp-dspark branch from e671e81 to 75669ca Compare July 30, 2026 21:26
Three remaining pieces of the feature as it exists on the kimi-k3 branch:

- tokenspeed_mla_backend: DCP target verify gathers Q to the full head
  count before launching TokenSpeed, so size the workspace for that launch
  shape and derive max_q_len from max_speculative_num_draft_tokens rather
  than the hardcoded ceiling.
- kv_cache_configurator: draft pools are replicated, not DCP-sharded, yet
  consume the shared allocator's virtual locs in
  [0, max_total * dcp_size) untranslated, so every token-loc-indexed draft
  capacity must cover the full virtual space.
- pool_configurator: budget the replicated draft pool at dcp_size x in the
  memory solve so the larger pool is accounted for instead of taken from
  the target's share.

All three are no-ops at dcp_size == 1.
@kpham-sgl

Copy link
Copy Markdown
Collaborator Author

/rerun-test registered/dcp/test_kimi_linear_dcp_dspark4.py

@github-actions

github-actions Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test registered/dcp/test_kimi_linear_dcp_dspark4.py:

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

cd test/ && python3 registered/dcp/test_kimi_linear_dcp_dspark4.py

@sgl-project sgl-project deleted a comment from github-actions Bot Jul 31, 2026
@sgl-project sgl-project deleted a comment from github-actions Bot Jul 31, 2026
@sgl-project sgl-project deleted a comment from github-actions Bot Jul 31, 2026
@kpham-sgl kpham-sgl changed the title [Kimi] Fix DCP + DSPARK draft KV pool OOB and add static-verify coverage [Kimi] Support DCP + DSpark (ported from kimi-k3 branch) Aug 1, 2026
@kpham-sgl

Copy link
Copy Markdown
Collaborator Author

@kpham-sgl
kpham-sgl merged commit 1496bfe into sgl-project:main Aug 1, 2026
155 of 198 checks passed
ch-wan added a commit that referenced this pull request Aug 1, 2026
86 main commits in (incl. the #33011/#33012/#33013 config refactor, #32692
GDN ReplaySSM fold, #32828 DCP+DSpark port, #31987 BCG eligibility rewrite,
unified-memory #32971/#32972/#33046). 24 conflicted files. Key resolutions:

- ReplaySSM: converge on main's --enable-gdn-replayssm-spec (the branch's
  --enable-linear-replayssm-spec rename is dropped) and main's GDN
  fold-every-commit semantics. The KDA fold keeps its fork behavior under
  the same flag: d/k rings stay allocated (KDA decode routes on their
  presence), the window stays --linear-replayssm-cache-len long with the
  power-of-two + 2x margin backstop, and the fused ring-write keeps the
  per-K vector gate layout (branched on IS_KDA next to main's scalar GDN
  layout). replayssm_ring_bytes_per_req accounts both layouts.
- spec_utils KDA commit: gate on replayssm_spec_fold + replayssm_is_kda;
  the old cursor-presence proxy is never allocated under fold and would
  have silently skipped the KDA fold.
- prefill BCG: fold the branch's mla_pinned_under_bcg exemption into
  main's rewritten can_replay_locally prefix guard.
- config refactor fallout: NS("exec.mamba") added to the branch-only
  linear_attn_verify_backend field (test_server_args_namespaces coverage);
  branch server_args writes verified pre-publish (kimi_k3_hook only).
- trtllm_mla: main's unified_mla_hooks predicate; the branch's fused
  KV-scatter+q-concat stays.
- forward_mla: keep the branch's broader DCP decode-phase predicate;
  main's re-added _is_dcp_mla_decode_phase helper (deleted on the branch)
  is dropped again.

Co-Authored-By: Claude Fable 5 <[email protected]>
kpham-sgl added a commit that referenced this pull request Aug 3, 2026
…locator

Follow-up to #32828, which sized the replicated DSPARK draft KV pool for the
DCP virtual loc space by scaling max_total_num_tokens by dcp_size, but left its
page_size at the per-rank value.

The shared PagedTokenToKVPoolAllocator is built with
page_size = get_schedule().page_size * dcp_size and reserves the padding slot by
handing out pages 1..num_pages, so the last page it can emit begins at exactly
`size` and spans a full allocator page. A KV pool only over-allocates one of its
own pages past `size`, so under dcp_size=8 the draft pool backed 64 of that
final 512-slot page and 448 slots had no memory behind them.

Once occupancy is high enough for the allocator to reach its last page, the
draft decode CUDA-graph replay writes into that tail and trips
  kvcache.cuh: Assertion `index >= 0 && index < size_limit` failed
on every TP rank.

Scale the draft pool's page granularity alongside its capacity, and express the
rule once as accessors on KVCacheConfigurator rather than inlining it per call
site. Every pool construction now takes pool_page_size; allocators and sizing
helpers keep the raw page. No-op at dcp_size == 1 and for non-draft workers.

Validated on 8xB300 (tp8, dcp8, DSPARK): 256/256 requests, zero asserts,
throughput unchanged. Reproduces in ~35s without the fix at 16384/1024,
concurrency 64, 256 prompts.
saturn-acc pushed a commit to saturn-acc/sglang that referenced this pull request Aug 16, 2026
@kpham-sgl
kpham-sgl deleted the kpham/test-kimi-linear-dcp-dspark branch August 24, 2026 22:25
Atituiset pushed a commit to Atituiset/sglang that referenced this pull request Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bypass-fastfail high priority run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant