Skip to content

[Perf] dsv4: Dequantize each shared sparse-prefill KV source once per forward - #45909

Merged
hnyls2002 merged 3 commits into
mainfrom
lsyin/dsv4-kv-dequant-once
Oct 23, 2026
Merged

hnyls2002 merged 3 commits into
mainfrom
lsyin/dsv4-kv-dequant-once

Conversation

@hnyls2002

@hnyls2002 hnyls2002 commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator
  • DeepSeek-V4.1's ratio-1/2 layers read the compressed KV of a few kv_source layers, and sparse prefill dequantized that cache into the shared buffer in every one of them. The layers that share a source now reuse its dequant: no later layer of the forward writes that cache, and graph replay keeps the layer order.
  • SparsePrefillWorkspace is renamed SparsePrefillKVBuffer and owns the reuse. get_with_head returns the rows and whether the head already holds the given source (source cache, gather ids, row count). A plain get, a reallocation, or the start of a new forward forgets the head.

Outputs are unchanged: the skipped dequants would have written the same rows.

Verification:

  • Every reused dequant in a DeepSeek-V4.1-Flash DEP4 prefill run matched a fresh dequant of the same rows.
  • GPU profiles on B300 and GB300 show the sparse-prefill KV dequant running once per kv_source instead of once per layer, with no other kernel or copy added. Prefill step time drops on both at every batch size tested, with and without the prefill graph.
  • No out-of-memory at the recipe memory fraction; GSM8K is unchanged.

CI States

Latest PR Test (Base): 🚫 Run #39872578951
Latest PR Test (Extra): ❌ Run #39872578855
Latest PR Test (AMD ROCm 10): 🚫 Run #39872578944

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_deepseek_v4.py test_q8kv8_sparse_prefill_backend.py test_dsv4_compressed_pools.py test_deepseek_v41_flash_gb300_encoder_bcg.py

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

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

cd test/ && python3 registered/attention/unittests/dsv4/test_deepseek_v4.py

🚀 1-gpu-h100 (2 tests): ✅ View workflow run

cd test/ && python3 registered/attention/unittests/dsv4/test_deepseek_v4.py
cd test/ && python3 registered/kernels/ops/attention/test_q8kv8_sparse_prefill_backend.py

🚀 ubuntu-latest (1 test): ✅ View workflow run

cd test/ && python3 registered/unit/mem_cache/test_dsv4_compressed_pools.py

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

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

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Oct 22, 2026
@hnyls2002
hnyls2002 merged commit 9c7dd3c into main Oct 23, 2026
219 of 297 checks passed
@hnyls2002
hnyls2002 deleted the lsyin/dsv4-kv-dequant-once branch October 23, 2026 00:08
chaohu2000 added a commit to flytiger-eco/sglang-for-sail that referenced this pull request Oct 27, 2026
… forward (sgl-project#45909)

(cherry picked from commit b5ce3ff9e547be0388ef34d26606763b41766626)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deepseek run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant