Latent Compaction with Test-Time Training
Summary (Overview)
- Novel approach to KV cache compression: Latent Compaction learns a compact, document-specific KV cache through test-time training, treating the cache as a trainable neural network with frozen model weights.
- Two-stage training pipeline: Stage 1 fits attention outputs and log-normalizers to the full cache (with reconstruction-selected entries frozen), followed by Stage 2 end-to-end distillation from the full-cache model using generic document prompts.
- Complementary initialization strategy: Cache entries are initialized using three rules—KVZip+ reconstruction scores (preservers), teacher attention (anchors), and key-space diversity (diversifiers).
- Superior empirical results: Achieves 96.7% accuracy at 32× compression on RULER (vs. 40.0% for KVZip+), with strong gains on LongBench and Phonebook Lookup across multiple model scales and families (Qwen3, MiniCPM5).
- No access to downstream questions: Training uses only generic prompts about the document, making the optimized cache reusable across unseen queries.
Introduction and Theoretical Foundation
Background and Motivation
Large key–value (KV) caches are a critical bottleneck in efficient LLM inference. Long contexts increase memory use and attention costs during generation, limiting batch sizes and increasing memory-bandwidth demands. Frontier-model platforms already offer context compaction (e.g., Claude's text summaries), but text summaries can omit details whose importance only becomes clear later.
The key research question: Can gradient descent on a compact KV cache preserve document information under aggressive memory budgets?
Theoretical Foundation
The paper builds on several theoretical threads:
- KV-cache eviction (H₂O, SnapKV, PyramidKV, KVZip+): Selecting original KV entries using attention or reconstruction scores.
- Learned context representations (Prefix-tuning, AutoCompressors, Cartridges, Attention Matching): Optimizing compact continuous representations with frozen model weights.
- Test-time training (TTT): Adapting model parameters using self-supervised objectives on unlabeled test inputs before prediction.
The core insight is that the KV cache can be treated as a neural network itself, optimized through test-time training to preserve document information for unseen questions.
Attention Preliminaries
For a query head with query , keys , values , and cache entries indexed by set :
where is the scalar normalizer and is the attention scale.
Methodology
Memory Architecture
Given an average budget of KV pairs per layer and KV head, Latent Compaction initializes KV slots total. Each slot carries a scalar attention bias .
For a query with compacted keys , values and biases :
Handling subsequent tokens: Question and generated tokens append ordinary KV pairs after the document. The combined output is:
where is the compressed-cache normalizer.
Initialization Strategy
Three complementary entry types:
| Entry Type | Selection Rule | Purpose |
|---|---|---|
| Preserver | Top KVZip+ reconstruction scores (global ranking across all layers/heads) | Preserve highest-information original entries |
| Anchor | High teacher attention scores + first document position (attention sink) | Attention-informed seeds |
| Diversifier | Farthest-first traversal in key space | Broad key-space coverage |
Anchor scores are computed as:
Diversifiers are selected via farthest-first traversal:
Budget allocation: slots per head for anchors + diversifiers; remaining slots from global KVZip+ ranking.
Training Stage 1: Attention Fitting
Fits each layer independently using captured teacher queries:
Hats denote standardization using fixed teacher statistics. Preservers are frozen during this stage; anchors and diversifiers receive updates.
Training Stage 2: End-to-End Refinement
All entries are jointly optimized using KL divergence and language modeling loss:
The teacher's top-20 token set is retained individually; the rest is grouped into a tail category.
Teacher Rollouts
- 480 generic text prompts (24 document requests × 20 response instructions)
- Each rollout generates up to 24 continuation tokens from the frozen full-cache model
- No downstream questions or answers are used
- Teacher forcing: student receives teacher tokens, not its own predictions
Empirical Validation / Results
Experimental Setup
- Default model: Qwen3-1.7B (frozen weights, BF16 computation, FP32 KV cache)
- Training: 1,000 stage-1 updates + 1,000 stage-2 updates, AdamW with learning rates and
- Baselines: KVZip+, Attention Matching, SnapKV, PyramidKV, full-cache, text-summary references
Main Results
RULER (16K context): Latent Compaction achieves 96.7% accuracy at 32× compression vs. 40.0% for KVZip+.
LongBench: Outperforms text summarization throughout and KVZip+ at 16× and 32× compression across Qwen3-0.6B, 1.7B, and 4B models.
Phonebook Lookup: Large gains at 16× compression; all methods approach zero at 64×+ compression.
Transfer Results
Retrieval advantages extend to:
- Qwen3: 0.6B, 1.7B, 4B, 8B model scales
- MiniCPM5: Different model family
Ablation Results
Table 1: Initialization ablations (Phonebook Lookup, 16× compression)
| Configuration | 4K | 8K | 16K | Avg. |
|---|---|---|---|---|
| Latent Compaction (25% anchors + 75% diversifiers) | 87.75 | 83.75 | 70.50 | 80.67 |
| Replace diversifiers with random document KVs | 29.25 | 20.00 | 12.25 | 20.50 |
| Replace diversifiers with Gaussian random vectors | 27.50 | 17.50 | 14.25 | 19.75 |
| Replace diversifiers with first document KVs | 65.50 | 42.50 | 22.50 | 43.50 |
| Replace anchors with KVZip+ | 69.25 | 58.75 | 43.50 | 57.17 |
Table 2: Stage-1 ablations (Phonebook Lookup, 16× compression)
| Method | 4K | 8K | 16K | Avg. |
|---|---|---|---|---|
| Latent Compaction | 87.75 | 83.75 | 70.50 | 80.67 |
| Remove stage 1 | 13.75 | 13.25 | 14.75 | 13.92 |
| Remove frozen preserver KVs in stage 1 | 83.25 | 60.75 | 43.50 | 62.50 |
| Preserver KVs trainable in stage 1 | 43.75 | 32.25 | 24.25 | 33.42 |
| Remove log Z MSE loss term | 42.50 | 38.00 | 29.00 | 36.50 |
Table 3: Stage-2 ablations (Phonebook Lookup, 16× compression)
| Method | 4K | 8K | 16K | Avg. |
|---|---|---|---|---|
| Latent Compaction | 87.75 | 83.75 | 70.50 | 80.67 |
| Remove stage 2 | 81.00 | 68.25 | 62.75 | 70.67 |
| KL-divergence only | 83.00 | 83.50 | 65.25 | 77.25 |
| Remove tail-probability term in KL | 82.00 | 81.75 | 61.00 | 75.25 |
| Full-vocabulary distillation | 87.75 | 84.25 | 70.00 | 80.67 |
Table 4: Architectural ablations (Phonebook Lookup, 16× compression)
| Method | 4K | 8K | 16K | Avg. |
|---|---|---|---|---|
| Latent Compaction | 43.75 | 32.25 | 24.25 | 33.42 |
| Remove attention biases () | 43.00 | 29.25 | 24.00 | 32.08 |
| Equal mix: | 0.25 | 0.00 | 0.25 | 0.17 |
Key Findings from Ablations
- Diversifiers are crucial: Replacing them with random or Gaussian vectors causes catastrophic accuracy drops (~60 points)
- Stage 1 is essential: Removing it reduces accuracy from 80.67% to 13.92%
- Freezing preservers in stage 1 matters: Trainable preservers reduce accuracy by ~47 points
- Log-normalizer loss is critical: Removing it drops accuracy by ~44 points
- Normalizer weighting (Eq. 5) is vital: Equal averaging collapses accuracy to ~0%
- Optimal training duration: 1,000 updates for both stages balances accuracy and cost
Theoretical and Practical Implications
Theoretical Contributions
-
KV cache as a trainable neural network: The paper demonstrates that treating the KV cache as a parameterized model and optimizing it with gradient descent can preserve retrieval accuracy under aggressive compression—a paradigm shift from traditional eviction-based methods.
-
Two-stage curriculum: The staged approach (attention fitting → end-to-end distillation) mirrors curriculum learning, first matching local attention statistics then refining global prediction quality.
-
Complementary selection theory: The combination of reconstruction importance (KVZip+), teacher attention, and key-space diversity provides theoretical justification for covering both information-theoretic importance and geometric coverage.
Practical Implications
-
Question-agnostic compression: Since training uses only generic prompts, the optimized cache can be reused across arbitrary downstream queries—critical for real-world deployment where questions are unknown in advance.
-
Model transferability: The procedure transfers across model scales (0.6B–8B) and families (Qwen3, MiniCPM5), suggesting broad applicability.
-
Logical vs. physical budget: The paper explicitly notes that results concern logical KV-pair budgets; physical memory savings depend on precision, biases, and padding choices.
Limitations
- Per-document training cost: 1,000 + 1,000 updates per document is computationally expensive, though amortizable across repeated use
- Extreme compression degradation: All methods approach zero accuracy at 64×+ compression
- Text summarization advantage at extreme ratios: On RULER at the most aggressive ratios, text summaries outperform Latent Compaction
Conclusion
Latent Compaction introduces a novel paradigm for KV cache compression: treating the cache as a trainable document-specific neural network optimized through test-time training. The method achieves substantial gains over budget-matched baselines across RULER, LongBench, and Phonebook Lookup benchmarks, with strong transfer across model scales and families.
Key takeaways:
- Initialization via complementary selection rules (preservers + anchors + diversifiers) is critical for success
- Two-stage training (attention fitting followed by end-to-end distillation) provides complementary benefits
- Attention normalization (biases and normalizer weighting) is essential for correct joint attention over document and subsequent tokens
Future directions:
- Reducing per-document preparation cost
- Studying broader task types beyond retrieval and long-context understanding
- Exploring physical memory optimization (precision, padding) alongside logical KV-pair budgets
The results demonstrate that treating the KV cache as a neural network and optimizing it with test-time training can preserve retrieval accuracy under aggressive compression, opening new avenues for efficient long-context LLM inference.
Related papers
- How Model Growth, Recursion, and Boundary Operators Influence Scaling Exponents
Architectural interventions like model growth and boundary operators improve scaling exponents, with grown models matching GPT-3 13B using roughly 20x less compute.
- Evolving Together, Failing Apart: The Skill-Policy Co-evolution Trap in Self-Improving Agents
Skill–policy co-evolution methods report inflated performance because their delivered skill banks are fragile to drift, erasing 52–93% of claimed gains.
- DuoDiscover: Scaling Autonomous Discovery Beyond the Evaluation Bottleneck
DuoDiscover co-discovers optimization targets and cheap proxy evaluators with fidelity testing, achieving up to 15x speedups and beating human experts across software and chip design.