Summary (Overview)

  • Core innovation: The paper introduces a certified sparse attention method that perturbs each key's score with an independent Exp(1) variable, transforming threshold retrieval into probability-proportional-to-size (PPS) sampling. This enables unbiased Horvitz–Thompson estimation of the softmax output with finite-sample error certificates that hold simultaneously across all threshold levels.
  • Key theoretical guarantee: At a suitable threshold, the estimator reads O(ε−2log⁡(1/δ))O(\varepsilon^{-2}\log(1/\delta)) values regardless of context length, which is proven optimal up to constants via a matching lower bound. The anytime-valid certificates ensure each attention head's error exceeds ε\varepsilon with probability at most δ\delta per decoding step.
  • Empirical validation: Across three LLMs and ten settings at 16K–128K tokens, no certificate was violated. At equal keys read, the method achieves 4.6–7.9× lower 90th-percentile error than the best of 15 baseline families, while eliminating the heavy error tail (max errors ≤ 0.029 vs. baselines' 0.39–1.62).
  • Efficiency: A 4-bit scan with deterministic bounds generates candidates exactly, reading only 16.4% of dense attention's bytes for metadata. On CPU, decoding steps at 32K–128K tokens run 1.1–1.4× faster than dense attention.
  • End-to-end quality: The method stays within one point of dense attention on tasks and within 0.1% in PG-19 perplexity, with 79–98% of outputs identical to dense attention's.

Introduction and Theoretical Foundation

Background and Motivation

Sparse attention aims to accelerate long-context decoding by reading only a small fraction of the KV cache. For Llama-3.1-8B with a 128K-token context, each decoding step requires reading ~16 GiB of 16-bit keys and values, making memory bandwidth the bottleneck. Existing heuristic methods—such as attention sinks, heavy hitters, page-level bounds, and approximate nearest neighbors—do not control per-query error, which exhibits heavy tails on real KV caches (90th-percentile errors of 0.051–0.090 but maxima of 0.4–1.6 for the best of 15 baselines).

Theoretical Foundation

The key insight is that perturbing each key's score with an independent exponential variable enables principled sampling. For each key ii with perturbation Ei∼Exp(1)E_i \sim \mathrm{Exp}(1) and unnormalized attention weight wi=esi−c∗w_i = e^{s_i - c^*}, the perturbed score threshold condition si−c∗+Ei≥log⁡τs_i - c^* + E_i \geq \log \tau holds with probability min⁡(1,wi/τ)\min(1, w_i/\tau). This creates threshold (Poisson PPS) sampling, under which Horvitz–Thompson estimates of the softmax numerator and denominator are unbiased. Lowering τ\tau monotonically adds keys, enabling a geometric grid search where each head stops at the first level whose certificate meets the target error.

Methodology

Problem Setup

For a fixed layer, KV head, and decoding step with nn cached keys kik_i and values viv_i:

  • Scores: si=q⊤ki/ds_i = q^\top k_i/\sqrt{d}, maximum c∗=max⁡isic^* = \max_i s_i
  • Unnormalized weights: wi=esi−c∗∈(0,1]w_i = e^{s_i - c^*} \in (0,1]
  • Denominator: D=∑iwiD = \sum_i w_i, Numerator: N=∑iwiviN = \sum_i w_i v_i
  • Attention output: o=N/Do = N/D, attention weights: ai=wi/Da_i = w_i/D

Error is measured on three scales: denominator (∣D^−D∣≤εD|\hat{D} - D| \leq \varepsilon D), output norm (∥o^−o∥≤ε∥o∥\|\hat{o} - o\| \leq \varepsilon\|o\|), and value scale (∥o^−o∥≤εM\|\hat{o} - o\| \leq \varepsilon M, where M2=∑iai∥vi∥2M^2 = \sum_i a_i\|v_i\|^2). The value scale is κ=M/∥o∥\kappa = M/\|o\| times the output norm.

Algorithm Components

1. Perturbed threshold sampling. The KV cache is split into a window (recent 64 tokens, always read exactly) and a pool. Each pool key has perturbation Ei=−ln⁡uiE_i = -\ln u_i from a 53-bit uniform hash. The sampled set at threshold τ\tau is:

S(τ)={i∈P:si−c∗+Ei≥log⁡τ}S(\tau) = \{i \in P: s_i - c^* + E_i \geq \log \tau\}

2. Horvitz–Thompson estimation. Light keys have inclusion probability wi/τw_i/\tau, giving HT weights τ\tau:

D^=DR+DB+τk,N^=NR+NB+τ∑i∈S∩Avi\hat{D} = D_R + D_B + \tau k, \qquad \hat{N} = N_R + N_B + \tau \sum_{i \in S \cap A} v_i

3. Anytime-valid certificates. On grid τj=2−j/r\tau_j = 2^{-j/r} with failure budgets δj=δ/((J+1)e˙)\delta_j = \delta/((J+1)\dot{e}), the algorithm computes:

  • Denominator interval: Chernoff bounds on the Poisson-binomial sample count
  • Centered numerator: Bernstein inequality in Hilbert space on the centered sum Zc=∑i∈A(τXi−wi)(vi−c)Z_c = \sum_{i\in A}(\tau X_i - w_i)(v_i - c)
  • Output error bound: β=(ζ+∥o^−c∥dD)/(D^−dD)\beta = (\zeta + \|\hat{o} - c\|dD)/(\hat{D} - dD)
  • Stopping rule: Stop at first certified level meeting target error

4. Candidate generation. A 4-bit per-block-per-channel quantization (as in KIVI) with AVX-512 VNNI provides deterministic upper bounds ui≥siu_i \geq s_i for all scores. Candidates are bucketed by earliest possible inclusion level via counting sort, with 8-bit refinement and exact 16-bit reads only for keys that may enter the sample. Exact maximum computation covers only 0.1–1% of the pool.

Empirical Validation / Results

Error at Matched Keys Read

Table 1. Error/​M at matched keys read (ε = 0.1; baselines read ≤ 1.1× our keys).

Model · dataOurs: keys / p90 / maxFamiliesBest baseline: keys, p90 / maxRatio (p90)Error/‖o‖ p90: ours / best
Llama · LongBench 16K2.70% / 0.011 / 0.02111/15MagicPIG 2.75%, 0.059/0.835.3×0.087/0.311 (3.6×)
Llama · RULER 32K1.35% / 0.011 / 0.02510/15RetroInfer 1.24%, 0.058/0.495.0×0.075/0.287 (3.8×)
Llama · RULER 64K0.70% / 0.012 / 0.02814/15RetroInfer 0.58%, 0.059/0.685.1×0.076/0.294 (3.8×)
Llama · LongBench-v2 64K0.61% / 0.011 / 0.02112/15RetroInfer 0.57%, 0.051/0.394.6×0.085/0.277 (3.2×)
Llama · RULER 128K0.46% / 0.012 / 0.02912/15RetroInfer 0.47%, 0.077/0.656.5×0.073/0.352 (4.8×)
Llama · LongBench-v2 128K0.42% / 0.012 / 0.02212/15RetroInfer 0.32%, 0.069/0.655.9×0.081/0.340 (4.2×)
Qwen3 · LongBench 16K2.15% / 0.010 / 0.02110/13RetroInfer 1.67%, 0.072/1.467.2×0.049/0.270 (5.5×)
Qwen3 · RULER 32K1.50% / 0.011 / 0.02510/13RetroInfer 1.37%, 0.073/1.626.9×0.046/0.252 (5.5×)
Qwen2.5 · LongBench 16K2.67% / 0.011 / 0.02211/13RetroInfer 2.26%, 0.072/0.956.6×0.057/0.308 (5.4×)
Qwen2.5 · RULER 32K1.73% / 0.011 / 0.02710/13RetroInfer 1.22%, 0.090/0.987.9×0.054/0.333 (6.2×)

Certificate Validity

Across 120 configurations (10 settings × 3 measures × 4 values of ε), no certificate was violated, no layer had a violation, and no head fell back to exact attention. Certificates are conservative: observed errors are about ε/10 at the 90th percentile, with largest errors 0.31ε (value scale) and 0.41ε (output norm).

End-to-End Performance

Table 2. End-to-end score change versus dense attention.

Model · dataKeys readΔ score [95% CI]Same output as dense
Llama · LongBench (300)5.26%−0.29 [−0.63, −0.03]0.80
Llama · RULER 32K (200)1.50%−0.65 [−2.05, +0.35]0.93
Llama · RULER 64K (100)0.78%0.00 [0.00, 0.00]0.98
Llama · RULER 128K (48)0.49%0.00 [0.00, 0.00]0.90
Qwen3 · LongBench (150)5.10%+0.17 [+0.06, +0.28]0.80
Qwen3 · RULER 32K (100)1.53%+1.00 [−0.20, +3.10]0.85
Qwen2.5 · LongBench (150)5.38%+0.07 [−0.09, +0.25]0.79
Qwen2.5 · RULER 32K (100)1.73%−0.10 [−0.30, 0.00]0.83

PG-19 perplexity changes by only −0.02% to +0.07% with KL divergence 0.0002–0.0006 from dense attention, whereas oracle top-k reading the same keys raises perplexity by 4.8–11.5%.

CPU Speed

Attention speedups over dense attention: 1.8–3.5× at 64K–128K and 1.0–2.1× at 16K–32K on Llama. Whole fp32 decoding steps are 1.1× faster at 32K and 1.4× at 128K. Fresh perturbations add a median 4% overhead.

Theoretical and Practical Implications

Theoretical Contributions

Theorem 1 (Unbiasedness and variance). ED^=D\mathbb{E}\hat{D} = D, EN^=N\mathbb{E}\hat{N} = N, with Var D^≤τDA\mathrm{Var}\,\hat{D} \leq \tau D_A and E∥Zc∥2≤τGA(c)\mathbb{E}\|Z_c\|^2 \leq \tau G_A(c).

Theorem 2 (Sample size independent of context). With τ=D/m\tau = D/m and probability at least 1−δ1-\delta:

∥o^−o∥≤σv2L/m+2RoL/(3m)1−η\|\hat{o} - o\| \leq \frac{\sigma_v\sqrt{2L/m} + 2R_o L/(3m)}{1 - \eta}

where L=ln⁡(4/δ)L = \ln(4/\delta), η=2L/m+L/(3m)\eta = \sqrt{2L/m} + L/(3m), σv2=M2−∥o∥2\sigma_v^2 = M^2 - \|o\|^2. Thus m=2Lε−2(1+o(1))m = 2L\varepsilon^{-2}(1+o(1)) values suffice for error εM\varepsilon M, independent of nn.

Theorem 3 (Lower bound). Any algorithm reading at most mm values requires m≥(κ2−1)ln⁡(1/(6δ))/(8.8ε2)m \geq (\kappa^2 - 1)\ln(1/(6\delta))/(8.8\varepsilon^2) for output-norm error and m≥ln⁡(1/(6δ))/(17.6ε2)m \geq \ln(1/(6\delta))/(17.6\varepsilon^2) for value-scale error, proving the PPS estimator is optimal up to constants.

Theorem 4 (Anytime-valid certificates). For each query head and error measure:

Pr⁡[o^ is certified and its error exceeds ε]≤δ\Pr[\hat{o} \text{ is certified and its error exceeds } \varepsilon] \leq \delta

The proof intersects confidence events across all levels, making the data-dependent stopping level harmless.

Practical Implications

  • Reliability: The method eliminates the heavy error tail of heuristic sparse attention, guaranteeing per-call error bounds that scale to full generations via union bounds (δ/(HT)\delta/(HT) per call).
  • Efficiency floor: The 4-bit scan sets a floor of 16.4% of dense attention's bytes, which caps achievable speedups and allows baselines at equal bytes to match typical (but not worst-case) errors.
  • Conservativeness: Certificates read 1.8–3.5× more keys than uncertified central-limit rules; the gap represents the cost of statistical guarantees.

Conclusion

This work demonstrates that exponential perturbations transform threshold retrieval into weight-proportional sampling, enabling a sparse attention kernel that estimates unbiasedly and certifies each call's error. The certificates held in every configuration tested across three LLMs and ten settings, removing the heavy error tail of heuristic approaches. While end-to-end task quality matches the strongest baselines at equal bytes, the method uniquely provides per-call guarantees and closer agreement with dense attention during sampling. The main limitation is the linear candidate-generation scan, which sets a bytes floor; a sublinear index with recall guarantees would remove this bottleneck. The method does not cover closed-loop generation with fixed perturbations, and deployments should not present it as a guarantee of unchanged model behavior—only as per-head, per-step error certificates with probability at least 1−δ1-\delta.

Related papers