Skip to content

[Feat] [NVIDIA] deepseek-v4.1: Support prefill CP with BCG in PD serving (2/N) - #40333

Open
BJWang-ant wants to merge 13 commits into
sgl-project:mainfrom
BJWang-ant:main-v4.1-cp-bcg
Open

BJWang-ant wants to merge 13 commits into
sgl-project:mainfrom
BJWang-ant:main-v4.1-cp-bcg

Conversation

@BJWang-ant

@BJWang-ant BJWang-ant commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

issue:#39700
base pr:#40323

Motivation

Enable DeepSeek V4.1 prefill nodes to use interleave context parallelism (CP) together with breakable CUDA graphs (BCG), including prefill/decode disaggregated serving.
This allows prefill computation to run across CP ranks while preserving graph replay correctness for batches with different prompt lengths and request layouts.

Modifications

  • Integrate interleave CP with BCG capture and replay. Keep CP-local embeddings, positions, token IDs, and live-token metadata consistent with the captured buffers. Align token IDs with the layouts used by TP-MoE and MegaMoE.
  • Handle variable-length batches and capture padding correctly. Select replay buckets using per-rank capacity, preserve captured metadata addresses, and process only live tokens when updating low-ratio compressed state.
  • Preserve global context and output ordering. Compute Engram hashes from global prompt context, gather CP outputs in token order, and trim padding before the logits tail, including DSPARK auxiliary hidden states.
  • Support prefill CP for vision-enabled V4.1 models. Prepare multimodal embeddings before CP sharding. Text requests can use BCG; requests containing image inputs fall back to eager CP.

gms8k preicition test:
image

perf:
image

hardware

B200 && H200


CI States

Latest PR Test (Base): ⏳ Run #42168284764
Latest PR Test (Extra): ❌ Run #42168284579
Latest PR Test (AMD ROCm 10): ⏳ Run #42168284814

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

@SYChen123

Copy link
Copy Markdown
Contributor

Fix: CP BCG megamoe path with vision inputs is now supported.

Image dataset test is ok.
image

@Oasis-Git Oasis-Git mentioned this pull request Oct 2, 2026
17 of 56 tasks
@BJWang-ant

Copy link
Copy Markdown
Contributor Author

/rerun-test test_dsv41_shared_prefill_kv.py test_deepseek_v41_pd_cp_dspark.py test_deepseek_v4_flash_fp4_h200.py test_deepseek_v4_flash_fp4_b200.py test_deepseek_v4_flash_fp4_megamoe_b200.py test_deepseek_v41_flash_gb300_dp4ep4.py test_deepseek_v41_flash_gb300_encoder_bcg.py test_deepseek_v41_flash_gb300_tp4ep4.py test_deepseek_v41_flash_gb300_trtllm_bounded_bcg.py

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

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

cd test/ && python3 registered/e2e/models/test_deepseek_v41_pd_cp_dspark.py

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

cd test/ && python3 registered/e2e/models/test_deepseek_v4_flash_fp4_h200.py

🚀 4-gpu-b200 (2 tests): ✅ View workflow run

cd test/ && python3 registered/e2e/models/test_deepseek_v4_flash_fp4_b200.py
cd test/ && python3 registered/e2e/models/test_deepseek_v4_flash_fp4_megamoe_b200.py

🚀 4-gpu-gb300 (4 tests): ✅ View workflow run

cd test/ && python3 registered/e2e/models/test_deepseek_v41_flash_gb300_dp4ep4.py
cd test/ && python3 registered/e2e/models/test_deepseek_v41_flash_gb300_encoder_bcg.py
cd test/ && python3 registered/e2e/models/test_deepseek_v41_flash_gb300_tp4ep4.py
cd test/ && python3 registered/e2e/models/test_deepseek_v41_flash_gb300_trtllm_bounded_bcg.py

⛔ test_dsv41_shared_prefill_kv.py: No test file found matching test_dsv41_shared_prefill_kv.py under test/registered/ or python/sglang/multimodal_gen/test/.

@BJWang-ant

Copy link
Copy Markdown
Contributor Author

@BJWang-ant
BJWang-ant force-pushed the main-v4.1-cp-bcg branch 2 times, most recently from 0b1404c to 99809cd Compare October 22, 2026 03:11
@Oasis-Git

Copy link
Copy Markdown
Collaborator

PR ready. Will merge later

@BJWang-ant

Copy link
Copy Markdown
Contributor Author
image image

@github-actions

This comment has been minimized.

@BJWang-ant

Copy link
Copy Markdown
Contributor Author

Required checks failed on 85af6fa; this PR cannot be merged until they pass.

Lint (run) Run pre-commit run --all-files locally and push the result. The run log shows any other failing step.

image

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

BJWang-ant and others added 13 commits November 6, 2026 13:16
Use live prompt rows for low-ratio compressed state when CP BCG replays a larger capture bucket. Adapt FP4 logits and SM100 metadata to the current DeepGEMM varlen API while keeping FP32 output contracts.

Validation: 34 CPU regression tests; full GSM8K 1272/1319 (96.44%), zero errors/truncations. All 940 real prefill batches per CP rank hit CUDA graph.
Remove the 0.2.8-specific BF16 weights, output casts, and forced varlen metadata/indices. Restore clean_logits arguments and the original FP32 output path while retaining CP BCG live-token handling.

Validated with DeepGEMM 0.2.1.post1 on B200: 34 CPU tests, flat/paged numerical checks, full GSM8K 1275/1319 (96.66%) with zero errors/truncations, and 562 real prefill batches per CP rank all using CUDA graph.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blackwell SM100/SM120 deepseek jit-kernel Multi-modal multi-modal language model run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants