Manuscript Offprint

arXiv:2610.40943

Kernel-based Interpolatory Methods for Context Compression of Attention Mechanisms

Michel Fabrice Serret, Laura Grigori

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

ABSTRACT

The bottleneck of attention mechanisms, which are the fundamental building block of modern language models, is their quadratic complexity in terms of context size. There has thus been an increasing interest in the compression of the context, also called KV-cache compression. In this article, we consider the problem of compressing the context of attention mechanisms by first formulating it in the Hilbert space associated with its kernel. In this formalism, attention can be represented as the ratio of two linear maps whose interpolant is also the ratio of interpolants, this allows us to consider the interpolation of the linear maps directly. We thus introduce two novel KV-cache compression methods which we call GAIM and Q-DAIM, based on the Generalized Empirical Interpolation Method (GEIM) and the Q-Discrete Empirical Interpolation Method (Q-DEIM), respectively. As the cost of these methods is quadratic in terms of context length, we propose surrogate models based on the Taylor series, the Performer and the Random Fourier Features method which allow the compression to be done in linear time. Finally, we extend this result to the streaming attention setting, providing new methods which allow one to penalize the selection of interpolation nodes based on the previously interpolated context and to update the previous interpolation based on new information. We then provide numerical results on the convergence of the residuals and the output error in future queries and preliminary results on the LongBench-E benchmark showing performance comparable to the state-of-the-art methods. These experiments suggest that the range revealed by our Q-DAIM method could help identify where information is concentrated in the KV cache, thus enabling an efficient compression.

1 Introduction

The attention mechanism, one of the main building blocks of the Transformer architecture [Vas+23], is based on functions that involve pairwise interactions of its inputs. Indeed, attention mechanisms are used to construct functions that can change depending on the context¹, given by their key K∈RN×dK \in \mathbb{R}^{N \times d} and value matrices V∈RN×dV \in \mathbb{R}^{N \times d} with N∈N∗N \in \mathbb{N}^*. They are applied to an input known as a query vector q∈Rdq \in \mathbb{R}^d. In the context of Large Language Models, this context corresponds to a set of NN tokens, sets of characters, and their associated query, key, and value vectors. The attention mechanism allows the models to encode the semantic information contained in the relationships of the input token with the context tokens. To do so, the rows of the key matrices, (Ki)i∈[N](K_i)_{i \in [N]}, are used to calculate a similarity between the input token's query vector and each contextual key, via a kernel function κexp⁡:x,y↦exp⁡(⟨x,y⟩/d)\kappa_{\exp}: x, y \mapsto \exp(\langle x, y \rangle/\sqrt{d}). This distribution of similarities over the keys is then normalised resulting in the normalised attention scores given by

¹For a more detailed description of attention in the context of LLMs, see [Ser26].

the softmax function

softmax(q,K)=(exp⁡(⟨q,Ki⟩/d)∑j∈[N]exp⁡(⟨q,Kj⟩/d))i∈[N]∈RN.\mathrm{softmax}(q,K)=\left(\frac{\exp(\langle q,K_{i}\rangle/\sqrt{d})}{\sum_{j\in[N]}\exp(\langle q,K_{j}\rangle/\sqrt{d})}\right)_{i\in[N]}\in\mathbb{R}^{N}.

For each context token i∈[N]i \in [N], the associated value row ViV_i is weighted by the attention score associated with its key. The attention on a single query q∈Rdq \in \mathbb{R}^d is then given by

Att(q,K,V)=softmax(q,K)TV=∑i∈[N]κexp(q,Ki)Vi∑j∈[N]κexp(q,Kj)∈Rd,(1)\mathrm{A t t}(q,K,V)=\mathrm{s o f t m a x}(q,K)^{\mathsf{T}}V=\sum_{i\in[N]}\frac{\kappa_{\mathrm{e x p}}(q,K_{i})V_{i}}{\sum_{j\in[N]}\kappa_{\mathrm{e x p}}(q,K_{j})}\in\mathbb{R}^{d}, \tag{1}

where κexp\kappa_{exp} is the exponential kernel of the scaled dot-product.

However, computing the attention has a quadratic cost in the sequence length NN and, at inference time, requires caching the key and value embeddings of all past tokens. Attention is hence the main computational and memory bottleneck of modern Large Language Models (LLMs). Implementations such as FlashAttention [Dao+22; Dao23] compute attention exactly while reducing memory traffic; however, it still has a quadratic scaling. Ever since the rise of LLMs in the last few years, there has been heightened interest in the development of sub-quadratic approximations of the attention mechanism. The methods proposed come from several fields of research, ranging from clustering and sparsity [KKL20; Zan+23; Han+23; Hoo+25] to low-rank and subspace projection-based methods [Wan+20; Sin+24]. Recent works also used sketching and tensor decompositions [PP25] as well as kernel-based approximations, which replace the exponential kernel of attention with finite-dimensional features [Cho+22; KMZ24] or by Nyström approximations [Che+21; LLS24; SM26] of the attention scores. A classification of these methods through the lens of numerical analysis can be found in [Ser+26]. Other methods attempt to compress the KV cache of a pretrained model directly, removing tokens from the KV cache depending on their associated attention-score statistics, discrepancy measures, or following heuristics based on the norm of the key and value vectors [Zha+23; Li+24; Xia+24; Yan+24; Han+25b; Che+26]. The observation at the basis of our method is shared with the WildCat method [SM26], attention can be written as the ratio of two linear maps, and the orthogonal projections of these maps onto a well-chosen subspace provide an approximation of the attention mechanism. Indeed, formulated in the Reproducing Kernel Hilbert Space (RKHS), HH, of the exponential kernel κexp\kappa_{\text{exp}} underlying scaled dot-product attention, attention becomes a ratio of linear maps in the query feature ϕ[q]∈H\phi[q] \in H,

Att(q,K,V)=ϕ[q]TKϕTVϕ[q]TKϕT1N,\mathrm{A t t}(q,K,V)=\frac{\phi[q]^{\mathsf{T}}K_{\phi}^{\mathsf{T}}V}{\phi[q]^{\mathsf{T}}K_{\phi}^{\mathsf{T}}\mathbf{1}_{N}},

where Kϕ:H→RNK_{\phi}: H \to \mathbb{R}^N denotes the linear map whose rows are the features ϕ[Ki],i∈[N]\phi[K_i], i \in [N]. The numerator is given by the feature-value operator Kϕ⊤VK_{\phi}^\top V and the denominator by the feature-normalization operator Kϕ⊤1NK_{\phi}^\top \mathbf{1}_N. As they share their left factor Kϕ⊤K_{\phi}^\top, both are generated by the same key features and have ranges in the same NN-dimensional subspace Span(Kϕ)\text{Span}(K_{\phi}) of HH. They can thus be approximated jointly through the augmented operator M:=Kϕ⊤VaugM := K_{\phi}^\top V^{\text{aug}}, with Vaug:=[V∣1N]∈RN×(d+1)V^{\text{aug}} := [V \mid \mathbf{1}_N] \in \mathbb{R}^{N \times (d+1)} the augmented value matrix.

Given a matrix L∈Rn×dL \in \mathbb{R}^{n \times d} of n<Nn < N keys, let ΠLϕ\Pi_{L_\phi} be the orthogonal projector onto Span(Lϕ):={∑jαjϕ[Lj]∈H∣αj∈R}\text{Span}(L_\phi) := \left\{ \sum_j \alpha_j \phi[L_j] \in H \mid \alpha_j \in \mathbb{R} \right\} and let Waug:=[W∣WNorm]∈Rn×(d+1)W^{\text{aug}} := [W \mid W_{\text{Norm}}] \in \mathbb{R}^{n \times (d+1)} be the weights such that Lϕ⊤Waug=ΠLϕML_\phi^\top W^{\text{aug}} = \Pi_{L_\phi} M. Projecting both linear maps yields the approximation

Att~L(q,K,V)=ϕ[q]TΠLϕKϕTVϕ[q]TΠLϕKϕT1N=ϕ[q]TLϕTWϕ[q]TLϕTWNorm,\widetilde{\mathrm{A t t}}_{L}(q,K,V)=\frac{\phi[q]^{\mathsf{T}}\Pi_{L_{\phi}}K_{\phi}^{\mathsf{T}}V}{\phi[q]^{\mathsf{T}}\Pi_{L_{\phi}}K_{\phi}^{\mathsf{T}}\mathbf{1}_{N}}=\frac{\phi[q]^{\mathsf{T}}L_{\phi}^{\mathsf{T}}W}{\phi[q]^{\mathsf{T}}L_{\phi}^{\mathsf{T}}W_{\mathrm{N o r m}}},

which WildCat [SM26] interprets as a Nyström-based approximation of the attention mechanism.

In this article, we adopt instead the point of view of interpolation. The rows of LL are the interpolation nodes, which play the role of the magic points of the generalized empirical interpolation method (GEIM) [MM13], B:=Span(Lϕ)\mathcal{B} := \text{Span}(L_\phi) is the basis space onto which we interpolate, and WaugW^{\text{aug}} is the projection of MM onto B\mathcal{B}, expressed in the node features. The pair (L,Waug)(L, W^{\text{aug}}) then replaces (K,Vaug)(K, V^{\text{aug}}) as the compressed KV cache. Since Kϕ⊤VK_\phi^\top V and Kϕ⊤1NK_\phi^\top \mathbf{1}_N are interpolated on the same basis space, the ratio of their interpolants is the interpolant of their ratio: it reproduces attention exactly whenever the query is one of the interpolation nodes. The compression of attention thus divides into two tasks: the selection of nodes LL, which determines B\mathcal{B}, and the projection of MM onto B\mathcal{B}, which determines WaugW^{\text{aug}}. The selection phase, described in §3.1.2 and §3.1.3, uses the information contained in the keys and the values, through MM, to choose the interpolation nodes LL that minimize a given residual norm. The natural residual is the worst-case attention error in the pp-norm, Rp(L)=max⁡q∈Rd∥Att(q,K,V)−Att~L(q,K,V)∥p\mathcal{R}_p(L) = \max_{q \in \mathbb{R}^d} \|\text{Att}(q, K, V) - \widetilde{\text{Att}}_L(q, K, V)\|_p. However, this residual is nonlinear and very sensitive to small errors in the denominator. We therefore consider five variants of the attention residual, based on different approximations of Rp\mathcal{R}_p. The projection phase, described in §3.2, is formalized as a Petrov-Galerkin problem: it computes the weights WaugW^{\text{aug}} for which Lϕ⊤WaugL_\phi^\top W^{\text{aug}} best approximates MM on a given test space T\mathcal{T}, the orthogonal projection above being the Galerkin case T=B\mathcal{T} = \mathcal{B}.

However, classical empirical interpolation methods such as GEIM [MM13] or Q-DEIM [DG16; DS18] cannot be applied directly to this problem for three reasons. First, due to the infinite-dimensional nature of the RKHS, operators such as MM and features such as the rows of KϕK_\phi cannot be constructed explicitly, and hence the usual pivot-based matrix factorizations cannot, in general, be applied. We have to resort instead to methods relying on kernel evaluations rather than on the elements of HH. Second, the kernel norms of the keys, ∥ϕ[Ki]∥H=exp⁡(∥Ki∥2/(2d))\|\phi[K_i]\|_H = \exp\left(\|K_i\|^2/(2\sqrt{d})\right), span several orders of magnitude, so that the exponential kernel Gram matrices involved in the projection are ill-conditioned. Third, evaluating the exact residual and its updates through kernel evaluations has a cost quadratic in the number of keys, which defeats the purpose of compression.

Our main contribution is to introduce two KV-cache compression methods for attention interpolation that overcome these obstacles, being numerically stable and scaling linearly with the context size NN:

  • GAIM, a greedy selection in the style of GEIM [MM13; Mad+07], which greedily picks the interpolation nodes minimizing the L∞L^\infty-norm of the chosen residual, by selecting at each step the node with the largest current residual. It evaluates the augmented residual operator MΔ:=M−ΠLϕM=ΠLϕ⊥MM_\Delta := M - \Pi_{L_\phi} M = \Pi_{L_\phi}^\perp M on the key features, KϕMΔK_\phi M_\Delta and selects the row with the largest L∞L^\infty-norm as the next interpolation node and updates the residual through a rank-one update.

  • Q-DAIM, a Q-DEIM-based selection [DG16; DS18], which minimizes the L2L^2-norm of the residual in the metric induced by the map using the orthogonal basis obtained through a CholeskyQR / Cholesky whitening of the augmented operator. It relies on a QR-like factorization Mˉ=UR\bar{M} = UR, where U:Rr→HU : \mathbb{R}^r \to H is an orthonormal basis in HH of the range of MM, of rank r≤d+1r \le d+1, and R∈Rr×(d+1)R \in \mathbb{R}^{r \times (d+1)}. As UU cannot be constructed explicitly, we instead compute a Cholesky factorization of its Gram matrix, G:=M⊤M=R⊤R∈R(d+1)×(d+1)G := M^\top M = R^\top R \in \mathbb{R}^{(d+1) \times (d+1)} which only requires kernel evaluations, to obtain RR. The orthogonal operator onto the range of MM is then given by U=MR†=Kϕ⊤VaugR†U = MR^\dagger = K_\phi^\top V^{\text{aug}} R^\dagger. By evaluating UU on the keys, F:=KϕU∈RN×rF := K_\phi U \in \mathbb{R}^{N \times r}, we obtain a matrix whose rows are the coordinates of the key features in the revealed range, then we select the nodes to be the pivots of a column-pivoted QR factorization of F⊤F^\top, which greedily maximizes the L2L^2 norm of the reconstructed basis of the revealed range. Additionally, the Q-DEIM interpolation operator then provides us with an alternative Petrov-Galerkin projection whose test space is given by the revealed range of MM.

In practice, both selections are carried out in the Gaussian reformulation described below. Both methods are designed for streaming attention, where the interpolation is applied on successive segments of the context as they come in, and where each interpolation can be improved by using information from previously interpolated segments. In §4, we decompose the interpolation over a stream into a four-stage process. An orthogonalization of the residual against a basis constructed from previously selected interpolation nodes, which we call deflation for brevity, the selection of new interpolation nodes, the projection of the values, and an optional update of the previously interpolated weights.

The contributions that make these methods numerically stable and computationally feasible are threefold.

(i.) A Gaussian-kernel and scaled key norm reformulation. §2 develops attention interpolation in the RKHS of the exponential kernel. To address the ill-conditioning of this formulation, we provide an exact Gaussian reformulation of the attention mechanism and highlight several of its invariants, namely query norm scaling, global key norm scaling, and global key translation. Combined, they separate the RKHS interpolation problem into two parts, a well-conditioned linear problem in translation-invariant Gaussian features and a kernel norm rescaling, which stabilizes our methods.

(ii.) Kernel-based selection and Petrov-Galerkin projections. Splitting the compression into selection and projection allows both phases to be carried out through kernel evaluations only. For the projection, we provide several alternative Petrov-Galerkin methods, which differ by their test space T\mathcal{T}, and hence by the metric, based on the interpolation nodes LL, in which Lϕ⊤WaugL_\phi^\top W^{\text{aug}} approximates MM.

(iii.) Finite-dimensional surrogate residuals. The exact residual and its update are costly, O(Nseg2d)O(N_{\text{seg}}^2 d), to evaluate directly, where NsegN_{\text{seg}} denotes the size of a segment. We therefore introduce finite-dimensional surrogate residuals based on finite-dimensional approximations of the exponential kernel's feature map. We namely consider feature maps constructed using the first-order Taylor approximation, Random Fourier Features [RR07] or from the Performer FAVOR+ features [Cho+22]. Due to the finite-dimensional nature of these maps, key features can be represented as matrices and this allows for a change in the order of operations that reduces the cost of selection and residual updates to O(Nsegd2)O(N_{\mathrm{seg}}d^2). These surrogate residuals are used as alternative selection criterion for our magic points. However, to limit the approximation error, the projection step is still obtained through an exact Petrov-Galerkin projection of the operator on the chosen nodes, which costs on the order of O(Nsegd2+d3)O(N_{\mathrm{seg}}d^2 + d^3) for a single segment of size NsegN_{\mathrm{seg}} with a number of interpolation nodes proportional to dd, nseg=O(d)n_{\mathrm{seg}} = O(d).

We provide a complexity analysis for segments of size Nseg∈NN_{\mathrm{seg}} \in \mathbb{N} with nsegn_{\mathrm{seg}} interpolation nodes per segment of our streaming interpolation methods in §4.3. We also provide a numerical study of our proposed interpolation methods in §5 on Qwen2.5-7B-Instruct [Qwe+25], in terms of the convergence of the residuals, of the attention error on future queries of the same text, and of the performance on the LongBench-E benchmark [Bai+24]. Overall, in a preliminary LongBench-E evaluation at 25% context compression, Q-DAIM obtains the best average score of all the methods we evaluated, retaining 87.1% of the score of the uncompressed model and slightly outperforming both GAIM and the RP-Cholesky selection of WildCat [SM26] implemented in the same framework. For this benchmark, we computed several variants of the model to isolate the impact of the different parameters of the methods on the result. We observe that a lower attention error does not necessarily translate into better benchmark scores, the selection of the interpolation nodes having a more decisive impact on performance than the projection. Interestingly, it appears that the revealed range of Q-DAIM provides both better selection and better projection performance than the GAIM or RP-Cholesky methods. Indeed, by looking at the variants where no projection is used, i.e. Waug=VaugW^{\mathrm{aug}} = V^{\mathrm{aug}}, Q-DAIM selection appears to outperform all other methods, and on the other hand the best performing variant on the most tasks for Q-DAIM is the one using the revealed-range projection, i.e. the Q-DEIM interpolation operator. This suggests that the range of the augmented operator revealed by Q-DAIM is a better indicator of the information retained by a method than the residuals and that the revealed range provides additional information which seems to not be accessible to the other methods. As the revealed range is only approximately reconstructed in this setting, being limited to dd vectors for its reconstruction but requiring the complete set of keys for a perfect reconstruction, this motivates future research for the direct reconstruction of UU.

The present work belongs to the kernel-based family of attention approximation methods and is most closely related to the WildCat method [SM26], which also approximates the augmented linear map similarly but whose selection uses a Randomly Pivoted Cholesky (RP-Cholesky) on the Gram matrix of the keys for a rescaled kernel. WildCat was also recently combined with the Thinformer approximation inside the causal Express wrapper of [Gon+26]. Compared to the WildCat [SM26] method, whose random selection is optimal to reconstruct the span of the keys in the Hilbert space HH, our method takes into account the value matrix and focuses on minimizing the residual of attention.

References (73)