MagicPIG: LSH Sampling for Efficient LLM Generation
Zhuoming Chen, Ranajoy Sadhukhan, Zihao Ye, Yang Zhou, Jianyu Zhang, Niklas Nolte, Yuandong Tian, Matthijs Douze, Léon Bottou, Zhihao Jia, Beidi Chen
摘要
Large language models (LLMs) with long context windows have gained significant attention. However, the KV cache, stored to avoid re-computation, becomes a bottleneck. Various dynamic sparse or TopK-based attention approximation methods have been proposed to leverage the common insight that attention is sparse. In this paper, we first show that TopK attention itself suffers from quality degradation in certain downstream tasks because attention is not always as sparse as expected. Rather than selecting the keys and values with the highest attention scores, sampling with theoretical guarantees can provide a better estimation for attention output. To make the sampling-based approximation practical in LLM generation, we propose MagicPIG, a heterogeneous system based on Locality Sensitive Hashing (LSH). MagicPIG significantly reduces the workload of attention computation while preserving high accuracy for diverse tasks. MagicPIG stores the LSH hash tables and runs the attention computation on the CPU, which allows it to serve longer contexts and larger batch sizes with high approximation accuracy. MagicPIG can improve decoding throughput by up to across various GPU hardware and achieve 54ms decoding latency on a single RTX 4090 for Llama-3.1-8B-Instruct model with a context of 96k tokens. The code is available at https://github.com/Infini-AI-Lab/MagicPIG.
问 Lune
几分钟读透这篇 Paper,不用再花一下午。
Lune 能读完全文,也能读引用它的顶会 Paper,讲清它的结论、证据和局限,每一点都注明出自哪篇 Paper。不用硬啃,也不靠猜。
已有 37 篇顶会 Paper 引用了它。别等审稿人问起,先弄清它们发现了什么。
脉络
- Efficient Streaming Language Models with Attention Sinks 引用了 FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness
- Efficient Streaming Language Models with Attention Sinks 引用了 FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning
- Efficient Streaming Language Models with Attention Sinks 引用了 Reformer: The Efficient Transformer
- FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness 引用了 Reformer: The Efficient Transformer
- FreeKV: Boosting KV Cache Retrieval for Efficient LLM Inference 引用了 Efficient Streaming Language Models with Attention Sinks
- FreeKV: Boosting KV Cache Retrieval for Efficient LLM Inference 引用了 FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning
- FreeKV: Boosting KV Cache Retrieval for Efficient LLM Inference 引用了 Twilight: Adaptive Attention Sparsity with Hierarchical Top-p Pruning
- FreeKV: Boosting KV Cache Retrieval for Efficient LLM Inference 引用了 MInference 1.0: Accelerating Pre-filling for Long-Context LLMs via Dynamic Sparse Attention
- FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning 引用了 FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness
- FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning 引用了 Reformer: The Efficient Transformer
- Twilight: Adaptive Attention Sparsity with Hierarchical Top-p Pruning 引用了 Efficient Streaming Language Models with Attention Sinks
- Twilight: Adaptive Attention Sparsity with Hierarchical Top-p Pruning 引用了 FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning
- Twilight: Adaptive Attention Sparsity with Hierarchical Top-p Pruning 引用了 RetrievalAttention: Accelerating Long-Context LLM Inference via Vector Retrieval
- RetrievalAttention: Accelerating Long-Context LLM Inference via Vector Retrieval 引用了 Efficient Streaming Language Models with Attention Sinks
- RetrievalAttention: Accelerating Long-Context LLM Inference via Vector Retrieval 引用了 FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness
- RetrievalAttention: Accelerating Long-Context LLM Inference via Vector Retrieval 引用了 Reformer: The Efficient Transformer
- RetrievalAttention: Accelerating Long-Context LLM Inference via Vector Retrieval 引用了 MInference 1.0: Accelerating Pre-filling for Long-Context LLMs via Dynamic Sparse Attention
- MInference 1.0: Accelerating Pre-filling for Long-Context LLMs via Dynamic Sparse Attention 引用了 RetrievalAttention: Accelerating Long-Context LLM Inference via Vector Retrieval
- KVzip: Query-Agnostic KV Cache Compression with Context Reconstruction 引用了 Efficient Streaming Language Models with Attention Sinks
- KVzip: Query-Agnostic KV Cache Compression with Context Reconstruction 引用了 FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning
- KVzip: Query-Agnostic KV Cache Compression with Context Reconstruction 引用了 RetrievalAttention: Accelerating Long-Context LLM Inference via Vector Retrieval
- KVzip: Query-Agnostic KV Cache Compression with Context Reconstruction 引用了 MInference 1.0: Accelerating Pre-filling for Long-Context LLMs via Dynamic Sparse Attention
- MInference 1.0: Accelerating Pre-filling for Long-Context LLMs via Dynamic Sparse Attention 引用了 Efficient Streaming Language Models with Attention Sinks
- MInference 1.0: Accelerating Pre-filling for Long-Context LLMs via Dynamic Sparse Attention 引用了 FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning
- MInference 1.0: Accelerating Pre-filling for Long-Context LLMs via Dynamic Sparse Attention 引用了 Reformer: The Efficient Transformer
引用它的顶会 Paper37
- MInference 1.0: Accelerating Pre-filling for Long-Context LLMs via Dynamic Sparse AttentionHuiqiang Jiang, Yucheng Li, Chengruidong Zhang, Qianhui Wu 等NeurIPS 2024 · 479 次引用
- RetrievalAttention: Accelerating Long-Context LLM Inference via Vector RetrievalDi Liu, Meng Chen, Baotong Lu, Huiqiang Jiang 等NeurIPS 2025 · 148 次引用
- KVzip: Query-Agnostic KV Cache Compression with Context ReconstructionJang-Hyun Kim, Jinuk Kim, Sangwoo Kwon, Jae W. Lee 等NeurIPS 2025 · 103 次引用
- Twilight: Adaptive Attention Sparsity with Hierarchical Top- PruningChaofan Lin, Jiaming Tang, Shuo Yang, Hanshuo Wang 等NeurIPS 2025 · 53 次引用
- FreeKV: Boosting KV Cache Retrieval for Efficient LLM InferenceGuangda Liu, Chengwei Li, Zhenyu Ning, Jing Lin 等ICLR 2026 · 17 次引用
它引用的 Paper23
- Measuring Massive Multitask Language UnderstandingDan Hendrycks, Collin Burns, Steven Basart, Andy Zou 等ICLR 2021 · 7,905 次引用
- FlashAttention: Fast and Memory-Efficient Exact Attention with IO-AwarenessTri Dao, Daniel Y. Fu, Stefano Ermon, Atri Rudra 等NeurIPS 2022 · 5,493 次引用
- Reformer: The Efficient TransformerNikita Kitaev, Lukasz Kaiser, Anselm LevskayaICLR 2020 · 2,878 次引用
- FlashAttention-2: Faster Attention with Better Parallelism and Work PartitioningTri DaoICLR 2024 · 2,600 次引用
- Efficient Streaming Language Models with Attention SinksGuangxuan Xiao, Yuandong Tian, Beidi Chen, Song Han 等ICLR 2024 · 1,714 次引用
相关 Paper
- Training-Free Hashing-Based Attention via Binary Principal ComponentsDaohai Yu, Zhanpeng Zeng, Keyu Chen, Wenhao Li 等ICML 2026
- ParisKV: Fast and Drift-Robust KV-Cache Retrieval for Long-Context LLMsYanlin Qi, Xinhang Chen, Huiqiang Jiang, Qitong Wang 等ICML 2026
- vAttention: Verified Sparse Attention via SamplingAditya Desai, Kumar Krishna Agrawal, Shuo Yang, Alejandro Cuadron 等ICLR 2026 · 3 次引用
- ShadowKV: KV Cache in Shadows for High-Throughput Long-Context LLM InferenceHanshi Sun, Li-Wen Chang, Wenlei Bao, Size Zheng 等ICML 2025
- MagicDec: Breaking the Latency-Throughput Tradeoff for Long Context Generation with Speculative DecodingRanajoy Sadhukhan, Jian Chen, Zhuoming Chen, Vashisth Tiwari 等ICLR 2025
