feat(attention): attention sinks over an NVFP4 KV cache in prefill and decode #6021
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 #6021"
general
weight: 0.35
lesj0610
<!-- .github/pull_request_template.md -->
📌 Description
BatchAttentionWithAttentionSinkWrappercannot be built for an NVFP4 KV cache, and the fa2 decode path has no attention-sink wrapper at all. On GPUs without XQA decode, such as SM8x, a sink model therefore cannot decode from a paged cache with FlashInfer, whatever the KV dtype.This PR:
BatchAttentionWithAttentionSinkWrapper._sink_jit_args, which prefill and decode share.- With
kv_data_type=torch.uint8on fa2 it declaresmaybe_k_cache_sfandmaybe_v_cache_sf, whichrun(..., kv_cache_sf=...)already fills. fa3 still rejects packed FP4 through the existing check.- The module name now carries the KV dtype, head dims, position encoding and fp16 QK reduction. These variants used to share one name, so a process that used two head dims ran the first-built module for both: on SM80, bf16 sinks at head_dim 64 and 128 in one process gave a relative error of 0.6 to 1.2 against a torch reference for whichever was built second.
BatchDecodeWithAttentionSinkWrapper, which builds the same module through the tensor-core decode wrapper, so sink decode is planned and captured in CUDA graphs like any decode wrapper. It is called asrun(q, paged_kv_cache, sinks, sm_scale, ...), like the prefill wrapper.BatchDecodeWithPagedKVCacheWrapperthejit_kwargsargument the prefill wrappers already have, and passes the NVFP4 block scales to custom modules as the prefill wrapper does.🔍 Related Issues
Fixes #5966. #6012 adds the same two scale tensors to the prefill sink wrapper; this PR also covers decode and the module-name collision. The module-name part overlaps #5535, which fixes the same collision through
get_batch_prefill_attention_sink_uri; I will rebase onto whichever lands first.🚀 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.).test_attention_sink_nvfp4_kvruns decode, and prefill in 33-token chunks (the repack path), over an NVFP4 cache and checks both against the prefill sink wrapper over the dequantized bf16 cache, with and without a sliding window. On SM80,tests/attention/test_attention_sink.py: 490 passed, 560 skipped (fa3), 96 xfailed.tests/utils/test_jit_example.py -k batch_decode: 4 passed.Also checked on SM80, outside the test suite:
mainover 768 input combinations: only the module name differs, plus the two scale tensors for fa2 with uint8 KV.🔬 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.
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
Summary by CodeRabbit
New Features
Added a public batch decode wrapper for attention-sink workloads, with support for NVFP4-quantized key/value caches.
Added optional JIT keyword arguments to paged KV-cache wrappers.
Documentation
Added API documentation for the attention-sink batch decode wrapper.
Tests
* Added coverage comparing quantized-cache decode and prefill results with BF16 reference outputs.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->