Manuscript Offprint

arXiv:2610.35020

Attention under Bounded Key-Query Similarity: Space Complexity and Transformer Anisotropy

Justin Y. Chen, Ying Feng, Piotr Indyk, Michael Kapralov, Ekaterina Kochetkova, Boris Prokhorov

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

A growing body of work on KV-cache compression aims to reduce the memory requirements of autoregressive generation. These methods compress the stored context while approximately preserving attention computation, enabling generation with reduced memory consumption. Almost tight theoretical results on the worst case space complexity of attention have recently been obtained, but they are achieved by instances where queries can be perfectly aligned with keys. This directly contradicts the observed anisotropy of the key/query geometry in real transformers. In particular, it has been shown empirically that key/query cosine similarities are small even for most correlated pairs, i.e., near-perfect alignment of queries with keys does not happen in practice. In this paper, we study the space complexity of attention approximation under the assumption that key/query cosine similarities belong to a small interval around zero, i.e., a query cannot align too much with any key. We give a nearly space optimal algorithm and a corresponding space lower bound. Surprisingly, the distribution of key/query cosine similarities in our lower bound exhibits the anisotropy property empirically established and studied in the literature. Additionally, we show that the simple uniform sampling algorithm is nearly optimal for a typical range of parameters, supporting its surprising effectiveness on real datasets.

1 INTRODUCTION

The high memory consumption of modern large language models (LLMs) is a major challenge in their deployment, as the decoding stage of transformers requires storage of all tokens seen so far. The growing body of work on Key-Value (KV) cache compression has been proposed to address this challenge. These algorithms rely on innovative ways of approximating the attention function of the context using small space, either by quantizing the vectors, or evicting some of them to retain the most informative ones. In both cases, the goal is to approximate the value of the attention function:

Attn(K,V,q)=∑i=1ne⟨ki,q⟩/dvi∑i=1ne⟨ki,q⟩/d.(1)\mathrm{Attn}(K,V,q)=\frac{\sum_{i=1}^{n}e^{\langle k_{i},q\rangle/\sqrt{d}}v_{i}}{\sum_{i=1}^{n}e^{\langle k_{i},q\rangle/\sqrt{d}}}. \tag{1}

where K=(k1,…,kn)⊂RdK = (k_1, \ldots, k_n) \subset \mathbb{R}^d is the set of all keys, V=(v1,…,vn)⊂RdV = (v_1, \ldots, v_n) \subset \mathbb{R}^d is the set of corresponding values and query q∈Rdq \in \mathbb{R}^d is the query.

We consider randomized algorithms for token eviction that are query-oblivious. That is, before seeing the specific query, the algorithm constructs a weighted summary by selecting a random subset of token indices I⊆[n]I \subseteq [n] together with positive weights wiw_i (and evicts the other tokens). Given a query qq, the algorithm returns

Attn^(K,V,q)=∑i∈Iwie⟨ki,q⟩/dvi∑i∈Iwie⟨ki,q⟩/d.(2)\widehat{\mathrm{Attn}}(K,V,q)=\frac{\sum_{i\in I}w_{i}e^{\langle k_{i},q\rangle/\sqrt{d}}v_{i}}{\sum_{i\in I}w_{i}e^{\langle k_{i},q\rangle/\sqrt{d}}}. \tag{2}

For every fixed query q, we require

Pr⁡[∥Attn^(K,V,q)−Attn(K,V,q)∥≤ε]≥23.(3)\Pr\Big[\|\widehat{\mathrm{Attn}}(K,V,q)-\mathrm{Attn}(K,V,q)\|\leq\varepsilon\Big]\geq\frac{2}{3}. \tag{3}

The probability is over the randomness used to construct the summary. The query is fixed independently of this randomness; we do not require simultaneous success for all queries. Assume that ∥ki∥≤rk\|k_i\| \leq r_k for every ii and ∥q∥≤rq\|q\| \leq r_q. We will assume ∥vi∥≤1\|v_i\| \leq 1.

Query-oblivious weighted token eviction (a.k.a. coresets) has been a subject of multiple recent theoretical investigations, leading to (almost) tight bounds on the worst case space complexity Haris & Onak (2025); Liberty et al. (2026); Chen et al. (2026), see Table 2 for details. These results show that an erkrq/de^{r_k r_q} / \sqrt{d} dependence in the space bound is sufficient and necessary. While these results are close to optimal in the worst case, some of their implications significantly deviate from what one sees in practical instances:

  1. The space lower bound of erkrq/de^{r_k r_q} / \sqrt{d} can be much larger than the size of the input itself, given that the values of rkr_k, rqr_q are often on the order of 15 - 20 (see, for example, Table 3 in Kochetkova et al. (2025) and our Figure 9) and d=128d = 128; in such cases, the upper bound becomes vacuous.

  2. The hard distribution of the keys used to prove the lower bounds is isotropic, whereas in practice, keys and queries are known to be anisotropic, concentrating in a relatively narrow cone of the high-dimensional space Godey et al. (2024).

  3. The worst case hard instances have the queries align perfectly (i.e., have a high dot product) with one of the keys; in contrast, in practice, the key-query cosine similarity is small in absolute value once the attention sink is excluded and stored separately (see e.g., Mazaré et al. (2025) and our Figure 1).

References (46)

  • Efficient coreset constructions via sensitivity sampling
  • PyramidKV: Dynamic KV cache compression based on pyramidal information funneling
  • Palu: KV-cache compression with low-rank projection
  • Towards tight bounds for streaming attention, 2026 (opens arXiv in a new tab)
  • Fast approximation of matrix coherence and statistical leverage
  • Cartridges: Lightweight and general-purpose long context representations via self-study, 2025 (opens arXiv in a new tab)
  • Ada-KV: Optimizing KV cache eviction by adaptive budget allocation for efficient LLM inference
  • Anisotropy is inherent to self-attention in transformers (opens the publisher in a new tab)
  • Compression barriers in autoregressive transformers
  • KVQuant: Towards 10 million context length LLM inference with KV cache quantization
  • Streaming attention approximation via discrepancy theory
  • SnapKV: LLM knows what you are looking for before generation
  • Nearly optimal attention coresets (opens arXiv in a new tab)
  • Scissorhands: Exploiting the persistence of importance hypothesis for LLM KV cache compression at test time
  • KIVI: A tuning-free asymmetric 2bit quantization for KV cache
  • Inference-time sparse attention with asymmetric indexing (opens arXiv in a new tab)
  • Convex optimization, volume 1
  • Random Attention: Rethinking KV Cache Eviction for Efficient Reasoning
  • Efficient streaming language models with attention sinks
  • SubGen: Token generation in sublinear time and memory (opens arXiv in a new tab)
  • TurboQuant: Online vector quantization with near-optimal distortion rate
  • H2O: Heavy-hitter oracle for efficient generative inference of large language models
  • The gradient formula follows by differentiation
  • If it is bounded, it is compact
  • The uniform sampling procedure described above retains at most
  • We write the attention error vector as
  • By Equation (5), we have $D \geq e^{aR^2}$
  • Bounding $\langle k_j, q_i \rangle - \langle k_i, q_i \rangle$ by Equation (9) and Equation (10), we get
  • Since all value vectors have unit norm, the triangle inequality gives
  • On $H_i^c$, the nonnegative coreset weights imply that
  • Since $v_i$ is a unit vector, another application of the Cauchy-Schwarz inequality gives
  • The sampled denominator and numerator in (13) are
  • The sensitivity upper bound gives
  • We let $q_i$ be a maximizing query for token $i$; these $q_1, \ldots, q_n$ need not be the same
  • Combining this with $\sigma_i / \lambda_i = \sum_{j=1}^n \sigma_j$, we have
  • Whenever $\widetilde{Q}_{uv}$ is nonempty, it is the logarithm of the reciprocal of token $i$'s attention weight within $I_u$, so
  • Applying Lemma 15 with $\eta = \log 2$, we obtain $z_i^{uv} \in \widetilde{Q}_{uv}$ satisfying
  • Since $0 \in Q$, we have $\sigma_i \geq 1/n$, so the scores are positive
  • The product of these bounds, divided by $\sqrt{d}$, is $B_{uv}$
  • Theorem 4 (Lower bound, Item 2)
  • By Equation (24)
  • On the complementary event, the approximation at $q_i$ is a convex combination of the value vectors $v_j$ with $j \neq i$
  • Projecting the error onto the unit vector $v_i$ yields, whenever $H_i$ does not hold
  • Rows show Llama 3.1 8B, Qwen3 8B, Ministral 3 8B; columns show layers 4, 8, 16, 24
  • Cosines are computed after model normalization and RoPE
  • Layer 8 on the LongBench v2 input (8,192 tokens)