TL;DR
Large Language Models (LLMs) devour GPU memory on long documents because they cache past attention states—the Key-Value (KV) cache. Existing compression methods alter the model’s core weights, locking you into a slower, lossy mode even on short prompts where you have plenty of memory to spare. EchoKV leaves the base model untouched, allowing it to run at full speed on short inputs and seamlessly drop—then reconstruct on the fly—parts of the cache only when memory gets tight.
What Problem Does This Paper Address?
When an LLM generates text, it stores the Keys and Values (intermediate representations of previous tokens) so it doesn’t have to recompute them at every step. This KV cache makes generation fast, but its memory footprint grows linearly with sequence length. Feed an LLM an entire code repository, and the KV cache quickly becomes the primary memory bottleneck.
Recent solutions shrink this cache using low-rank matrix decompositions (like Singular Value Decomposition, or SVD), folding the compression directly into the LLM's projection weights. Here is the catch: parameter modification is a one-way street at runtime. Once you alter the model's weights to compress the cache, you cannot easily toggle back to standard, uncompressed inference when GPU memory is abundant. You pay a quality and latency tax on short, everyday prompts just to survive the occasional massive document.
The authors ask: Can we build a KV cache compression system that runs natively at full power by default, and switches to compressed mode on-demand—even mid-session—only when memory runs low?
Methods
Instead of compressing the entire cache into a dense latent vector, EchoKV simply discards a chunk of the KV dimensions when memory gets tight, and uses a tiny linear neural network (~50M parameters for an 8B model) to predict the missing pieces from what remains during decoding.
Because KV representations share heavy redundancies both across adjacent layers and within the same layer, the predictor reconstructs a layer's dropped dimensions by looking at two things:
- Global Input: Working in small groups of layers, the first layer in each group keeps its entire KV cache intact, acting as a high-fidelity anchor for subsequent layers in that group.
- Local Input: Within the current layer, the first $m$ flattened feature dimensions are kept in contiguous memory to preserve local, layer-specific nuances.
To train these predictors (one for Keys, one for Values per compressed layer) in just a few minutes on a single A100 GPU, the authors introduce a two-stage training recipe:
- Stage 1 (KV-MSE): Trains the linear predictor to directly mimic the dropped KV values using Mean Squared Error. This aligns the representations.
- Stage 2 (Output-MSE): Fine-tunes the predictor so that the actual attention output matches the uncompressed model. Crucially, unlike standard KL-divergence losses that require materializing gigantic attention matrices, Output-MSE works natively with FlashAttention, slashing training time by nearly 3×.
(Note: Following standard practice, EchoKV also keeps the first 4 "attention sink" tokens and the most recent 128 tokens at full precision.)
Datasets
No new benchmarks were introduced. The authors used established datasets across all stages:
- Predictor Training: Primarily LongAlpaca (long-context instructions). To test robustness, they also trained variants on Alpaca (short instructions), ShareGPT (multi-turn chat), and C4 (noisy web pre-training text).
- Evaluation: LongBench (real-world long-context tasks like QA, summarization, and code) and RULER (synthetic stress tests like Needle-in-a-Haystack at 32K, 64K, and 128K context lengths), tested across Llama-3.1-8B, Mistral-7B, and Mistral-Small-24B.
Key Insights and Ideas
- Predictors calibrate geometry, not semantics: Training the lightweight network on short, noisy web text (C4) takes ~2 minutes and yields virtually the same LongBench score (48.65) as training on curated long-context data like LongAlpaca (48.53, ~23 minutes). The predictor isn't learning language; it's just learning the fixed geometric correlations between the model's attention heads.
- Keys and Values are asymmetrically fragile: Dropping and reconstructing Keys hurts model accuracy much faster than reconstructing Values at tight budgets. Cross-layer and intra-layer similarity is simply stronger for Values, whereas Keys are more sensitive and benefit from hybrid low-rank approaches.
- Mid-flight compression: Because EchoKV uses the untouched base model weights, an active FullKV session can be compacted mid-conversation without recomputing the prompt prefix—just slice away the dropped dimensions!
Key Results
- Quality at Tight Budgets: On LongBench with Llama-3.1-8B, compressing the cache to 50% retains almost full performance (48.53 vs. 49.88 FullKV), beating SVD baselines like Palu (31.25) and CommonKV (46.27). At an aggressive 30% ratio, EchoKV scores 45.27 while Palu collapses to 4.91 and CommonKV drops to 31.08.
- Synthetic Retrieval (RULER, 32K, 50% ratio): EchoKV leads compression baselines across all model sizes—scoring 83.52 on Llama-3.1-8B (vs. 87.63 FullKV and 69.68 CommonKV) and 90.52 on Mistral-Small-24B (vs. 93.67 FullKV).
- Adaptive Throughput: On an 80GB A100 (batch size 8), EchoKV runs as native FullKV up to 28K tokens with zero throughput penalty. At 32K and 36K tokens—where FullKV, Palu, and CommonKV all crash with Out-Of-Memory (OOM) errors—EchoKV switches on compression and continues generating at ~2.2–2.7 tokens/s.
Limitations and Future Work
- Decoding Latency: Reconstructing dropped KV slices on the fly isn't free—it adds compute during decoding, trading higher per-token latency for the ability to fit long requests into memory without crashing.
- Extreme Contexts & Ratios: At 128K context length on RULER, EchoKV experiences a noticeable quality dip (62.54 vs. 75.46 FullKV), and at mild compression (70% ratio), methods like ThinK slightly edge it out on some models.
- Future Directions: Because EchoKV is orthogonal to quantization (shrinking bit-widths) and token eviction (dropping unimportant words), combining them could unlock massive compression. Furthermore, the authors highlight heterogeneous compression—using low-rank projections for tricky Keys while using EchoKV reconstruction for Values—as a highly promising path forward.
Summary updated