[Bugfix][TurboQuant] Fix CUDA graph capture crash with spec-decode + chunked-prefill (#40807) - #43747
Open
oneraghavan wants to merge 1 commit into
Open
Conversation
…chunked-prefill (vllm-project#40807) TurboQuant's _prefill_attention continuation branch calls .tolist() on GPU tensors, which is illegal during CUDA graph capture. This crashes engine initialization when TurboQuant KV cache is combined with speculative decoding and chunked prefill. Three-layer fix: 1. Downgrade _cudagraph_support from UNIFORM_BATCH to UNIFORM_SINGLE_TOKEN_DECODE so spec-decode K+1 verify batches automatically fall to PIECEWISE mode (continuation runs eager). 2. Populate CPU-resident copies of query_start_loc and seq_lens in build_for_cudagraph_capture as defense-in-depth. 3. Add is_current_stream_capturing() guard in _prefill_attention continuation branch to return zeros safely during capture warmup. Signed-off-by: raghavan <oneraghavan@gmail.com>
oneraghavan
requested review from
LucasWilkinson and
MatthewBonanni
as code owners
May 27, 2026 05:02
Contributor
Author
|
Hi @LucasWilkinson @MatthewBonanni — could you take a look when you get a chance? This fixes a CUDA graph capture crash in TurboQuant's |
4 tasks
This was referenced May 28, 2026
Contributor
Author
|
Friendly ping — this PR is ready for review. Let me know if there are any changes needed or blockers. Happy to address feedback. Thanks! |
Contributor
Author
2 tasks
justtestingthingsx
pushed a commit
to meandmyboiclaude/vllm
that referenced
this pull request
Jul 25, 2026
…ec-decode + chunked-prefill)
Contributor
|
This pull request has merge conflicts that must be resolved before it can be |
justtestingthingsx
pushed a commit
to meandmyboiclaude/vllm
that referenced
this pull request
Aug 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Fixes #40807.
TurboQuant's
_prefill_attentioncontinuation branch calls.tolist()on GPU tensors (query_start_locandseq_lens), which is illegal during CUDA graph capture. This crashes engine initialization when TurboQuant KV cache (turboquant_k8v4,turboquant_4bit_nc, orturboquant_3bit_nc) is combined with--speculative-config method=mtpand--enable-chunked-prefill:The crash occurs at
turboquant_attn.py:570in the continuation-prefill path, which is only entered whenmax_query_len != max_seq_len— exactly the condition created by spec-decode K+1 verify batches during CUDA graph capture warmup.Root Cause
_cudagraph_supportwas set toUNIFORM_BATCH, telling vLLM's compilation framework that TurboQuant supports full CUDA graph capture for multi-token batches (including spec-decode K+1 verify batches).max_query_len != max_seq_len, falling into the continuation branch that calls.tolist()on GPU tensors — illegal during graph capture.build_for_cudagraph_capturedid not guarantee CPU-resident copies ofquery_start_locandseq_lenswere populated, so the fallback.tolist()path could be reached.Fix
Three-layer defense:
Downgrade
_cudagraph_supportfromUNIFORM_BATCHtoUNIFORM_SINGLE_TOKEN_DECODE. This tells the compilation framework that TurboQuant only supports full CUDA graph capture for single-token decode batches. When spec-decode is active (uniform_decode_query_len > 1), the framework automatically downgrades toPIECEWISEmode — K+1 verify batches run eager (correct), while 1-token decode retains CUDA graph (fast).Populate CPU-resident copies in
build_for_cudagraph_capture. Ifseq_lens_cpuorquery_start_loc_cpuareNone, they are now explicitly created. This ensures the prefill path always has CPU-resident data and never falls through to.tolist()on GPU tensors.Add
is_current_stream_capturing()guard in_prefill_attentioncontinuation branch. Defense-in-depth: if the continuation branch is somehow reached during CUDA graph capture despite fix 1, it returns zeros instead of crashing. Safe because attention outputs during capture are only used for memory profiling, not graph content.Relation to Other PRs
cu_seqlens_k = cu_seqlens_qassumption). Complementary; this PR fixes the crash, [Bugfix][Spec-Decode] TurboQuant K+1 spec-verify routing (fixes #40880) #40914 fixes the correctness..tolist()crash) which had no open PR.Related Issues
Test Plan
7 tests covering:
_cudagraph_supportisUNIFORM_SINGLE_TOKEN_DECODE.tolist()on CPU tensors is safeis_current_stream_capturing()guard returns zeros (requires CUDA)Test Result