arXiv(opens in a new tab)cs.CLOct 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2610.20582

Latent Compaction with Test-Time Training

Yingfa Chen, Xingyu Shen, Chaojun Xiao, Xu Han

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original. This text is shared under the same licence.

ABSTRACT

Long contexts enlarge key-value (KV) caches, increasing memory use and attention costs during generation. Compressing these caches must preserve information for unseen questions. We introduce Latent Compaction, which learns a compact document-specific cache through test-time training. We initialize cache entries using reconstruction importance, teacher attention, and key-space diversity. Training first fits attention outputs and log-normalizers to those of the full cache, with reconstruction-selected entries held fixed. It then jointly optimizes the entire cache through end-to-end distillation from the full-cache model. Model weights remain frozen throughout, and training uses only generic prompts about the document, without access to downstream questions or answers. Experiments on RULER, LongBench, and Phonebook Lookup demonstrate substantial gains over budget-matched compression baselines. On a RULER, for example, our method achieves 96.7% accuracy at 32×32\times compression, compared with 40.0% for KVZip+. The method also transfers across model scales and families, with retrieval gains on both Qwen3 and MiniCPM5. These results show that treating the KV cache as a neural network and optimizing it with test-time training can preserve retrieval accuracy under aggressive compression. 1^{1}

1 INTRODUCTION

Large key-value (KV) caches are a major bottleneck to efficient LLM inference: long contexts limit batch sizes and increase memory-bandwidth demands at each decoding step (Zhang et al., 2023; Liu et al., 2024), motivating context compression.

Frontier-model platforms already offer context compaction to sustain conversations beyond a single context window (Anthropic, 2026; OpenAI, 2026). Claude, for example, replaces older context with a text summary. Summaries can omit details whose importance only becomes clear later (Anthropic, 2025), motivating compression of the model's KV representation directly. We study document compression before downstream questions arrive: the cache must preserve information for unseen queries, while preparation costs can be amortized across repeated use.

Eviction methods select original KV entries using attention or reconstruction (Li et al., 2024; Cai et al., 2025; Kim et al., 2025). Cartridges learns compact caches through self-study (Eyuboglu et al., 2025), while Attention Matching fits attention outputs and mass (Zweiger et al., 2026). These approaches motivate test-time training of document memory (Sun et al., 2020): can gradient descent on a compact KV cache preserve document information under an aggressive memory budget?

We introduce Latent Compaction, which trains a document-specific KV cache with frozen model weights. Initialization combines globally selected preservers with anchors and diversifiers. Stage 1 fixes preservers and fits the other entries to full-cache attention outputs and log-normalizers. Stage 2 jointly optimizes all entries using the model's predictions on generic document prompts. Downstream questions and answers are excluded; the trained cache is fixed during reuse. For a 4K document at 32×32\times compression, each layer/head averages 96 preservers and 32 anchors and diversifiers.

Experiments on RULER, LongBench, and Phonebook Lookup demonstrate the benefits of Latent Compaction across synthetic retrieval and natural-document understanding tasks. The method substantially improves retrieval accuracy over budget-matched compression baselines across context

1^{1}The code is released at https://www.github.com/THUNLP/latent-compaction

(a) RULER · 16K context length

Figure

(b) RULER · 16× compression

(c) RULER · 32× compression

(d) Phonebook · 16K context length

(e) Phonebook · 16× compression

(f) Phonebook · 32× compression

KVZip+ Attention Matching SnapKV PyramidKV

Text summ. Latent compaction Uncompressed

Figure 1: Latent Compaction and baselines across compression ratios and context lengths on RULER and Phonebook Lookup with Qwen3-1.7B.

lengths and compression ratios, while LongBench results show gains on broader long-context tasks. Additional Phonebook Lookup experiments demonstrate transfer across model scales and families: the retrieval advantages extend to multiple Qwen3 model sizes and MiniCPM5 models. Ablations identify the roles of initialization, both training stages, and attention normalization. These results concern logical KV-pair budgets rather than measured memory savings or inference speedups.

Our contributions are:

• A novel method for learning compact context representation trained with gradient descent and initialized through complementary selection rules.

• A document-specific test-time training procedure that learns from the frozen model’s attention and predictions without access to downstream questions or answers.

• Superior performance on a wide range of empirical downstream evaluation across three benchmarks and multiple model scales and families, with ablations of initialization, training, and attention normalization.

References (37)