Skip to content

[Perf] [NVIDIA] deepseek-v4.1: Reuse dequantized compressed KV in PD CP prefill (7/N) - #40421

Merged
Oasis-Git merged 7 commits into
sgl-project:mainfrom
BJWang-ant:main-reuse-kvcache
Nov 5, 2026
Merged

Oasis-Git merged 7 commits into
sgl-project:mainfrom
BJWang-ant:main-reuse-kvcache

Conversation

@BJWang-ant

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

Copy link
Copy Markdown
Contributor

issue:#39700
base pr: #40179

Summary

DeepSeek V4.1 consumer layers can share the same compressed KV storage, but sparse prefill currently dequantizes that storage into a BF16 workspace on every layer.

Reuse the dequantized compressed KV within a forward to avoid repeated reads, dequantization, and workspace writes.
image

Changes

  • Limit reuse to CP sparse BF16 prefill with compression ratios 1 and 2.
  • Keep separate workspaces per compression ratio.
  • Track validity by source layer and workspace address within the per-forward gather cache.
  • Refresh on producer execution, source changes, workspace reallocation, or a new forward.
  • Continue updating SWA and top-k inputs for every layer.

This retains additional scratch memory for the separate workspaces.

Validation

  • GPU regression tests cover shared sources, source updates, ratio interleaving, consecutive forwards, and workspace resizing.
  • All 16 short/long-context smoke-test outputs match the baseline.
  • In a six-step trace, compressed KV dequantization calls decrease from 228 to 24 (89.5% fewer).

Performance

DeepSeek V4.1 Flash on 8×B200 with PD disaggregation; prefill uses TP4/EP4, CP, BCG, MegaMoE, and DSpark. Results are medians of three unprofiled runs using the unchanged benchmark script, with 512 requests and an output length of 500, which is 60k unprefix cache of 64k all input length.

image

precision

gsm8k test result
image

trace comparison

before
image

after
image


CI States

Latest PR Test (Base): 🚫 Run #41813675179
Latest PR Test (Extra): ❌ Run #41813675111
Latest PR Test (AMD ROCm 10): ❌ Run #41813675138

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

@BJWang-ant BJWang-ant changed the title [Perf] Reuse shared compressed KV dequantization in DeepSeek V4.1 CP prefill [DSV4.1][PD][7/N][Perf] Reuse shared compressed KV dequantization in DeepSeek V4.1 CP prefill Sep 20, 2026
@Oasis-Git Oasis-Git mentioned this pull request Oct 2, 2026
17 of 56 tasks
@BJWang-ant

Copy link
Copy Markdown
Contributor Author

/tag-run-ci-label

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Oct 9, 2026
@BJWang-ant

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@BJWang-ant
BJWang-ant force-pushed the main-reuse-kvcache branch 4 times, most recently from c6d77af to b14c6e3 Compare October 11, 2026 11:05
@BJWang-ant

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@BJWang-ant

Copy link
Copy Markdown
Contributor Author

/rerun-test test_deepseek_v41_flash_gb300.py

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

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

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

@BJWang-ant

Copy link
Copy Markdown
Contributor Author

@BJWang-ant BJWang-ant changed the title [DSV4.1][PD][7/N][Perf] Reuse shared compressed KV dequantization in DeepSeek V4.1 CP prefill [Perf] deepseek-v4.1: Reuse dequantized compressed KV in PD CP prefill (7/N) Oct 19, 2026
@BJWang-ant BJWang-ant changed the title [Perf] deepseek-v4.1: Reuse dequantized compressed KV in PD CP prefill (7/N) [Perf] [Nvidia] deepseek-v4.1: Reuse dequantized compressed KV in PD CP prefill (7/N) Oct 19, 2026
@github-actions

This comment has been minimized.

@BJWang-ant BJWang-ant changed the title [Perf] [Nvidia] deepseek-v4.1: Reuse dequantized compressed KV in PD CP prefill (7/N) [Perf] [NVIDIA] deepseek-v4.1: Reuse dequantized compressed KV in PD CP prefill (7/N) Oct 19, 2026
@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

@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 (1 test): ✅ View workflow run

cd test/ && python3 registered/e2e/models/test_deepseek_v4_flash_fp4_b200.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

/rerun-test 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

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

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

@BJWang-ant
BJWang-ant force-pushed the main-reuse-kvcache branch 2 times, most recently from 86349c2 to e58302f Compare October 20, 2026 11:37
@github-actions github-actions Bot added quant LLM Quantization jit-kernel labels Oct 20, 2026
@BJWang-ant

Copy link
Copy Markdown
Contributor Author

/rerun-test 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

@Oasis-Git

Copy link
Copy Markdown
Collaborator

PR ready. Will merge later

@github-actions

This comment has been minimized.

@BJWang-ant

Copy link
Copy Markdown
Contributor Author
image

@BJWang-ant

Copy link
Copy Markdown
Contributor Author

Required checks failed on 2c6ee0f; 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

@Oasis-Git
Oasis-Git merged commit 06c60f4 into sgl-project:main Nov 5, 2026
146 of 165 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deepseek jit-kernel quant LLM Quantization run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants