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.
Figures & tables
Projection method
W
AW
BW
GAIM
ΠLϕ
E˘LL
E˘LKVηaug
PG least squares
ΣK
E˘LKE˘KL
E˘LKE˘KKVηaug
Q-DAIM revealed-range
IL/ΠU
FP,:FP,:T
FP,:FTVηaug
Least squares
-
E˘KL
E˘KKVηaug
WildCat τ scaling
Pτ=LϕTEτ−2L,L−1Lϕτ−2
E˘τ−1L,τ−1L
E˘τ−1L,τ−1KVη,τaug
Table 1: Matrices and projectors associated with the different projection methods.
Deflation
M
G
S˘
R
None
K˘seg,ϕTVsegaug
VsegaugTE˘KsegKsegVsegaug
E˘KsegKseg
E˘KsegKsegVsegaug
Basis
ΠLϕ⊥K˘seg,ϕTVsegaug
VsegaugTS˘LVsegaug
S˘L
S˘LVsegaug
Range
ΠU⊥K˘seg,ϕTVsegaug
VsegaugTS˘UVsegaug
S˘U
S˘UVsegaug
Table 2: Modified matrices for each deflation type.
Basis (Galerkin) / Range / PG least squares / least squares
§ 3.2
Table 3: Parameters for interpolation of streaming attention.
Matrix
Size
Post-Compression
Nodes
L
n×d
Weights
Waug
n×(d+1)
Running mean
μg
d
Range-correction weights
Wˉ,WˉNorm
d+1
Sink
(K,V)sink
2tsinkd
Table 4: Data in memory per head and per layer kept throughout the context compression.
Selection
Residual instantiation
Selection
Residual update
Total
Exact kernel
GAIM
O(Nseg2d)
O(Nsegnsegd)
O(Nsegnseg(nseg+d))
O(Nseg(Nsegd+nseg2))
Q-DAIM †
O(Nsegd(Nseg+d))
O(Nseg(nseg+r))
O(Nsegrmin(nseg,r))
O(Nsegd(Nseg+d))
Surrogate
GAIM-LIN
O(NsegDd)
O(Nsegnsegd)
O(NsegnsegD)
O(NsegD(d+nseg))
GAIM-LIN-O ∗
O(NsegDd)
O(Nsegnsegd)
O(NsegnsegD+nseg3)
O(NsegD(d+nseg)+nseg3)
Table 5: Computational cost of each step, for a single head, per segment. The selection and residual update costs are summed over the nseg picks, and the surrogate costs assume D≥d .
Layer
Variant
n=32
n=128
n=512
All
0
v2
23 (17)
22 (16)
20 (7)
17
7
v2
27 (10)
26 (10)
24 (8)
18
14
v2
28 (6)
28 (6)
26 (2)
23
21
v2
28 (7)
28 (8)
28 (4)
26
Table 6: Number of query heads per layer (out of 28 ) on which range correction lowers the maximum error in L∞ norm, maxq∈Q∥Att(q,K,V)−AttL(q,K,V)∥∞ . GAIM exact v2, nodes selected in the L∞ score norm, tsink=32 . In parentheses we give the heads for which the error decreases by more than 10% . Last column: heads improved under every variant and every budget.
GAIM exact v4
Q-DAIM exact v5
Layer
n=32
n=128
n=512
All
n=32
n=128
n=512
All
0
9 (4)
9 (8)
8 (4)
6
25 (19)
25 (19)
16 (14)
15
7
20 (6)
22 (11)
24 (14)
18
21 (5)
24 (12)
25 (20)
19
14
25 (9)
24 (17)
21 (17)
19
25 (0)
28 (7)
28 (16)
25
21
25 (4)
21 (15)
22 (17)
17
28 (1)
28 (10)
26 (19)
26
Table 7: Number of query heads per layer (out of 28 ) on which the temperature-scaled projection lowers the maximum error in L∞ norm, maxq∈Q∥Att(q,K,V)−AttL(q,K,V)∥∞ . GAIM exact v4 with the nodes selected in the L∞ score norm, and Q-DAIM exact v5, tsink=32 , RC on, the projection is solved in the kernel rescaled as in [ SM26 ] , τ≈2.04 . In parentheses we give the heads for which the error decreases by more than 10% . The last column is the number of heads that improved for all n .
Selection method
Nseg
Deflation
RoPE Strip.
Centering
τ
RC
Proj.
Qasper
MFQA
HotpotQA
2Wiki
GovRep
MultiNews
TREC
TriviaQA
SAMSum
PCount
PRetr
LCC
RepoB-P
Mean
% dense
Dense
–
–
–
–
–
–
–
54.9
61.8
57.1
60.8
34.7
26.9
72.0
86.7
46.7
16.0
100.0
68.6
65.6
57.84
100.0
GAIM exact [v3, L∞ ]
128
range
off
(c,c)
1
on
Gal.
45.8
58.4
48.2
36.0
31.1
23.2
64.0
85.5
41.3
4.0
80.0
52.7
56.1
48.18
83.3
GAIM-LIN [v1, L∞ ]
128 †
none
off
(c,c)
1
on
Gal.
48.8
59.3
52.2
36.4
30.0
22.7
64.0
88.8
41.2
8.0
84.0
47.2
53.0
48.88
84.5
128 †
none
off
(c,c)
1
on
none
40.5
57.7
49.2
47.3
30.9
23.6
68.0
85.0
37.5
8.0
92.0
44.2
56.6
49.27
85.2
128 †
none
off
(c,c)
1
off
Gal.
43.9
52.3
48.0
43.7
30.3
23.1
60.0
86.8
39.0
8.0
92.0
52.5
55.3
48.84
84.4
128 †
none
off
(c,c)
1
off
none
46.5
54.3
45.8
38.5
31.1
23.2
68.0
84.9
37.8
4.0
80.0
51.4
61.4
48.23
83.4
Table 8: LongBench-E - 25 prompts per task at 25% context compression. Key centers are given as the tuple (selection, solve), c = segment mean, g = global mean. The Exact and CompressKV rows are the values reported in Table 4 of [ SM26 ] (25% compression) on the complete benchmark (compared to our 25 samples/task). For comparison, the percentages rows give, per task, our best method on average (Q-DAIM exact, Nseg=64 ) and the best score per task relative to Dense, and CompressKV relative to Exact. Proj.: Galerkin/basis projection (Gal.), none (each node keeps its own value with a unit weight, [VL∣1] ), or Q-DAIM’s revealed-range projection restricted to the revealed rank (range r ). Methods optionally use the τ temperature scaled kernel for comparison with WildCat [ SM26 ] . RP-Cholesky corresponds to an implementation of the WildCat selection and projection on our harness. † : run on PyTorch 2.14, whose GPU (MPS) attention kernels round differently.
Scaling language models to long contexts is often bottlenecked by the size of the key-value (KV) cache. In deployed settings, long contexts are typically managed through compaction in token space via summarization. However, summarization can be highly lossy, substantially harming downstream performance. Recent work on Cartridges has shown that it is possible to train highly compact KV caches in latent space that closely match full-context performance, but at the cost of slow and expensive end-to-end optimization. This work describes an approach for fast context compaction in latent space through Attention Matching, which constructs compact keys and values to reproduce attention outputs and preserve attention mass at a per-KV-head level. We show that this formulation naturally decomposes into simple subproblems, some of which admit efficient closed-form solutions. Within this framework, we develop a family of methods that significantly push the Pareto frontier of compaction time versus quality, achieving up to 50x compaction in seconds on some datasets with little quality loss.
KV-cache compression is often justified by attention maps with a few large weights. This is incomplete: large weights may not contain most of the mass, omitted values can cancel, and preserving the attention output may not preserve the task. We separate these questions. Global score gaps -- not threshold counts -- determine how many tokens are needed to retain a target mass. For a realized row, the weighted sum of omitted values is the exact missing statistic. A controlled retrieval--aggregation model explains when truncation helps and when it hurts. These results motivate CertKV, a training-free compressor that reserves one tail-summary slot per head and allocates the rest by value dispersion. Under matched budgets, CertKV is top-two in seven of nine LongBench-v2 settings, remains in the leading compressed tier on 128K RULER, and realizes a ten-fold cache budget in a packed Llama prototype. Compressibility depends on the mass, values, future queries, and task -- not on a sparse-looking map alone.
Chiwun Yang, Xiaoyu Li
City University of Hong Kong · University of New South Wales
Long-context language modeling is increasingly constrained by the Key-Value (KV) cache, whose memory and decode-time access costs scale linearly with the prefix length. This bottleneck has motivated a range of context-compression methods, from token-level summarization to recent optimization-based KV compression methods. These post-hoc methods operate on the KV cache of a fixed pretrained model, so their effectiveness is fundamentally limited by how well the model's internal representations can be compressed. In this work, we formalize the notion of KV compressibility and show that it is a property of the learned representations, rather than of the context alone. We prove that almost any sequence-to-vector function admits both highly compressible and inherently non-compressible transformer implementations, highlighting the need to guide transformers toward compressible representations during training. Motivated by this, we propose KV-Compression Aware Training (KV-CAT), a continued pretraining procedure that incentivizes the emergence of compressible representations. We introduce a train-time KV sparsification policy that masks KV slots during training. This forces the model to use fewer KV slots and encourages it to learn representations amenable to post-hoc compression. Empirically, we show that KV-CAT improves the quality-budget tradeoff of downstream compression methods across retrieval, long-context question answering, and perplexity-based evaluation of compressed-prefix continuation.
Yoav Gelberg, Yam Eitan, Michael Bronstein +2
University of Oxford · 2Technion – Israel Institute of Technology · 3AITHYRA +1