Skip to content

[Refactor] kimi-k3.1: Move the DCP prefill KV gather out of the DSA backend - #48754

Closed
kpham-sgl wants to merge 2 commits into
sgl-project:kimi-k3.1-day-0from
kpham-sgl:kpham/k31-dcp-dsa-kv-gather
Closed

kpham-sgl wants to merge 2 commits into
sgl-project:kimi-k3.1-day-0from
kpham-sgl:kpham/k31-dcp-dsa-kv-gather

Conversation

@kpham-sgl

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

Copy link
Copy Markdown
Collaborator

Moves the Kimi-K3.1 DCP prefill KV all-gather out of the DSA attention backend, following the ownership the MLA DCP path already has on main, with DSA-specific entry points. Landing it here first lets the DCP runtime port (#48721) take it as a plain port.

Modifications

Owner MLA (main, unchanged) DSA (this PR)
Planner (layers/dcp/planner.py) prepare_decode_context_parallel_metadata prepare_decode_context_parallel_metadata_dsa -> DecodeContextParallelMetadataDsa
Comm (layers/dcp/comm.py) all_gather_kv_cache_for_mla_extend all_gather_kv_cache_for_extend_dsa
Model forward (forward_mla.py) bcg_dcp_extend_kv_gather bcg_dcp_extend_kv_gather_dsa; also called on the MHA one-shot path
Backend reads attn_dcp_metadata.dcp_kv_buffer reads attn_dcp_metadata.dcp_kv_buffer
  • The planner builds this rank's cached-prefix rows and the destination rows of a buffer laid out request after request, positions 0..seq_len-1, padded to a page: the order the ragged top-k indices already address, so no index remapping.
  • The comm helper all-gathers the prefix rows as packed cache rows and encodes the extend tokens locally the way the pool writes them (fp8_ds_mla quantization with the pool's scale mode, or the raw cast-on-write layout of the trtllm path). No KV write has to precede the gather, and the extend tokens need no collective.
  • The DSA backend's dcp_gather_kv_cache and DSAMetadata.dcp_local_kv_rows are removed; the flashmla_kv and trtllm prefill paths read the buffer. Target verify still attends over the local shard.
  • Kimi-K3 selects the DSA planner when index-K is sharded, so K3.1 DCP prefill no longer allocates the MLA gather buffer it never read.
  • Not changed: the indexer still gathers index-K itself.

Tests

Not run yet; static checks only (pre-commit, ruff F, py_compile). Owed: Kimi-K3.1 TP8/DCP8 prefill with a cached prefix against DCP1 (GSM8K via sgl-eval and a logprob comparison), on both the flashmla_kv and trtllm DSA prefill backends.


CI States

Latest PR Test (Base): ❌ Run #42339754403
Latest PR Test (Extra): ❌ Run #42339754393
Latest PR Test (AMD ROCm 10): ❌ Run #42339754358

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

…ackend

Follow the MLA DCP split of ownership with DSA-specific entry points:
- prepare_decode_context_parallel_metadata_dsa (planner) builds this
  rank's prefix rows and a buffer laid out request after request, the
  order the ragged top-k indices address;
- all_gather_kv_cache_for_extend_dsa (comm) all-gathers the cached
  prefix rows and encodes the extend tokens as the pool writes them
  (fp8_ds_mla quantization, or the raw cast-on-write layout);
- bcg_dcp_extend_kv_gather_dsa (forward_mla) and the MHA one-shot path
  call it; the flashmla_kv and trtllm prefill paths only read
  attn_dcp_metadata.dcp_kv_buffer. Target verify still attends over the
  local shard.
Kimi-K3 picks the DSA planner when index-K is sharded, so K3.1 no longer
allocates the unused MLA gather buffer.
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.

2 participants