Summary (Overview)
- NestedKV is a training-free KV cache compression method for long-context LLMs that reframes cache eviction as continuum-memory anomaly detection over the key stream, inspired by the Continuum Memory System in Nested Learning theory.
- The method maintains three time-scale key anchors — stable (global mean), episodic (block mean), and current (sliding-window mean) — and scores each token by its cosine anomaly against each scale, retaining tokens anomalous against any scale.
- A training-free outer learner combines the per-scale rankings via two mechanisms: (1) head-adaptive softmax blending that up-weights the most discriminative scale per attention head, and (2) surprise-gated routing that switches to the strongest individual memory when the three scales disagree.
- The score is key-only, pairs with adaptive per-head memory allocation, and requires no training or LLM modification — remaining compatible with optimized attention kernels.
- Across RULER (4k–32k), LooGLE, LongBench, LongBench-E, InfiniteBench, and MMLU-Pro on Qwen3 and Llama-3.2 models, NestedKV is strongest under aggressive compression (e.g., +19.10 points over KeyDiff on RULER at r=0.75 on Qwen3-4B) while preserving short-prompt capability.
Introduction and Theoretical Foundation
Background and Motivation
Long-context language models face a fundamental bottleneck: the key-value (KV) cache grows linearly with context length and batch size, dominating inference cost even when model weights are fixed. This motivates a growing line of training-free KV cache compression research aimed at reducing cache memory without fine-tuning.
The Single-Anchor Limitation
Most existing methods choose one importance signal for token ranking:
| Method | Anchor Signal |
|---|---|
| H2O / attention-based (Liu et al., 2023) | Past attention mass (persistence-of-importance) |
| StreamingLLM (Xiao et al., 2024) | Recency + attention sinks |
| SnapKV (Li et al., 2024b) | Observation window near prompt end |
| PyramidKV (Cai et al., 2024) | Layer-wise cache budgets |
| KeyDiff (Park et al., 2026) | Geometric distinctiveness of keys from mean direction |
The authors argue this is brittle: "A token may be important because it is globally unusual in the document, because it marks a local topic shift inside one segment, or because it is part of the recent stream that will shape immediate generation." Under aggressive compression, these notions diverge — a global mean can miss local episodes; a local rule can overfit repetitive blocks; a recent-window rule can discard earlier retrieval evidence.
Theoretical Basis: Nested Learning and Continuum Memory
The method is grounded in the Nested Learning perspective, which posits that models maintain compressed context flows through nested memory systems with a self-modifying update rule (Behrouz et al., 2026a). NestedKV instantiates this at test time:
- Inner learners: Three time-scale memory anchors (stable, episodic, current) each produce an independent token ranking.
- Outer learner: A training-free combination rule that adapts per head and per token, instantiating the "self-modifying compressor motif" with no trainable parameters.
Methodology
2.1 KV Compression as Nested Memory Maintenance
For layer and KV head , the full prefill memory is:
NestedKV constructs a compressed memory:
where is the head-specific memory budget and is the fixed NestedKV policy (no learned parameters). All scores use normalized keys , focusing on directional structure in key space.
2.2 Continuum Memory State
For every cached token , NestedKV maintains three memory anchors:
Stable memory (document-level mean):
Episodic memory (block mean, block size ):
Current memory (sliding-window mean, window size ):
2.3 Per-Scale Anomaly Scores
Each token receives three anomaly scores (negative cosine similarity):
Interpretation: Low means token is typical w.r.t. scale (redundant); high means the token carries information not explained by that scale. Each score is min-max normalized per head (), and the first positions are pinned (assigned large values) for attention stability.
2.4 Outer Learner: Head-Adaptive Blend with Surprise Routing
Head-adaptive blend weights: For each head, measure how discriminative each scale is:
Blend weights via softmax over reliability gaps anchored by a fixed log-prior:
with prior and fixed temperature . The blended score:
Compression-induced surprise (cross-scale disagreement):
Winner score (strongest individual memory):
Routed score (sigmoid gate over surprise):
with fixed gate threshold and sharpness .
2.5 Compression Operator
Keeps positions anomalous against at least one memory scale.
2.6 Head-Wise Memory Competition
Instead of uniform per-head budgets, NestedKV selects the globally highest-residual (head, token) pairs:
with a small per-head safeguard, inducing head-specific budgets:
Empirical Validation / Results
Experimental Setup
- Models: Qwen3-0.6B/4B/8B/32B, Llama-3.2-1B/3B-Instruct
- Benchmarks: RULER (13 tasks, 4k–32k contexts), LongBench, LooGLE, LongBench-E, InfiniteBench, MMLU-Pro
- Compression ratios: (fraction of KV entries evicted)
- Baselines: StreamingLLM, SnapKV, Expected Attention, PyramidKV, KeyDiff, Full KV (upper bound)
RULER Results (Table 1, Qwen3-4B)
| Context | Method | r=0.25 | r=0.50 | r=0.75 |
|---|---|---|---|---|
| 4k | KeyDiff | 89.12 | 75.06 | 60.22 |
| 4k | NestedKV | 93.60 | 90.40 | 79.32 |
| 8k | KeyDiff | 82.72 | 74.36 | 62.53 |
| 8k | NestedKV | 91.11 | 89.35 | 78.52 |
| 16k | KeyDiff | 76.84 | 72.51 | 62.20 |
| 16k | NestedKV | 90.44 | 88.36 | 79.89 |
| 32k | KeyDiff | 68.62 | 63.38 | 55.77 |
| 32k | NestedKV | 85.25 | 82.61 | 73.11 |
Key finding: At r=0.75, NestedKV improves over KeyDiff by +19.10 (4k), +15.99 (8k), and +17.69 (16k) on Qwen3-4B.
LongBench Results (Figure 5, Qwen3-4B)
- At r=0.75: NestedKV = 50.06 vs. KeyDiff = 30.77
- At r=0.85: NestedKV = 45.38 vs. SnapKV = 40.61
- At r=0.95: NestedKV = 37.32 vs. KeyDiff = 17.55
Qwen3-32B Scaling (Table 2)
NestedKV is highest-scoring in all six 4k/8k configurations: e.g., 95.10 vs. KeyDiff's 90.23 at 4k/r=0.25, and 76.71 vs. 71.17 at 8k/r=0.75.
Short-Context Preservation (MMLU-Pro)
- At r=0.25: NestedKV = 36.5 vs. Full KV = 36.3 (essentially lossless)
- At r=0.75: NestedKV = 33.1 vs. SnapKV = 22.0, PyramidKV = 21.4
Ablation Study (Table 3, Qwen3-4B RULER 4k, r=0.75)
| Variant | Score | Δ |
|---|---|---|
| NestedKV (full) | 79.32 | — |
| w/o adaptive (uniform budget) | 70.91 | -8.41 |
| w/o continuum (single anchor) | 71.33 | -7.99 |
| w/o both | 60.22 | -19.10 |
The combined removal exceeds the sum of individual deltas (16.40), showing the two components are coupled by the discrete top-k decision.
Surprise Gate Ablation (Table 4)
| Variant | Score |
|---|---|
| NestedKV (Surprise Gate) | 79.32 |
| Only average (blend only) | 76.25 |
| Only max (winner only) | 75.54 |
Efficiency (Table 5, Qwen3-4B, 32k context, r=0.75)
| Method | KV | Prefill (s) | Decode (ms/tok) | Peak (GB) |
|---|---|---|---|---|
| Full KV | 100% | 6.28 | 38.90 | 21.48 |
| KeyDiff | 25% | 6.34 | 31.46 | 18.11 |
| SnapKV | 25% | 6.50 | 31.49 | 18.11 |
| NestedKV | 25% | 6.36 | 31.47 | 18.11 |
NestedKV's three-time-scale scoring adds only ~0.5% prefill overhead over single-anchor KeyDiff, with identical decode latency and peak memory.
Theoretical and Practical Implications
Theoretical Implications
-
Reframing KV compression: The paper reframes training-free KV cache compression as continuum-memory anomaly detection over the key stream, giving token eviction a Nested Learning interpretation as bounded test-time memory maintenance.
-
Multi-scale vs. single-anchor scoring: The results demonstrate that no single importance signal (attention, recency, distinctiveness) is sufficient under aggressive compression — the three scales capture complementary information, and their combination degrades more gracefully.
-
Head specialization: The head-adaptive blending reveals that different attention heads specialize in different temporal roles (stable vs. episodic vs. current), validating the need for per-head adaptation rather than uniform mixing.
-
Surprise as a routing signal: Cross-scale disagreement (surprise) is a useful meta-signal for deciding whether to trust the blended average or the strongest individual memory — a novel mechanism not present in prior work.
Practical Implications
-
Deployment-ready: NestedKV is training-free, key-only (compatible with optimized attention kernels like FlashAttention), and requires no LLM modification.
-
Graceful degradation: The method's main benefit is robustness under aggressive compression (r=0.75–0.95), which is precisely the regime where memory savings matter most for long-context deployment.
-
Scalability: Gains hold across model families (Qwen3, Llama-3.2) and scales (0.6B to 32B), suggesting the approach generalizes well.
-
Minimal overhead: The additional prefill cost is negligible (~0.5% over KeyDiff), making it practical for real-world serving.
Conclusion
Main Takeaways
NestedKV treats KV cache compression as bounded test-time memory maintenance using a continuum of three time-scale key statistics (stable, episodic, current) as inner learners, combined by a training-free outer learner with head-adaptive blending and surprise-gated routing. The method is:
- Strongest under aggressive compression: The multi-time-scale scoring degrades more gracefully when the retained cache must be small.
- Robust across benchmarks and models: Consistently best or near-best on RULER, LongBench, LooGLE, and MMLU-Pro across Qwen3 and Llama-3.2 families.
- Training-free and efficient: No learned parameters, minimal prefill overhead, compatible with optimized kernels.
Limitations and Future Directions
-
Assumption of redundancy: The method assumes redundancy w.r.t. key statistics is a useful eviction signal — this is weaker for code-completion tasks where local repetition is the pattern to preserve. Future variants should adapt continuum weights to input structure.
-
Prefill-only, query-agnostic: NestedKV does not recompute scores during decoding or use query information. Decoding-time recompression and query-aware variants remain open future work.
-
Frozen models only: The method does not explore learned or fine-tuned variants that could further improve difficult settings.
-
Code-like local regularity: The paper suggests reducing episodic/current redundancy penalties when the prompt exhibits code-like structure, pointing to a need for input-adaptive continuum weights.
Related papers
- How Do Agents Fail on AutoResearch: End-to-End Diagnostic Evaluation on 100 Real-World Frontier Research Tasks
Autonomous research agents fail across all models because they lack a metacognitive loop: they cannot check outputs against evidence, act on identified flaws, or question their methods.
- DART: Decoded Attention over Recurrent States for Efficient Long-Context Sequence Modeling
DART augments Mamba-2 with attention-style key-value retrieval over compressed recurrent states, achieving 75% cache memory savings while substantially improving long-range recall and retrieval tasks.
- EVOMAL: Self-Poisoning in Self-Evolving Coding Agents
Self-evolving LLM coding agents are vulnerable to self-poisoning, where agents unknowingly author and propagate malicious skills, achieving attack success rates up to 86.7% and forming self-sustaining worms.