feat: support DeepSeek-V4 prefill context parallelism - #2097
Open
LMxyzptlk wants to merge 1 commit into
Open
Conversation
LMxyzptlk
requested review from
Clement-Wang26,
DongheJin,
DragonFive,
JimHsiung,
Kang-Meng,
RobbieLeung,
XuZhang99,
liujinguang0125,
liutongxuan,
walsonyang,
xiao-yu-chen,
yingxudeng,
yq33victor and
zhang-minchao
as code owners
August 1, 2026 06:16
LMxyzptlk
force-pushed
the
feat/deepseek-v4-pcp
branch
from
August 1, 2026 06:54
45c05e1 to
a8d0ae7
Compare
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.
NPU TORCH 后端 DeepSeek-V4 / V4-MTP Prefill Context Parallelism (PCP) 支持
概述
本 PR 为 NPU TORCH 后端的 DeepSeek-V4 和 DeepSeek-V4-MTP 增加 Prefill Context Parallelism(PCP)支持。
采用正交的 DP × CP × TP 并行拓扑:
Prefill 阶段将 query token 切分到不同 CP rank。每个 Decoder Layer 执行完成后,对 CP-local hidden state 进行 all-gather,并恢复全局 token 顺序后继续执行。Decode 阶段保持非 CP 执行。
主要修改
1. 正交 CP × TP 通信组
NPU TORCH 后端的 TP group 缩小为:
dp_rank和tp_rank不变,仅改变cp_rankParallelArgs暴露实际生效的 TP size2. DeepSeek-V4 Prefill 切分
新增 DeepSeek-V4 CP context,用于计算:
Prefill 执行流程:
3. Sparse Attention 与 Indexer 元数据
将 CP-local attention read view 与全局 KV write metadata 分离:
同时修复 CP-local query block 与 KV window 末尾的对齐关系,覆盖普通 Prefill 和 cached-prefix 场景。
4. DeepSeek-V4-MTP 兼容
该修改用于修复以下错误:
该错误的原因是不同 CP shard 独立生成了 speculative token,导致 scheduler 输入 token 与非 driver CP shard 缓存的 target state token 不一致。
5. ACL Graph 兼容
cp_size > 1与enable_graph=true不能同时启用的全局限制6. 测试
新增单元测试,覆盖:
q_len < cp_size时允许出现空 CP segmentcp_size=1时保持 identity已知限制
当前 DeepSeek-V4 CP 路径不支持: