Skip to content

[DSv4][Bugfix] Fix DSpark verifier state rewrite window - #32183

Closed
slchenchn wants to merge 2 commits into
sgl-project:mainfrom
slchenchn:agent/fix-dspark-verifier-rewrite-window
Closed

slchenchn wants to merge 2 commits into
sgl-project:mainfrom
slchenchn:agent/fix-dspark-verifier-rewrite-window

Conversation

@slchenchn

@slchenchn slchenchn commented Jul 23, 2026 •

Copy link
Copy Markdown

Motivation

DSpark verifies gamma + 1 target rows, but the DeepSeek-V4 compressed-state prefill planner protected at most four MTP rows through the hard-coded kMaxMTPDraftTokens = 4.

For example, with gamma = 4, the target verifies five rows. At certain compression boundaries, the planner omitted the first verifier row from the write plan, so subsequent compressed state was not guaranteed to be reconstructed from the verifier-committed token sequence.

The verifier already knew the correct window through speculative_num_draft_tokens; that runtime value was not propagated to the compressed-state planner.

Modifications

  • Propagate the DSpark target-verifier width from DeepseekV4AttnBackend through the compressor metadata and Python JIT wrapper to the C++ prefill planner.
  • Use the runtime verifier width when calculating the first state row to rewrite in both host-input and device-input planner paths.
  • Keep verify_width = 0 as the default so regular prefill and non-DSpark speculative algorithms preserve their existing behavior.
  • Add registered C4 planner regression coverage for: - verifier widths 2, 4, 5, 8, and 12

Accuracy Tests

Before the fix, the write plan omitted ragged row 0:

[[1, 0], [2, 1], [3, 2], [4, 3], [-1, -1]]

With the runtime verifier width applied, all five rows are rewritten:

[[0, 15], [1, 0], [2, 1], [3, 2], [4, 3]]

Added regression tests assert that every verifier row appears in the write plan for all supported boundary cases.

Local non-GPU validation:

  • pre-commit passed for all modified files.
  • scripts/ci/check_registered_tests.py passed.
  • Python compilation checks passed.
  • test_c4_v2.py successfully collected 39 tests, including the 10 new verifier-window cases.

The final branch's GPU unit tests and end-to-end accuracy tests are left to GitHub CI.

Speed Tests and Profiling

Not benchmarked locally.

The change does not affect regular prefill or non-DSpark speculative algorithms. For DSpark verifier windows larger than four, it
adds the state writes required to reconstruct the full accepted verification path.

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): ❌ Missing run-ci label -- add it to run CI tests.
Latest PR Test (Extra): ❌ Blocked -- run-ci is required first.

@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.

@slchenchn slchenchn changed the title Agent/fix dspark verifier rewrite window [DSv4][Bugfix] Fix DSpark verifier state rewrite window Jul 24, 2026
@slchenchn

Copy link
Copy Markdown
Author

@Qiaolin-Yu @BBuf Could you please help triage/review this DSv4 + DSpark correctness fix and enable the base CI for the current commit?

The PR is currently blocked on the missing run-ci label. It fixes an incomplete compressed-state rewrite when the DSpark verifier window exceeds the previous fixed width of 4, and includes a registered C4 planner regression test.

@hassellof

Copy link
Copy Markdown
Contributor

Hardware validation of this PR on SM120, plus a datapoint that I think
strengthens the case for merging it and shows it is not the whole story.

Setup. 4× RTX PRO 6000 Blackwell (sm_120), TP=4 + DP attention + EP=4,
DeepSeek-V4-Flash-0731, sglang v0.5.16 with this PR backported (paths
rewritten for the pre-refactor tree), fp8 KV, 1M context.

This PR does what it says. With the backport applied and the plan kernel
instrumented, verify_width = 6 demonstrably reaches plan_compress_prefill
(logged 328× during live serving), so the kMaxMTPDraftTokens = 4 clamp is
correctly overridden and the write plan covers all verify rows. That part is
verified, not inferred.

It is necessary but not sufficient for the corruption we see. With this
PR active, draft depth 5 still corrupts generations under real agentic load —
repetition collapse, token salad, </think> leaking into content, no errors
in the log. What we then found is that the fault is not depth-monotonic:

gamma verify rows requests corruption events
3 4 10,885 (5 cold launches) 0
4 5 11,040 (5 cold launches) 0
5 6 2,148 (inferred) / 2,138 (explicit) 10 / 7
6 7 2,282 0
7 8 2,198 0

Depths above the broken one are clean, and depth 5 is exactly
dspark_block_size in the checkpoint — the value you get when the flag is
omitted. So there appears to be a second defect keyed to the draft head's
native block size, sitting underneath the write-window bug this PR fixes.
Details, repro protocol and the list of things we ruled out by measurement
are in #33800.

I mention it here for two reasons: so nobody concludes "this PR didn't fix
it, therefore it's wrong" — the write-window bug is real and this fix is
correct — and because your test IDs ("legacy-limit" at 4, "first-over-limit"
at 5) land on exactly the boundary where our sweep breaks, which may be a
useful coincidence when someone digs into the remaining issue.

We ship this PR as a backport in our production image for this hardware —
the recipe, the full patch set and the measured numbers are at
https://github.com/ombori/deepseek-v4-flash-0731-sglang-4x-rtx-pro-6000 if the v0.5.16 path rewrites are useful to anyone.

Happy to run any candidate patch on this hardware; the repro takes about
30 minutes per arm.

xuxiuk pushed a commit to xuxiuk/sglang that referenced this pull request Aug 6, 2026
Backport the correctness fix from sgl-project#32183 to the pre-kernel-migration DSpark branch. Propagate the runtime verifier width into both CPU and GPU C4 prefill planners so every gamma+1 verifier row is rewritten.

Upstream-Commit: ee481e7

Co-authored-by: chenshuailin <[email protected]>
ormandj added a commit to ormandj/sglang-deepseek-v4-flash-sm120 that referenced this pull request Aug 6, 2026
Adds sgl-project/sglang#32183 to the carried set. It propagates the runtime
DSpark verifier width into the DeepSeek-V4 compressed-state planner instead of
the hardcoded kMaxMTPDraftTokens = 4 rewrite window. At the DSpark depth this
image uses the verify width is 8, so the planner rewrote only part of the
window and compressed attention state accumulated pollution every 4 tokens.

Long single-file code generation degraded as a result: reasoning leaked into
the output, forbidden placeholders appeared, the code fence was left unclosed,
and generation terminated early with finish_reason=stop far below the token
limit. Short answers were unaffected, so eval scores did not surface it.

Measured on the validated configuration, scoring each generation by whether the
code fence closes and the extracted script passes node --check:

  long write, temperature 1.0   0/8 -> 14/14
  long write, greedy            0/1 -> 3/3
  decode throughput             237.5 -> 319.8 tok/s
  accept length                 4.04 -> 5.5

Throughput improves because the draft model is no longer verifying against a
degraded target.

sglang effective tree 0491c1f4 -> 85d0a01a; every other pin unchanged.
Leoyzen added a commit to Leoyzen/sglang that referenced this pull request Aug 8, 2026
…project#32035 sgl-project#33656 sgl-project#32183 sgl-project#33145)

Applied PRs (latest from GitHub):
  sgl-project#33288  Indexer logits OOM fix
  sgl-project#30393  HiCache packed/sidecar draft caches
  sgl-project#31170  DPA prefix_affinity load balancing
  sgl-project#33795  DSpark compact ragged-verify CUDA graph JIT race
  sgl-project#32467  C128 plan-kernel warp barrier
  sgl-project#33865  DSpark x prefill CP unblock
  sgl-project#30371  SWA state pool sizing (storage page)
  sgl-project#33358  FlashMLA norm-rope K-tokens-per-block ILP
  sgl-project#33872  num_draft_tokens clamp + extend_len==0 skip (supersede sgl-project#32183)
  sgl-project#34002  Sidecar backup vacuously-successful fix (replaces sgl-project#33656, with tests)
  sgl-project#33862  Reclaim redundant host mirrors after storage backup
  sgl-project#31315  Avoid repeated Mooncake gets after stale hits
  sgl-project#32327  Q8KV8 sparse MLA prefill backend (flashmla_sparse_q8)
  sgl-project#31668  Fix sidecar pool life-time (use-after-free on prefetch abort)
  sgl-project#31195  TP0 verify-token-budget broadcast (adapted to get_schedule() API)

Dropped (per user request or superseded):
  sgl-project#32771  IndexCache C4 top-k reuse — has bug
  sgl-project#32035  DSpark C128 online compressor — has bug
  sgl-project#33656  Superseded by sgl-project#34002 (same fix + unit tests)
  sgl-project#32183  Superseded by sgl-project#33872 (included in supersede PR)
  sgl-project#33145  Base f01f706 already has superior reasoning-effort profile system

Conflicts resolved:
  sgl-project#31195: adapted to base get_schedule().disable_overlap_schedule API
  sgl-project#32327: path remapped jit_kernel/ -> kernels/jit/ and kernels/ops/attention/
  sgl-project#31668: applied cleanly on top of sgl-project#30393+sgl-project#34002+sgl-project#33862 modifications

@Phoenix3334 Phoenix3334 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related B300/TP8 investigation note: I have not isolated this verifier-window fix in its own A/B test, so I am treating it as a separate correctness layer rather than attributing the B300 failures to it. The independent evidence localized #31195 to cross-TP Graph-tier consistency (120/120, zero divergence) and #32467 to plan-kernel producer correctness (2592/6000 invalid plans unpatched -> 0/30000 patched, plus clean #32467-only startup/replay in the tested B300 paths). I have reflected that separation in #31023 / #33356 / #32432.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks @slchenchn. Closing this because it has had no updates in 91 days.

Reopen it if the work is still relevant.

Some directories moved recently, so an older branch may need retargeting:
sgl-kernel/ -> python/sglang/kernels/aot/, python/sglang/jit_kernel/
-> python/sglang/kernels/jit/, docs/ -> docs/docs/ (.mdx),
bench_serving.py -> benchmark/serving.py, test/srt/ -> test/registered/.

@github-actions github-actions Bot closed this Nov 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.

3 participants