← Back to Pull requests

[Attention] Decode FlashInfer spec queries with fa2 on pre-SM90 GPUs #60532

Merged
lesj0610 merged 2 files (108 lines) on Oct 22, 2026 15:46 UTC
View on GitHub
lesj0610 lesj0610 commented on Oct 08, 2026 03:25 UTC
Author

Overview

On pre-SM90 GPUs FlashInfer has no XQA or trtllm-gen decode, so speculative decoding verification steps (1 + num_speculative_tokens tokens per request) are split off as prefills, and get_cudagraph_support reports UNIFORM_SINGLE_TOKEN_DECODE, which drops spec decode from FULL_AND_PIECEWISE to PIECEWISE. FlashInfer's fa2 tensor-core decode already takes uniform multi-token queries (q_len_per_req) and keeps them CUDA-graph safe (flashinfer-ai/flashinfer#3871, in 0.7.0.post1), so this sends uniform verification queries through it and reports UNIFORM_BATCH there.

Claims

  • On pre-SM90 GPUs, FlashInfer spec decode runs its verification steps in full CUDA graphs. On SM80 with Qwen3.8-27B NVFP4 and MTP (3 tokens), decode goes from 73.6 to 108.1 tok/s at TP=1 and from 61.0 to 83.1 tok/s at TP=2, with the same greedy output.

  • Without speculative decoding nothing changes: same throughput, same tokens and the same KV cache size.

  • SM90 and later keep their decode selection and graph support; single-token native decode is planned exactly as before.
  • Validation

    test_flashinfer_fa2_spec_decode_correctness (new, runs on pre-SM90 GPUs and skips elsewhere) checks uniform 4-token queries over three requests against SDPA, eager and under CUDA graph replay, and that the decode was planned with q_len_per_req=4. The test harness's num_speculative_tokens option built its speculative config as a SimpleNamespace that lacks fields the builders now read, so it fails for FlashInfer on every GPU; it now builds a real SpeculativeConfig. test_flashinfer_varlen_cudagraph_capability mocks a trtllm-gen platform and now also pins the device capability, since the varlen bound is None on pre-SM90 GPUs.

    Everything below ran on SM80 with the FlashInfer 0.7.0.post1 release wheel that vLLM pins, installed apart from any source build. pytest tests/v1/attention/test_attention_backends.py tests/v1/attention/test_flashinfer_dcp_spec_reorder.py tests/kernels/attention/test_flashinfer.py -k "flashinfer or FLASHINFER" gives 149 passed, 53 skipped on this PR and 147 passed, 53 skipped on main (32fbfa15e8); the two new cases are the difference.

    End to end, main (32fbfa15e8) against main + this PR: Qwen3.8-27B NVFP4 weights, NVFP4 KV cache, FlashInfer, batch 1, default compile and CUDA graph settings, 256 greedy tokens, median of three runs after warm-up.

    | | main | this PR |
    | --- | ---: | ---: |
    | TP=1, MTP with 3 tokens | 73.6 tok/s (PIECEWISE) | 108.1 tok/s (decode FULL) |
    | TP=1, no spec decode | 57.2 tok/s | 57.5 tok/s |
    | TP=2, MTP with 3 tokens | 61.0 tok/s (PIECEWISE) | 83.1 tok/s (decode FULL) |
    | TP=2, no spec decode | 59.0 tok/s | 59.0 tok/s |

    Output tokens are identical between the two builds in every row, and MTP accepts the same drafts (684 of 1032 at TP=1, 668 of 1092 at TP=2). KV cache size is unchanged without spec decode and about 0.05 GiB smaller with MTP, which now captures FULL decode graphs.

    Details

  • Spec queries count as decodes on pre-SM90 GPUs (supports_spec_as_decode), so the reorder threshold becomes 1 + num_speculative_tokens. DCP still forces it back to 1.

  • get_cudagraph_support returns UNIFORM_BATCH on pre-SM90 GPUs. DCP and non-causal draft attention stay at UNIFORM_SINGLE_TOKEN_DECODE, and get_varlen_cudagraph_max_query_len returns None there since fa2 has no varlen decode.

  • The native decode branch already gets only uniform decodes (require_uniform=True sends mixed lengths to prefill). With more than one token per request it plans the wrapper per request with q_len_per_req; FULL uniform-decode graphs are captured only up to max_num_seqs * (1 + num_speculative_tokens) tokens, so there the token count is exactly requests × query length. Single-token decode keeps planning by token count.

  • FlashInfer freezes a CUDA-graph decode wrapper to its batch size and query length, so the wrapper cache is keyed by both.
  • An earlier attempt (#50885) targeted SM12x and was closed once XQA covered that architecture; it did not cover pre-SM90.

    ---

    <details>
    <summary> Pull Request Checklist </summary>

  • I used vLLM's /pr-checklist skill. (Mandatory for agents, optional for humans).

  • AI assistance was used during the creation of this PR.
  • Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.

  • Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.

  • Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.

  • Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide.

  • </details>

    Diff: 108 lines (+88 / -20) across 2 files Reviewer: pavanimajety Review duration: 20900m
    All Vouch review confidence checks passed
    Residual risk 0.04 = Change Risk (0.38) × (1 − Review Confidence (0.90)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.38 · 108 lines diff across 2 files
    0.38
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.88 · 5 substantive comment(s)
    0.88
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    90%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.281
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    16 items
    claude[bot] claude[bot] commented on Oct 08, 2026 03:25 UTC
    Reviewer

    Claude Code Review

    This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

    lesj0610 lesj0610 commented on Oct 08, 2026 11:20 UTC
    Author

    request review @mgoin

    wzhao18 wzhao18 commented on code on Oct 13, 2026 17:30 UTC
    Code Review
    vllm/v1/attention/backends/flashinfer.py:1
    @@ -1101,8 +1108,10 @@ def get_varlen_cudagraph_max_query_len(
         ) -> int | None:
             # The uniform gate already covers DCP, head geometry, the XQA head-dim
             # limit and causality, and yields None for subclasses that force NEVER.
    +        # Pre-SM90 fa2 has no varlen decode.
             if (
    -            cls.get_cudagraph_support(vllm_config, kv_cache_spec)
    +            not current_platform.has_device_capability(90)

    Can we embed this logic inside cls.get_cudagraph_support(vllm_config, kv_cache_spec) instead of explicit SM >= 90 check here?

    lesj0610 lesj0610 commented on code on Oct 14, 2026 01:40 UTC
    Code Review
    vllm/v1/attention/backends/flashinfer.py:1
    @@ -1101,8 +1108,10 @@ def get_varlen_cudagraph_max_query_len(
         ) -> int | None:
             # The uniform gate already covers DCP, head geometry, the XQA head-dim
             # limit and causality, and yields None for subclasses that force NEVER.
    +        # Pre-SM90 fa2 has no varlen decode.
             if (
    -            cls.get_cudagraph_support(vllm_config, kv_cache_spec)
    +            not current_platform.has_device_capability(90)

    Updated: the pre-SM90 native fa2 selection is now shared through _use_fa2_native_decode(), which the varlen check also uses.

    wzhao18 wzhao18 commented on code on Oct 14, 2026 03:27 UTC
    Code Review
    vllm/v1/attention/backends/flashinfer.py:1
    @@ -929,6 +937,7 @@ def __init__(
                 1,
                 supports_spec_as_decode=(
                     self.flashinfer_trtllm_api_decode_kernel is not None
    +                or _native_decode_on_fa2(self.is_kvcache_nvfp4)

    What I find bothering is that we are predicting that later it will run FA2 based on
    _native_decode_on_fa2 returning True. Can we make this more robust? like resolving the backend in init and save it as self.use_fa2 and then we consistently gate relevant logic behind this. Does the kernel API allow confirm that the backend is fa2?

    lesj0610 lesj0610 commented on code on Oct 14, 2026 15:15 UTC
    Code Review
    vllm/v1/attention/backends/flashinfer.py:1
    @@ -929,6 +937,7 @@ def __init__(
                 1,
                 supports_spec_as_decode=(
                     self.flashinfer_trtllm_api_decode_kernel is not None
    +                or _native_decode_on_fa2(self.is_kvcache_nvfp4)

    __init__ now sets self.use_fa2, and the native decode wrappers use backend="fa2" when that flag is set. The pinned FlashInfer version has no public getter for the resolved backend, so this avoids relying on auto. Spec decode classification and multi-token planning use the same flag, while the class-level graph checks share _use_fa2_native_decode().

    wzhao18 wzhao18 commented on code on Oct 14, 2026 15:54 UTC
    Code Review
    vllm/v1/attention/backends/flashinfer.py:1
    @@ -925,10 +930,11 @@ def __init__(
                 == FlashInferDecodeKernel.TRTLLM_GEN
                 and not self.use_dcp
             )
    +        self.use_fa2 = _use_fa2_native_decode()

    nit: maybe name as self.use_fa2_native_decode to clarify this suggests uniform multi-token queries are supported? because "auto" may resolve to "fa2" as well but only certain SM supports that feature, am I understanding correctly?

    wzhao18 wzhao18 commented on Oct 14, 2026 15:54 UTC
    Contributor

    overall looks good to me. @pavanimajety Can you take a look? I am not quite familiar with the flashinfer attention integration.

    lesj0610 lesj0610 commented on code on Oct 15, 2026 20:40 UTC
    Code Review
    vllm/v1/attention/backends/flashinfer.py:1
    @@ -925,10 +930,11 @@ def __init__(
                 == FlashInferDecodeKernel.TRTLLM_GEN
                 and not self.use_dcp
             )
    +        self.use_fa2 = _use_fa2_native_decode()

    Renamed to self.use_fa2_native_decode. This flag explicitly selects native fa2 and enables uniform multi-token decode on that path. The pre-SM90 gate is specific to this PR; fa2's multi-token support itself isn't limited to those GPUs.

    JaheimLee JaheimLee commented on Oct 21, 2026 03:09 UTC
    Contributor

    Hi, any update?

    pavanimajety pavanimajety commented on code on Oct 21, 2026 15:56 UTC
    Code Review
    tests/v1/attention/test_attention_backends.py:1
    @@ -487,8 +487,8 @@ def _test_backend_correctness(
         if max_num_batched_tokens is not None:
             vllm_config.scheduler_config.max_num_batched_tokens = max_num_batched_tokens
         if num_speculative_tokens > 0:
    -        vllm_config.speculative_config = SimpleNamespace(
    -            num_speculative_tokens=num_speculative_tokens
    +        vllm_config.speculative_config = SpeculativeConfig(
    +            method="ngram", num_speculative_tokens=num_speculative_tokens

    Any reason we are changing / hardcoding the method to ngram in the test?

    pavanimajety pavanimajety approved these changes on Oct 21, 2026 15:57 UTC
    Approved Reviewer

    Flashinfer changes look good to me.

    pavanimajety pavanimajety commented on Oct 21, 2026 15:58 UTC
    Contributor

    /ci run

    github-actions[bot] github-actions[bot] commented on Oct 21, 2026 15:59 UTC
    Bot

    ✅ Triggered Buildkite CI #96463 for commit 42e87cb53879.

    lesj0610 lesj0610 commented on code on Oct 21, 2026 22:41 UTC
    Code Review
    tests/v1/attention/test_attention_backends.py:1
    @@ -487,8 +487,8 @@ def _test_backend_correctness(
         if max_num_batched_tokens is not None:
             vllm_config.scheduler_config.max_num_batched_tokens = max_num_batched_tokens
         if num_speculative_tokens > 0:
    -        vllm_config.speculative_config = SimpleNamespace(
    -            num_speculative_tokens=num_speculative_tokens
    +        vllm_config.speculative_config = SpeculativeConfig(
    +            method="ngram", num_speculative_tokens=num_speculative_tokens

    I used ngram to create a real SpeculativeConfig without needing a draft model, following the other spec-decode tests in this file. The test exercises attention with speculative query lengths, not the drafting method itself.

    The new fa2 test is the first caller that passes num_speculative_tokens to this helper. The old SimpleNamespace only contained that field, but this path also reads enable_adaptive_verification and parallel_drafting. Using SpeculativeConfig gives those fields their defaults.

    Reviewers
    Assignees
    lesj0610 lesj0610
    Labels
    risk: low confidence: 90.3% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 37.5% (MEDIUM) · Higher = larger blast radius
    37.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 90.3% · Lower = rushed or shallow review
    90.3%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 3.6% · Safe to merge
    3.6%