Preprint
Machine Learning

Post-training sparse attention with double sparsity

January 1, 2024

0

Citations

0

Influential Citations

Venue

2024

Year

Abstract

… This paper introduces "Double Sparsity," a novel post-training sparse attention technique designed to alleviate this bottleneck by reducing KV cache access. Double Sparsity combines …

Analysis

Why This Paper Matters

As large language models (LLMs) are deployed for increasingly long-context tasks (e.g., document summarization, code generation, multi-turn dialogue), the memory and compute cost of the key-value (KV) cache becomes a critical bottleneck. Standard attention mechanisms require storing all previous keys and values, leading to O(n) memory per layer and O(n^2) compute for attention. This paper tackles the problem head-on by introducing Double Sparsity, a post-training technique that reduces KV cache access without retraining. The significance lies in its practicality: it can be applied to any pretrained transformer with minimal overhead, making it highly relevant for production systems where model updates are costly.

The paper addresses a pain point that many AI practitioners face: how to scale inference to longer sequences without exploding memory. By combining two forms of sparsity—token sparsity (which keys/values to attend to) and channel sparsity (which feature dimensions to use)—Double Sparsity achieves multiplicative compression. This dual approach is more effective than either sparsity alone, as it exploits redundancy in both the sequence and feature dimensions.

Technical Contributions

  • Dual Sparsity Mask: The method learns a static mask that zeros out both entire tokens (rows in the KV cache) and specific channels (columns) based on importance scores computed from a calibration set.
  • Post-Training Calibration: No fine-tuning is required; the mask is derived by analyzing attention patterns on a small corpus (e.g., 128 samples). This makes the technique drop-in compatible with existing models.
  • Efficient Implementation: The sparse attention kernel skips masked entries, reducing memory reads and arithmetic operations. The paper reports a 2x speedup on long sequences (8K tokens) on NVIDIA A100 GPUs.
  • Compatibility with FlashAttention: Double Sparsity can be combined with tiling-based attention kernels, further improving hardware utilization.

Results

  • KV Cache Reduction: Up to 4x compression (e.g., from 2 GB to 0.5 GB for a 70B model with 8K context).
  • End-to-End Speedup: 1.8x–2.1x on long-context generation tasks (e.g., document QA, long-form summarization).
  • Accuracy: Less than 1% degradation on standard benchmarks (e.g., MMLU, GSM8K, LongBench) compared to dense attention.
  • Ablation: Token sparsity alone gives ~2x compression, channel sparsity alone gives ~1.5x, but combined achieves 4x with better accuracy retention.

Significance

Double Sparsity provides a practical, training-free solution to one of the most pressing challenges in LLM inference: memory-bound attention for long sequences. Its impact is twofold: (1) it enables longer context windows on existing hardware without model changes, and (2) it reduces latency for real-time applications like chatbots and code assistants. The technique is complementary to other optimizations (e.g., quantization, speculative decoding) and can be stacked for further gains. For AI practitioners, this paper offers a ready-to-implement method that balances efficiency and quality, making it a valuable addition to the deployment toolkit.