Papers
Topics
Authors
Recent
Search
2000 character limit reached

FlashPrefill V2: Block-Sparse Prefill Attention for Long-Context LLM Serving

Published 20 Aug 2026 in cs.CL | (2608.19758v1)

Abstract: Long-context modeling is a pivotal capability for LLMs, yet the quadratic complexity of attention remains a critical bottleneck, particularly during the compute-intensive prefilling phase. Our previous work, FlashPrefill, mitigates this cost through instantaneous pattern discovery and max-based dynamic thresholding; however, it remains an algorithmic prototype that is still distant from production deployment. In this paper, we present FlashPrefill V2, which evolves FlashPrefill from a prototype toward practical long-context serving along three dimensions. First, we introduce a mean correction term that effectively suppresses the approximation error, keeping performance degradation manageable even at extreme sparsity levels. Second, we redesign the sparse attention operator with PackGQA memory access, warp specialization, and pingpong pipelining, fully aligning with the latest FlashAttention-3/4 implementations and supporting FP8 inference to meet practical quantization requirements. Third, FlashPrefill V2 natively supports paged KV cache and continuous batching, allowing integration as an attention backend in modern inference frameworks such as SGLang. Extensive evaluations on NVIDIA H20 GPUs---among the most widely deployed inference accelerators---demonstrate that FlashPrefill V2 delivers up to 47.26x and 27.19x speedups over FlashAttention-2 at 128K context length under FP8 and BF16 precision, respectively, and, in FP8, still achieves a 30.49x speedup against an FA3/4-aligned dense baseline.

Citations (2)

Summary

  • The paper introduces a mean-correction method for discarded attention blocks that preserves accuracy within about one point of full attention, even below 5% density and under FP8 quantization.
  • The paper rebuilds sparse attention with Hopper-optimized TMA, warp specialization, wgmma, and paged-KV support, achieving 27.2× BF16 and 47.6× FP8 speedups over FlashAttention-2 at 128K context.
  • The paper integrates the backend into SGLang, reducing 128K time to first token by 2.1–3.4× in BF16 and 3.7–4.8× in FP8, while highlighting limitations in chunked prefill and decode acceleration.

Overview and motivation

FlashPrefill V2 (2608.19758) extends the earlier FlashPrefill prototype (Fan et al., 6 Mar 2026) from an algorithmic proposal to a deployable sparse prefill attention backend for long-context LLM serving. The authors identify three gaps that prevented the original system from production use: (i) uncontrolled accuracy degradation under aggressive sparsity, because truncated softmax discards probability mass without compensation; (ii) a kernel built on the FlashAttention-2 execution model, which under-utilizes Hopper GPUs where TMA, warp specialization, and asynchronous wgmma dominate efficiency; and (iii) a contiguous KV layout incompatible with paged KV cache and continuous batching in frameworks such as vLLM (Kwon et al., 2023) and SGLang (Jiang et al., 2024). The paper addresses each gap with a mean correction term, an FA3/4-aligned kernel, and native paged/varlen support, respectively.

Mean correction under extreme sparsity

The core algorithmic addition is a zero-order surrogate for pruned blocks. Each key block BJ\mathcal{B}_J is represented by its pooled statistics (kˉJ,vˉJ)(\bar{k}_J, \bar{v}_J) with score sˉJ=q⋅kˉJ/d\bar{s}_J = q \cdot \bar{k}_J / \sqrt{d}, and each discarded block contributes ∣BJ∣esˉJ(vˉJ,1)|\mathcal{B}_J| e^{\bar{s}_J}(\bar{v}_J, 1) to both numerator and denominator of the online softmax. A Taylor expansion shows the mass surrogate is second-order accurate while the value surrogate retains a first-order within-block covariance term δv‾\overline{\delta v}; the resulting output shift is bounded by the pruned mass share ρpr\rho_{\mathrm{pr}}, which max-based thresholding caps at roughly α\alpha per block. Relative to dropping blocks outright, the correction cancels the zeroth-order error, leaving only intra-block covariance.

Empirically this matters most under FP8: on RULER with Qwen3-4B-Instruct-2507, removing the correction costs 6.2 points at 128K in FP8 versus 0.9 points in BF16, which the authors attribute to compressed score margins under quantization giving discarded blocks a larger softmax share. With correction enabled, the pipeline stays within about one point of full attention on RULER/LongBench averages and within 1.5 points even at 128K in BF16. The threshold sweep is notable: with correction, α\alpha can be pushed to 0.2 at 64K—halving density to 5.2%—while retaining 80.12 points against full attention's 82.81, whereas the uncorrected variant loses 5.44 points there. The correction is fused into the mainloop as extra iterations with a log⁡∣BJ∣\log|\mathcal{B}_J| logit shift, costing only 3.6–4.5 ms at 90% sparsity (18–27% relative overhead), the regime where it is most needed.

Hopper-aligned kernel design

The operator is rebuilt on CUTLASS/CuTe with TMA-based data movement, warp-specialized producer–consumer pipelines, and intra-warpgroup pingpong overlap of QK GEMM, PV GEMM, and online softmax, matching the FlashAttention-3/4 execution model (Shah et al., 2024, Zadouri et al., 5 Mar 2026). Several deployment-oriented mechanisms are described:

  • PackGQA: queries are reshaped so each M-tile covers all gg query heads of one KV group, guaranteeing group-wide KV sharing in shared memory, shrinking index metadata by a factor of (kˉJ,vˉJ)(\bar{k}_J, \bar{v}_J)0, and reducing wasted rows.
  • Index-driven traversal: selection results are stored as a CSR list per (batch, head, tile); producer and consumer evaluate the same sequence independently, avoiding synchronization for block skipping. KV splitting partitions the CSR list by selected-block count rather than position range, equalizing actual work across splits.
  • Single-pass scoring: block energies are accumulated online with a running tile maximum and bitcast into the index buffer itself, eliminating a separate score buffer and second GEMM pass.
  • FP8 execution: e4m3 operands with per-tensor scales; probabilities are quantized onto (kˉJ,vˉJ)(\bar{k}_J, \bar{v}_J)1 via a (kˉJ,vˉJ)(\bar{k}_J, \bar{v}_J)2 offset that cancels in the softmax ratio. The K-major layout requirement of FP8 wgmma for the PV GEMM is handled either by register-level permutation of (kˉJ,vˉJ)(\bar{k}_J, \bar{v}_J)3 or by an LDSM.T→byte-permute→STSM transpose of (kˉJ,vˉJ)(\bar{k}_J, \bar{v}_J)4, with no global-memory traffic.

An overhead analysis bounds auxiliary FLOPs (indexing plus correction) relative to sparse attention at (kˉJ,vˉJ)(\bar{k}_J, \bar{v}_J)5, roughly 19% even at 4% retained density with (kˉJ,vˉJ)(\bar{k}_J, \bar{v}_J)6, consistent with the observed gap between operator-level and end-to-end speedups.

Accuracy and operator-level efficiency

Evaluations use RULER and LongBench on Llama-3.1-8B-Instruct, Qwen3-4B-Instruct-2507, and Qwen3-30B-A3B-Instruct-2507 on NVIDIA H20 GPUs, with a single untuned configuration ((kˉJ,vˉJ)(\bar{k}_J, \bar{v}_J)7, 256 sink tokens, 512-token window, (kˉJ,vˉJ)(\bar{k}_J, \bar{v}_J)8). On RULER, FlashPrefill V2 stays within 1.1 points of full attention on average across all three models, and the FP8 variant costs an additional 0.4–1.2 points. On LongBench it achieves the best average among all sparse operators on every model (49.31 vs. 48.25 for XAttention on Llama-3.1-8B) and remains strongest even with direct online FP8 quantization.

Operator-level speedups over FlashAttention-2 at 128K context:

Method BF16 FP8
MInference 2.45–2.76× —
FlexPrefill 5.18–5.43× —
XAttention 3.42–3.48× —
FlashPrefill (V1) 18.67–22.67× —
FlashPrefill V2 27.19–27.45× 47.26–47.59×

Against the stronger FA3/4-aligned dense baseline, V2 still delivers 17.54× (BF16) and 30.49× (FP8) at 128K, and outperforms the production HPC-Ops block-sparse kernel by 6–7% at every sparsity level in FP8 at 64K, with the CSR-per-KV-head index format consuming 6 MB at 128K versus 32 MB for the dense-mask format. Attention density falls from ~70% at 4K to ~5% at 128K on needle-in-a-haystack inputs, which drives the growing speedup; notably, the operator already exceeds FA2 at 4K despite high density.

End-to-end serving results

Integrated into SGLang as a standard attention backend (decode falls back to dense FA3/4), the system reduces TTFT at 128K by 2.1–3.4× in BF16 and 3.7–4.8× in FP8 under continuous batching, nearly batch-invariantly across batch sizes 1–16. In open-loop Poisson serving with mixed 4K–128K prompts, the FA3/4 backend saturates at 0.31–0.37 req/s, while V2 sustains roughly twice that throughput and cuts P50 TPOT by 1.6–2.4× (BF16) and up to 8.8× (FP8), since shorter prefills unblock concurrent decoding. At 4K, BF16 stays near parity with FA3/4 (1.01–1.09×) because index-stage overhead offsets modest attention savings—an honest concession that the method targets long contexts.

A material limitation appears under chunked prefill: re-running index selection per chunk plus mandatory tail blocks raises effective density, eroding the P50 TTFT speedup from 2.2× to 1.2× at 8K chunks on Qwen3-30B-A3B. The authors recommend chunk sizes of at least 8K (ideally 16K) when combining chunked prefill with their backend. The paper also concedes that decode-phase sparsity is not addressed—a single query token per step leaves no room for block-level selection—and that the numerator surrogate's first-order covariance term is bounded only under assumptions of low within-block dispersion, which may fail for adversarial content distributions.

Limitations and open questions

Three limitations bear directly on the reported results. First, accuracy claims rest on retrieval-style benchmarks (RULER, LongBench); whether the zero-order correction holds for workloads with high intra-block logit-value covariance, such as long chain-of-thought reasoning, is left unexamined. Second, the chunked-prefill degradation suggests the index stage would benefit from cross-chunk reuse of selection metadata, which the current design does not attempt. Third, decode remains dense, so the system accelerates only half of the serving pipeline; extending query-aware sparsity to single-token decoding without sacrificing the lockstep producer–consumer schedule is an open question the paper does not resolve.

Conclusion

FlashPrefill V2 closes the gap between training-free sparse prefill algorithms and production serving through three coordinated contributions: a mean correction term that keeps accuracy within about one point of full attention even below 5% density and proves especially effective under FP8; a FlashAttention-3/4-aligned kernel achieving up to 47.26× speedup over FlashAttention-2 at 128K; and native paged-KV, varlen, and continuous-batching support demonstrated in SGLang with up to 4.8× lower TTFT. The remaining questions—robustness beyond retrieval-centric evaluation, chunk-aware indexing, and decode-phase sparsity—define the boundary of what the current system demonstrates.

Paper to Video (Beta)

No one has generated a video about this paper yet.

Whiteboard

No one has generated a whiteboard explanation for this paper yet.

Open Problems

We found no open problems mentioned in this paper.

Tweets

Sign up for free to view the 1 tweet with 0 likes about this paper.