TL;DR
NestedKV is a training-free key-value (KV) cache compression method that treats token eviction as a multi-time-scale anomaly detection problem. By tracking context across global, episodic, and local windows and routing tokens based on "compression-induced surprise," it maintains high accuracy even when discarding up to 95% of the KV cache.
What Problem Does This Paper Address?
As Large Language Models (LLMs) handle increasingly massive context windows, they hit a hard physical bottleneck: the key-value (KV) cache. The KV cache stores past token representations to avoid redundant computations during generation, but it grows linearly with context length and batch size, quickly dominating GPU memory.
To fit long contexts into memory, researchers use training-free cache compression to evict less important tokens. However, existing methods rely on a single proxy for token importance—such as past attention mass, recency, or global geometric distinctiveness. The authors show that this single-view approach is brittle. A token containing a crucial answer might have low attention mass or look typical globally, yet be highly significant within its local topic block. Under aggressive compression, single-signal methods suffer from severe blind spots and drop vital information.
Methods
NestedKV introduces a key-only compression policy inspired by the Continuum Memory System in Nested Learning. Instead of collapsing token importance into one metric, it evaluates tokens across three nested time-scales:
- Stable Memory: Summarizes the entire prefilled context to capture document-level regularities.
- Episodic Memory: Summarizes local blocks (segments) to capture passage- or turn-level structure.
- Current Memory: Summarizes the immediate sliding window (e.g., the last 64 tokens) to capture short-range continuity.
For every token, NestedKV computes a cosine anomaly score against each of these three scales. If a token's key vector deviates significantly from a summary, it is considered "anomalous" (informative) and a candidate for retention.
To combine these three distinct views without any training or model modification, NestedKV employs a two-axis Outer Learner:
- Head-Adaptive Blend: Different attention heads specialize in different temporal roles. NestedKV dynamically measures how discriminative each memory scale is for a given head and adjusts the mixing weights via a softmax function.
- Surprise-Guided Routing: If the three memory scales agree on a token's importance, it uses the blended score. If they strongly disagree (high standard deviation among rankings), this is flagged as compression-induced surprise. The system then routes the token to its maximum individual anchor score, ensuring that if a token is highly anomalous in any single view, it survives eviction.
Finally, the layer-wise memory budget is distributed competitively across heads based on their normalized residuals, allowing heads with higher information density to claim more cache space.
Datasets
The authors evaluated NestedKV using Qwen3 (0.6B to 32B) and Llama-3.2 (1B and 3B) models across a comprehensive suite of benchmarks:
- RULER (4k–32k): A synthetic benchmark testing long-context retrieval and aggregation.
- LongBench & LongBench-E: Real-world long-context understanding tasks.
- LooGLE: Long- and short-dependency question answering over long documents.
- InfiniteBench: Challenging book-length QA (
longbook_qa_eng) and repository-scale code debugging (code_debug). - MMLU-Pro: A 10-choice multi-domain knowledge benchmark used to verify that short-context capabilities are preserved.
Key Insights and Ideas
- Reframing Eviction as Anomaly Detection: Instead of asking "which tokens did the model attend to most?", NestedKV asks "which tokens provide information that isn't already compressed/explained by our memory summaries?"
- The Value of "Surprise": Cross-scale disagreement is a powerful signal. A token that looks completely ordinary on a global scale but highly unusual in a local window triggers high "surprise," protecting it from being averaged out and deleted.
- Graceful Degradation: The benefit of multi-time-scale scoring becomes starkly apparent under extreme compression. While single-signal methods experience catastrophic performance drops when the cache budget becomes tight, NestedKV's multi-anchor approach degrades gracefully.
Key Results
NestedKV demonstrates its clear superiority under aggressive compression ratios ($r$, the fraction of KV entries removed):
- RULER Benchmark: On Qwen3-4B at $r=0.75$ (retaining only 25% of the cache), NestedKV outperformed the strong KeyDiff baseline by up to 19.10 points at 4k context and maintained stable performance up to 32k.
- LongBench: At $r=0.75$, NestedKV boosted the Qwen3-4B average score to 50.06 (compared to KeyDiff's 30.77). Under extreme compression ($r=0.95$, keeping just 5% of the cache), NestedKV retained a score of 37.32, while KeyDiff collapsed to 17.55.
- Short-Context Preservation: On MMLU-Pro, NestedKV remained virtually lossless at $r=0.25$ (36.5% vs. Full KV's 36.3%) and held at 33.1% at $r=0.75$, whereas baselines like SnapKV and PyramidKV collapsed down to ~22%.
Limitations and Future Work
- Domain Specificity (Code vs. Text): NestedKV assumes that local repetition implies redundancy. This holds for natural language but can fail in code-completion tasks, where local repetitive structures are exactly what the model needs to predict the next line.
- Prefill-Only Compression: NestedKV is currently query-agnostic and prunes the prompt KV cache exactly once after the prefill stage. It does not dynamically re-compress or update memory routing weights during the autoregressive decoding phase. Extending this multi-scale continuum memory to decoding-time recompression remains an open challenge for future work.
Summary updated