Skip to content

[Feat] kimi-k3.1: Prefill Context Parallelism Support - #48504

Closed
Fridge003 wants to merge 1 commit into
mainfrom
codex/k31-prefill-cp-extract
Closed

Fridge003 wants to merge 1 commit into
mainfrom
codex/k31-prefill-cp-extract

Conversation

@Fridge003

@Fridge003 Fridge003 commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Part of #48414


CI States

Latest PR Test (Base): ❌ Run #41954074888
Latest PR Test (Extra): ❌ Run #41954074850
Latest PR Test (AMD ROCm 10): ❌ Run #41954074463

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

Add CP/TP sharing, PCP8/EP8 MegaMoE, DFlash and PP breakable prefill
graph support, row/DSA preparation fusion, CP-spanning shared experts,
and PCP-aware Mooncake L3 deduplication and RDMA reads.

Adapt the extraction to main's current KDA waits, KV interfaces,
indexer API and MegaMoE fast paths. Retain the final donor's reverts.

Source: #48414 at 0ec7cb2
Origins: radixark/sglang-k31#22, #34, #37, #51, #76, #80, #110, #147

Co-authored-by: Yuhao Yang <[email protected]>
Co-authored-by: Baizhou Zhang <[email protected]>
@github-actions github-actions Bot added documentation Improvements or additions to documentation quant LLM Quantization hicache Hierarchical Caching for SGLang jit-kernel unified-radix-cache mooncake labels Nov 5, 2026
@Fridge003 Fridge003 changed the title [Feat] kimi-k3.1: Extract prefill CP support from #48414 [Feat] kimi-k3.1: Prefill Context Parallelism Support Nov 5, 2026
Fridge003 added a commit that referenced this pull request Nov 6, 2026
Port of radixark/sglang-k31#22, split out of #48504.

Enable `--enable-prefill-cp --cp-strategy interleave --attn-cp-size N` for
Kimi-K3.1 on the prefill CP layer-boundary framework:

- Share the CP and TP groups for KimiK31ForConditionalGeneration.
- Partition KDA heads over linear_attn_parallel_group() (the TP group under
  CP-TP group sharing) and reorder KDA rows between interleave and sequence
  order around the recurrence.
- Keep the latent MoE off the residual stream under attention CP and
  reduce-scatter its sum onto this rank's CP rows (output_on_cp_shards).
- Shard the embeddings in the model and gather the rows, plus DFlash aux
  hidden states, before the logits.
- Allow a Kimi-K3.1 PD prefill node with DFLASH; reject decode nodes and
  Kimi-K3 prefill CP.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fridge003 added a commit that referenced this pull request Nov 6, 2026
…prefill CP

Port of radixark/sglang-k31#34, split out of #48504 and
rebased onto #46890.

- MegaMoE: mask the CP padding rows of a static graph bucket before
  dispatch and after combine; allocate the EP symmetric workspace at load so
  it counts against the KV budget; bound the Kimi MegaMoE eager decode /
  verify rows and the prefill rows (chunk, max prefill tokens and prefill
  graph buckets) in the token-budget check.
- Breakable prefill graphs: admit Kimi-K3.1 to the interleave BCG adapter
  (EP only as MegaMoE over the CP group); run the DSA indexer split op on
  this rank's live rows and keep the unused top-k rows at -1, also during
  capture (on_capture).
- trtllm DSA: pad 65-127 query heads to 128 for trtllm-gen (attention TP 1
  under CP-TP group sharing leaves every head on one rank).
- DFlash: allow integrated as well as PD prefill; let a PD pair register a
  replicated MLA draft KV across different physical TP sizes.
- Size the linear-attention verify scratch for CUDA graph batch padding.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fridge003 added a commit that referenced this pull request Nov 6, 2026
…CP row copies

Port of radixark/sglang-k31#51, split out of #48504.

- mega_moe_pre_dispatch: take an optional device count of live rows and
  zero the input / route the padding rows to -1 inside the kernel, so a
  replayed graph bucket needs no separate masking pass.
- attention.indexer_q_quant_head_gate: one Triton kernel for Kimi's no-RoPE
  indexer Q quantization and BF16 head-gate scaling in the prefill split op.
- memory.interleave_rows: coalesced copies between interleave CP rank order
  and sequence order (KDA reorder, aligned CP gathers).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fridge003 added a commit that referenced this pull request Nov 6, 2026
…ll CP

Port of radixark/sglang-k31#80, split out of #48504.

- Let interleave CP BCG run on pipeline stages for Kimi-K3.1: a later stage
  takes the previous stage's CP-local hidden states, so only positions are
  sharded; middle stages send the rows an eager stage would send.
- Size the PP proxy per capture bucket to its CP-local rows and zero the
  rows past the received shard so a replay never reads a previous replay's
  rows. Zigzag BCG keeps pp_size == 1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fridge003 added a commit that referenced this pull request Nov 6, 2026
Port of radixark/sglang-k31#147, split out of #48504.

With interleave prefill CP the FFN sees equal padded token-row shards, so
the shared experts can gather rows over CP as well as attention TP and
reduce-scatter back. --shared-experts-tp-size may now divide attention TP x
CP (it still never crosses attention DP replicas or PP stages); a width
beyond attention TP requires --enable-prefill-cp --cp-strategy interleave.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fridge003 added a commit that referenced this pull request Nov 6, 2026
Port of radixark/sglang-k31#31, split out of #48504.

- Allow --dsa-prefill-backend / --dsa-decode-backend trtllm for Kimi-K3.1
  (the default stays flashmla_kv; ROCm keeps triton). Both phases read one
  KV pool and PD peers exchange it, so they must match; an unset phase
  follows the set one. trtllm is rejected with --dcp-size > 1 for now.
- Mooncake: reject a non-DCP MLA P/D pair whose per-page KV item lengths
  differ (flashmla_kv 656 B vs trtllm 576 B per token) instead of silently
  copying mismatched rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Fridge003 Fridge003 closed this Nov 7, 2026
Fridge003 added a commit that referenced this pull request Nov 7, 2026
…prefill CP

Port of radixark/sglang-k31#34, split out of #48504 and
rebased onto #46890.

- MegaMoE: mask the CP padding rows of a static graph bucket before
  dispatch and after combine; allocate the EP symmetric workspace at load so
  it counts against the KV budget; bound the Kimi MegaMoE eager decode /
  verify rows and the prefill rows (chunk, max prefill tokens and prefill
  graph buckets) in the token-budget check.
- Breakable prefill graphs: admit Kimi-K3.1 to the interleave BCG adapter
  (EP only as MegaMoE over the CP group); run the DSA indexer split op on
  this rank's live rows and keep the unused top-k rows at -1, also during
  capture (on_capture).
- trtllm DSA: pad 65-127 query heads to 128 for trtllm-gen (attention TP 1
  under CP-TP group sharing leaves every head on one rank).
- DFlash: allow integrated as well as PD prefill; let a PD pair register a
  replicated MLA draft KV across different physical TP sizes.
- Size the linear-attention verify scratch for CUDA graph batch padding.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fridge003 added a commit that referenced this pull request Nov 7, 2026
…CP row copies

Port of radixark/sglang-k31#51, split out of #48504.

- mega_moe_pre_dispatch: take an optional device count of live rows and
  zero the input / route the padding rows to -1 inside the kernel, so a
  replayed graph bucket needs no separate masking pass.
- attention.indexer_q_quant_head_gate: one Triton kernel for Kimi's no-RoPE
  indexer Q quantization and BF16 head-gate scaling in the prefill split op.
- memory.interleave_rows: coalesced copies between interleave CP rank order
  and sequence order (KDA reorder, aligned CP gathers).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fridge003 added a commit that referenced this pull request Nov 7, 2026
…ll CP

Port of radixark/sglang-k31#80, split out of #48504.

- Let interleave CP BCG run on pipeline stages for Kimi-K3.1: a later stage
  takes the previous stage's CP-local hidden states, so only positions are
  sharded; middle stages send the rows an eager stage would send.
- Size the PP proxy per capture bucket to its CP-local rows and zero the
  rows past the received shard so a replay never reads a previous replay's
  rows. Zigzag BCG keeps pp_size == 1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Fridge003
Fridge003 deleted the codex/k31-prefill-cp-extract branch November 18, 2026 22:14
@Fridge003
Fridge003 restored the codex/k31-prefill-cp-extract branch November 18, 2026 22:14
@Fridge003
Fridge003 deleted the codex/k31-prefill-cp-extract branch November 18, 2026 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation hicache Hierarchical Caching for SGLang jit-kernel mooncake quant LLM Quantization unified-radix-cache

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant