Skip to content

[CP]: Support CP V2 Strategy for dsv4 - #33532

Merged
Fridge003 merged 8 commits into
sgl-project:mainfrom
hzh0425:cp/deepseek-v4-cpv2
Aug 7, 2026
Merged

Fridge003 merged 8 commits into
sgl-project:mainfrom
hzh0425:cp/deepseek-v4-cpv2

Conversation

@hzh0425

@hzh0425 hzh0425 commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Modifications

Accuracy Tests

Speed Tests and Profiling

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): ❌ Run #31148530718
Latest PR Test (Extra): ✅ Run #31148530638

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@hzh0425

hzh0425 commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/cp/test_dsv4_prefill_cp.py

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/cp/test_dsv4_prefill_cp.py:

🚀 8-gpu-h200 (1 test): ❌ View workflow run

cd test/ && python3 registered/cp/test_dsv4_prefill_cp.py

@hzh0425
hzh0425 force-pushed the cp/deepseek-v4-cpv2 branch from fc2dbe9 to 40dcabd Compare August 4, 2026 11:21
@hzh0425

hzh0425 commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/cp/test_dsv4_prefill_cp.py

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/cp/test_dsv4_prefill_cp.py:

🚀 8-gpu-h200 (1 test): ✅ View workflow run

cd test/ && python3 registered/cp/test_dsv4_prefill_cp.py

Comment thread test/registered/cp/test_dsv4_prefill_cp.py Outdated
Comment thread python/sglang/srt/model_executor/runner/eager_runner.py Outdated
Comment thread python/sglang/srt/layers/cp/utils.py
hzh0425 added 2 commits August 7, 2026 12:03
# Conflicts:
#	python/sglang/srt/layers/attention/dsv4/compressor.py
@hzh0425

hzh0425 commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/cp/test_deepseek_v4_flash_fp4_b200_cp.py

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/cp/test_deepseek_v4_flash_fp4_b200_cp.py:

🚀 4-gpu-b200 (1 test): ✅ View workflow run

cd test/ && python3 registered/cp/test_deepseek_v4_flash_fp4_b200_cp.py

@hzh0425

hzh0425 commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/cp/test_deepseek_v4_flash_fp4_b200_cp.py

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/cp/test_deepseek_v4_flash_fp4_b200_cp.py:

🚀 4-gpu-b200 (1 test): ✅ View workflow run

cd test/ && python3 registered/cp/test_deepseek_v4_flash_fp4_b200_cp.py

@Fridge003
Fridge003 merged commit 1480687 into sgl-project:main Aug 7, 2026
256 of 271 checks passed
kfhfar pushed a commit to kfhfar/sglang that referenced this pull request Aug 7, 2026
cursor Bot pushed a commit to learning-sketch/sglang that referenced this pull request Aug 8, 2026
Clarify enable switches for shared-KV / layer-split / direct-KV and
add an upstream-merged callout for sgl-project#33532.

Co-authored-by: learning <learning-sketch@users.noreply.github.com>
Xia-Weiwen pushed a commit to Xia-Weiwen/sglang that referenced this pull request Aug 10, 2026
saturn-acc pushed a commit to saturn-acc/sglang that referenced this pull request Aug 16, 2026
AMD-yanfeiwang added a commit to AMD-yanfeiwang/sglang that referenced this pull request Aug 20, 2026
backend, so on ROCm the model/runner would split tokens for CP-v2 while the HIP
attention backend built metadata for the un-split layout. Nothing gates CP-v2 by
platform (SGLANG_ENABLE_CP_V2, environ.py:319, and is_cp_v2_active have no
is_hip branch), so enabling it on ROCm produced wrong metadata rather than an
error. This ports the contract instead of gating it off.

The contract, mirroring deepseek_v4_backend.py: CP-v2 pads the causal metadata
rows for per-rank partitioning (P rows) while cache-write locations stay
one-per-logical-token (N rows). So the reindex must anchor its global-field
post-condition to N, not to the padded metadata length.

  * apply_cp_reindex gains num_tokens (default None -> pre_global_len), keeping
    the CP-v1 model-hook calls at deepseek_v4.py:2698 and
    deepseek_v4_nextn.py:272 byte-compatible.
  * init_compression_metadata gains num_tokens; its raw_out_loc/seq_lens_casual
    shape-equality assert would otherwise fail on the first CP-v2 prefill, since
    those two now legitimately differ.
  * make_core_attn_metadata and init_forward_metadata_prefill thread num_tokens
    and forward_batch so cp_v2_active and padded_num_tokens can be computed.
  * HIP-only: unified_kv mirrors c4/c128_out_loc with a page offset
    (UnifiedKvMetadata). Those are write addresses too, so they are checked to
    stay global. They are nested under .unified and so cannot join
    _CP_GLOBAL_FIELDS, which getattrs off self.

No kernel work was needed: the shared triton metadata kernel already implements
the num_write_tokens < bs masking CP-v2 relies on, and HIP's flashmla scheduler
metadata is a no-op (_create_flashmla_metadata returns None under is_hip).

dspark_block_size is deliberately not added to make_core_attn_metadata -- HIP
has no get_dspark_swa_page_indices, and it is unrelated to CP-v2.

NOT YET VALIDATED ON HARDWARE. Signatures and imports check out on ROCm; the
8xMI355X run is pending.

中文:将 CP V2(sgl-project#33532)移植到 DeepSeek-V4 HIP backend。sgl-project#33532 只接入了 CUDA backend,
因此在 ROCm 上 model/runner 会按 CP-v2 切分 token,而 HIP attention backend 仍按未切分
布局构造 metadata;且 CP-v2 没有任何平台门控,在 ROCm 上打开只会得到错误的 metadata 而
不是报错。本提交选择移植该能力而非关闭它。契约(对齐 deepseek_v4_backend.py):CP-v2 会
把因果 metadata 行数补齐以便按 rank 切分(P 行),而 cache 写入地址仍是每个逻辑 token 一行
(N 行),因此 reindex 的全局字段后置条件必须以 N 为基准而非补齐后的长度。改动包括:
apply_cp_reindex 增加 num_tokens(默认 None 回退,保持 CP-v1 调用点二进制兼容);
init_compression_metadata 增加 num_tokens(否则其 raw_out_loc/seq_lens_casual 形状相等
断言会在首次 CP-v2 预填充时失败);make_core_attn_metadata 与
init_forward_metadata_prefill 透传 num_tokens 与 forward_batch;HIP 特有的
unified_kv 的 c4/c128_out_loc 同为写地址,一并校验其保持全局。无需改内核。尚未在硬件上
验证。
jakki-amd pushed a commit to jakki-amd/sglang that referenced this pull request Sep 9, 2026
Atituiset pushed a commit to Atituiset/sglang that referenced this pull request Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants