Lune

NeurIPS2023顶会

Fast Attention Requires Bounded Entries

Josh Alman, Zhao Song

摘要

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.

问 Lune

几分钟读透这篇 Paper,不用再花一下午。

Lune 能读完全文,也能读引用它的顶会 Paper,讲清它的结论、证据和局限,每一点都注明出自哪篇 Paper。不用硬啃,也不靠猜。

已有 47 篇顶会 Paper 引用了它。别等审稿人问起,先弄清它们发现了什么。

可以从这些问题问起

Lune 可以查阅

全文 · 引用它的顶会 Paper · 相关的 Paper

获取答案

免费开始,无需绑卡

脉络

  • Deja Vu: Contextual Sparsity for Efficient LLMs at Inference Time 引用了 Language Models are Few-Shot Learners
  • Pixelated Butterfly: Simple and Efficient Sparse training for Neural Network Models 引用了 Language Models are Few-Shot Learners
  • H2O: Heavy-Hitter Oracle for Efficient Generative Inference of Large Language Models 引用了 Transformers are RNNs: Fast Autoregressive Transformers with Linear Attention
  • H2O: Heavy-Hitter Oracle for Efficient Generative Inference of Large Language Models 引用了 Language Models are Few-Shot Learners
  • H2O: Heavy-Hitter Oracle for Efficient Generative Inference of Large Language Models 引用了 HyperAttention: Long-context Attention in Near-Linear Time
  • On the Role of Attention Masks and LayerNorm in Transformers 引用了 Language Models are Few-Shot Learners
  • The Hedgehog & the Porcupine: Expressive Linear Attentions with Softmax Mimicry 引用了 Transformers are RNNs: Fast Autoregressive Transformers with Linear Attention
  • HyperAttention: Long-context Attention in Near-Linear Time 引用了 Transformers are RNNs: Fast Autoregressive Transformers with Linear Attention
  • HyperAttention: Long-context Attention in Near-Linear Time 引用了 Kernel Density Estimation through Density Constrained Near Neighbor Search
  • HyperAttention: Long-context Attention in Near-Linear Time 引用了 Pixelated Butterfly: Simple and Efficient Sparse training for Neural Network Models
  • HyperAttention: Long-context Attention in Near-Linear Time 引用了 Language Models are Few-Shot Learners
它引用的引用它的从左到右按年份排列,引用越多,位置越高。

引用它的顶会 Paper47

  1. H2O: Heavy-Hitter Oracle for Efficient Generative Inference of Large Language ModelsZhenyu Zhang, Ying Sheng, Tianyi Zhou, Tianlong Chen 等NeurIPS 2023 · 1,003 次引用
  2. Deja Vu: Contextual Sparsity for Efficient LLMs at Inference TimeZichang Liu, Jue Wang, Tri Dao, Tianyi Zhou 等ICML 2023 · 318 次引用
  3. HyperAttention: Long-context Attention in Near-Linear TimeInsu Han, Rajesh Jayaram, Amin Karbasi, Vahab Mirrokni 等ICLR 2024 · 104 次引用
  4. The Hedgehog & the Porcupine: Expressive Linear Attentions with Softmax MimicryMichael Zhang, Kush Bhatia, Hermann Kumbong, Christopher RéICLR 2024 · 103 次引用
  5. On the Role of Attention Masks and LayerNorm in TransformersXinyi Wu, Amir Ajorlou, Yifei Wang, Stefanie Jegelka 等NeurIPS 2024 · 54 次引用

它引用的 Paper6

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

相关 Paper

  1. Subquadratic Algorithms and Hardness for Attention with Any TemperatureShreya Gupta, Boyang Huang, Barna Saha, Yinzhan Xu 等ICLR 2026 · 5 次引用
  2. How to Capture Higher-order Correlations? Generalizing Matrix Softmax Attention to Kronecker ComputationJosh Alman, Zhao SongICLR 2024 · 53 次引用
  3. Algorithm and Hardness for Dynamic Attention Maintenance in Large Language ModelsJan van den Brand, Zhao Song, Tianyi ZhouICML 2024 · 35 次引用
  4. Conv-Basis: A New Paradigm for Efficient Attention Inference and Gradient Computation in TransformersYingyu Liang, Heshan Liu, Zhenmei Shi, Zhao Song 等EMNLP Findings 2025
  5. Improved Algorithms for Kernel Matrix-Vector Multiplication Under Sparsity AssumptionsPiotr Indyk, Michael Kapralov, Kshiteej Sheth, Tal WagnerICLR 2025
黄昏的海面,两侧是细线勾勒的悬崖