arXiv:2610.24991cs.LGOct 2026

Manuscript Offprint

arXiv:2610.24991

Certified Sparse Attention via Perturbed Retrieval

Runguo Li

Abstract

Sparse attention speeds up long-context decoding by reading few keys of the KV cache, but existing methods do not control the error of a query, and on real KV caches their errors have heavy tails. We show that perturbing the score of every key with an independent Exp(1) variable turns threshold retrieval into sampling keys with probability proportional to their attention weights. Lowering the threshold along a geometric grid gives nested samples, a Horvitz–Thompson estimate of the output at every level, and confidence bounds that hold simultaneously over all levels, so each head stops at the first level whose certificate meets the target error ε\varepsilon. With fresh perturbations at every decoding step, each certificate fails with probability at most δ\delta during generation. At a suitable threshold, the estimator reads O(ε−2log⁡(1/δ))O(\varepsilon^{-2} \log(1/\delta)) values regardless of the context length, and no adaptive method reads fewer, up to constants. A 4-bit scan with deterministic bounds, shared across a grouped-query-attention group, generates the candidates exactly but reads every key. On three LLMs and ten settings at 16K–128K tokens, no certificate is violated, and at equal keys read our 90th-percentile error is 4.6–7.9× lower than that of the best of 15 baseline families. At equal bytes, the best baselines have 0.6–1.6 times our 90th-percentile error and at least 4.9 times our largest. End to end, our method stays within one point of dense attention on tasks and within 0.1% in PG-19 perplexity, and the strongest baselines at equal bytes score as well. On CPU, decoding steps at 32K–128K tokens run 1.1–1.4× faster than dense attention on the same 16-bit cache.

1 Introduction

To generate one token, every attention head reads the entire KV cache of its context. For Llama-3.1-8B, which uses grouped-query attention (GQA) with 8 KV heads in each of its 32 layers, a 128K-token context means reading about 16 GiB of 16-bit keys and values per decoding step, so decoding is limited by memory bandwidth. Attention weights concentrate on a small fraction of tokens, and sparse attention reads only the keys that a heuristic predicts to matter: recent tokens and attention sinks (Xiao et al., 2024b), heavy hitters (Zhang et al., 2023), page-level bounds (Tang et al., 2024), learned or hashed signatures (Desai et al., 2025), or approximate nearest neighbors of the query (Liu et al., 2025a; Chen et al., 2026b).

These heuristics do not control the error of an individual query, and on real KV caches this error has a heavy tail. On ten settings from 16K to 128K tokens, the best of 15 baseline families, reading as many keys as our method, has a 90th-percentile error of 0.051–0.090 relative to the value scale but maximum errors of 0.4–1.6 (Section 6.2). Sampling-based methods add randomness, but not a finite-sample certificate for each query. vAttention (Desai et al., 2026) sizes a uniform sample under a central-limit approximation, MagicPIG (Chen et al., 2025) samples keys by locality-sensitive-hashing collision probabilities, and SANTA (Lee et al., 2026a) samples values from the exact softmax.

We ask whether sparse attention can read few keys and still certify its error at every step. Suppose that each key ii carries a perturbation Ei∼Exp(1)E_i \sim \text{Exp}(1) drawn independently of the query, and let wi=esi−c∗w_i = e^{s_i - c^*} be its unnormalized attention weight. Then the keys whose perturbed score si−c∗+Eis_i - c^* + E_i exceeds log⁡τ\log \tau

(a) Perturbed retrieval is PPS sampling

Figure

(b) One query of a GQA group (Algorithm 1)

Figure

Figure 1. (a) Each key ii carries a perturbation Ei∼Exp(1)E_i \sim \text{Exp}(1), drawn afresh at every decoding step, and is in the sample at threshold τ\tau exactly when its perturbed score lies above the line of τ\tau, which happens with probability min⁡(1,wi/τ)\min(1, w_i/\tau); lowering τ\tau only adds keys (shades give the level at which a key enters). (b) One query of a GQA group (Algorithm 1, Appendix B). The shared 4-bit scan bounds every score, so its candidates contain the sample; 8-bit refinement and exact keys decide which candidates enter S(τj)S(\tau_j), and the values of sampled keys give the Horvitz–Thompson estimate. Each head stops at the first level whose error bound βj\beta_j (Lemma 1) meets the target, and Pr[certified and ∥o^m−om∥>εM]≤δ\text{Pr}[\text{certified and } \|\hat{o}_m - o_m\| > \varepsilon M] \leq \delta (Theorem 4). Synthetic data; logarithms in (a) are base 2.

form a Poisson sample that contains key i with probability min⁡(1,wi/τ)\min(1, w_i/\tau). This is threshold sampling with probabilities proportional to size (PPS) (Duffield et al., 2005, 2007), under which the Horvitz–Thompson (HT) estimates (Horvitz and Thompson, 1952) of the softmax numerator and denominator are unbiased. Lowering τ\tau only adds keys, so we descend a geometric grid of thresholds and stop as soon as a confidence bound, valid simultaneously over all levels, meets the target (Figure 1).

We certify the error of the resulting estimate per head and decoding step, with finite-sample bounds that stay valid at a data-dependent stopping level (Sections 3–4). At a suitable threshold, 2ε−2log⁡(4/δ)(1+o(1))2\varepsilon^{-2} \log(4/\delta)(1 + o(1)) values reach error εM\varepsilon M with probability 1−δ1 - \delta independently of the context length, which is optimal up to constants; our stopping rule, which does not know this threshold, reads more (Section 5). A shared 4-bit scan recovers the sample exactly but reads every key (Section 4.4). On three LLMs and ten settings, we compare with 15 baseline families at matched keys and bytes, end to end, and in speed on CPU (Section 6). The certificates read 1.8−3.5×1.8 - 3.5 \times the keys of an uncertified central-limit rule, and the linear scan sets a floor on the bytes read. At equal bytes, the strongest baselines reach our typical error and our end-to-end quality, while their largest errors stay at least 4.9×4.9 \times ours (Sections 6.2 and 7).