Sparse attention reduces the cost of long-context decoding, but token selection introduces additional scoring and ranking overhead. Moreover, uniform page scoring overlooks differences in relevance between near and far context. We propose Near-Far Attention (NFA), which adapts retrieval to regional attention patterns while keeping candidate scoring lightweight. During prefill, the Lightweight Gate Estimator identifies regions that can be skipped during decoding, adding less than 1% to dense-prefill time. For the remaining regions, the Calibration-Free Subspace Extractor supplies compact features shared by page-level and token-level scoring without offline calibration. The Distance-Aware Two-Level Selector then scores near and far pages differently and jointly ranks candidate tokens under a shared budget. Evaluations across model families, parameter scales, and GQA/MLA architectures show aggregate task quality comparable to full attention. On Qwen3-8B at 512K context length, NFA achieves up to 5.49× operator speedup and 2.97× whole-model decoding speedup over FlashInfer, including selection overhead.
Figures & tables
Fig. 1: Observations on Qwen3-8B. (a) Retained attention mass relative to oracle TopK under a shared 32-coordinate budget; dots denote documents and diamonds denote means. (b) A representative example of the regional coverage differences between Avg and MinMax observed across profiled queries. (c) Regional attention patterns over contiguous query windows, summarized by median attention mass for each task and layer (F: far; N: near). Profiling settings are given in Section IV-A .
Fig. 2: Overview of NFA. (a) Prefill-time regional attention statistics determine per-layer skip flags, which remain fixed during decoding (1: skip; 0: compute). (b) Compact query and key representations are shared by both selection levels. (c) Region-specific page selection is followed by joint token ranking; selected and protected positions participate in full-dimensional attention.
Fig. 3: Qwen3-8B task quality: (a) LongBench v1 average; (b) LongBench v2 accuracy; (c) RULER scores across context lengths. Vertical dashed lines in (a) and (b) mark FullKV. Configurations are given in Section IV-A .
Method
S-Doc QA
M-Doc QA
Summ.
Few- shot
Syn.
Code
Avg.
Qwen3-32B (GQA; 16 tasks)
FullKV
40.88
47.73
27.47
59.61
59.25
16.20
42.37
Quest
36.13
38.96
27.20
49.53
51.88
26.51
38.26
JSSA
42.17
50.53
27.44
60.48
58.25
15.55
43.09
AsyncTLS
37.53
43.36
27.02
55.01
49.16
16.95
38.81
NFA
39.97
46.83
27.19
60.52
57.75
15.68
41.90
TABLE I: LongBench v1 scores across models. Categories average their constituent tasks; Avg. is the unweighted mean over 16 tasks. Bold and underlined values mark the best and second-best sparse methods; FullKV is the dense reference.
Fig. 4: NFA speedup over FlashInfer: (a) operator time including selection; (b) whole-model decoding. Dashed lines denote parity. Missing points exceed GPU memory capacity.
Fig. 5: Whole-model decoding latency of NFA, JSSA, Quest, and AsyncTLS on Qwen3-8B at batch size one with a total attention budget of 1024 tokens, including protected positions. Latency includes selection overhead. Lower is better.
Fig. 6: Gate ablation on Qwen3-8B. (a) Selection latency under forced skip states, normalized to no skip. (b) Threshold sensitivity at K2=1024 . Lines: HotpotQA F1 (Hot) and GovReport ROUGE-L (Gov), 200 examples each. Bars: all-layer L1+L2+attention latency per decode step on one 32K input per task at BS1. The dotted line marks the default τ=0.1 .
Fig. 7: Subspace ablation. (a) GLM average over HotpotQA/GovReport (200 examples each); all subsets use 32 NoPE coordinates. (b) Qwen3-8B scoring latency at 64K, gating disabled.
Fig. 8: NFA regional page selection versus single-pool Avg and MinMax on Qwen3-8B across RULER context lengths.
Long-context LLMs increasingly rely on extended, reusable prefill prompts for agents and domain Q&A, pushing attention and KV-cache to become the dominant decode-time bottlenecks. While sparse attention reduces computation and transfer costs, it often struggles to maintain accuracy at high sparsity levels due to the inherent distribution shift between Queries and Keys. We propose Centroid-Scoring Attention (CSAttention), a training-free sparse attention method optimized for high-throughput serving of reusable contexts. CSAttention adopts a storage-for-computation strategy tailored to the offline-prefill/online-decode setting: it front-loads computation into a one-time offline prefill phase that can be amortized across multiple queries, while aggressively optimizing per-step decoding latency. Specifically, CSAttention constructs query-centric lookup tables during offline prefill, whose size remains fixed during decoding, and enables online decoding to replace full-context scans with efficient table lookups and GPU-friendly score accumulation. Extensive experiments demonstrate that CSAttention achieves near-identical accuracy to full attention. Under high sparsity (95%) and long-context settings (32K-128K), CSAttention consistently outperforms state-of-the-art sparse attention methods in both model accuracy and inference speed, achieving up to 4.6x inference speedup over the most accurate baseline at a context length of 128K.
Chuxu Song, Zhencan Peng, Jiuqi Wei +1
Department of Computer Science, Rutgers University · Oceanbase, Ant Group.
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.
We introduce a training-free sparse attention method that builds a prompt-specific key index to accelerate both prefill and decoding. The method clusters the keys into large semantic blocks that group tokens from noncontiguous positions. Each query position selects blocks by scoring their centroids and attends to the original keys and values within them. Queries that select the same block are processed together, so prefill stays fast even though each query chooses its own blocks. Large blocks make centroid scoring and this grouped processing cheap, so each query can attend to more tokens in the same time. Larger blocks with a larger token budget can thus be both faster and more accurate on long-context tasks than smaller blocks with a smaller budget. We evaluate two hybrid LLMs, Qwen3.5-4B and 35B-A3B, on one NVIDIA H200. Including the cost of building and using the index, whole-model wall-clock speedups over dense attention are 2.3-2.4x for prefill and 1.7-2.0x for decoding at 512K tokens, and 2.9-3.0x for prefill at 1M. The 35B-A3B model stays close to dense attention on five RULER tasks through 1M, on LongBench-v2 overall, and on MRCR through 256K. The 4B model loses accuracy mainly on multi-key retrieval, yet outperforms dense Qwen3.5-2B, whose latency is similar at 512K, on all three benchmarks.