Skip to content

[Bug]: XQA decode under FULL cudagraph capture silently corrupts attention output (fp8 and nvfp4 KV)Β #49010

Open

Description

@0xdespot

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)

  1. Shape/scalar baking. The XQA call takes block_tables, seq_lens, and a python-int max_seq_len directly. Warmup capture runs with small dummy sequences; if the table shape or max_seq_len is baked at capture time, replays on longer sequences attend over a truncated table β€” which matches the "fluent locally, blind at depth" behavior exactly.
  2. 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

  1. 0xdespot commented on Jul 18, 2026

    @0xdespot
    Author

    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):

    config needle @2.5K/10K/16K/49K
    eager + MTP 4/4 pass
    PIECEWISE + MTP 4/4 pass
    FULL + MTP 0/4 fail
    FULL, no MTP 4/4 pass

    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=False in 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_decode is false, rather than gating XQA generally.

  2. seanyourhighness commented on Jul 28, 2026

    @seanyourhighness

    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). Model nvidia/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-7 returns as MOUSE: 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:

    vllm/v1/worker/gpu_model_runner.py:3807   _model_forward
    vllm/compilation/cuda_graph.py:254        __call__          <- graph replay
    vllm/model_executor/models/qwen3_5.py:496 forward
    vllm/model_executor/models/qwen3_next.py:589 forward
    vllm/model_executor/layers/mamba/gdn/qwen_gdn_linear_attn.py:1731  qwen_gdn_attention_core
    vllm/model_executor/layers/mamba/gdn/qwen_gdn_linear_attn.py:1513  _forward
    torch.AcceleratorError: CUDA error: an illegal memory access was encountered
    

    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_len from 1 to 1 + 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: PIECEWISE as 4/4 clean. On nvfp4 KV with MTP it does not corrupt, it dies on the first request:

    torch.AcceleratorError: CUDA error: an illegal memory access was encountered
      gpu_model_runner.py:301 get_output -> torch/cuda/streams.py:254 synchronize
    EngineDeadError
    

    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 on decode_mode() == FULL, so PIECEWISE skips spec-decode capture-size alignment and a partial-acceptance step reads slot_mapping/positions at 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

    patches prefix cache cudagraph narrative / code acceptance 32k needle
    stock on FULL_AND_PIECEWISE 98.88 / 111.83 57.8% (len 2.74) FAIL
    49891 on FULL_AND_PIECEWISE 105.84 / 104.51 57.8% (len 2.73) FAIL
    49891+46324 on FULL_AND_PIECEWISE 100.61 / 113.45 60.3% (len 2.81) FAIL
    49891+46324 on FULL_AND_PIECEWISE (repeat) 100.81 / 108.60 59.2% (len 2.71) FAIL
    49891+46324 off FULL_AND_PIECEWISE β€” β€” CRASH
    stock on PIECEWISE β€” β€” CRASH
    49891+46324 on PIECEWISE 58.03 / 72.19 65.8% (len 2.97, peak 3.51) PASS
    (MTP off) on FULL_AND_PIECEWISE 58–66 / 66.4 β€” PASS

    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.

  3. seanyourhighness commented on Jul 29, 2026

    @seanyourhighness

    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_decode for TRTLLM-GEN, not XQA. Therefore stock resolves reorder_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.html

    Fix and exact red/green proof

    The local patch:

    • advertises selected SM12x XQA as spec-as-decode capable;
    • builds/caches a stable bit-packed causal mask by (padded request count, q_len);
    • stores it in decode metadata and passes it to trtllm_batch_decode_with_kv_cache;
    • removes the q_len>1 XQA NotImplementedError.

    The regression is exact:

    • stock red: reorder_batch_threshold == 1, where MTP n=3 requires 4;
    • patched green: all requests are XQA decode and q_len=4 mask rows are 1, 3, 7, 15.

    GPU evidence

    RTX 5090/SM120, Qwen3.6-27B NVFP4, NVFP4 KV, 131k context, MTP n=3, prefix cache on:

    • true FULL_AND_PIECEWISE verified;
    • three distinct cache-busted ~31k cold needles: 3/3 exact;
    • cached replay: 3/3 exact;
    • 50 Hz /metrics probe observed real overlap (cold max_running=2; replay max_running=3);
    • holding the drafter change constant, FULL masked-XQA acceptance is at PIECEWISE parity by category: narrative 57.66% vs 58.97%; code 79.54% vs 78.54%;
    • FULL throughput: 101.84 narrative / 128.62 code tok/s.

    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.

  4. seanyourhighness commented on Aug 24, 2026

    @seanyourhighness

    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:

    • exact server tensors standalone: 0.053-0.072 ms/XQA call at c3;
    • integrated FULL graph: 1.437 ms/call;
    • same integrated path on the isolated stream: 0.278 ms/call;
    • all-NVFP4 262K profile c1/c3/c8: 94.08 / 258.68 / 539.62 tok/s;
    • 184,024-token needle recovered exactly; arithmetic canary 437 passed.

    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.

  5. github-actions commented on Nov 27, 2026

    @github-actions

    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!

  6. added
    stale
    on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions