TL;DR
When large language models read massive documents, their short-term memory—the Key-Value (KV) cache—balloons in size and chokes GPU bandwidth. ResKV solves this by grouping semantically similar memory vectors together and only pruning and quantizing the tiny differences (residuals) from each group's average. This simple mathematical shift slashes memory usage and delivers over 4× faster generation throughput without making the model forget what it just read.
What Problem Does This Paper Address?
As LLMs scale to 100K+ token contexts, the KV cache—which stores intermediate attention representations for past tokens so the model doesn't recompute them—grows linearly with sequence length. During text generation, streaming this massive cache from GPU memory for every single new word creates a severe memory bottleneck.
One popular way to shrink the KV cache is channel-wise unstructured pruning: zeroing out the least important feature dimensions inside each token's vector. However, existing pruning methods operate directly on raw vectors and hit two walls:
- Steep accuracy drops at high sparsity: Zeroing out 75% or more of a raw vector distorts its direction too much, confusing the attention mechanism.
- Quantization incompatibility: Ideally, we want to combine pruning with low-bit quantization (shrinking 16-bit numbers to 4-bit). Because different tokens lose different channels, you have to quantize per-token. Unfortunately, raw Key vectors contain notorious "outlier" channels with massive values that ruin per-token quantization scales.
Prior pruning methods completely overlooked a well-known quirk of LLMs: many KV vectors across a sequence are semantically very similar to one another.
Methods
Instead of pruning raw vectors, ResKV borrows a classic idea from signal compression: store a shared reference, and compress only the residuals.
- Pre-RoPE Global Clustering: Before positional encodings (RoPE) are applied, ResKV uses global K-means clustering to group cached Key and Value vectors into $N_C$ semantic clusters (defaulting to 32), computing a high-precision BF16 centroid for each.
- Residual Extraction, Pruning, and Quantization: Each token's cluster centroid is subtracted from its original vector, leaving behind a low-magnitude, near-zero residual vector. ResKV then applies unstructured channel-wise pruning (tracking kept channels with a compact 128-bit binary mask) and low-bit per-token quantization exclusively to these residuals. Centroids stay in fast on-chip shared GPU memory, while tiny sparse residuals sit in off-chip memory.
- Asymmetric Flash Decoding: ResKV integrates directly into Flash Decoding, treating Keys and Values differently to save compute. Because RoPE requires full dense vectors, Keys are fully reconstructed on the fly (adding the centroid back to the sparse residual) before computing attention scores. For Values, ResKV uses deferred centroid fusion: it accumulates attention-weighted sparse residuals across token chunks first, and only multiplies in the Value centroids once globally at the very end.
During inference, initial "attention sink" tokens (the first four tokens) and a small sliding window of recent tokens are kept uncompressed, flushing into existing clusters once the window fills up.
Datasets
Because ResKV is a plug-and-play inference method, no training datasets are required. The authors evaluate on Llama-3-8B, Llama-3.1-8B, and Qwen3-8B using established long-context benchmarks (no new benchmarks are introduced):
- WikiText-2: Used for motivational analysis of vector magnitudes and cosine distances.
- LongBench: Evaluates real-world tasks including single/multi-document QA, summarization, code completion, few-shot learning, and synthetic tasks (tested at 8K and 16K lengths).
- RULER & Needle-In-A-Haystack (NIAH): Used to test retrieval fidelity across 13 tasks at 16K context length and varying document depths.
Key Insights and Ideas
- Cluster before RoPE: Rotary Positional Embeddings twist vectors in space based on where they sit in the text, destroying their natural semantic similarity. Intercepting raw Keys before RoPE yields much tighter clusters and smaller residuals.
- Residuals tame the outliers: Subtracting the cluster centroid absorbs the massive channel-wise outliers that normally break quantization. On Llama-3-8B, the average feature magnitude drops from 19.77 in raw/pruned Key vectors down to just 3.69 in residual vectors—making per-token INT4 quantization suddenly viable alongside unstructured pruning.
- Minimal angular distortion: At 75% sparsity, standard pruning methods warp Key vectors to cosine distances of 0.05–0.08 from the original. Compensating pruned residuals with centroids keeps the average cosine distance at a tiny 0.01.
- Linearity gives Values a free lunch: Because the attention output is just a weighted sum of Value vectors, you don't actually need to reconstruct full Value vectors per token. Factoring out the centroids saves massive per-token arithmetic during decoding.
Key Results
- Throughput Speedups: With an 8K input and 2K output on Llama-3.1-8B at 75% sparsity, ResKV hits 4.27× higher generation throughput than the FlashAttention-2 dense baseline (at batch size 16) and 2.63× higher end-to-end throughput than Mustafar, a competing channel-pruning baseline (at batch size 32).
- Memory Savings: At batch size 32 and 75% sparsity, ResKV cuts peak GPU memory from 75.97 GB down to 47.70 GB—a 37.2% reduction, allowing larger batch sizes on a single GPU.
- Accuracy Retention: At 50% sparsity, ResKV retains ~99.6–99.8% of dense baseline accuracy on LongBench. At 75% sparsity on Llama-3-8B, it beats SparK and Mustafar by 2.05 and 2.26 points. Under extreme 87.5% sparsity, where baselines collapse, ResKV outperforms them by +6.5 to +9.2 points across Llama-3-8B and Qwen3-8B.
Limitations and Future Work
The authors highlight two practical trade-offs:
- Prefill Latency: Running K-means clustering on prompt tokens introduces a mild, one-time latency overhead during the prefill stage before generation begins.
- Centroid Drift in Long Generations: Once the clusters are established up to the predefined maximum count, newly generated tokens during decoding are assigned to existing centroids. If the generated text shifts to a wildly different topic, new KV vectors may be dissimilar to the old centroids, shrinking the accuracy advantage of residual pruning. No specific future work directions are explicitly outlined beyond these observations.
Summary updated