Latent Compaction with Test-Time Training
cs.CL, cs.LG
Submitted: 2026-10-14
Updated: 2026-10-14
Comments: 19 pages, 21 figures
Code: https://github.com/OpenBMB/MiniCPM
License: http://creativecommons.org/licenses/by-sa/4.0/
The gist: Long contexts enlarge key--value (KV) caches, increasing memory use and attention costs during generation.
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 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. The code is released at https://www.github.com/THUNLP/latent-compaction
Sources
- RestoreKV: Recovering Full-Cache Behavior Under Aggressive Query-Agnostic KV Cache Eviction
- LongBench: A Bilingual, Multitask Benchmark for Long Context Understanding
- Adapting Language Models to Compress Contexts
- Ada-KV: Optimizing KV Cache Eviction by Adaptive Budget Allocation for Efficient LLM Inference
- In-context Autoencoder for Context Compression in a Large Language Model
- RULER: What's the Real Context Size of Your Long-Context Language Models?
- KVzap: Fast, Adaptive, and Faithful KV Cache Pruning
- KVzip: Query-Agnostic KV Cache Compression with Context Reconstruction
- Prefix-Tuning: Optimizing Continuous Prompts for Generation
- SnapKV: LLM Knows What You are Looking for Before Generation
- KIVI: A Tuning-Free Asymmetric 2bit Quantization for KV Cache
- Test-Time Training with Self-Supervision for Generalization under Distribution Shifts
- End-to-End Test-Time Training for Long Context
- H$_2$O: Heavy-Hitter Oracle for Efficient Generative Inference of Large Language Models
- Fast KV Compaction via Attention Matching
Related papers
- Exploring Solution Divergence and Its Effect on Large Language Model Problem Solving
- Ishigaki-IDS-Bench: A Benchmark for Generating Information Delivery Specification from BIM Information Requirements
- Subliminal Steering: Stronger Encoding of Hidden Signals
- MedStruct-S: A Benchmark for Key Discovery, Key-Conditioned QA and Semi-Structured Extraction from OCR Clinical Reports
- The End of Transformers? On Challenging Attention and the Rise of Sub-Quadratic Architectures
- Untangling the Mechanisms of Misleading Context in Medical Question Answering