Lune

ICLR2024Top-tier venue

HyperAttention: Long-context Attention in Near-Linear Time

Insu Han, Rajesh Jayaram, Amin Karbasi, Vahab Mirrokni, David P. Woodruff, Amir Zandieh

Abstract

We present an approximate attention mechanism named "HyperAttention" to address the computational challenges posed by the growing complexity of long contexts used in Large Language Models (LLMs). Recent work suggests that in the worst-case scenario, quadratic time is necessary unless the entries of the attention matrix are bounded or the matrix has low stable rank. We introduce two parameters which measure: (1) the max column norm in the normalized attention matrix, and (2) the ratio of row norms in the unnormalized attention matrix after detecting and removing large entries. We use these fine-grained parameters to capture the hardness of the problem. Despite previous lower bounds, we are able to achieve a linear time sampling algorithm even when the matrix has unbounded entries or a large stable rank, provided the above parameters are small. HyperAttention features a modular design that easily accommodates integration of other fast low-level implementations, particularly FlashAttention. Empirically, employing Locality Sensitive Hashing (LSH) to identify large entries, HyperAttention outperforms existing methods, giving significant speed improvements compared to state-of-the-art solutions like FlashAttention. We validate the empirical performance of HyperAttention on a variety of different long-context length datasets. For example, HyperAttention makes the inference time of ChatGLM2 50% faster on 32k context length while perplexity increases from 5.6 to 6.3. On larger context length, e.g., 131k, with causal masking, HyperAttention offers 5-fold speedup on a single attention layer.

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.

47 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

  • Big Bird: Transformers for Longer Sequences cites Reformer: The Efficient Transformer
  • The Fine-Grained Complexity of Gradient Computation for Training Large Language Models cites Language Models are Few-Shot Learners
  • Informer: Beyond Efficient Transformer for Long Sequence Time-Series Forecasting cites Reformer: The Efficient Transformer
  • An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale cites Language Models are Few-Shot Learners
  • H2O: Heavy-Hitter Oracle for Efficient Generative Inference of Large Language Models cites Reformer: The Efficient Transformer
  • H2O: Heavy-Hitter Oracle for Efficient Generative Inference of Large Language Models cites Language Models are Few-Shot Learners
  • NoMAD-Attention: Efficient LLM Inference on CPUs Through Multiply-add-free Attention cites Big Bird: Transformers for Longer Sequences
  • NoMAD-Attention: Efficient LLM Inference on CPUs Through Multiply-add-free Attention cites H2O: Heavy-Hitter Oracle for Efficient Generative Inference of Large Language Models
  • NoMAD-Attention: Efficient LLM Inference on CPUs Through Multiply-add-free Attention cites Reformer: The Efficient Transformer
  • Tensor Product Attention Is All You Need cites H2O: Heavy-Hitter Oracle for Efficient Generative Inference of Large Language Models
  • Tensor Product Attention Is All You Need cites Language Models are Few-Shot Learners
  • PolySketchFormer: Fast Transformers via Sketching Polynomial Kernels cites Big Bird: Transformers for Longer Sequences
  • PolySketchFormer: Fast Transformers via Sketching Polynomial Kernels cites Reformer: The Efficient Transformer
  • PolySketchFormer: Fast Transformers via Sketching Polynomial Kernels cites Language Models are Few-Shot Learners
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers47

  1. H2O: Heavy-Hitter Oracle for Efficient Generative Inference of Large Language ModelsZhenyu Zhang, Ying Sheng, Tianyi Zhou, Tianlong Chen et al.NeurIPS 2023 · 1,003 citations
  2. Tensor Product Attention Is All You NeedYifan Zhang, Yifeng Liu, Huizhuo Yuan, Zhen Qin et al.NeurIPS 2025 · 48 citations
  3. The Fine-Grained Complexity of Gradient Computation for Training Large Language ModelsJosh Alman, Zhao SongNeurIPS 2024 · 33 citations
  4. PolySketchFormer: Fast Transformers via Sketching Polynomial KernelsPraneeth Kacham, Vahab Mirrokni, Peilin ZhongICML 2024 · 27 citations
  5. NoMAD-Attention: Efficient LLM Inference on CPUs Through Multiply-add-free AttentionTianyi Zhang, Jonah Yi, Bowen Yao, Zhaozhuo Xu et al.NeurIPS 2024 · 25 citations

Builds on17

  1. Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah et al.NeurIPS 2020 · 64,255 citations
  2. An Image is Worth 16x16 Words: Transformers for Image Recognition at ScaleAlexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn et al.ICLR 2021 · 21,477 citations
  3. Informer: Beyond Efficient Transformer for Long Sequence Time-Series ForecastingHaoyi Zhou, Shanghang Zhang, Jieqi Peng, Shuai Zhang et al.AAAI 2021 · 7,289 citations
  4. Big Bird: Transformers for Longer SequencesManzil Zaheer, Guru Guruganesh, Kumar Avinava Dubey, Joshua Ainslie et al.NeurIPS 2020 · 3,159 citations
  5. Reformer: The Efficient TransformerNikita Kitaev, Lukasz Kaiser, Anselm LevskayaICLR 2020 · 2,878 citations

Related papers

  1. Fast Attention Over Long Sequences With Dynamic Sparse Flash AttentionMatteo Pagliardini, Daniele Paliotta, Martin Jaggi, François FleuretNeurIPS 2023 · 26 citations
  2. RACE Attention: A Strictly Linear-Time Attention for Long-Sequence TrainingSahil Joshi, Agniva Chowdhury, Amar Kanakamedala, Ekam Singh et al.ICLR 2026 · 2 citations
  3. Token Sparse Attention: Efficient Long-Context Inference with Interleaved Token SelectionDongwon Jo, Beomseok Kang, Jiwon Song, jae-joon kimICML 2026 · 1 citation
  4. FSA: An Alternative Efficient Implementation of Native Sparse Attention KernelRan Yan, Youhe Jiang, Zhuoming Chen, Haohui Mai et al.ICLR 2026 · 10 citations
  5. SALE : Low-bit Estimation for Efficient Sparse Attention in Long-context LLM PrefillingXiaodong Ji, Hailin Zhang, Fangcheng Fu, Bin CuiICML 2026 · 3 citations
Dusk over the sea between two cliffs drawn in fine vertical lines