Manuscript Offprint

arXiv:2608.28293

A Probabilistic Interpretation of KV Cache Eviction

Renato Geh, Alex Chen, Daniel Israel, Aditya Grover, Guy Van den Broeck

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

Renato Geh

University of California, Los Angeles

renatolg@cs.ucla.edu

Daniel Israel

University of California, Los Angeles

disrael@cs.ucla.edu

Alex Chen

University of California, Los Angeles

itisalex@ucla.edu

Aditya Grover

University of California, Los Angeles

adityag@cs.ucla.edu

Guy Van den Broeck

University of California, Los Angeles

guyvdb@cs.ucla.edu

Abstract

The premise and promise of KV (cache) eviction is simple: higher throughput can be achieved by evicting some entries from the KV cache, at a negligible cost to quality. This holds empirically for many existing methods, though most rely on creative heuristics for selecting which entries to drop. Despite recent advances, the problem of KV eviction has remained informal in the literature. This paper aims to properly formalize this problem through the lens of probabilistic reasoning and reveal what can be learned from this perspective. Concretely, we (1) formalize the problem of KV eviction and, unfortunately, prove that it is computationally hard, (2) show that by framing it probabilistically, KV eviction reduces to the problem of expectation estimation, which can be approximated through sampling, (3) show that through this probabilistic interpretation, correcting for evicted entries during decoding—a previously ignored problem—becomes feasible, and (4) reveal that existing methods in the literature are zero-variance biased estimators that can be easily adapted in order to enable decode time correction. In practice, we show that this probabilistic version of KV eviction coupled with decode time correction is more robust to different tasks compared to existing eviction methods and achieves competitive performance at the same compression budget.

1 Introduction

Key-Value (KV) cache compression poses a natural proposition: increase throughput and decrease memory footprint by sacrificing some precision in the KV cache. Popular methods for this utilize quantization [17, 28], compaction [30, 12], eviction [26, 21, 22, 29], inter alia, to shrink down the size of the cache and speed up inference. Among these techniques, KV (cache) eviction presents the simplest solution: given a prompt and the KV cache associated with it, evict some entries of the cache at a (hopefully) negligible cost to generation quality. Despite this simplicity, the problem itself is quite challenging, and existing KV eviction strategies elaborate sophisticated heuristics in order to identify which entries to evict, performing surprisingly well in practice. Although these recent advances are indeed quite impressive, there is a distinct lack of formality in the literature. This paper aims to address this, and in its wake expose key insights on the structure of KV eviction.

As a first result, by formalizing KV eviction we reveal that the problem of KV eviction is unfortunately computationally hard. However, through a probabilistic interpretation of the attention mechanism,

Preprint.

softmax⁡(Q⋅K⊤d)⏞p(V)⋅V=Ep[V]\overbrace{\operatorname{softmax}\left(\frac{\mathbf{Q}\cdot\mathbf{K}^{\top}}{\sqrt{d}}\right)}^{p\left(\mathbf{V}\right)}\cdot\mathbf{V}=\mathbb{E}_{p}[\mathbf{V}] pt(V)=[0.30.10.40.2]V=[2.03.01.05.0]\begin{aligned}p_{t}(\mathbf{V})&=\begin{bmatrix}0.3&0.1&0.4&0.2\end{bmatrix}\\\mathbf{V}&=\begin{bmatrix}2.0&3.0&1.0&5.0\end{bmatrix}\end{aligned}

Top-k:

I=top−k(pt(V))={1,3,4}\boldsymbol{I}=\mathrm{top-}k(p_{t}(\mathbf{V}))=\{1,3,4\}

Probabilistic eviction:

π(vi)=pt(vi)⋅∣vi∣∑j=1tpt(vj)⋅∣vj∣\pi(\mathbf{v}_{i})=\frac{p_{t}(\mathbf{v}_{i})\cdot|\mathbf{v}_{i}|}{\sum_{j=1}^{t}p_{t}(\mathbf{v}_{j})\cdot|\mathbf{v}_{j}|} u={u1,u2,…,um}∼π\boldsymbol{u}=\left\{u_{1},u_{2},\ldots,u_{m}\right\}\sim\pi c(vi)=countsofviinu=[3,0,3,14]c(\mathbf{v}_{i})=counts of\mathbf{v}_{i} in\mathbf{u}=[3,0,3,14] I=unique(u)={1,3,4}\boldsymbol{I}=unique(\boldsymbol{u})=\{1,3,4\}

eviction time

Ground-truth:

Epn[V]=2.1\mathbb{E}_{p_{n}}[\mathbf{V}]=2.1

Available:

p~n(V)=[10,⊔,20,40,10,20]\tilde{p}_{n}(\mathbf{V})=[10,\sqcup,20,40,10,20] V=[2.0,⊔,1.0,5.0,2.0]\mathbf{V}=[2.0,\sqcup,1.0,5.0,2.0] In={1,3,4}∪{5}\boldsymbol{I}_{n}=\left\{1,3,4\right\}\cup\left\{5\right\}

Top-k (uncorrected):

Epn[V∣In]=∑i∈Inp~n(vi)∑j∈Inp~n(vj)⋅vi≈1.84\mathbb{E}_{p_{n}}[\mathbf{V}|I_{n}]=\sum_{i\in I_{n}}\frac{\tilde{p}_{n}(\mathbf{v}_{i})}{\sum_{j\in I_{n}}\tilde{p}_{n}(\mathbf{v}_{j})}\cdot\mathbf{v}_{i}\approx1.84

Bias: unbounded Variance: 0

Probabilistic eviction (corrected):

μ(V;m)=E^pn[VIn]+Ep~n[Vt+1:n]z^In+zt+1:n≈2.18\mu(\mathbf{V};m)=\frac{\hat{\mathbb{E}}_{p_{n}}[\mathbf{V}_{I_{n}}]+\mathbb{E}_{\tilde{p}_{n}}[\mathbf{V}_{t+1:n}]}{\hat{z}_{I_{n}}+z_{t+1:n}}\approx2.18

Bias: O(1/m)\mathcal{O}(1/m) Variance: O(1/m)\mathcal{O}(1/m)

t=4t = 4

decode time

n=5n = 5

Figure 1: Correction can attenuate the effects of eviction at decode time. Evicting entries deforms the distribution and biases the expectation, as the normalizing constant is altered by the evicted entries. Existing eviction methods deterministically evict the top-k scored entries, which although zero-variance, may have arbitrarily large bias. Probabilistic eviction addresses this unintended deformation through self-normalized importance sampling, whose error is upper bounded by O(m−1)\mathcal{O}(m^{-1}), where m is the number of samples.

eviction can be viewed as a problem of expectation estimation, which is well studied in the statistical methods literature [23]. We then reveal that the usual KV eviction setup ignores the distributional shift that occurs after eviction: because of missing entries, the distribution over all entries is distorted, and therefore so is the expectation. Thus, within this framing an expectation estimator (and KV eviction strategy) aims to achieve low error at decode time by either reducing its bias, variance, or both. Interestingly, most existing KV eviction methods are trivially subsumed within this framework.

The common approach in KV eviction is to score entries by using the attention weights and values, and then take the top-k entries according to these scores [21, 29, 22]; this estimator is zero-variance as it is deterministic. However, it can have an arbitrarily large bias. We instead suggest that these scores should be viewed as unnormalized distributions on entries which to evict, allowing us to later reuse them as a proposal distribution to correct for the distortion caused by eviction through self-normalized importance sampling. This is an attractive option because self-normalized importance sampling has reasonable upper bounds on bias and variance [23, 1]. Figure 1 summarizes our approach.

In summary, our contributions are as follows:

  1. We show that KV eviction is NP-complete (Section 3);

  2. We formalize KV eviction as an expectation estimation problem and show an asymptotically correct estimator for the decode time expectation with bounded bias and variance (Sections 4 and 5);

  3. We show the interplay of bias versus variance in this estimator and how existing eviction methods are subsumed by this framework (Section 6 and Appendix D);

  4. We empirically validate our findings by showing that coupling probabilistic eviction and decode time correction is not only competitive at the same compression budget but is more robust across different tasks (Section 7).

References (26)