Abstract
Large Language Model (LLM) inference is increasingly bottlenecked by the memory and computational costs of the Key-Value (KV) cache, particularly as sequence lengths grow. We present Double Sparsity, a post-training technique that leverages both token and channel sparsity to accelerate attention operations. By identifying influential feature channels offline and maintaining a compact "label cache," this method achieves up to a 14.1× speedup in attention operations and a 16.3× throughput boost for long-context offloading, all without requiring model retraining or fine-tuning.
Introduction
As LLMs tackle increasingly long sequences, the KV cache becomes a massive bottleneck. During decoding, the model must access the entire history of previous tokens to generate the next one. For long contexts, this cache can dwarf the model weights, leading to slow, memory-bound inference. Existing sparse attention solutions often suffer from permanent accuracy loss due to token eviction or hardware inefficiency caused by non-contiguous memory access. Double Sparsity addresses these challenges by combining algorithmic efficiency with hardware-friendly memory patterns.
Methodology
The Double Sparsity framework operates across two dimensions:
- Token Sparsity: Only a small subset of previous tokens are typically important for generating the next word.
- Channel Sparsity: Specific feature channels (dimensions in the embedding) are disproportionately influential in determining token importance.
Offline Calibration and Label Cache
A key insight of this work is that while token importance is dynamic, the channels signaling that importance are relatively static. Through offline calibration on a small validation set, "outlier channels" are identified. At runtime, the system maintains a Label Cache—a tiny, 4-bit compressed version of the KV cache containing only these outlier channels.
As shown in the figure above, the GPU scans the contiguous Label Cache to identify the top-k most important tokens. Full-precision data is then fetched only for those specific tokens from the main KV cache, ensuring efficient memory access.
Double Sparsity-Offload
For memory-constrained systems, the full KV cache is stored on the CPU. Leveraging the high cosine similarity (often >95%) between consecutive transformer layers, the system uses embeddings from the current layer to predict and prefetch tokens needed for the next layer, effectively masking communication overhead.
Key Insights and Results
Experimental evaluations across Llama-2 and Mixtral-8x7B models demonstrate that Double Sparsity maintains robust performance even at high sparsity levels. A "sweet spot" was identified at 1/16 sparsity (ignoring 15 out of every 16 tokens and channels) with minimal impact on perplexity.
Performance Highlights
- Acceleration: Achieved up to 14.1× acceleration in attention operators and 1.9× end-to-end inference speedup on NVIDIA A100 GPUs.
- Offloading: Double Sparsity-Offload outperformed previous state-of-the-art methods like FlexGen by 16.3× at sequence lengths of 256K.
- Retrieval Accuracy: Unlike eviction-based methods, Double Sparsity maintains high accuracy on "needle-in-a-haystack" tasks because the full KV cache remains accessible if needed.
Limitations and Future Work
While effective, the method faces challenges with Grouped-Query Attention (GQA) models, requiring "QK-outlier" workarounds. Future research will focus on improving asynchronous communication to better overlap CPU-GPU transfers and further reducing the memory footprint of the label cache.
Summary updated