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 , and the goal is to construct the matrix , where is the `attention matrix', and is applied entry-wise. Straightforward methods for this problem explicitly compute the attention matrix , and hence require time even when is small. In this paper, we investigate whether faster algorithms are possible by implicitly making use of the matrix . We present two results, showing that there is a sharp transition at . If and , there is an time algorithm to approximate up to additive error. If and , assuming the Strong Exponential Time Hypothesis from fine-grained complexity theory, it is impossible to approximate up to additive error in truly subquadratic time . 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.
Lune can draw on
the full paper · the top-tier papers that cite it · related work
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
Cited by top-tier papers47
- 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
- Deja Vu: Contextual Sparsity for Efficient LLMs at Inference TimeZichang Liu, Jue Wang, Tri Dao, Tianyi Zhou et al.ICML 2023 · 318 citations
- HyperAttention: Long-context Attention in Near-Linear TimeInsu Han, Rajesh Jayaram, Amin Karbasi, Vahab Mirrokni et al.ICLR 2024 · 104 citations
- The Hedgehog & the Porcupine: Expressive Linear Attentions with Softmax MimicryMichael Zhang, Kush Bhatia, Hermann Kumbong, Christopher RéICLR 2024 · 103 citations
- 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
- Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah et al.NeurIPS 2020 · 64,255 citations
- Transformers are RNNs: Fast Autoregressive Transformers with Linear AttentionAngelos Katharopoulos, Apoorv Vyas, Nikolaos Pappas, François FleuretICML 2020 · 2,665 citations
- Deja Vu: Contextual Sparsity for Efficient LLMs at Inference TimeZichang Liu, Jue Wang, Tri Dao, Tianyi Zhou et al.ICML 2023 · 318 citations
- Pixelated Butterfly: Simple and Efficient Sparse training for Neural Network ModelsBeidi Chen, Tri Dao, Kaizhao Liang, Jiaming Yang et al.ICLR 2022 · 94 citations
- Kernel Density Estimation through Density Constrained Near Neighbor SearchMoses Charikar, Michael Kapralov, Navid Nouri, Paris SiminelakisFOCS 2020 · 9 citations
Related papers
- Subquadratic Algorithms and Hardness for Attention with Any TemperatureShreya Gupta, Boyang Huang, Barna Saha, Yinzhan Xu et al.ICLR 2026 · 5 citations
- How to Capture Higher-order Correlations? Generalizing Matrix Softmax Attention to Kronecker ComputationJosh Alman, Zhao SongICLR 2024 · 53 citations
- Algorithm and Hardness for Dynamic Attention Maintenance in Large Language ModelsJan van den Brand, Zhao Song, Tianyi ZhouICML 2024 · 35 citations
- 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
- Improved Algorithms for Kernel Matrix-Vector Multiplication Under Sparsity AssumptionsPiotr Indyk, Michael Kapralov, Kshiteej Sheth, Tal WagnerICLR 2025
