WorksComputer Science
Attention under Bounded Key-Query Similarity: Space Complexity and Transformer Anisotropy
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.
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:
where is the set of all keys, is the set of corresponding values and query 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 together with positive weights (and evicts the other tokens). Given a query , the algorithm returns
For every fixed query , we require
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 for every and . We will assume .
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 [9]; Liberty et al. [13]; Chen et al. [4], see Table 2 for details. These results show that an 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:
Table 2. Worst-case space complexity of attention. , suppress poly() factors.
The space lower bound of can be much larger than the size of the input itself, given that the values of are often on the order of (see, for example, Table 3 in Kochetkova et al. [11] and our Figure 9) and ; in such cases, the upper bound becomes vacuous.
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. [8].
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. [16] and our Figure 1).
Figure 1. Cosine similarities between the final 256 queries and preceding context keys in layer 8 of Qwen3-8B, for an 8K-token LongBench v2 input, excluding the first key (attention sink).
Figure 9. Key and query magnitudes across models. Layer 8 on the LongBench v2 input (8,192 tokens). Columns show Llama 3.1 8B, Qwen3 8B, Ministral 3 8B. The top row uses 7,935 keys per model: all eligible earlier-context keys. Blue baseline marks indicate the initial key (attention sink) norm in each model. The bottom row uses the final 256 queries.
Our results
Reflecting this discrepancy, we study the space complexity of attention approximation under the following assumption:
Every key/query cosine similarity lies in some range , where the magnitudes , i.e., no query can align significantly with any key.
Before we state our main theorem, we need to introduce some notation. Fix radius parameters . Suppose for every , and fix a pair of parameters . We take the admissible query set to be
Let denote the optimal worst-case number of retained tokens subject to
for every fixed admissible . The algorithm knows keys, values, and parameters , but not the particular query in . All norms are Euclidean, and all logarithms are natural. We use to suppress factors polylogarithmic in .
Our main result shows that importance sampling is a nearly optimal token eviction policy for attention approximation. Surprisingly, for a wide range of parameters (see Figure 2) all importance weights can be set to , i.e. the most basic uniform sampling is optimal. Formally, we define two regions in the space of parameters , see also Figure 2 for an illustration:

Figure 2. Uniform sampling and importance sampling regions in parameter space.
Definition 1 (Uniform & importance sampling regimes). We say that fixed parameters lie in the uniform sampling regime if and .
We say that fixed parameters lie in the importance sampling regime in any other case.
Our main result is as follows.
Theorem 2. Fix any constant independently of , and assume . Fix parameters and . Suppose for every key, and the admissible query set is described as Equation (4). Let , then
In the uniform sampling regime, uniform sampling achieves asymptotically tight space bounds:
In the importance sampling regime, importance sampling achieves asymptotically tight space bounds:
Theorem 2 is achieved by uniform sampling when the key/query cosine similarities are small ( and ), and by an importance sampling scheme for larger cosine similarities. Interestingly, even though uniform sampling is by no means the best token eviction policy, it is quite competitive with some earlier works on token eviction for KV cache compression, especially query-independent ones. See, for example, Table 1 in Kochetkova et al. [11] for a comparison of SnapKV and BalanceKV with uniform sampling. The recent work of Wang et al. [18] provides more evidence for this phenomenon. Figure 2 helps explain this from the perspective of theory: the empirical values for widely used models lie in or close to the uniform sampling regime.
| Model | Layer 4 | Layer 8 | Layer 16 | Layer 24 |
| Llama 3.1 8B | ||||
| Qwen3 8B | ||||
| Ministral 3 8B |
Table 1. Cosine similarity between mean query and key vectors. Values are means standard deviations across example/context-length configurations common to all models and layers.
In addition to the theorem statement, the proof of the theorem provides insights into another empirical phenomenon. Specifically, the anisotropy of the key/query space that has been empirically observed in the literature Godey et al. [8] appears naturally in our lower bound instance. In our hard input distribution on key and query vectors, the keys and queries are similarly distributed except that the keys are positively shifted along a specific direction while the queries are negatively shifted along . This construction, which is critical to establishing a matching space lower bound, is indeed anisotropic: the keys have a large positive projection on a common direction, and the queries have a large negative projection on the same direction, similarly to distributions observed in practice (Table 1, Figure 5). See § 2.2 for more details.
Figure 5. Query-key geometry in Llama 3.1 8B on LongBench v2 example (8K context, layer 8, head 0). A joint PCA is fitted with equal total weight for queries and keys. Initial-token (attention sink) is excluded. See Section F.1 for further plots.
Related work
Related work on worst-case space complexity of attention approximation. Prior work (Haris & Onak, [9]; Liberty et al., [13]; Chen et al., [4]) has established nearly tight asymptotic bounds on the space complexity of approximating attention in the worst case. The algorithmic landscape is diverse, with approaches drawing on sketching, random sampling, discrepancy theory, and kernel-density estimation. Provable attention approximation has also led to implemented KV cache compression methods. SubGen (Zandieh et al., [20]) combines online key clustering with sampling of values to obtain approximation guarantees that exploit clustering structure, and evaluates its implementation on long-context question-answering tasks. BalanceKV Kochetkova et al. [11] develops a streaming compression algorithm based on geometric discrepancy and vector balancing, with both theoretical guarantees and empirical evaluations of attention approximation and end-to-end generation on long-context benchmarks. A comparison is given in Table 2. We note that the worst case setting is crucially different from our setup in that queries can be arbitrarily well aligned with key.
Related work on KV cache compression. We mention the lines of the most relevant work.
KV subset selection. A prominent approach to KV-cache compression retains a subset of the original key-value pairs. HO combines accumulated-attention heavy hitters with recent tokens Zhang et al. [22], while Scissorhands uses token importance that persists across decoding steps Liu et al. [14]. StreamingLLM keeps initial attention sinks and a sliding window of recent tokens Xiao et al. [19]. SnapKV selects KV positions per head before generation using a window at the prompt’s end Li et al. [12]. PyramidKV splits a fixed cache budget across layers Cai et al. [2], while Ada-KV splits it across heads using an attention-output error bound Feng et al. [7]. These approaches exploit historical attention, prompt observations, or layer/head structure, rather than establishing optimal retained-token complexity under an explicit restriction on future key-query similarities.
Compressed KV representations. Another line of work reduces storage per cached vector. KIVI quantizes keys per channel and values per token Liu et al. [15]. KVQuant combines distribution-aware quantization, pre-RoPE key quantization, and separate outlier handling Hooper et al. [10]. TurboQuant uses random rotations for data-oblivious vector quantization, with guarantees on mean-squared and inner-product distortion Zandieh et al. [21]. Palu caches low-dimensional intermediate representations from low-rank factorizations of key/value projections Chang et al. [3]. Cartridges learns context representations through self-study Eyuboglu et al. [6]. These representations fall outside our weighted-subset model, so our retained-token lower bounds do not apply to arbitrary quantized or low-rank encodings.
Random KV eviction. Wang et al. [18] propose a method that reserves cache space for the input prompt and the most recent tokens, then fills the remaining slots by uniform random sampling, independently across KV heads at each eviction event. Their method is competitive with importance-based policies on reasoning benchmarks, providing further evidence that random sampling can be effective in practice.
Uniform sampling regime
Upper Bound
The upper bound in the small cosine similarities regime is shown by a simple approach: sampling tokens uniformly.
Consider the small cosine similarities regime of Theorem 1, where and . Our assumptions are , , and
We write . Set . If , retain the full dataset. Otherwise, sample tokens independently and uniformly with replacement. Writing for their

Figure 3. Empirical bounds and for 8B models Llama 3.1, Qwen3, and Ministral 3. Each point represents one context (from LongBench v2/InfiniteBench/SCBench)–context-length (8/32/128/256 k)–layer (4/8/16/24) configuration, with endpoints and computed as 0.001 and 0.999 quantiles of cosine similarities distribution. Initial-token (attention sink) is excluded. See Section F.1 for more plots.
Figure 6. Query–key cosine similarities across models and attention layers. Rows show Llama 3.1 8B, Qwen3 8B, Ministral 3 8B; columns show layers 4, 8, 16, 24. All panels use the same prepared LongBench v2 example. Each panel uses an input of 8,192 tokens and compares the final 256 queries from query head 0 against 7,935 earlier-context keys from the corresponding KV head 0. The initial key is excluded. Cosines are computed after model normalization and RoPE.
indices, return the estimate
The intuition behind uniform sampling is that no individual token can account for too large a fraction of the attention mass. Indeed, for every and every admissible query ,
Thus, the attention denominator is at least , whereas the contribution of any individual token is at most . Consequently, each token accounts for at most an fraction of the attention mass.
Lemma 1 (Upper bound, Item 1). The uniform sampling procedure described above retains at most
tokens and gives an additive- approximation to attention with probability at least 2/3 for each fixed admissible query.
We defer the full proof of Lemma 1 to Section B. We use Chebyshev’s inequality to bound the attention denominator, and use Markov’s inequality to bound the numerator of the error.
Lower Bound
Recall that in our model (2), the token-eviction algorithm (randomly) selects tokens and assigns them nonnegative weights before seeing the query. We will prove lower bounds against such algorithms.
Theorem 3 (Lower bound, Item 1). Consider , , and in the uniform sampling regime (Theorem 1). Consider and , and let . Pick any integer satisfying
There is a fixed dataset of key-value pairs, with keys of norm and unit-norm values in , together with queries of norm , such that every key satisfies
For this dataset, satisfying Equation (3) at each of these queries requires .
Our lower bound constructs groups of identical key-value pairs, each paired with a different query. A visualization of the construction is given in Figure 4. For each group, we build the key and corresponding query from a set of nearly orthogonal vectors (Lemma 2):
Figure 4. A visualization of the hard instance in our lower bound construction. The keys and queries are shifted away from each other along direction . Orthogonal to , each key-query pair follows its own common direction .
Lemma 2 (Nearly orthogonal vectors). Consider integer and . Let be an integer such that . There exist unit vectors such that for every .
To see this, choose independently and uniformly from , so that each vector has unit norm. Hoeffding’s inequality and a union bound show that the probability of any pair satisfying is at most under the assumed bound on . We give the full proof in Section C.
In order to keep all key-query cosine similarities in , queries and keys are anisotropically shifted away from each other along a fixed direction . A pair of keys and queries in the same group are (a weighted version of) where the sign on differs for the key and query (along with a normalization term to set their respective norms to ).
Each query has similarity with its own group’s key , while the near orthogonality caps its similarity close to with the other groups’ keys . The exponential in attention amplifies this gap, giving the query’s own group almost all the attention mass. We also choose nearly orthogonal value vectors, so a convex combination of other groups’ value vectors cannot well-approximate attention. The algorithm must therefore retain a key-value pair from each group with constant probability, otherwise it would fail with probability more than on some group’s query.
The resulting construction holds an intriguing connection to patterns in real data. In Figure 5, we see that queries and keys are separated along a common direction and otherwise hold a somewhat similar distribution though with different scales for queries and keys. These qualities also appear in our hard instance (Figure 4).
Lower bound construction
Goal. We construct keys and queries whose scaled inner products are for matching pairs and for nonmatching pairs , where . In Section C.1, we use this gap to make each query concentrate its attention on copies of its matching key, forcing an accurate summary to retain many key groups.
Construction. Let be the first three standard basis vectors. Choose unit vectors satisfying Lemma 2 in dimension , with pairwise inner products bounded in magnitude by . Embed them into the last coordinates of , and denote the resulting vectors by . Define
where and . Specifically, we set
We have since . Since and are fixed and , for sufficiently large we have , so . Moreover, . Therefore, and the keys and queries are well defined with norms exactly equal to and . The components along and serve the purpose of achieving the desired inner products while the padding along and increases the norms of the keys/queries to fix the denominator of cosine similarity.
Verifying the inner products. For every , . For matching pairs, gives
For nonmatching pairs, gives
Constructing the value vectors. Apply Lemma 2 a second time to obtain unit value vectors satisfying
Since , the assumption ensures that this is possible. The final proof of the coreset size lower bound using these key, query and value vectors is given in Section C.
Importance sampling regime
Upper Bound
When the interval is wide, the exponential in attention can make a few tokens much more influential than the rest. To account for this, uniform sampling would need to retain many tokens. We thus use importance sampling instead. Unlike uniform sampling, which treats all tokens equally, importance sampling gives higher sampling probabilities to tokens that can contribute more to attention. This is a standard idea in randomized linear algebra through leverage-score sampling Drineas et al. [5] and in coreset construction through sensitivity sampling Braverman et al. [1].
Since we sample before seeing the query, we want to sample a token with probability proportional to the largest possible attention it could receive. This quantity is its sensitivity: for a nonempty query set containing all admissible queries, define
Unfortunately, these sensitivities may be difficult to compute exactly. Instead, it suffices to use sampling scores , i.e., upper bounds of each sensitivities. In the sampling procedure, we sample each token with probability , where . We set the number of samples proportional to , so smaller sampling scores yield a smaller sample size. This leaves two tasks: compute valid sampling scores and show that their sum is small.
We formalize the sampling procedure in Algorithm 1. For each sampled token , we retain the corresponding key-value pair together with a positive weight. If we sample the same token more than once, we keep one copy and add the weights together.
Algorithm 1 Attention compression by score-based sampling and reweighting
Require: key-value pairs $(k_1,v_1),\ldots,(k_n,v_n)$, accuracy $0 < \varepsilon < 1$, and sampling scores $s_1,\ldots,s_n > 0$
1: $S \leftarrow \sum_{i=1}^{n} s_i,\quad m \leftarrow \lceil 96S/\varepsilon^2\rceil$
2: if $m \ge n$ then
3: return $\{(k_i,v_i,1):i\in[n]\}$
4: end if
5: $\pi_i \leftarrow s_i/S$ for every $i\in[n]$
6: Subsample $m$ tokens using probabilities $\pi_i$ ▷ with replacement
7: $c_i \leftarrow$ number of times token $i$ was sampled
8: return $\{(k_i,v_i,c_i/(m\pi_i)):c_i>0\}$ ▷ one copy per token
We refer to the set returned by Algorithm 1 as the summary. Given a query , the summary produces an estimator
where denotes the set of retained token indices. The denominator is positive, since the summary is nonempty and all retained weights are positive.
We first state the approximation guarantee of Algorithm 1. Using a number of tokens proportional to , the estimator from Equation (13) approximates the attention with high probability.
Lemma 3 (Approximation guarantee). Suppose and for every . Then Algorithm 1 returns a weighted attention summary of size at most
For every fixed query , its estimate satisfies
where the probability is over the sampling in Algorithm 1.
We defer the full proof of Lemma 3 to Section D. Similar to the proof of Lemma 1, we use Chebyshev’s inequality to bound the attention denominator, and use Markov’s inequality to bound the numerator of the error.
Lemma 3 reduces the problem to constructing sampling scores whose sum is small. To this end, we first bound the total sensitivity of any query set for which all key-query inner products lie in a fixed interval. This condition is satisfied by our query set . However, need not be convex, making it difficult to compute sampling scores. We therefore partition the keys and possible query norms into small ranges and, for each pair of ranges, replace the cosine-similarity constraints by fixed inner-product bounds. This partitions the problem into a collection of smaller convex relaxations on which we can approximate the sensitivities. Applying the total-sensitivity bound to these relaxations allows us to control the sum . These two steps are formalized in Lemmas 4 and 5.
Lemma 4 (Total sensitivity bound). Suppose and for every , and let be a nonempty compact query set such that
For sensitivities defined in Equation (12) with the supremum taken over , we have
At a high level, the two terms in Equation (14) come from two different ways of controlling the total sensitivity. The first term follows from the fact that . For the second term, we pair each key with a query attaining its sensitivity and assign weights to these pairs proportionally to their sensitivities. Writing for the weighted mean key and query, using Jensen’s inequality, the proof gives
Averaging these two bounds yields . The full proof is deferred to Section D.
It remains to construct the sampling scores.
Lemma 5 (Computing sampling scores). Let and , and write , . Suppose for every , and
For sensitivities defined in Equation (12) with the supremum taken over , we can compute sampling scores satisfying for every , and
Moreover, such sampling scores can be obtained by solving convex optimization problems, using only the keys and the parameters .
The full proof is deferred to Section D.
We now combine the approximation guarantee (Lemma 3) with the sampling score bound (Lemmas 4 and 5) to prove the upper bound in the importance sampling regime.
Corollary 1 (Upper bound, Item 2). Under the assumptions of Lemma 5, fix independently of , suppose for every , and let . Then Algorithm 1, with the scores constructed there, retains at most
tokens and gives an additive- approximation to attention with probability at least for each fixed admissible query.
Proof. By Lemma 5, the sampling scores satisfy and , where . Since are fixed, is a constant. Substituting into Lemma 3 and absorbing into the implicit constant proves the upper bound.
Lower bound
The lower bound in the importance sampling regime uses the same construction and analysis as in the uniform sampling regime (§ 2.2). The only change in the theorem statement is that must satisfy
The full statement (Theorem 4) and proof are given in Section E.
Open Problems
The following questions naturally arise from our work:
Can we provably explain why transformers learn this geometry? In particular, under what assumptions on the data and training dynamics can we prove that small key–query cosine similarities and negative alignment between mean keys and queries emerge?
Do real KV caches have other structure that our model misses? Our hard instances share some geometric features with trained models, but real caches may have additional properties that make them easier to compress?
ACKNOWLEDGMENTS
JC,YF, PI, were supported in part by the NSF TRIPODS program (award DMS-2022448) and Wistron Corporation. Ekaterina Kochetkova and Boris Prokhorov were supported by the Swiss National Science Foundation grant 10004935 - Sublinear Algorithms for Non-linear Structures (Project MINT)
AI USE STATEMENT
In this work, we used generative AI tools to provide critical ingredients for proving mathematical claims in the importance sampling regime, assist in the writing of proofs, propose or refine hypotheses and implement methods.
We have not used generative AI tools to help formulate mathematical claims, develop theoretical models or conceptual frameworks, design or provide feedback on research methodology or experiments, interpret results, support qualitative and thematic data analysis. Generating synthetic data sets, cleaning and reformatting datasets and assisting with translation are not applicable to this work.
Additionally, we used generative AI tools for creating scientific figures, suggesting experimental parameters, creating software code, drafting parts of the paper, sourcing/searching for information, editing to improve readability, proposing a title for the paper.
We have reviewed all AI-assisted work. We checked LLM-generated parts of the proof and rewrote it ourselves. We take responsibility for the final content of this work, including text, claims or artifacts produced with the aid of generative AI.
Preliminaries
Standard Inequalities and Identities
We record several standard inequalities and identities used in the proofs.
Lemma 6 (Markov’s inequality). Let be a nonnegative random variable. Then, for every ,
In particular, for any random vector with finite second moment,
Lemma 7 (Chebyshev’s inequality). Let be a real-valued random variable with finite variance. Then, for every ,
Lemma 8 (Hoeffding’s inequality). Let be independent random variables such that for every . Define
Then, for every ,
Lemma 9 (Jensen’s inequality). Let satisfy , and let . Then
Lemma 10 (Cauchy-Schwarz inequality). Let , and let and be vectors in a Euclidean space. Then
Lemma 11 (Arithmetic-geometric mean inequality). For every ,
Lemma 12 (Weighted centering). Let and let be vectors in a Euclidean space. Let
Then
In particular, if , then
Convex Optimization
We record the convex optimization facts used to compute the sampling scores. The optimization guarantee below is stated in the oracle model.
Lemma 13. Let and . The function
is convex and continuously differentiable, with
The convexity statement follows from convexity of log-sum-exp and composition with an affine map; see Vandenberghe & Boyd [17]. The gradient formula follows by differentiation.
Lemma 14. A set defined by finitely many affine inequalities and constraints of the form
is closed and convex. If it is bounded, it is compact.
Proof. The function is continuous and convex. Thus its non-positive sublevel set is closed and convex, and these properties are preserved by intersection. Compactness follows from closedness and boundedness.
Lemma 15 (Additive-accuracy convex minimization). Let be a nonempty compact convex set, and let be continuous and convex. Then, for every , the convex optimization problem
admits an additive- solution; that is, there exists satisfying
Proof. Since is compact and is continuous, attains its minimum on . An exact minimizer is, in particular, an additive- solution.
Proofs from sec:upper-uniform
Lemma 1 (Upper bound, Item 1). The uniform sampling procedure described above retains at most
tokens and gives an additive- approximation to attention with probability at least for each fixed admissible query.
Proof. If the algorithm retains all tokens, the estimate is exact. Otherwise, fix an admissible query , we write the true average and the empirical average of kernels as
We will show that
where
for uniform samples . We write the attention error vector as
We will use Chebyshev’s inequality to bound the denominator, and use Markov’s inequality to bound the norm of the numerator. By Equation (5), we have . Moreover, since are independent,
where is uniform on . Thus, by Chebyshev’s inequality (Lemma 7),
On the other hand, we can bound the expected squared norm of the numerator as
Hence, by Markov’s inequality (Lemma 6), the probability that the numerator has norm larger than is at most .
Therefore, with probability at least , we have simultaneously and numerator norm at most , which implies .
Proofs from Section 2.2
Here we prove a standard lemma which is used in the lower bound about packing nearly orthogonal vectors in high dimensions.
Lemma 2 (Nearly orthogonal vectors). Consider integer and . Let be an integer such that . There exist unit vectors such that for every .
Proof. We will prove the result by a standard application of the probabilistic method. For all , choose each coordinate of each vector independently and uniformly from . Then, is a unit vector. Note that for any , is the sum of independent random variables with mean zero and bounded in magnitude by . Hoeffding’s inequality (Lemma 8) gives . A union bound over the pairs upper bounds the failure probability by
Therefore, such a set of vectors must exist.
Proof of thm:lb-attn
Here we present the proof of the lower bound in the uniform sampling regime. Refer to the main body in § 2.2 for the construction of key, query, and value vectors.
Proof. Each group will contain copies of the same key-value pair, with one additional copy in the first groups, so that and . For , let if and if . The attention instance will have copies of the key-value pair . By the setting of , there will be exactly key-value pairs. As , for all .
At distinct query , let be the attention mass on the copies of . Bounding by Equation (9) and Equation (10), we get
Recall the condition . Then, .
The attention output assigns mass to and total mass to the other value vectors. Since all value vectors have unit norm, the triangle inequality gives
Let be the event that the coreset retains at least one copy of . On , the nonnegative coreset weights imply that
Since by Equation (11) for every , we obtain
Since , the Cauchy-Schwarz inequality and Equation (15) give
On , we have already shown that . Since is a unit vector, another application of the Cauchy-Schwarz inequality gives
Hence success at the fixed query implies . Since answering accurately requires retaining a copy of , the success guarantee Equation (3) implies for every . Since each retained pair represents at most one group,
By definition, is the optimal worst-case number of tokens retained by an algorithm, so, from above, .
Proofs from sec:upperimportance
Lemma 3 (Approximation guarantee). Suppose and for every . Then Algorithm 1 returns a weighted attention summary of size at most
For every fixed query , its estimate satisfies
where the probability is over the sampling in Algorithm 1.
Proof. If the algorithm retains all tokens, the estimate is exact. Otherwise, fix and write
Thus . The sampled denominator and numerator in (13) are
Since each index is sampled with probability , we have and . The sensitivity upper bound gives
Using ,
Similarly, using independence and applying Lemma 12 to a centered sample, we obtain
where we used and (16).
Using Chebyshev’s inequality (Lemma 7) for and Markov’s inequality (Lemma 6) for , followed by a union bound, we obtain
hold together with probability at least , since .
On this event, . Also, because . Therefore,
where the last inequality uses . The algorithm retains at most tokens, which gives the stated size bound.
Lemma 4 (Total sensitivity bound). Suppose and for every , and let be a nonempty compact query set such that
For sensitivities defined in Equation (12) with the supremum taken over , we have
Proof. In this proof, we replace each key by and each query by . This preserves all inner products and hence all sensitivities, while giving both keys and queries the common norm bound . We use the same notation for the rescaled keys and query set.
Since is compact and the attention weights are continuous, for each there exists a query attaining the sensitivity of token . We let be a maximizing query for token ; these need not be the same.
Define
For each , applying Jensen’s inequality (Lemma 9, with each set to ) gives
By the definition of , . Combining this with , we have
Applying Equation (18) to the right-hand side,
We bound this expression in two ways. First, . Also, , since every belongs to . Hence
Second, centering the vectors (Lemma 12) gives , and the same bound holds for the queries. Applying Cauchy–Schwarz (Lemma 10) to (19), we obtain
The last two inequalities follow from the arithmetic-geometric mean inequality (Lemma 11) and Young’s inequality for inner products, , respectively. Averaging this bound with from (20) gives
Together with , this proves the lemma.
Lemma 5 (Computing sampling scores). Let and , and write , . Suppose for every , and let
For sensitivities defined in Equation (12) with the supremum taken over , we can compute sampling scores satisfying for every , and
Moreover, such sampling scores can be obtained by solving convex optimization problems, using only the keys and the parameters , , , .
Proof. We group keys and queries by norm, compute sampling scores within each pair of groups by convex optimization, and then bound the sum of these scores using Lemma 4.
Partitioning by norm. Set . Partition the keys into norm bins
Similarly, partition the possible query norms into intervals of width , assigning each endpoint to the interval on its left and including zero in the first interval.
For , denote
If and an admissible query has norm in the -th interval, then
Thus, for each nonempty , the compact convex domain
contains every admissible query whose norm lies in the -th interval.
Bounding sensitivities locally. For , define the local sensitivity
with when is empty. For an admissible query whose norm lies in the -th interval,
Consequently, .
Computing the sampling scores. For , define
By Lemma 13, this objective is convex and continuously differentiable, with an explicit gradient. Whenever is nonempty, it is the logarithm of the reciprocal of token ’s attention weight within , so
Moreover, for every , . The lower bound follows from the term , and the upper bound follows from the defining inner-product bounds of .
By Lemma 14 and the definition of , each nonempty domain is compact and convex. Applying Lemma 15 with , we obtain satisfying
Set . Exponentiating Equation (21) gives . For empty domains, set , so the same inequalities hold under the convention . We are now ready to describe the sampling scores . For , define
Together with the local sensitivity bound, this gives . Since , we have , so the scores are positive.
Bounding the sum within each pair of bins. Write . For , the endpoint definitions give
Since ,
The keys in have norm at most , and queries in have norm at most . The product of these bounds, divided by , is . For each nonempty domain, Lemma 4 therefore gives
The same bound holds trivially for empty domains. Hence
Summing over the bins. If , then , and the desired bound follows immediately. Otherwise, . Since ,
Using , we obtain
Finally, and , so
Each key participates in at most optimization problems, giving at most such problems in total. ∎
Proofs from Section 3.2
In this section, we give the proof of Theorem 4, the lower bound in the importance sampling regime.
Theorem 4 (Lower bound, Item 2). Consider , , and in the importance sampling regime (Theorem 1). Consider and , and let . Pick any integer satisfying
There is a fixed dataset of key-value pairs, with keys of norm and unit-norm values in , together with queries of norm , such that every key satisfies
For this dataset, satisfying Equation (3) at each of these queries requires .
The construction and analysis are essentially the same as that in the uniform sampling regime § 2.2 with slightly more complicated parameter settings in order to capture all possible values of .
Goal. We construct keys and queries such that each matching pair has scaled inner product , exceeding that of every nonmatching pair , , by at least , where . We will then use this gap to make each query concentrate its attention on copies of its matching key, forcing an accurate summary to retain many key groups.
Construction. Let be the first three standard basis vectors. Choose unit vectors satisfying Lemma 2 in dimension , with pairwise inner products bounded in magnitude by . Embed them into the last coordinates of , and denote the resulting vectors by . Define
where we set
Note that as and . Note that as and . Therefore, and the keys and queries are well defined with norms exactly equal to and . The components along and serve the purpose of achieving the desired inner products while the padding along and increases the norms of the keys/queries to fix the denominator of cosine similarity.
Verifying the inner products. It remains to bound the scaled inner products between queries and keys. For any , the inner product between the matching pair is:
For any non-matching pair ,
The second choice in the minimum defining ensures . Thus, every key-query cosine similarity belongs to , since .
For any , the scaled inner product between key-query pairs at the same index exceeds that of any other key-query pair by
By the definition of ,
The last inequality uses for .
Constructing the value vectors. Apply Lemma 2 a second time to obtain unit value vectors satisfying
Since , the assumption ensures that this is possible.
Full construction
Proof of Theorem 4. Choose and such that . For , let if and if . The attention instance will have copies of the key-value pair . By the setting of , there will be exactly key-value pairs. As , for all .
At distinct query , let be the attention mass on the copies of . By Equation (25),
Recall the condition . Then,
So, attention focuses significant mass on :
The first inequality follows because all value vectors have norm one, so their distance from is at most two.
Let be the event that the coreset retains at least one copy of . On the complementary event, the approximation at is a convex combination of the value vectors with . This follows directly from the nonnegative weights in the definition of query-oblivious weighted token-eviction. Therefore
as all distinct value vectors are nearly orthogonal.
On the other hand, Equation (27) gives . Projecting the error onto the unit vector yields, whenever does not hold,
Hence success at the fixed query implies .
The per-query guarantee of a query-oblivious weighted token-eviction policy now gives for each separately. Since each retained pair represents at most one group,
By definition, is the optimal worst-case number of tokens retained by an algorithm, so, from above, .
Experiments
Q/K Cosine similarity
Figure 7. Query–key cosine similarities across inputs. The plot uses Qwen3 8B at layer 8 on (a) LongBench v2, (b) InfiniteBench, (c) SCBench. Each panel uses an input of 8,192 tokens and compares the final 256 queries from query head 0 against 7,935 earlier-context keys from the corresponding KV head 0. The initial key (attention sink) is excluded. Cosines are computed after model normalization and RoPE.
Figure 8. Query–key cosine similarities with initial token (attention sink) Qwen3 8B at layer 8 on LongBench v2 example input of 8,192 tokens and compares the final 256 queries from query head 0 against a sample of 16 earlier-context keys from the corresponding KV head 0 and the initial key (attention sink). Cosines are computed after model normalization and RoPE.
Key/Query norms
References
- [1]Vladimir Braverman, Dan Feldman, Harry Lang, Adiel Statman, and Samson Zhou. Efficient coreset constructions via sensitivity sampling. In Vineeth N. Balasubramanian and Ivor Tsang (eds.), Proceedings of The 13th Asian Conference on Machine Learning, volume 157 of Proceedings of Machine Learning Research, pp. 948–963. PMLR, 17–19 Nov 2021. URL https://proceedings.mlr.press/v157/braverman21a.html.
- [2]Zefan Cai, Yichi Zhang, Bofei Gao, Yuliang Liu, Yucheng Li, Tianyu Liu, Keming Lu, Wayne Xiong, Yue Dong, Junjie Hu, and Wen Xiao. PyramidKV: Dynamic KV cache compression based on pyramidal information funneling. In Second Conference on Language Modeling, 2025. URL https://openreview.net/forum?id=ayi7qezU87.arxiv.org/abs/2406.02069
- [3]Chi-Chih Chang, Wei-Cheng Lin, Chien-Yu Lin, Chong-Yan Chen, Yu-Fang Hu, Pei-Shuo Wang, Ning-Chi Huang, Luis Ceze, Mohamed Abdelfattah, and Kai-Chiang Wu. Palu: KV-cache compression with low-rank projection. In The Thirteenth International Conference on Learning Representations, 2025. URL https://proceedings.iclr.cc/paper_files/paper/2025/hash/7da6e0e00702c60607a6ae05c802ef85-Abstract-Conference.html.arxiv.org/abs/2407.21118
- [4]Justin Y. Chen, Ying Feng, Piotr Indyk, Michael Kapralov, Ekaterina Kochetkova, and Boris Prokhorov. Towards tight bounds for streaming attention, 2026. URL https://arxiv.org/abs/2606.07205.
- [5]Petros Drineas, Malik Magdon-Ismail, Michael W. Mahoney, and David P. Woodruff. Fast approximation of matrix coherence and statistical leverage. Journal of Machine Learning Research, 13 (111):3475–3506, 2012. URL https://www.jmlr.org/papers/v13/drineas12a.html.
- [6]Sabri Eyuboglu, Ryan Ehrlich, Simran Arora, Neel Guha, Dylan Zinsley, Emily Liu, Will Tennien, Atri Rudra, James Zou, Azalia Mirhoseini, and Christopher Re. Cartridges: Lightweight and general-purpose long context representations via self-study, 2025. URL https://arxiv.org/abs/2506.06266.
- [7]Yuan Feng, Junlin Lv, Yukun Cao, Xike Xie, and S. Kevin Zhou. Ada-KV: Optimizing KV cache eviction by adaptive budget allocation for efficient LLM inference. In Advances in Neural Information Processing Systems, volume 38, 2025. URL https://openreview.net/forum?id=tcisuhGsQZ.arxiv.org/abs/2407.11550
- [8]Nathan Godey, Éric Villemonte de la Clergerie, and Benoît Sagot. Anisotropy is inherent to self-attention in transformers. In Yvette Graham and Matthew Purver (eds.), Proceedings of the 18th Conference of the European Chapter of the Association for Computational Linguistics, EACL 2024 - Volume 1: Long Papers, St. Julian’s, Malta, March 17-22, 2024, pp. 35–48. Association for Computational Linguistics, 2024. DOI: 10.18653/v1/2024.eacl-long.3. URL https://doi.org/10.18653/v1/2024.eacl-long.3.
- [9]Themistoklis Haris and Krzysztof Onak. Compression barriers in autoregressive transformers. In Nika Haghtalab and Ankur Moitra (eds.), The Thirty Eighth Annual Conference on Learning Theory, June 30 - July 4, 2025, Lyon, France, volume 291 of Proceedings of Machine Learning Research, pp. 2577–2875. PMLR, 2025. URL https://proceedings.mlr.press/v291/haris25a.html.arxiv.org/abs/2502.15955
- [10]Coleman Hooper, Sehoon Kim, Hiva Mohammadzadeh, Michael W. Mahoney, Yakun Sophia Shao, Kurt Keutzer, and Amir Gholami. KVQuant: Towards 10 million context length LLM inference with KV cache quantization. In Advances in Neural Information Processing Systems, volume 37, 2024. URL https://proceedings.neurips.cc/paper_files/paper/2024/hash/028f8c3d95339a40c461b42c99a4-Abstract-Conference.html.arxiv.org/abs/2401.18079
- [11]Ekaterina Kochetkova, Kshiteej Jitesh Sheth, Insu Han, Amir Zandieh, and Michael Kapralov. Streaming attention approximation via discrepancy theory. In Advances in Neural Information Processing Systems, volume 38, 2025. URL https://papers.neurips.cc/paper_files/paper/2025/hash/1de510838fadd72f79a7a90e9c564f0c-Abstract-Conference.html.arxiv.org/abs/2502.07861
- [12]Yuhong Li, Yingbing Huang, Bowen Yang, Bharat Venkitesh, Acyr Locatelli, Hanchen Ye, Tianle Cai, Patrick Lewis, and Deming Chen. SnapKV: LLM knows what you are looking for before generation. In Advances in Neural Information Processing Systems, volume 37, 2024. URL https://proceedings.neurips.cc/paper_files/paper/2024/hash/28ab41824260e0f7323e54185d19bde-Abstract-Conference.html.arxiv.org/abs/2404.14469
- [13]Edo Liberty, Alexandr Andoni, and Eldar Kleiner. Nearly optimal attention coresets. CoRR, abs/2605.05602, 2026. doi: 10.48550/ARXIV.2605.05602. URL https://doi.org/10.48550/arXiv.2605.05602.
- [14]Zichang Liu, Aditya Desai, Fangshuo Liao, Weitao Wang, Victor Xie, Zhaozhuo Xu, Anastasios Kyrillidis, and Anshumali Shrivastava. Scissorhands: Exploiting the persistence of importance hypothesis for LLM KV cache compression at test time. In Advances in Neural Information Processing Systems, volume 36, 2023. URL https://proceedings.neurips.cc/paper_files/paper/2023/hash/a452a7c6c463e4ae8fbdc614c6e983e6-Abstract-Conference.html.arxiv.org/abs/2305.17118
- [15]Zirui Liu, Jiayi Yuan, Hongye Jin, Shaochen Zhong, Zhaozhuo Xu, Vladimir Braverman, Beidi Chen, and Xia Hu. KIVI: A tuning-free asymmetric 2bit quantization for KV cache. In Proceedings of the 41st International Conference on Machine Learning, volume 235 of Proceedings of Machine Learning Research, pp. 32332–32344. PMLR, 2024. URL https://proceedings.mlr.press/v235/liu24bz.html.DOI
- [16]Pierre-Emmanuel Mazaré, Gergely Szilvasy, Maria Lomeli, Francisco Massa, Naila Murray, Hervé Jégou, and Matthijs Douze. Inference-time sparse attention with asymmetric indexing. arXiv preprint arXiv:2502.08246, 2025. URL https://arxiv.org/abs/2502.08246.
- [17]Lieven Vandenberghe and Stephen Boyd. Convex optimization, volume 1. Cambridge university press Cambridge, 2004.
- [18]Heng Wang, Jielin Qiu, Wenting Zhao, Cheng Qian, Liangwei Yang, Jiawei Han, Heng Ji, Silvio Savarese, Shelby Heinecke, and Huan Wang. Random attention: Rethinking KV cache eviction for efficient reasoning. arXiv preprint arXiv:2609.03430, 2026. URL https://arxiv.org/abs/2609.03430.
- [19]Guangxuan Xiao, Yuandong Tian, Beidi Chen, Song Han, and Mike Lewis. Efficient streaming language models with attention sinks. In The Twelfth International Conference on Learning Representations, 2024. URL https://openreview.net/forum?id=NG7sS51zVF.arxiv.org/abs/2309.17453
- [20]Amir Zandieh, Insu Han, Vahab Mirrokni, and Amin Karbasi. SubGen: Token generation in sublinear time and memory. arXiv preprint arXiv:2402.06082, 2024. URL https://arxiv.org/abs/2402.06082.
- [21]Amir Zandieh, Majid Daliri, Majid Hadian, and Vahab Mirrokni. TurboQuant: Online vector quantization with near-optimal distortion rate. In The Fourteenth International Conference on Learning Representations, 2026. URL https://proceedings.iclr.cc/paper_files/paper/2026/hash/5c802ef38ab6e366c2ea06eee554c088-Abstract-Conference.html.arxiv.org/abs/2504.19874
- [22]Zhenyu Zhang, Ying Sheng, Tianyi Zhou, Tianlong Chen, Lianmin Zheng, Ruisi Cai, Zhao Song, Yuandong Tian, Christopher Ré, Clark Barrett, Zhangyang Wang, and Beidi Chen. H2O: Heavy-hitter oracle for efficient generative inference of large language models. In Advances in Neural Information Processing Systems, volume 36, 2023. URL https://proceedings.neurips.cc/paper_files/paper/2023/hash/6ceefa7b15572587b78ecfcebb2827f8-Abstract-Conference.html.DOI






