Skip to content

[Feat] kimi-k3.1: PD disaggregation under decode context parallelism - #48741

Merged
kpham-sgl merged 12 commits into
sgl-project:mainfrom
kpham-sgl:kpham/k31-dcp-pd-hicache
Nov 8, 2026
Merged

kpham-sgl merged 12 commits into
sgl-project:mainfrom
kpham-sgl:kpham/k31-dcp-pd-hicache

Conversation

@kpham-sgl

@kpham-sgl kpham-sgl commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Original authors: @yhyang201, @kpham-sgl, @alphabetc1

HiCache under DCP moved to its own PR, #48877.

Port of #48414

Kimi-K3.1 shards the DSA index-K cache by token under DCP (#48721), so PD disaggregation has to move index-K the way it already moves the sharded MLA KV. Its DFLASH MLA draft keeps DCP owner rows like the target, so the draft KV has to follow the target's rows too. This PR ports both from the Kimi-K3.1 Day-0 branch (#48414) and lifts #48721's DCP rejection of PD over Mooncake.

  • A DCP-1 prefill sends each token's index-K key and scale with its KV row into the owning decode rank's page layout (dsa_index_k_dcp_entries, _dsa_index_k_dcp_params, plus room in the DCP pack buffer).
  • The page-wise DSA state send skips index-K whenever the relayout already moves it.
  • A same-DCP prefill pages index-K in units of dsa_index_k_page_tokens on decode.
  • A decode whose draft pool keeps DCP owner rows (rows_are_dcp_collapsed) says so at registration (draft_rows_dcp_collapsed, on Mooncake and NIXL), and the relayout then sends the draft along the target's row mapping instead of raw widened rows.

Against the raw ports (the first commit of each):

  • PD state registration on main goes through the storage's wire entries. The index-K token bytes are read from the owner DSA pool (index_key_bytes_per_token), so the FP4 indexer's layout is split correctly, and a page must be exactly page_size x (key + scale) bytes.
  • The Day-0 per-pack torch.cuda.set_device is dropped: main binds the Mooncake transfer workers to their GPU already.
  • Ascend's prepare_dcp_token_item_lens / send_kvcache_dcp overrides take and forward draft_rows_collapsed and dsa_index_k, and NPUMLATokenToKVPool reports its rows as not collapsed (NPU drafts index allocator-global slots).
  • The ported index-K transfer test stubs main's _await_transfer_futures.

Left for later ports: the DFLASH draft KV ring's PD state, and sliding-window MLA drafts on trtllm_mla / cutedsl_mla (#49110).

Modifications

  • disaggregation/mooncake/conn.py, disaggregation/common/dcp_pack.py, disaggregation/utils.py, disaggregation/base/conn.py: index-K relayout under PD DCP.
  • disaggregation/{common,mooncake,nixl}/conn.py, disaggregation/common/utils.py, disaggregation/decode.py, mem_cache/memory_pool.py: the DCP-collapsed draft transfer.
  • disaggregation/ascend/conn.py, hardware_backend/npu/memory_pool_npu.py: the Ascend signatures and the NPU draft flag.
  • disaggregation/decode.py, layers/dcp/layout.py: dsa_index_k_page_tokens for the decode's index-K page list.
  • arg_groups/model_overrides/kimi_k3.py: Kimi-K3.1 DCP allows PD over Mooncake.

Tests

  • Unit: TestDcpDsaIndexKTransfer (test_mooncake_transfer_batching.py), TestDsaIndexKPageTokens (test_dcp_layout_unit.py), TestDsaIndexKTokenBytes (test_disaggregation_wire.py), and the ported collapsed-draft cases in test_dcp_pack.py, test_disaggregation_wire.py and test_receiver_connection_pool.py.
  • GPU: PD 1P1D on GB300 with DFLASH, a TP8 / DCP8 decode against a DCP1 and a DCP8 prefill: GSM8K 98.5% and 98.0% (sgl-eval, 200 examples), details in the comment below.

CI States

Latest PR Test (Base): ❌ Run #42461024434
Latest PR Test (Extra): ❌ Run #42461024425
Latest PR Test (AMD ROCm 10): ✅ Run #42461024477

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

# Conflicts:
#	python/sglang/srt/arg_groups/model_overrides/kimi_k3.py
- setup_state_kv_args read the index-K bytes through storage.view() of the
  DSA state entry, which static storage registers without a view, so every
  DSA model in PD raised KeyError at bootstrap. It now reads the owner
  pool, and takes the key/scale split from the pool instead of assuming
  FP8 keys, which mis-split the FP4 indexer's pages.
- The index-K relayout checks that a page is exactly page_size x (key +
  scale) bytes.
- Kimi-K3.1 DCP rejects speculative decoding under PD until the draft pool
  transfer is ported.
- Drop the per-pack set_device: Mooncake transfer workers are already
  bound to their GPU (run_on_device), and it broke CPU pack tests.
- KVArgs declares dsa_index_k_token_bytes; drop the getattr reads.
- Tests: fix the two CPU tests broken by the above, cover the sharded
  branch of dsa_index_k_page_tokens, and add a static DSA pool case for
  the index-K token bytes (FP8, FP4, kpool).
@kpham-sgl

kpham-sgl commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_nixl_backend_basic.py test_dcp_pack.py test_mooncake_transfer_batching.py test_ascend_page_dcp.py test_receiver_connection_pool.py test_disaggregation_wire.py
(3 tries)

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

🚀 ubuntu-latest (6 tests): ✅ View workflow run

cd test/ && python3 registered/unit/disaggregation/test_mooncake_transfer_batching.py  # base-a
cd test/ && python3 registered/dcp/test_dcp_layout_unit.py  # base-a
cd test/ && python3 registered/unit/disaggregation/test_dcp_pack.py  # base-a
cd test/ && python3 registered/unit/disaggregation/test_dsa_sharded_pd_transfer.py  # base-a
cd test/ && python3 registered/unit/disaggregation/test_disaggregation_wire.py  # base-a
cd test/ && python3 registered/unit/test_model_overrides.py  # base-a

@kpham-sgl kpham-sgl removed run-ci CI: run the baseline test suite on this PR run-ci-nv-extra CI: NVIDIA/shared Extra suite (requires run-ci) bypass-fail-fast CI: a failing job no longer aborts its siblings (lint still gates) labels Nov 8, 2026
kpham-sgl and others added 3 commits November 7, 2026 16:40
Main already moves the draft KV in the DCP1 -> DCP-N relayout (sgl-project#37709),
into the draft layout main's pool keeps.
…sgl-project#48414

Copy the Day-0 hunks that let a decode whose MLA draft pool keeps DCP owner
rows (rows_are_dcp_collapsed) say so at registration, so the DCP1 -> DCP-N
relayout sends the draft along the target's row mapping instead of raw
widened rows. The KV ring and index-K lines of the same hunks are left out.

Co-authored-by: Yuhao Yang <[email protected]>
- AscendKVManager overrides prepare_dcp_token_item_lens and
  send_kvcache_dcp with the old signatures, so a DCP relayout on Ascend
  raised TypeError on draft_rows_collapsed and dsa_index_k. Accept them and
  forward them on the non-page-interleaved path.
- NPUMLATokenToKVPool reports rows_are_dcp_collapsed = False: NPU drafts
  index allocator-global slots, and only the DSA builder marks a widened
  pool dcp_replicated, so the MLA property would call an NPU draft collapsed.
@kpham-sgl

Copy link
Copy Markdown
Collaborator Author

Accuracy at 7221465: Kimi-K3.1 PD under DCP with DFLASH, on GB300.

Prefill Decode GSM8K Decode accept len
TP8, DCP1 (index-K + draft KV relayout) TP8 / DCP8 98.5% 3.9-4.1
TP8 / DCP8 (page-wise index-K) TP8 / DCP8 98.0% 3.9-4.1

Reference: unified TP8 / DCP8 without speculative decoding on main scored 99.0% with the same eval settings (an earlier main commit and nightly image, so not a strict A/B).

Setup:

  • 1P1D, each side 2 nodes x 4 GPUs, --tp-size 8 --ep-size 2, DCP --dcp-size 8 --dcp-comm-backend fi_a2a, Mooncake over RDMA, sglang_router --pd-disaggregation --mini-lb.
  • DFLASH with a full-attention MLA DFlash2 draft (7 layers, block size 8) on --speculative-draft-attention-backend cutedsl_mla. The sliding-window drafts need [Feat] dflash: Serve sliding-window MLA drafts on trtllm_mla and cutedsl_mla #49110.
  • Image lmsysorg/sglang:nightly-dev-cu13-20261108-9d547e19 with this branch mounted.
  • GSM8K: sgl-eval 0.1.3, 200 examples, temperature 1.0, top_p 0.95, max_tokens 16384, through the router.
  • Accept len is the decode server's logged value over the last batches of the run. Neither arm logged a pack fallback or a transfer error.

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

🚀 ubuntu-latest (5 tests): ✅ View workflow run

cd test/ && python3 registered/unit/disaggregation/test_dcp_pack.py  # base-a
cd test/ && python3 registered/unit/disaggregation/test_disaggregation_wire.py  # base-a
cd test/ && python3 registered/unit/disaggregation/test_receiver_connection_pool.py  # base-a
cd test/ && python3 registered/unit/disaggregation/test_ascend_page_dcp.py  # base-a
cd test/ && python3 registered/unit/disaggregation/test_mooncake_transfer_batching.py  # base-a

@kpham-sgl kpham-sgl added run-ci CI: run the baseline test suite on this PR run-ci-nv-extra CI: NVIDIA/shared Extra suite (requires run-ci) bypass-fail-fast CI: a failing job no longer aborts its siblings (lint still gates) labels Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

🚀 ubuntu-latest (6 tests): ✅ View workflow run

cd test/ && python3 registered/unit/disaggregation/test_nixl_backend_basic.py  # base-a
cd test/ && python3 registered/unit/disaggregation/test_dcp_pack.py  # base-a
cd test/ && python3 registered/unit/disaggregation/test_mooncake_transfer_batching.py  # base-a
cd test/ && python3 registered/unit/disaggregation/test_ascend_page_dcp.py  # base-a
cd test/ && python3 registered/unit/disaggregation/test_receiver_connection_pool.py  # base-a
cd test/ && python3 registered/unit/disaggregation/test_disaggregation_wire.py  # base-a

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

Labels

bypass-fail-fast CI: a failing job no longer aborts its siblings (lint still gates) deepseek hicache Hierarchical Caching for SGLang memory-pool mooncake npu run-ci CI: run the baseline test suite on this PR run-ci-nv-extra CI: NVIDIA/shared Extra suite (requires run-ci)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants