feat(qsa_ops): add Qwen4Exp quantized sparse attention #5862
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #5862"
general
weight: 0.35
lesj0610
<!-- .github/pull_request_template.md -->
📌 Description
Qwen4Exp's quantized sparse attention (QSA) for SM80 and newer, as
flashinfer.qsa_ops, with the two pieces of common code it needs.A QSA layer scores a compressed index cache, keeps the top blocks per query, and attends over those tokens where they sit in the paged KV cache. The package has the per-step kernels (pre-indexer, paged scorer, route expansion and mapping, output gate) and three objects that run them out of caller-owned workspaces, so a captured CUDA graph can replay a whole step:
QSASelection,QSAAttentionandQSA.qsa_capabilities()tells a serving stack what the build carries.Two changes to existing code support it:
BlockSparseAttentionWrapperruns on a paged KV cache (plan(..., kv_cache_page_size=...); dense, FP8 or NVFP4; NHD or HND) and reports its workspace size before planning, so several live plans can share one arena. It also fixes the default FP8 scales, which were sized by the block width instead of the KV-head count.top_k_ragged_transformtakesout,workspaceand a resolvedbackend, so a caller can run it without allocating and with the backend fixed up front. Calls without them are unchanged.The kernels run on SM80 and every later architecture: the JIT and AOT builds target 8.x through 12.x, and there are no architecture-specific paths, so newer GPUs run the same mma.sync and cp.async code rather than tuned variants. SM7x is excluded because the scorer's m16n8k16 arrived with SM80. The pre-indexer, scorer and route are one JIT module; the gate is a second one built without fast math, so a subnormal logistic is not flushed to zero.
cp_async.cuhgains one L1-caching copy andmma.cuhthe m16n8k16 helpers; existing functions are untouched.#5859, #5860 and #5861 were folded into this PR and closed.
🔍 Related Issues
Tracked in #5669.
🚀 Pull Request Checklist
Thank you for contributing to FlashInfer! Before we review your pull request, please make sure the following items are complete.
✅ Pre-commit Checks
pre-commitby runningpip install pre-commit(or used your preferred method).pre-commit install.pre-commit run --all-filesand fixed any reported issues.🧪 Tests
unittest, etc.).Each kernel is checked against a torch reference; the selection, the attention and a whole step against torch, including workspace lifetimes, plan freezing and CUDA-graph replay. The paged block-sparse route is checked against dense attention over the same entries for bf16, FP8 and NVFP4 caches, and the top-k caller-buffer path against the per-call transform. On sm_80 everything in
tests/qsa_ops,tests/attention/test_block_sparse.py,tests/utils/test_topk.pyand the trace tests passes; the SM90-only FP8 default-scale test skips. Nothing has run on SM90 or newer.🔬 Experimental Track
<!-- Only for PRs submitted under the experimental policy (CONTRIBUTING.md → "Experimental APIs and Backends").
Leave this section untouched for normal PRs. -->
flashinfer/experimental/and/or an@flashinfer_experimental_api. Tracking issue: #- [ ] The tracking issue names an owner, the reason for the experimental path, and a graduation plan with a target release.
- [ ] Core changes are limited to a thin entry point (signature, shared validation, feature-gate check, backend selection, handoff).
- [ ] Tests live in
tests/experimental/and were validated on the intended hardware; a runnable example is included.- [ ] Nothing is registered in
flashinfer/aot.py, and no experimental backend is reachable frombackend="auto"withoutFLASHINFER_ALLOW_EXPERIMENTAL_AUTO_BACKENDS=1. (Calling an@flashinfer_experimental_apior naming a backend explicitly is itself the opt-in and needs no environment variable.)- [ ] Test scope declared below. The experimental CI lane runs exactly these targets, so keep them as narrow as the change allows.
<!-- Required for experimental PRs. Replace the commented lines below with your targets.
Do not delete the fence or change its
experimental-teststag — the experimental-trackwatcher reads it verbatim to decide which targets to ask CI for. -->
``
experimental-tests
`One target per line: a directory or a file. (A pytest ::selector is not
supported -- the sharding runner cannot consume one.) Must be under
tests/experimental/ and must exist. Delete these comment lines and add yours, e.g.
# tests/experimental/test_my_backend.py
tests/experimental/my_backend/
# Declaring the whole tree (tests/experimental/) is allowed but means every
experimental PR pays for every other feature's tests, in every matrix cell.
Reviewer Notes
The only changes to shared paths are paged_kv_t
, which gains astorage_page_sizefield and aresolve_slotstep on every paged kernel's address computation (a uniform branch that is a no-op when the logical block is the page), and the three keyword arguments ontop_k_ragged_transform. Everything else is new code underflashinfer/qsa_ops,include/flashinfer/attention/qsaandcsrc/qsa_*`. The paged route is served by the FA2 kernel on every architecture; FA3 and trtllm-gen do not take a paged route here, so on SM90 and newer QSA attention runs FA2. Nothing has run on SM90 or newer.