Skip to content

[Spec] Fix wrong tokens from compact-verify CUDA graphs when a token tier is captured more than once - #42709

Merged
kpham-sgl merged 3 commits into
sgl-project:mainfrom
ormandj:ragged-capture-layout-per-tier
Oct 9, 2026
Merged

kpham-sgl merged 3 commits into
sgl-project:mainfrom
ormandj:ragged-capture-layout-per-tier

Conversation

@ormandj

@ormandj ormandj commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

With compact ragged verify (SGLANG_RAGGED_VERIFY_MODE=compact), DecodeCudaGraphRunner captures a token tier more than once when there are several attention graph variants (for example the DSv4.1 candidate graphs candidate_unfiltered / candidate_filtered) or several PD-mux streams. Each capture calls _capture_ragged_verify_layout, which allocated a new RaggedVerifyLayout and replaced _captured_ragged_layouts[num_tokens]. At replay, _stage_ragged_verify_layout copies the live verify_lens / qo_indptr only into that registered layout, which belongs to the last capture. Graphs from the earlier captures still read the layout they were captured with. That layout holds synthetic capture offsets, and replay no longer refreshes it.

A graph that reads an earlier capture's layout tensors directly computes with the wrong offsets whenever the live layout differs from the capture-time one. On current main, PD-mux with the TRT-LLM MLA backend is exposed: its ragged verify path pads and unpads queries with the captured verify_lens / qo_indptr inside the graph. For DSv4.1 target verify on current main the defect is latent, because its backend copies the live layout into its own buffers outside the graph. The ragged Engram hashing and token_req_indices in #40567 read qo_indptr inside the DSv4.1 verify graph; with them, the candidate_unfiltered graphs map tokens to the wrong requests.

I measured an A/B on DeepSeek-V4.1-Flash (TP4, 4x RTX PRO 6000 Blackwell, SM120, DSpark gamma 5, compact verify, #40567 applied) with an earlier revision of this fix, which copied the live layout into each capture instead of sharing one layout per tier. I compared the log-prob of each generated token with a plain prefill of the same text:

  • Without the fix, per-token differences reached 14.4 nats. At temperature 1, 9 of 32 streams looped to the length cap.
  • With the fix, the maximum difference was 0.79-0.86 nats, and none of the 32 streams looped or hit the cap.

Eager verify was correct in both builds.

Modifications

_capture_ragged_verify_layout creates the layout once per token tier and returns the same object for later captures of that tier. Every graph of the tier now captures the tensors that replay refreshes.

Accuracy Tests

  • TestRaggedVerifyLayoutPerTier (CPU, test/registered/unit/model_executor/runner/test_decode_cuda_graph_runner.py) calls the capture-layout helper twice for tier 24 with two variant labels, stages a live layout, and checks both returned layouts' qo_indptr_device / verify_lens against the live padded layout. On main the first layout keeps its synthetic offsets (7 of 9 qo_indptr entries differ).
  • The end-to-end A/B in Motivation (earlier revision of the fix).

Speed Tests and Profiling

Not benchmarked. The replay staging code is unchanged; capture reuses one registered layout per token tier across attention variants and PD-mux streams.

Checklist

Developed with AI assistance.


CI States

Latest PR Test (Base): ❌ Run #37864565786
Latest PR Test (Extra): ❌ Run #37864565460
Latest PR Test (AMD ROCm 10): ❌ Run #37864565822

@ormandj ormandj changed the title [Spec] Fix compact verify CUDA graphs replaying a stale layout when a token tier is captured more than once [Spec] Fix wrong tokens from compact-verify CUDA graphs when a token tier is captured more than once Oct 6, 2026
…UDA graphs

A token tier can be captured several times (attention graph variants, PD-mux
streams), but every capture allocated a new RaggedVerifyLayout and replaced
the registered one. Replay stages the live verify_lens / qo_indptr into the
registered layout only, so graphs from earlier captures read stale synthetic
(or freed) offsets.
@ormandj
ormandj force-pushed the ragged-capture-layout-per-tier branch from 4bc70e9 to d4a2117 Compare October 7, 2026 05:42
@ormandj ormandj mentioned this pull request Oct 7, 2026
17 of 56 tasks
@jhinpan

jhinpan commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

We confirm this bug and this fix on AMD MI355X (gfx950).

We found it while we evaluated DSpark compact verify on DeepSeek-V4.1-Flash (TP4, 4x MI355X, DSpark block size 5, verify width 6, compact verify, with #40567 applied). Compact verify sampled from a flatter distribution than the target.

What we saw without the fix

  • Inside the compact target-verify CUDA graph, low_ratio_req_indices was [slot, 0, 0, 0, 0, 0] for one request with 6 verify tokens, in every step. Only the first token mapped to the live request. The other five mapped to request slot 0. Positions and out-cache locations were correct.
  • The first request after server start (the warm-up) mapped correctly. Every later request mapped as above.
  • A 1-token request, such as the /health probe, produced a NaN target logit row.

A/B on one tree, with and without the change in this PR

Target logits at each verify step, compared with a target-only prefill of the same prefix and draft tokens (greedy, 6 prompts of about 1.1k tokens):

top-1 agreement log-prob slope |diff| > 0.5 nats
static verify 90.4% 0.995 32.8%
compact 69.7% 0.845 56.0%
compact + this fix 90.2% 1.006 31.9%

Static is the baseline. The generation servers run --enable-decoder-swa-bounded-replay and the scoring server does not.

Sampling at temperature 1.0 and top_p 1.0 (384 prompts at concurrency 64, up to 1024 tokens), scored by a target-only server:

mean target log-prob per token tokens below -5 per 1k reached 1024 tokens
target only -0.435 8.1 52%
static verify -0.427 7.9 49%
compact -1.107 63.3 26%
compact + this fix -0.415 7.8 51%

Our local fix was the same change as this PR (one layout per token tier). Our CPU test of _capture_ragged_verify_layout behaves like TestRaggedVerifyLayoutPerTier: without the fix, the first variant keeps its capture layout.

#40567 makes the DSv4.1 verify graph read qo_indptr, so landing this PR first keeps compact verify correct when #40567 lands.

@kpham-sgl

Copy link
Copy Markdown
Collaborator

/rerun-test test_basic_sanity_dspark.py test_decode_cuda_graph_runner.py

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

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

cd test/ && python3 registered/core/test_basic_sanity_dspark.py

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

cd test/ && python3 registered/unit/model_executor/runner/test_decode_cuda_graph_runner.py

@kpham-sgl
kpham-sgl merged commit 438df9a into sgl-project:main Oct 9, 2026
105 of 121 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants