TL;DR
MiniCache is a training-free, "plug-and-play" method that slashes the memory footprint of Large Language Models (LLMs) by compressing the Key-Value (KV) cache across the depth dimension. By exploiting the high similarity between adjacent layers in a model's middle-to-deep sections, it achieves up to a 5x increase in throughput and a 41% reduction in memory usage when combined with existing quantization techniques, all while maintaining near-lossless accuracy.
What Problem Does This Paper Address?
As LLMs tackle increasingly long sequences, the Key-Value (KV) cache—which stores previous token states to speed up generation—becomes a massive bottleneck. For long-context applications, the KV cache can actually grow to be several times larger than the model weights themselves, leading to "Out of Memory" errors or forcing tiny batch sizes that severely limit inference throughput.
While existing research has focused on intra-layer redundancy (using fewer bits per token or dropping "unimportant" tokens within a single layer), the authors of MiniCache noticed a neglected dimension: inter-layer redundancy. They observed that in the deeper halves of models like LLaMA-3 or Mistral, the KV states for the same token are remarkably similar across adjacent layers. MiniCache targets this "depth-wise" redundancy to squeeze more performance out of existing hardware.
Methods
MiniCache introduces a simple yet mathematically elegant strategy to merge KV caches across layers without requiring any retraining or fine-tuning:
- Cross-Layer Merging: Starting from the midpoint of the model (e.g., layer 16 of a 32-layer model), the system merges the KV states of layer $l$ and $l-1$ into a single shared representation.
- Magnitude-Direction Disentanglement: Instead of a simple average (which loses critical information), MiniCache separates state vectors into their magnitude (length) and direction.
- Spherical Linear Interpolation (SLERP): To merge the directions, the authors use SLERP. This technique interpolates along the shortest path on a unit sphere, preserving the geometric integrity of the high-dimensional vectors far better than linear averaging.
- Token Retention Strategy: Not all tokens are "mergeable." The authors found that a small subset of "outlier" tokens have very different states across layers. MiniCache identifies these using angular distance and keeps them unmerged to prevent accuracy degradation.
- Restoration: During the attention mechanism, the shared directional vector is rescaled by the original, layer-specific magnitudes to approximate the original states.
Datasets
The authors conducted a massive evaluation across a diverse set of benchmarks to ensure robustness:
- Reasoning & QA: GSM8K (math), COQA (conversational QA), and TruthfulQA.
- General Language Understanding: Benchmarks from the
lm-eval-harness, including PIQA, RTE, WinoGrande, and OpenBookQA. - Long Context: The LongBench suite (including LCC and RepoBench-P) to test performance on sequences up to 32k+ tokens.
- Real-world Workloads: Synthetic workloads derived from the ShareGPT dataset to measure actual GPU memory savings and throughput.
Key Insights and Ideas
- The "Middle-to-Deep" Sweet Spot: The paper's most critical observation is that while early layers in an LLM learn very distinct features, the deeper layers exhibit high "angular similarity." This suggests that as information flows deeper, the incremental changes per layer become smaller, allowing for aggressive compression.
- Direction is the Essence: By keeping the original magnitudes but sharing the direction, MiniCache preserves the "saliency" of the activations. This is inspired by weight normalization techniques and proves highly effective for activations as well.
- Orthogonality is Key: Because MiniCache operates on the depth dimension, it is completely compatible with width or precision based methods. You can use MiniCache on top of 4-bit quantization (like KIVI) to get the best of both worlds.
Key Results
- Compression & Efficiency: On LLaMA-2-7B, MiniCache alone achieves a 1.53× compression ratio. When stacked with 4-bit quantization, that jumps to an impressive 5.02×.
- Memory Savings: In a batch-serving scenario (batch size 128), MiniCache reduced peak GPU memory usage by 25GB (a 41% saving) compared to the standard FP16 baseline.
- Throughput Boost: By freeing up memory, the system can handle larger batches and process tokens faster, resulting in an approximate 5× throughput increase.
- Near-Lossless Accuracy: On the COQA dataset, LLaMA-3-70B maintained its performance even when 87.5% of the layers were subjected to KV cache merging.
Limitations and Future Work
- Pairwise Limitation: The current implementation only merges pairs of adjacent layers. The authors suggest that future work could explore merging three or more layers simultaneously for even higher compression ratios.
- Static Starting Point: Currently, merging always starts at the midpoint ($L/2$). A more adaptive approach that chooses the starting layer based on real-time similarity metrics could potentially improve the accuracy-efficiency trade-off.
- Interpolation Complexity: While SLERP is effective, the authors mention that more advanced techniques like Spherical Cubic Interpolation might further reduce the minimal information loss currently observed.
Summary updated