Repository navigation
Description
Environment
GPU: RTX 5090 (SM120, 32 GB) | driver 595.71.05, CUDA 13.2
vLLM 0.25.1 | flashinfer-python 0.6.13 | torch 2.11.0
Model: unsloth/Qwen3.6-27B-NVFP4 (hybrid GDN + full attention, 24 Q heads / 4 KV heads, head_dim 256, MTP head)
What happened
While wiring up nvfp4 KV cache on a 5090 (SM120, separate RFC incoming), we hit a corruption bug that turned out to have nothing to do with nvfp4: routing decode through the XQA kernel (FlashInferDecodeKernel.XQA) while FULL cudagraph capture is active produces subtly wrong attention. No crash, no NaN, fluent short-form output β but long-range recall is broken and spec-decode acceptance collapses. This burnt a couple days because every symptom pointed somewhere else first.
What we measured (needle-in-haystack, planted codeword, chat endpoint, temp 0):
| setup | needle @2.5K/10K/16K/49K | MTP acceptance |
|---|---|---|
| stock vLLM (native wrapper decode) | 4/4 pass | 86β100% |
| XQA decode + FULL graphs, fp8 KV | 0/4 | 63β71% short ctx, ~50% deep |
| XQA decode + FULL graphs, nvfp4 KV | 0/4 | 5β27% |
XQA decode + --enforce-eager |
4/4 pass | 100% |
XQA decode + cudagraph_mode: PIECEWISE |
4/4 pass | 92β100% |
The failure is distinctive: the model retrieves the neighborhood of the needle but garbles the content ("MOONWEASEL-7" comes back as "MOON-XP-1429"). It looks like the kernel is attending over a truncated or stale view of the KV cache.
The kernel itself is fine. Calling trtllm_batch_decode_with_kv_cache(backend="xqa") standalone (no graphs) at 8K context with the real head geometry gives cosine 1.00000 vs a bf16 reference (0.99967 with fp8 KV). Only the captured-graph replay path is wrong.
Root-cause candidates (couldn't fully separate)
- Shape/scalar baking. The XQA call takes
block_tables,seq_lens, and a python-intmax_seq_lendirectly. Warmup capture runs with small dummy sequences; if the table shape ormax_seq_lenis baked at capture time, replays on longer sequences attend over a truncated table β which matches the "fluent locally, blind at depth" behavior exactly. - Workspace reuse. flashinfer slices the XQA multi-CTA semaphore + scratch region from the head of the shared trtllm workspace (
decode.py:semaphore = workspace_u8[:8MB]), and that same workspace is touched by eager prefill calls between graph replays.
Suggestion
The existing code comments already keep spec-as-decode off XQA and hint at graph limitations on SM90, but nothing gates FULL capture off the XQA branch, and the failure is completely silent. Suggest: gate XQA decode to PIECEWISE/eager as a correctness fix, then make the branch replay-safe (persistent max-shape buffers, semaphore hygiene inside the graph) to get FULL-graph perf back.
Repro scripts are small and self-contained if anyone would like them.
Activity
0xdespot commentedon Jul 18, 2026
Update after more bisection β the diagnosis in the original report needs a correction. The full config matrix (same needle-in-haystack oracle, nvfp4 KV, SM120):
So XQA decode under FULL cudagraph capture is fine on its own β pure q_len=1 decode through captured XQA passes at every depth. The corruption only appears when MTP speculative decoding and FULL capture are combined. We also ruled out PDL: forcing
enable_pdl=Falsein the xqa path did not fix the FULL+MTP case.Revised hypothesis: the drafter's captured forward (or the spec-uniform capture path) corrupts state shared with the target. On this hybrid-GDN model the prime suspect is the mamba/GDN recurrent state β progressive state corruption would explain both the depth-dependent blindness and the acceptance decay with context, while rejection sampling alone can't (corrupted drafts should be harmless at temp 0; the target's own verify output was wrong). The existing comment in
flashinfer.py("keep specdec cuda graphs limited to trtllm-gen until vLLM wires the XQA...") suggests this boundary was known β the gap is that nothing enforces it, and the failure is silent.One more data point that may save others time: on this model FULL graphs buy essentially nothing anyway β no-MTP decode measures 38.8 tok/s under FULL vs 38.9 eager (decode is dominated by the 48 GDN layer kernels, not launch overhead). PIECEWISE + MTP is both correct and the fastest working combination (95.6 tok/s with
num_speculative_tokens=4).Suggested minimal fix stands, with sharper scope: gate FULL capture off when spec-decode is active and
supports_spec_as_decodeis false, rather than gating XQA generally.[Attention] Enable NVFP4 KV cache on SM120 (consumer Blackwell)
seanyourhighness commentedon Jul 28, 2026
Reproduced your symptom on sm_120, and I have a fault localization that points somewhere other than XQA β plus a datapoint that contradicts the "PIECEWISE is safe" workaround on this configuration. Both seem worth having.
Rig: RTX 5090 (sm_120) 32,607 MiB, driver 610.62, CUDA 13.0, WSL2, 575 W stock. vLLM 0.25.1 (
752a3a5) + a local SM120 NVFP4 V-scale write fix (separate defect, vllm#50084 / #46329), FlashInfer 0.6.15.post1 (you were on 0.6.13). Modelnvidia/Qwen3.6-27B-NVFP4β Qwen3.6 hybrid GDN,model_type: qwen3_5, 24 Q / 4 KV heads, head_dim 256, MTP head β nvfp4 KV, 131,072 ctx, seqs 6, batched 4096, MTP n=3.Your corruption signature reproduces essentially verbatim. Planted codeword
MOONWEASEL-7returns asMOUSE: The user is aβ neighbourhood retrieved, content garbled, no crash, no NaN, fluent short-form output.The stack trace points at GDN linear attention, not XQA
Under
--compilation-config '{"cudagraph_mode":"FULL_AND_PIECEWISE"}'I can get the fault to surface synchronously:On this hybrid model the failing kernel is the GDN linear-attention recurrent-state path, reached through graph replay β not
trtllm_batch_decode_with_kv_cache(backend="xqa"). Your standalone-XQA check (cosine 1.00000 without graphs) is consistent with that: the XQA kernel may be fine and still be exonerated here, because on hybrids there is a second state-carrying path inside the same captured graph.The trigger is the spec-decode query length, which fits your candidate #1
Without MTP, the identical config β same nvfp4 KV, same FULL_AND_PIECEWISE, same prefix caching β is needle-clean at 5,042 / 20,044 / 32,030 / 64,036 prompt tokens. Turning MTP on breaks it.
MTP raises
uniform_decode_query_lenfrom 1 to1 + num_speculative_tokens = 4(cudagraph_dispatcher.py:37), which changes the shapes used for FULL capture. That is your root-cause candidate #1 (shape/scalar baking) with a concrete trigger: it is not that long sequences alone break replay, it is that the spec-decode query length changes the captured shape and the recurrent-state path then dereferences metadata staged for a different one.PIECEWISE is not safe here β it crashes
You list
cudagraph_mode: PIECEWISEas 4/4 clean. On nvfp4 KV with MTP it does not corrupt, it dies on the first request:That turns out to be a separate, already-fixed-in-review bug: vllm#46324 (open since 2026-06-22).
adjust_cudagraph_sizes_for_spec_decode()is gated ondecode_mode() == FULL, so PIECEWISE skips spec-decode capture-size alignment and a partial-acceptance step readsslot_mapping/positionsat another graph's offsets. With that one-line PR applied, PIECEWISE runs clean and passes the needle β so your workaround is correct, it just needs #46324 to be usable with spec decode. Worth adding to this issue, since anyone following the current guidance on a spec-decode setup hits a hard crash instead of a mitigation.Full matrix
Two things fall out that may help narrow it:
Acceptance tracks correctness. In the working arm acceptance rises 57.8% β 65.8% and accept length 2.74 β 2.97 (peak 3.51), over 22 samples rather than 4-5. Consistent with your observation that acceptance collapses under the bug β the target is verifying drafts against corrupted attention, so acceptance is a cheap proxy signal for this defect.
Prefix caching is not the variable. club-3090 flagged that this config also forms the vllm#43559 pair (hybrid MTP + prefix caching) and proposed disabling prefix caching. On this rig that made it worse β FULL capture with prefix caching off crashes rather than corrupts, and the one passing arm has prefix caching on. Across seven arms the only consistent discriminator is cudagraph mode.
One caution for anyone reading
vllm#49757 looks directly relevant (it addresses dummy runs writing mamba/GDN state through stale block-table rows) and applies cleanly and compiles on 0.25.1 β but is harmful there, converting the silent corruption into a hard crash in this same GDN path by re-staging state from zeroed dummy block tables on every FULL replay. It targets current
main. I mention it only so nobody backports it to a release branch expecting a fix.Happy to run instrumented builds on this rig β
CUDA_LAUNCH_BLOCKING=1, compute-sanitizer, or a shape dump at capture vs replay β if that would help pin candidate #1.Disclosure per AGENTS.md: this work was AI-assisted. The hardware, measurements and analysis are mine.
seanyourhighness commentedon Jul 29, 2026
Correction to my earlier GDN localization: the missing route is masked XQA speculative decode
I have now isolated and fixed the tested SM120/Qwen3.6 NVFP4 MTP failure without falling back to PIECEWISE. The earlier claim that GDN FULL replay itself was the culprit was wrong: GDN is where the bad attention result became visible, not the primary source.
What stock vLLM does
For a uniform MTP verification batch with n=3, each request has q_len=4. The FlashInfer metadata builder only advertises
supports_spec_as_decodefor TRTLLM-GEN, not XQA. Therefore stock resolvesreorder_batch_threshold == 1, so the q_len=4 verification traffic is not routed as XQA decode. The XQA forward path also explicitly raises for q_len>1.FlashInfer's XQA API supports uniform multi-token decode when supplied with its uint16 bit-packed causal mask (
q_len_per_req+mask): https://docs.flashinfer.ai/generated/flashinfer.decode.trtllm_batch_decode_with_kv_cache.htmlFix and exact red/green proof
The local patch:
trtllm_batch_decode_with_kv_cache;NotImplementedError.The regression is exact:
reorder_batch_threshold == 1, where MTP n=3 requires 4;GPU evidence
RTX 5090/SM120, Qwen3.6-27B NVFP4, NVFP4 KV, 131k context, MTP n=3, prefix cache on:
FULL_AND_PIECEWISEverified;Controls:
Scope
This does not close #43559/#48375's prefix-cache recurrent-state bug, nor #50021's bounds bug. It does change the causal interpretation here: q_len=1 XQA/FULL passing does not prove the MTP verification route is correct; stock had not wired q_len>1 XQA verification at all.
I recommend a small current-main fix based on the selected FlashInfer backend's capabilities, rather than an SM120-only branch: native FlashInfer uses q_len_per_req (#47979), XQA uses q_len_per_req plus mask, and TRTLLM-GEN retains its existing path.
seanyourhighness commentedon Aug 24, 2026
Follow-up with a current-main PR: #53543
The patch enables the existing SM120 masked-XQA speculative-decode route for
NVFP4 KV and adds the opt-in isolated-stream fix from the later root-cause
work. This is distinct from the native-FA2 routes in #49891/#47979.
Corrected causal evidence:
Current-main tests include a real SM120 masked-XQA/NVFP4 comparison at
q_len=8/head_dim=256 plus unit coverage for dtype selection and capture-safe
stream fork/join ordering.
Disclosure: AI-assisted implementation and write-up; I reviewed the submitted
diff and verified the reported runs.
[Attention] Wire NVFP4 KV cache to FlashInfer XQA/FA2 on SM12x
github-actions commentedon Nov 27, 2026
This issue has been automatically marked as stale because it has not had any activity within 90 days. It will be automatically closed if no further activity occurs within 30 days. Leave a comment if you feel this issue should remain open. Thank you!