Repository navigation
[Feat] kimi-k3.1: Prefill context parallelism (CP-TP group sharing) - #48709
Merged
Merged
Conversation
Fridge003
requested review from
BBuf,
Edwardf0t1,
HaiShaw,
Ying1123,
ch-wan,
ispobock and
merrymercy
as code owners
November 5, 2026 20:28
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
This was referenced Nov 5, 2026
Collaborator
Author
|
_forward_cp almost copied eager_runner._execute_extend_cp. Please use eager_runner._execute_extend_cp instead. |
Collaborator
Author
|
Please remove the changes in |
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]>
…main's interleave copies Kimi-K3 now hands its CP boundary to EagerRunner._execute_extend_cp via prepare_cp_inputs (the multimodal wrapper injects image embeddings first), replacing the model-local _forward_cp copy. A middle PP stage returns its proxy before the aux unpack, and a wrapper that exposes its causal LM as .model runs that LM's text body. interleave.py reverts to main; the interleave_rows kernel replaces those copies in the fused-kernels PR. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fridge003
force-pushed
the
k31-pcp/1-core
branch
from
November 6, 2026 08:49
5a5c193 to
1cc046d
Compare
Collaborator
Author
|
Addressed both comments in 1cc046d (also rebased onto main, resolving the conflict with #48721):
Not yet run on GPU: Kimi eager CP and GLM CP need a re-check. |
_kimi_k3_overrides now refuses --enable-prefill-cp for Kimi-K3 before its DCP branch, so the SimpleNamespace standing in for the resolved server args needs the field; without it every _kimi_k3_mode case raised AttributeError. Co-Authored-By: Claude Opus 5.5 <[email protected]>
17 of 21 tasks
This was referenced Nov 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original authors: @yhyang201
Port of #48414
Prefill context parallelism for Kimi-K3.1 (radixark/sglang-k31#22), the first PR of the split of #48504:
--enable-prefill-cp --cp-strategy interleave --attn-cp-size Non the layer-boundary prefill CP framework (#42044), sharing the CP and TP groups.Against the raw port: main split the KDA attention into
forward_pre_o_proj+forward(#45202), so the reorder back to interleave rows now endsforward_pre_o_proj, keeping its output on the input's rows;forwardis unchanged. Left for the next PRs of the stack: MegaMoE, breakable prefill graphs, integrated (non-PD) DFlash and PP × PCP graphs.Split of #48504. Stack: #48709 (core) → #48710 (MegaMoE / BCG / DFlash) → #48711 (fused kernels) → #48712 (PP × PCP BCG). Independent: #48713 (shared-expert TP across PCP), #48714 (trtllm DSA), #48715 (Linker PCP L3).
Modifications
cp_tp_group_sharing_hook.py,model_overrides/kimi_k3.py): addKimiK31ForConditionalGenerationto CP-TP group sharing with the interleave strategy. Prefill only: a decode node and Kimi-K3 prefill CP are rejected; DFLASH is allowed on a PD prefill node.kimi_k3.py,configs/kimi_linear.py,runtime_context.py): partition heads overlinear_attn_parallel_group()(the TP group under CP-TP group sharing) via the newlinear_attn_tp_rank(); reorder rows from interleave to sequence order before the recurrence and back beforeo_proj(one strided copy,cp/interleave.py).output_on_cp_shards(layer_boundary/), it reduce-scatters its gathered TP-partial sums onto this rank's CP rows (KimiK3MoE._forward_cp_shard_rows).Accuracy Tests
Measured on sglang-k31 dev with the original PR, not re-run on this branch:
Speed Tests and Profiling
PD TTFT through the router, bs=1, same decode (sglang-k31 dev):
Tests
test_kimi_k3_stage_kernels.pyandtest_producer_completion.pyplan K3 stages with the parallel layout the declaration now reads (k3_planning).🤖 Generated with Claude Code
CI States
Latest PR Test (Base): ❌ Run #42291603844
Latest PR Test (Extra): ❌ Run #42291603756
Latest PR Test (AMD ROCm 10): ❌ Run #42291603549
Tip
Base CI only covers the core cases, and its workload may not exercise your change. Use
/rerun-testto run the tests your change touches, or copy this prompt for an agent: