Lune

NeurIPS2023Top-tier venue

Fast Attention Requires Bounded Entries

Josh Alman, Zhao Song

Abstract

In modern machine learning, inner product attention computation is a fundamental task for training large language models such as Transformer, GPT-1, BERT, GPT-2, GPT-3 and ChatGPT. Formally, in this problem, one is given as input three matrices Q,K,V∈[−B,B]n×dQ, K, V \in [-B,B]^{n \times d}, and the goal is to construct the matrix Att(Q,K,V):=diag(A1n)−1AV∈Rn×d\mathrm{Att}(Q,K,V) := \mathrm{diag}(A {\bf 1}_n)^{-1} A V \in \mathbb{R}^{n \times d}, where A=exp⁡(QK⊤/d)A = \exp(QK^\top/d) is the `attention matrix', and exp⁡\exp is applied entry-wise. Straightforward methods for this problem explicitly compute the n×nn \times n attention matrix AA, and hence require time Ω(n2)\Omega(n^2) even when d=no(1)d = n^{o(1)} is small. In this paper, we investigate whether faster algorithms are possible by implicitly making use of the matrix AA. We present two results, showing that there is a sharp transition at B=Θ(log⁡n)B = \Theta(\sqrt{\log n}). ∙\bullet If d=O(log⁡n)d = O(\log n) and B=o(log⁡n)B = o(\sqrt{\log n}), there is an n1+o(1)n^{1+o(1)} time algorithm to approximate Att(Q,K,V)\mathrm{Att}(Q,K,V) up to 1/poly(n)1/\mathrm{poly}(n) additive error. ∙\bullet If d=O(log⁡n)d = O(\log n) and B=Θ(log⁡n)B = \Theta (\sqrt{\log n}), assuming the Strong Exponential Time Hypothesis from fine-grained complexity theory, it is impossible to approximate Att(Q,K,V)\mathrm{Att}(Q,K,V) up to 1/poly(n)1/\mathrm{poly}(n) additive error in truly subquadratic time n2−Ω(1)n^{2 - \Omega(1)}. This gives a theoretical explanation for the phenomenon observed in practice that attention computation is much more efficient when the input matrices have smaller entries.

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

  • Deja Vu: Contextual Sparsity for Efficient LLMs at Inference Time cites Language Models are Few-Shot Learners
  • Pixelated Butterfly: Simple and Efficient Sparse training for Neural Network Models cites Language Models are Few-Shot Learners
  • H2O: Heavy-Hitter Oracle for Efficient Generative Inference of Large Language Models cites Transformers are RNNs: Fast Autoregressive Transformers with Linear Attention
  • H2O: Heavy-Hitter Oracle for Efficient Generative Inference of Large Language Models cites Language Models are Few-Shot Learners
  • H2O: Heavy-Hitter Oracle for Efficient Generative Inference of Large Language Models cites HyperAttention: Long-context Attention in Near-Linear Time
  • On the Role of Attention Masks and LayerNorm in Transformers cites Language Models are Few-Shot Learners
  • The Hedgehog & the Porcupine: Expressive Linear Attentions with Softmax Mimicry cites Transformers are RNNs: Fast Autoregressive Transformers with Linear Attention
  • HyperAttention: Long-context Attention in Near-Linear Time cites Transformers are RNNs: Fast Autoregressive Transformers with Linear Attention
  • HyperAttention: Long-context Attention in Near-Linear Time cites Kernel Density Estimation through Density Constrained Near Neighbor Search
  • HyperAttention: Long-context Attention in Near-Linear Time cites Pixelated Butterfly: Simple and Efficient Sparse training for Neural Network Models
  • HyperAttention: Long-context Attention in Near-Linear Time 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. Deja Vu: Contextual Sparsity for Efficient LLMs at Inference TimeZichang Liu, Jue Wang, Tri Dao, Tianyi Zhou et al.ICML 2023 · 318 citations
  3. HyperAttention: Long-context Attention in Near-Linear TimeInsu Han, Rajesh Jayaram, Amin Karbasi, Vahab Mirrokni et al.ICLR 2024 · 104 citations
  4. The Hedgehog & the Porcupine: Expressive Linear Attentions with Softmax MimicryMichael Zhang, Kush Bhatia, Hermann Kumbong, Christopher RéICLR 2024 · 103 citations
  5. On the Role of Attention Masks and LayerNorm in TransformersXinyi Wu, Amir Ajorlou, Yifei Wang, Stefanie Jegelka et al.NeurIPS 2024 · 54 citations

Builds on6

  1. Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah et al.NeurIPS 2020 · 64,255 citations
  2. Transformers are RNNs: Fast Autoregressive Transformers with Linear AttentionAngelos Katharopoulos, Apoorv Vyas, Nikolaos Pappas, François FleuretICML 2020 · 2,665 citations
  3. Deja Vu: Contextual Sparsity for Efficient LLMs at Inference TimeZichang Liu, Jue Wang, Tri Dao, Tianyi Zhou et al.ICML 2023 · 318 citations
  4. Pixelated Butterfly: Simple and Efficient Sparse training for Neural Network ModelsBeidi Chen, Tri Dao, Kaizhao Liang, Jiaming Yang et al.ICLR 2022 · 94 citations
  5. Kernel Density Estimation through Density Constrained Near Neighbor SearchMoses Charikar, Michael Kapralov, Navid Nouri, Paris SiminelakisFOCS 2020 · 9 citations

Related papers

  1. Subquadratic Algorithms and Hardness for Attention with Any TemperatureShreya Gupta, Boyang Huang, Barna Saha, Yinzhan Xu et al.ICLR 2026 · 5 citations
  2. How to Capture Higher-order Correlations? Generalizing Matrix Softmax Attention to Kronecker ComputationJosh Alman, Zhao SongICLR 2024 · 53 citations
  3. Algorithm and Hardness for Dynamic Attention Maintenance in Large Language ModelsJan van den Brand, Zhao Song, Tianyi ZhouICML 2024 · 35 citations
  4. Conv-Basis: A New Paradigm for Efficient Attention Inference and Gradient Computation in TransformersYingyu Liang, Heshan Liu, Zhenmei Shi, Zhao Song et al.EMNLP Findings 2025
  5. Improved Algorithms for Kernel Matrix-Vector Multiplication Under Sparsity AssumptionsPiotr Indyk, Michael Kapralov, Kshiteej Sheth, Tal WagnerICLR 2025
Dusk over the sea between two cliffs drawn in fine vertical lines