[Attention] Decode FlashInfer spec queries with fa2 on pre-SM90 GPUs #60532
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.
request review @mgoin
Can we embed this logic inside cls.get_cudagraph_support(vllm_config, kv_cache_spec) instead of explicit SM >= 90 check here?
Updated: the pre-SM90 native fa2 selection is now shared through _use_fa2_native_decode(), which the varlen check also uses.
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?
__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().
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?
overall looks good to me. @pavanimajety Can you take a look? I am not quite familiar with the flashinfer attention integration.
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.
Hi, any update?
Any reason we are changing / hardcoding the method to ngram in the test?
Flashinfer changes look good to me.
/ci run
✅ Triggered Buildkite CI #96463 for commit 42e87cb53879.
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.
pavanimajety
lesj0610
Overview
On pre-SM90 GPUs FlashInfer has no XQA or trtllm-gen decode, so speculative decoding verification steps (1 +
num_speculative_tokenstokens per request) are split off as prefills, andget_cudagraph_supportreportsUNIFORM_SINGLE_TOKEN_DECODE, which drops spec decode fromFULL_AND_PIECEWISEtoPIECEWISE. 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 reportsUNIFORM_BATCHthere.Claims
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 withq_len_per_req=4. The test harness'snum_speculative_tokensoption built its speculative config as aSimpleNamespacethat lacks fields the builders now read, so it fails for FlashInfer on every GPU; it now builds a realSpeculativeConfig.test_flashinfer_varlen_cudagraph_capabilitymocks a trtllm-gen platform and now also pins the device capability, since the varlen bound isNoneon 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 onmain(32fbfa15e8); the two new cases are the difference.End to end,
main(32fbfa15e8) againstmain+ 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 (decodeFULL) || 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 (decodeFULL) || 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
supports_spec_as_decode), so the reorder threshold becomes 1 +num_speculative_tokens. DCP still forces it back to 1.get_cudagraph_supportreturnsUNIFORM_BATCHon pre-SM90 GPUs. DCP and non-causal draft attention stay atUNIFORM_SINGLE_TOKEN_DECODE, andget_varlen_cudagraph_max_query_lenreturnsNonethere since fa2 has no varlen decode.require_uniform=Truesends mixed lengths to prefill). With more than one token per request it plans the wrapper per request withq_len_per_req; FULL uniform-decode graphs are captured only up tomax_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.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>
/pr-checklistskill. (Mandatory for agents, optional for humans).</details>