atlas

Research map / Architectures and efficiency / Attention and transformers

MagicPIG: LSH Sampling for Efficient LLM Generation

ICLR 2025 · Architectures and efficiency › Attention and transformers · approach: Sparse attention for long-context LLMs · 2 citations (OpenAlex)

Read the paperCheck your idea against 108,967 papers

AI-extracted summary. Written by AI from the paper's full text. Numbers and claims can be wrong or missing context, so check the paper before you cite or build on it.

Proposes MagicPIG, which replaces TopK attention approximation with LSH-based importance sampling of KV cache entries, offloading hash tables and sparse attention to CPU to speed up long-context LLM decoding.

Problem

Long-context LLM decoding is bottlenecked by the KV cache, and TopK-based sparse attention approximations both degrade accuracy on aggregation tasks and incur high search overhead and no memory savings.

Approach

Treat attention output as an expectation and estimate it by self-normalized importance sampling with SimHash-based LSH sampling probabilities (keys sampled if they collide with the query in at least two of L hash tables), with hash tables and attention computation placed on CPU and projections on GPU.

Key results

Measured effects reported in the paper

What was changedWhereMeasuredEffect
Use MagicPIG (10,220) instead of full attentionLlama-2-7b-chat · lm-eval-harness comprehensive tasksAvg. accuracy: 49.1 -> 47.4Hurt
Use MagicPIG (10,220) instead of Quest (32,0.1)Llama-3.1-8B-Instruct · lm-eval-harness comprehensive tasksAvg. accuracy: 59.2 -> 71.2Helped
Use MagicPIG (8,75) instead of full attentionLlama-3.1-8B-Instruct · LongBench long-context tasksAvg. accuracy: 71.2 -> 70.7Hurt
Use MagicPIG (9,120) instead of Quest (16,0.04)Llama-3.1-8B-Instruct · RULERAvg. accuracy: 82.1 -> 87.6Helped
Offload attention and KV cache work to CPU with MagicPIGLLM decoding · L20, CodeLlama-13B, 16K contextThroughput: 5.0×Helped
Add centering before LSH sampling (ablation)MagicPIG · RULER retrieval and FWE tasksAccuracy: Without centering, the accuracy drops to almost zero in retrieval (NIAH) and degrades to 65% in FWE.Helped
Use sampling-based MagicPIG instead of exact TopK attention (ablation)MagicPIG · RULER CWEAccuracy: up to 3%Helped
Use sampling-based MagicPIG instead of exact TopK attention (ablation)MagicPIG · RULER FWEAccuracy: up to 8%Helped
Increase L from 35 to 240 at 4% computation cost while varying K from 7 to 10 (ablation)MagicPIG · RULER 16KAccuracy: 88.5 -> 94.2Helped
Set K to 8 instead of 7 with L fixed at 120 (ablation)MagicPIG · RULER 16KAccuracy: 94.3 -> 94.1No clear effect

Surprising findings

Limitations

Experimental setup

Datasets: GSM8K MMLU CoQA QASPER LCC RepoBench-P TriviaQA PassageRetrieval TREC RULER infini-igsm LongBench

Benchmarks: GSM8K MMLU CoQA LongBench RULER infini-igsm

Metrics: accuracy computation cost ratio (FLOPs vs full attention) decoding throughput (tokens/s) time between tokens latency

Baselines: Quest TopK attention Full attention Loki Oracle sampling

Builds on: Quest Reformer ScatterBrain SimHash recursive attention

Closest papers by meaning

Writing a paper in this area? scime draft is a free LaTeX editor with AI included, real-time co-authors and a check of your references and venue rules before you submit. It also imports OpenAI Prism projects.

Open scime draft

Get the next scime Dispatch and a monthly field update

Free. We send a confirmation link first; every email has a one-click unsubscribe. Privacy