Lune

ICLR2025Top-tier venue

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

Abstract

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 5×5\times 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.

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

37 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • Efficient Streaming Language Models with Attention Sinks cites FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness
  • Efficient Streaming Language Models with Attention Sinks cites FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning
  • Efficient Streaming Language Models with Attention Sinks cites Reformer: The Efficient Transformer
  • FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness cites Reformer: The Efficient Transformer
  • FreeKV: Boosting KV Cache Retrieval for Efficient LLM Inference cites Efficient Streaming Language Models with Attention Sinks
  • FreeKV: Boosting KV Cache Retrieval for Efficient LLM Inference cites FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning
  • FreeKV: Boosting KV Cache Retrieval for Efficient LLM Inference cites Twilight: Adaptive Attention Sparsity with Hierarchical Top-p Pruning
  • FreeKV: Boosting KV Cache Retrieval for Efficient LLM Inference cites MInference 1.0: Accelerating Pre-filling for Long-Context LLMs via Dynamic Sparse Attention
  • FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning cites FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness
  • FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning cites Reformer: The Efficient Transformer
  • Twilight: Adaptive Attention Sparsity with Hierarchical Top-p Pruning cites Efficient Streaming Language Models with Attention Sinks
  • Twilight: Adaptive Attention Sparsity with Hierarchical Top-p Pruning cites FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning
  • Twilight: Adaptive Attention Sparsity with Hierarchical Top-p Pruning cites RetrievalAttention: Accelerating Long-Context LLM Inference via Vector Retrieval
  • RetrievalAttention: Accelerating Long-Context LLM Inference via Vector Retrieval cites Efficient Streaming Language Models with Attention Sinks
  • RetrievalAttention: Accelerating Long-Context LLM Inference via Vector Retrieval cites FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness
  • RetrievalAttention: Accelerating Long-Context LLM Inference via Vector Retrieval cites Reformer: The Efficient Transformer
  • RetrievalAttention: Accelerating Long-Context LLM Inference via Vector Retrieval cites 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 cites RetrievalAttention: Accelerating Long-Context LLM Inference via Vector Retrieval
  • KVzip: Query-Agnostic KV Cache Compression with Context Reconstruction cites Efficient Streaming Language Models with Attention Sinks
  • KVzip: Query-Agnostic KV Cache Compression with Context Reconstruction cites FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning
  • KVzip: Query-Agnostic KV Cache Compression with Context Reconstruction cites RetrievalAttention: Accelerating Long-Context LLM Inference via Vector Retrieval
  • KVzip: Query-Agnostic KV Cache Compression with Context Reconstruction cites 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 cites Efficient Streaming Language Models with Attention Sinks
  • MInference 1.0: Accelerating Pre-filling for Long-Context LLMs via Dynamic Sparse Attention cites FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning
  • MInference 1.0: Accelerating Pre-filling for Long-Context LLMs via Dynamic Sparse Attention cites Reformer: The Efficient Transformer
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers37

  1. MInference 1.0: Accelerating Pre-filling for Long-Context LLMs via Dynamic Sparse AttentionHuiqiang Jiang, Yucheng Li, Chengruidong Zhang, Qianhui Wu et al.NeurIPS 2024 · 479 citations
  2. RetrievalAttention: Accelerating Long-Context LLM Inference via Vector RetrievalDi Liu, Meng Chen, Baotong Lu, Huiqiang Jiang et al.NeurIPS 2025 · 148 citations
  3. KVzip: Query-Agnostic KV Cache Compression with Context ReconstructionJang-Hyun Kim, Jinuk Kim, Sangwoo Kwon, Jae W. Lee et al.NeurIPS 2025 · 103 citations
  4. Twilight: Adaptive Attention Sparsity with Hierarchical Top-pp PruningChaofan Lin, Jiaming Tang, Shuo Yang, Hanshuo Wang et al.NeurIPS 2025 · 53 citations
  5. FreeKV: Boosting KV Cache Retrieval for Efficient LLM InferenceGuangda Liu, Chengwei Li, Zhenyu Ning, Jing Lin et al.ICLR 2026 · 17 citations

Builds on23

  1. Measuring Massive Multitask Language UnderstandingDan Hendrycks, Collin Burns, Steven Basart, Andy Zou et al.ICLR 2021 · 7,905 citations
  2. FlashAttention: Fast and Memory-Efficient Exact Attention with IO-AwarenessTri Dao, Daniel Y. Fu, Stefano Ermon, Atri Rudra et al.NeurIPS 2022 · 5,493 citations
  3. Reformer: The Efficient TransformerNikita Kitaev, Lukasz Kaiser, Anselm LevskayaICLR 2020 · 2,878 citations
  4. FlashAttention-2: Faster Attention with Better Parallelism and Work PartitioningTri DaoICLR 2024 · 2,600 citations
  5. Efficient Streaming Language Models with Attention SinksGuangxuan Xiao, Yuandong Tian, Beidi Chen, Song Han et al.ICLR 2024 · 1,714 citations

Related papers

  1. Training-Free Hashing-Based Attention via Binary Principal ComponentsDaohai Yu, Zhanpeng Zeng, Keyu Chen, Wenhao Li et al.ICML 2026
  2. ParisKV: Fast and Drift-Robust KV-Cache Retrieval for Long-Context LLMsYanlin Qi, Xinhang Chen, Huiqiang Jiang, Qitong Wang et al.ICML 2026
  3. vAttention: Verified Sparse Attention via SamplingAditya Desai, Kumar Krishna Agrawal, Shuo Yang, Alejandro Cuadron et al.ICLR 2026 · 3 citations
  4. ShadowKV: KV Cache in Shadows for High-Throughput Long-Context LLM InferenceHanshi Sun, Li-Wen Chang, Wenlei Bao, Size Zheng et al.ICML 2025
  5. MagicDec: Breaking the Latency-Throughput Tradeoff for Long Context Generation with Speculative DecodingRanajoy Sadhukhan, Jian Chen, Zhuoming Chen, Vashisth Tiwari et al.ICLR 2025
Dusk over the sea between two cliffs drawn in fine vertical lines