Training Transformers for KV Cache Compressibility

Yoav Gelberg, Yam Eitan, Michael Bronstein, Yarin Gal, Haggai MaronarXiv 2026

TL;DR

Post-hoc Key-Value (KV) cache compression methods are fundamentally limited by how compressible a pretrained model's internal representations happen to be. This paper introduces KV-Compression Aware Training (KV-CAT), a continued pretraining method that uses a train-time sparsification policy and self-distillation to explicitly incentivize models to learn highly compressible representations. The resulting models achieve up to a 5× speedup in compression optimization and significantly better accuracy on long-context tasks under tight memory budgets.

What Problem Does This Paper Address?

As large language models (LLMs) are increasingly deployed to process massive documents, long codebases, and extended chat histories, they run into a severe hardware bottleneck: the Key-Value (KV) cache. During inference, transformers store key and value vectors for every single token to avoid recomputing them. This cache grows linearly with context length, quickly dominating GPU memory and slowing down decoding speeds.

To mitigate this, researchers have developed post-hoc compression techniques that prune or compact the KV cache at inference time. However, these methods operate on fixed, pretrained models. The authors of this paper point out a fundamental blind spot: compressibility isn't just a property of the input text; it's a property of the model's internal representations. If a model wasn't trained to be compressed, post-hoc methods hit a hard performance ceiling. This paper asks: Can we train transformers to inherently generate more compressible KV caches?

Methods

The authors propose KV-Compression Aware Training (KV-CAT), a continued pretraining framework designed to bake compressibility directly into the model's representations.

Figure 1: KV-Compression Aware Training (KV-CAT). A context a goes through both masked (left) and dense (right) forward passes. In the masked forward pass, routers (orange) compute masks for groups of consecutive layers, marking KV slots as active (green) or inactive (muted green). In the dense forward pass (blue), all KV slots are kept. The output of the masked forward pass is used to compute Lmask, router distributions are used to compute Lbudget, and the outputs of the dense forward pass are used to compute Lanchor. These are jointly used to update the parameters.

During training, the model processes input sequences through two parallel paths:

  1. The Dense Pass: A standard forward pass where all KV slots are preserved.
  2. The Masked Pass: Lightweight, learned "router" modules sit between layer groups and dynamically mask out a constant fraction (e.g., 50%) of the KV slots, forcing the model to operate under an information bottleneck.

The model is optimized using a joint loss function:

  • Self-Distillation Loss ($\mathcal{L}_{\text{mask}}$): Forces the masked pass's output distribution to match the dense pass's distribution, teaching the model to pack essential information into fewer slots.
  • Anchor Loss ($\mathcal{L}_{\text{anchor}}$): Standard next-token prediction on the dense pass to ensure the model doesn't lose its baseline capabilities.
  • Budget Loss ($\mathcal{L}_{\text{budget}}$): A regularizer ensuring the routers hit the target retention rate.

Crucially, at inference time, the training routers are discarded. Standard post-hoc compression algorithms are applied to the model, which is now far more amenable to being compressed.

Datasets

  • Continued Pretraining: FineWeb-Edu (5.24 billion tokens used to train Qwen2.5-0.5B and Qwen2.5-1.5B variants).
  • Downstream Evaluation:
  • Standard QA (No Compression): HellaSwag, WinoGrande, PIQA, OpenBookQA, ARC-Easy, and ARC-Challenge.
  • Perplexity Evaluation: Held-out FineWeb blocks, WikiText-103, PG-19, and arXiv.
  • Retrieval: A synthetic, deterministic needle-in-a-haystack passkey retrieval task.
  • Long-Context QA: A 221-example subset across 7 subdomains of LongBench v2.

Key Insights and Ideas

  • Compressibility is a Trainable Property: The authors mathematically prove that for almost any sequence-to-vector function, there exist transformer implementations that are perfectly compressible (down to a single KV pair) and others that are completely incompressible. Standard training doesn't care which one it finds; KV-CAT explicitly guides the model toward the compressible ones.
  • No Free Lunch? Think Again: Introducing compression constraints during training typically degrades uncompressed performance. However, by utilizing a dense anchor loss, KV-CAT successfully decouples the two: the model maintains its standard dense performance while gaining massive resilience to post-hoc compression.
  • Adaptive Masking Wins: Ablation studies showed that using learned, adaptive routers during training aligns much better with test-time optimization-based compressors than simple random dropping or static attention-mass filtering.

Key Results

  • Preserved Base Performance: Without any compression applied, KV-CAT models match or slightly exceed the base Qwen2.5 models on standard benchmarks, proving that the training doesn't degrade standard capabilities.
  • 5× Faster Compression Optimization: For gradient-based KV cache compression, KV-CAT checkpoints reach the same level of suffix perplexity up to 5× faster (requiring fewer optimization steps) than the base model.
Figure 2: KV-CAT speeds up gradient-based KV cache compression. We plot the gap in suffix perplexity under full/compressed-prefix inference throughout gradient-based KV cache optimization. Each panel fixes a different KV keep ratio. Across ratios, the KV-CAT checkpoint achieves a comparable ∆PPL in fewer optimization steps than the base model, yielding up to a 5× speedup.
  • Better Perplexity Retention: Under Attention Matching compression, KV-CAT yields up to 3.21× better retention of suffix perplexity at tight budgets compared to the base model.
  • Superior Long-Context Accuracy: On LongBench v2, KV-CAT improves average question-answering accuracy across all retention ratios, showing an average relative improvement of up to 39% over the base model under compression. Similarly, needle retrieval accuracy jumps by 11–19 percentage points at moderate keep ratios.

Limitations and Future Work

  • Training Overhead: KV-CAT requires continued pretraining and dual forward passes, which increases compute costs and time during the training phase.
  • Implementation Complexity: Introducing routing modules and multi-term loss functions adds engineering friction for production integration.
  • Scale Limits: The empirical evaluation was restricted to relatively small models (0.5B and 1.5B parameters). Whether these findings seamlessly translate to 7B+ or 70B+ parameter models remains an open question for future research.

Summary updated

BibTeX
@misc{gelberg2026training,
  author = {Yoav Gelberg and Yam Eitan and Michael Bronstein and Yarin Gal and Haggai Maron},
  title = {{Training Transformers for KV Cache Compressibility}},
  year = {2026},
  eprint = {2605.05971},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2605.05971},
}
Figure