Datasets:
image imagewidth (px) 2.06k 4.01k |
|---|
Geometric vs. Eviction KV Cache Compression: Pre-RoPE Clustering, SnapKV Hybrids & Multi-Depth NIAH
This repository presents a rigorous, statistically grounded benchmark of physical prefill KV Cache compression on Qwen/Qwen2.5-1.5B-Instruct across 3 context lengths (1024, 2048, and 3072 tokens) x 3 independent prompt/needle seeds x 5 needle depths (10%, 30%, 50%, 70%, 90%), totaling N = 45 needle evaluations per configuration (n = 9 independent trials per depth cell).
We evaluate pure geometric clustering (Post-RoPE AW E-Means, Pre-RoPE AW E-Means), token eviction baselines (Naive Drop, StreamingLLM, H2O, SnapKV), and two hybrid architectures (Pinned AW E-Means and SnapKV + Pre-RoPE E-Means).
1. Experimental Design & Metric Definitions
Evaluated Methods (Identical Memory Budget at 4x and 8x)
All methods preserve the initial attention sinks (S=4) and the final instruction window (R=84), compressing the middle context segment of length M down to K_mid = M / ratio:
- Naive Drop: Uniform positional subsampling across the middle segment.
- StreamingLLM (Xiao et al., 2023): Retains attention sinks plus the contiguous tail of the middle segment.
- H2O (De-biased Heavy-Hitter Oracle) (Zhang et al., 2023): Retains top-K tokens ranked by cumulative attention normalized by causal query exposure, eliminating local diagonal bias.
- SnapKV (Li et al., 2024): Selects top-K tokens using average-pooled (
kernel_size=7) attention weights from the final observation window. - Post-RoPE AW E-Means: Clusters stored post-RoPE keys into
K_midattention-weighted barycenters. - Pre-RoPE AW E-Means: Exact-inverts Rotary Position Embeddings (
k_pre = R(-p) k_rope), clusters keys in canonical phase-aligned space, and re-applies Forward RoPE at each cluster's weighted mean position. - Pinned AW E-Means: Allocates 65% of the middle budget to tokens selected by lexical rarity (digits/uppercase codes) x pooled attention, clustering the remaining 35% into AW E-Means centroids.
- SnapKV + Pre-RoPE E-Means: Allocates 80% of the middle budget to exact SnapKV pooled heavy-hitters and compresses the remaining 20% background tokens into Pre-RoPE AW E-Means centroids.
Metric Definitions
- Teacher-Forced Reference Perplexity (
Ref PPL): Cross-entropy perplexity computed by teacher-forcing the ground-truth uncompressed Baseline continuation over the compressed KV cache. - Self-Generated Perplexity (
Self PPL): Perplexity computed on each method's own greedy output. - Output Embedding Cosine Similarity (
Embed CosSim): Cosine similarity betweenall-MiniLM-L6-v2embeddings of the generated response and the baseline response. - Last Hidden State Cosine Similarity (
Hidden CosSim): Cosine similarity of the mean-pooled final Transformer layer hidden states relative to the baseline.
2. Empirical Results (N = 45 Needles per Method, Mean ± SE)
Note on Baseline Limitations: The uncompressed baseline model (
Qwen2.5-1.5B-Instruct) achieves an overall recall of 91.1%, occasionally dropping needles at early depths (e.g., 66.7% at the 10% depth mark). This indicates an inherent limitation in the base 1.5B model's long-context attention retrieval. Consequently, all compressed methods should be evaluated relative to this ~91.1% ceiling.
Summary Table Across 1024, 2048, and 3072 Tokens
| Method | Ratio | Mean KV (MB) | NIAH Recall (N=45) | Ref PPL (TF) | Self PPL | Embed CosSim | Hidden CosSim | Tok/s |
|---|---|---|---|---|---|---|---|---|
| Baseline | 1x | 56.00 | 91.1% ± 3.5% | 1.114 ± 0.013 | 1.114 | 1.0000 | 1.0000 | 16.2 |
| Naive Drop | 4x | 16.35 | 0.0% ± 0.0% | 3.223 ± 0.225 | 1.368 | 0.5673 | 0.9825 | 19.6 |
| StreamingLLM | 4x | 16.35 | 6.7% ± 3.3% | 4.567 ± 0.418 | 1.361 | 0.6087 | 0.9814 | 19.1 |
| H2O | 4x | 16.35 | 4.4% ± 2.9% | 1.722 ± 0.063 | 1.372 | 0.7828 | 0.9869 | 20.0 |
| SnapKV | 4x | 16.35 | 84.4% ± 4.4% | 1.189 ± 0.022 | 1.160 | 0.9553 | 0.9974 | 19.4 |
| Post-RoPE AW E-Means | 4x | 16.35 | 0.0% ± 0.0% | 3.668 ± 0.395 | 1.370 | 0.6222 | 0.9806 | 20.2 |
| Pre-RoPE AW E-Means | 4x | 16.35 | 0.0% ± 0.0% | 3.413 ± 0.278 | 1.408 | 0.6018 | 0.9815 | 18.1 |
| Pinned AW E-Means | 4x | 16.35 | 73.3% ± 10.5% | 1.216 ± 0.023 | 1.188 | 0.8822 | 0.9959 | 18.9 |
| SnapKV + PreRoPE EMeans | 4x | 16.35 | 80.0% ± 6.7% | 1.187 ± 0.023 | 1.171 | 0.9129 | 0.9961 | 20.2 |
| Naive Drop | 8x | 9.73 | 0.0% ± 0.0% | 4.765 ± 0.366 | 1.480 | 0.6186 | 0.9781 | 18.4 |
| StreamingLLM | 8x | 9.73 | 6.7% ± 3.3% | 4.610 ± 0.413 | 1.355 | 0.6052 | 0.9811 | 20.0 |
| H2O | 8x | 9.73 | 2.2% ± 2.2% | 2.358 ± 0.140 | 1.319 | 0.5809 | 0.9831 | 21.1 |
| SnapKV | 8x | 9.73 | 46.7% ± 12.5% | 1.434 ± 0.056 | 1.262 | 0.8560 | 0.9915 | 19.9 |
| Post-RoPE AW E-Means | 8x | 9.73 | 0.0% ± 0.0% | 4.945 ± 0.441 | 1.445 | 0.5708 | 0.9778 | 20.4 |
| Pre-RoPE AW E-Means | 8x | 9.73 | 0.0% ± 0.0% | 4.621 ± 0.328 | 1.513 | 0.5824 | 0.9778 | 18.4 |
| Pinned AW E-Means | 8x | 9.73 | 40.0% ± 12.0% | 1.644 ± 0.128 | 1.327 | 0.7622 | 0.9891 | 20.4 |
| SnapKV + PreRoPE EMeans | 8x | 9.73 | 44.4% ± 11.9% | 1.610 ± 0.115 | 1.351 | 0.7544 | 0.9898 | 20.3 |
Recall by Needle Depth (n = 9 Trials per Cell)
| Method | Ratio | 10% Depth | 30% Depth | 50% Depth | 70% Depth | 90% Depth | Total Hits (N=45) |
|---|---|---|---|---|---|---|---|
| Baseline | 1x | 66.7% (6/9) | 100.0% (9/9) | 88.9% (8/9) | 100.0% (9/9) | 100.0% (9/9) | 91.1% (41/45) |
| Naive Drop | 4x | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/45) |
| StreamingLLM | 4x | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/9) | 33.3% (3/9) | 6.7% (3/45) |
| H2O | 4x | 0.0% (0/9) | 22.2% (2/9) | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/9) | 4.4% (2/45) |
| SnapKV | 4x | 66.7% (6/9) | 100.0% (9/9) | 88.9% (8/9) | 100.0% (9/9) | 66.7% (6/9) | 84.4% (38/45) |
| Post-RoPE AW E-Means | 4x | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/45) |
| Pre-RoPE AW E-Means | 4x | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/45) |
| Pinned AW E-Means | 4x | 55.6% (5/9) | 88.9% (8/9) | 77.8% (7/9) | 88.9% (8/9) | 55.6% (5/9) | 73.3% (33/45) |
| SnapKV + PreRoPE EMeans | 4x | 66.7% (6/9) | 100.0% (9/9) | 88.9% (8/9) | 88.9% (8/9) | 55.6% (5/9) | 80.0% (36/45) |
| Naive Drop | 8x | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/45) |
| StreamingLLM | 8x | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/9) | 33.3% (3/9) | 6.7% (3/45) |
| H2O | 8x | 0.0% (0/9) | 11.1% (1/9) | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/9) | 2.2% (1/45) |
| SnapKV | 8x | 44.4% (4/9) | 77.8% (7/9) | 33.3% (3/9) | 55.6% (5/9) | 22.2% (2/9) | 46.7% (21/45) |
| Post-RoPE AW E-Means | 8x | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/45) |
| Pre-RoPE AW E-Means | 8x | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/9) | 0.0% (0/45) |
| Pinned AW E-Means | 8x | 44.4% (4/9) | 77.8% (7/9) | 22.2% (2/9) | 33.3% (3/9) | 22.2% (2/9) | 40.0% (18/45) |
| SnapKV + PreRoPE EMeans | 8x | 44.4% (4/9) | 77.8% (7/9) | 33.3% (3/9) | 44.4% (4/9) | 22.2% (2/9) | 44.4% (20/45) |
3. Data-Driven Analysis of Findings
I. Pure Geometric Clustering & Pre-RoPE vs. Post-RoPE
- Why Pure Centroids Fail Exact Alphanumeric Retrieval: Both
Post-RoPEandPre-RoPEAW E-Means fail to recover multi-token alphanumeric codes. Even after eliminating RoPE rotational phase interference via exact inverse rotation, averaging distinct tokens into a single continuous barycenter blurs discrete BPE subtoken identities. - Effect of Pre-RoPE Clustering on Perplexity: While removing phase cancellation before clustering preserves key vector norms and slightly improves Reference PPL (e.g., dropping from 3.668 in Post-RoPE to 3.413 in Pre-RoPE at 4x), it does not substitute for discrete token retention on exact-match tasks. 0% recall remains 0%.
II. Token Eviction vs. Hybrid Pinning
- SnapKV Supremacy: Pure
SnapKVremains the most robust selector for exact factual retrieval, achieving 84.4% recall at 4x and 46.7% at 8x. It consistently outperforms our heuristically pinned method (Pinned AW E-Meansat 73.3% and 40.0%), confirming that observation-window attention pooling is a superior signal to static lexical rarity. - The Honest Truth About Hybrid Methods: The data reveals that exact factual retrieval is entirely driven by the exact-match eviction selector (e.g., SnapKV or Pinning). Clustering the remaining background tokens via E-Means provides a continuous representation of the dropped text but does not rescue exact recall. In the
SnapKV + Pre-RoPE E-Meanshybrid, dedicating 80% of the budget to exact SnapKV tokens and clustering the rest yields 80.0% recall at 4x and 44.4% at 8x—slightly lower than pure SnapKV, as discrete slots are traded off for background centroids.
III. Factual Recall vs. Global Semantic Similarity
While eviction-based methods (like SnapKV) excel at exact-token factual recall, they physically discard vast amounts of background context. Conversely, clustering methods attempt to provide a smoother global semantic representation of the entire text. However, as shown by the Output Embedding CosSim, retaining the exact Heavy-Hitters (SnapKV) produces text geometrically closer to the baseline than averaging the background (E-Means). The SnapKV + Pre-RoPE E-Means hybrid attempts to bridge this by retaining exact facts while synthesizing the discarded background into continuous representations.
IV. Resolving the Perplexity Paradox (Ref PPL vs. Self PPL)
Measuring perplexity on a compressed model's own generated text (Self PPL, right) creates an illusion where 8x compression appears comparable to or lower than 4x because the degraded model repeats high-probability generic phrases. Evaluating Teacher-Forced Reference PPL (Ref PPL, left) on the ground-truth baseline continuation eliminates this artifact and penalizes information loss monotonically from 1x to 4x and 8x.
4. Repository Artifacts
results.json: Complete trial logs (N=45 needles per method) and aggregated mean/SE tables.samples.md: Side-by-side generated responses across context lengths and methods.config.json: Experimental configuration and RoPE inversion telemetry.
- Downloads last month
- 124


