Modern large language models increasingly require long contexts for reasoning and multi-document tasks, but attention's quadratic complexity creates a severe computational bottleneck. We present Block Sparse Flash Attention (BSFA), a drop-in replacement that accelerates long-context inference while preserving model quality. Unlike methods that predict importance before computing scores, BSFA computes exact query-key similarities to select the top-k most important value blocks for each query. By comparing per-block maximum scores against calibrated thresholds, we skip approximately 50% of the computation and memory transfers for pruned blocks. Our training-free approach requires only a one-time threshold calibration on a small dataset to learn the per-layer and per-head attention score distributions. We provide a CUDA kernel implementation that can be used as a drop-in replacement for FlashAttention. On Llama-3.1-8B, BSFA achieves up to 1.13x end-to-end speedup on LongBench with only a 1.1% accuracy drop, and up to 1.24x on Needle-in-a-Haystack retrieval at a 1% accuracy drop. The attention kernel itself accelerates by up to 1.38x. We compare BSFA against five recent sparse attention baselines (SpargeAttention, MInference, FlexPrefill, XAttention, and BLASST), and verify the method on Qwen2.5-7B and on A6000 and H100 GPUs. The implementation is available at https://github.com/Danielohayon/Block-Sparse-Flash-Attention.
Figures & tables
Figure 1 : Accuracy-latency trade-offs on RULER for 32K (top-left), 64K (top-right), and 128K (bottom). BSFA (blue) maintains high accuracy with consistent speedups, outperforming SpargeAttention (orange). Each point is a different sparsity level (Table 6 ).
Figure 2 : BSFA mechanism. (a) Per-block maxima smax(i,j) are computed exactly within the FlashAttention tile. The center column visualizes the calibrated threshold tensor Tℓ,h,i(k) ( k=6 shown), one value per query row, with hatched −∞ entries where fewer than k off-diagonal candidates exist. (b) Off-diagonal blocks are kept (green) if smax(i,j)≥Tℓ,h,i(k) . Diagonal blocks (orange) always run; skipped blocks (grey) avoid the Vj load and the PV matmul. The highlighted row i=14 traces a single gating decision across all three panels.
Method
Param.
Accuracy ↑
Speedup ↑
Dense FlashAttention-2
All
40.24%
1.00 ×
BSFA
k =32
39.39% (-2.1%)
1.16 ×
k =64
39.78% (-1.1%)
1.13 ×
k =96
39.88% (-0.9%)
1.10 ×
k =128
40.03% (-0.5%)
1.08 ×
SpargeAttention
τ =0.4
30.06% (-25.3%)
1.09 ×
Table 1 : Main results on LongBench (Llama-3.1-8B). Accuracy is on the full 27-task benchmark ( ∼ 4,750 samples) via lm-evaluation-harness, and speedup is end-to-end TTFT on the 10 longest narrativeqa samples ( ∼ 65K tokens each). All methods on A100 unless marked ⋆ (H100, since BLASST has no public A100 implementation). Sliding Window does not run as a sparse-attention kernel against the same baseline, so we report accuracy only. Bracketed numbers show relative degradation from the dense baseline.
Method
Param.
Accuracy ↑
< 4K
4–8K
8–16K
16–32K
32–65K
Dense FlashAttention-2
All
40.24%
1.00 ×
1.00 ×
1.00 ×
1.00 ×
1.00 ×
BSFA
k =64
39.78% (-1.1%)
0.96 ×
0.97 ×
1.01 ×
1.05 ×
1.19 ×
MInference
default
40.06% (-0.45%)
0.17 ×
0.31 ×
0.48 ×
0.58 ×
0.99 ×
FlexPrefill
γ =0.9
35.11% (-12.8%)
0.71 ×
0.90 ×
1.05 ×
1.18 ×
1.59 ×
γ =0.99
38.90% (-3.3%)
0.69 ×
0.80 ×
0.93 ×
0.99 ×
1.12 ×
XAttention
default
39.95% (-0.7%)
0.85 ×
0.90 ×
0.97 ×
1.01 ×
1.09 ×
Table 2 : End-to-end TTFT speedup on a LongBench mixed-length subset (160 samples spanning 295–65,461 tokens), broken down by sequence-length bucket. Speedup is reported against dense FlashAttention-2 within each bucket. Accuracy column is the full 27-task LongBench score from Table 1 , repeated here for ease of speedup-vs-accuracy correlation. Llama-3.1-8B on A100 unless marked ⋆ (H100). SpargeAttention was not measured on this subset. Bold cells highlight regressions below dense ( <1.00× ).
Param.
Accuracy ↑
E2E Speedup ↑
Attn-only Speedup ↑
SDPA
84.96%
1.00 ×
1.00 ×
k =192
83.08% (-2.2%)
1.13 ×
1.38 ×
k =256
83.39% (-1.8%)
1.09 ×
1.30 ×
k =384
84.24% (-0.8%)
1.05 ×
1.19 ×
Table 3 : Attention-kernel-only versus end-to-end speedup at RULER 64K (BSFA, Llama-3.1-8B, A100). Accuracy is on RULER 64K with relative degradation from dense in brackets. Kernel-only timing isolates the attention call from work BSFA cannot accelerate (Q/K/V/O projections, RoPE, GQA expansion, MLP, the LM head).
Figure 3 : Accuracy vs. Time-to-First-Token (TTFT) speedup on the 64K Needle-in-a-Haystack Single-key task. BSFA retains 99% of baseline accuracy at k=32 with a 1.24× speedup, exploiting that retrieval concentrates signal in few blocks. SpargeAttention is shown as a multi-operating-point reference. The remaining baselines (MInference, FlexPrefill, XAttention, BLASST) were not evaluated on this task and are compared on LongBench in Tables 1 – 2 .
Table 7
Appendix figures & tables2 assets
Supplementary material from the paper’s appendix.
Appendix
Seq Length
Method
Sparsity Param.
Accuracy ↑
Pred./Meas. Density
Speedup ↑
32K
Dense FlashAttention-2
All
85.98%
1.00
1.00 ×
BSFA
k =64
84.94% (-1.2%)
0.24/0.28 ± 0.04
1.07 ×
k =96
85.52% (-0.5%)
0.35/0.38 ± 0.05
1.04 ×
k =128
86.00% (+0.0%)
0.45/0.47 ± 0.05
1.03 ×
k =192
86.42% (+0.5%)
0.62/0.62 ± 0.05
1.00 ×
SpargeAttention
τ =0.6
75.62% (-12.1%)
-
0.91 ×
Appendix
Table 6 : Full RULER results across multiple sparsity levels. Accuracy column shows absolute accuracy with relative degradation from baseline in brackets. Pred./Meas. Density shows predicted (Eq. 3 ) vs. measured density during inference (predicted/measured ± std). Speedup is end-to-end TTFT vs. dense FlashAttention-2 on the same samples.
Method
Param.
Speedup ↑
Dense FA-2
All
1.00 ×
BSFA
k =192
1.13 ×
k =256
1.09 ×
k =384
1.05 ×
SpargeAttention
τ =0.5
1.03 ×
MInference
default
1.15 ×
Appendix
Table 7 : End-to-end TTFT speedup on RULER 64K (Llama-3.1-8B). All methods on A100 unless marked ⋆ (H100). XAttention was not measured on RULER.
Recent advances in sparse attention mechanisms have demonstrated strong potential for reducing the computational cost of long-context training and inference in large language models (LLMs). Native Sparse Attention (NSA), one state-of-the-art approach, introduces natively trainable, hardware-aligned sparse attention that delivers substantial system-level performance boosts while maintaining accuracy comparable to full attention. However, the kernel implementation of NSA forces a loop order that is only efficient with a relatively large number of query heads in each Grouped Query Attention (GQA) group, whereas existing LLMs widely adopt a much smaller number of query heads in each GQA group -- such an inconsistency significantly limits the applicability of this sparse algorithmic advance. In this work, we propose Flash Sparse Attention (FSA), an alternative kernel implementation that enables efficient NSA computation across a wide range of popular LLMs with a varied, smaller number of heads in each GQA group on modern GPUs. Compared to vanilla NSA kernel implementation, our empirical evaluation demonstrates that FSA achieves (i) up to 3.5x and on average 1.6x kernel-level latency reduction, (ii) up to 1.25x and 1.09x on average end-to-end training speedup on state-of-the-art LLMs, and (iii) up to 1.36x and 1.11x on average for prefill-phase speedup in LLM generative inference. The source code is open-sourced and publicly available at https://github.com/Relaxed-System-Lab/Flash-Sparse-Attention.
Ran Yan, Youhe Jiang, Zhuoming Chen +3
1. The Hong Kong University of Science and Technology · 2. Carnegie Mellon University
Long contexts have become standard in pretrained LLMs, yet they remain expensive to run: prefill compute grows quadratically with sequence length, and every decode step re-reads a key-value cache that grows linearly with it. Sparse attention cuts these costs by attending only to a relevant subset of past tokens, but selecting that subset is itself expensive. We present SpotAttention, a lightweight selector that attaches to a frozen pretrained transformer and learns by KL distillation to estimate its attention distribution. The selector picks the top-K keys each query attends to, and because its estimate is a calibrated distribution, a dual top-p rule reads the per-query, per-layer budget directly from it. Across Qwen3 (dense, 4B-32B) and Qwen3.5 (hybrid linear/full attention, 4B-9B), SpotAttention matches dense accuracy at contexts up to 128K tokens, eight times the training length. Decode at L=128K runs 3.9x faster than FlashAttention and 1.8x faster than Twilight, the strongest training-free baseline. Quantizing the selector's K-cache to INT4 or FP4 microscale shrinks it 3.5x at no accuracy cost.
Attention is the dominant source of latency during long-context LLM inference, an increasingly popular workload with reasoning models and RAG. We propose Kascade, a training-free sparse attention method that leverages known observations such as 1) post-softmax attention is intrinsically sparse, and 2) the identity of high-weight keys is stable across nearby layers. Kascade computes exact Top-k indices in a small set of anchor layers, then reuses those indices in intermediate reuse layers. The anchor layers are selected algorithmically, via a dynamic-programming objective that maximizes cross-layer similarity over a development set, allowing easy deployment across models. The method incorporates efficient implementation constraints (e.g. tile-level operations), across both prefill and decode attention. The Top-k selection and reuse in Kascade is head-aware and we show in our experiments that this is critical for high accuracy. Kascade achieves up to 4.1x speedup in decode attention and 2.2x speedup in prefill attention over FlashAttention-3 baseline on H100 GPUs while closely matching dense attention accuracy on long-context benchmarks such as LongBench and AIME-24.