On the Computational Hardness of Transformers
Barna Saha, Yinzhan Xu, Christopher Ye, Hantao Yu
摘要
The transformer architecture has revolutionized modern AI across language, vision, and beyond. It consists of L layers of multi-head attention, where each layer runs H attention heads in parallel and feeds the combined output to the subsequent layer. In attention, each token within an input of length N is represented by an embedding vector of dimension m. Computationally, an attention mechanism primarily involves multiplying three N × m matrices, while applying a softmax operation to the intermediate product of the first two matrices. A significant body of work has been devoted to analyzing the time complexity of attention, leading to several recent advances.
On the other hand, known algorithms for transformers compute each attention head independently. This raises a fundamental question that has recurred throughout theoretical computer science under the guise of "direct sum" problems: can multiple instances of the same problem be solved more efficiently than solving each instance separately? Many answers to this question, both positive and negative, have arisen in fields spanning communication complexity and algorithm design. Thus, a key challenge in understanding the computational hardness of transformers is to determine whether their computation can be performed more efficiently than LH independent evaluations of attention.
In this paper, we resolve this question in the negative, and give the first non-trivial computational lower bounds for multi-head multi-layer transformers. In the small embedding regime (m = N o(1) ), computing LH attention heads separately takes LHN 2+o(1) time. We establish that this is essentially optimal under the Strong Exponential Time Hypothesis (SETH). In the large embedding regime (m = N ), one can compute LH attention heads separately using LHN ω+o(1) arithmetic operations (plus exponents), where ω is the matrix multiplication exponent. We establish that this is optimal, by showing that LHN ω-o(1) arithmetic operations are necessary when ω > 2. Our lower bound in the large embedding regime relies on a novel application of the Baur-Strassen theorem, a powerful algorithmic tool underpinning the famous backpropagation algorithm.
问 Lune
几分钟读透这篇 Paper,不用再花一下午。
Lune 能读完全文,也能读引用它的顶会 Paper,讲清它的结论、证据和局限,每一点都注明出自哪篇 Paper。不用硬啃,也不靠猜。
脉络
- Segment Anything 引用了 An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
- Segment Anything 引用了 Language Models are Few-Shot Learners
- FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness 引用了 Big Bird: Transformers for Longer Sequences
- FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness 引用了 An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
- FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness 引用了 Language Models are Few-Shot Learners
- An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale 引用了 Language Models are Few-Shot Learners
它引用的 Paper33
- Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah 等NeurIPS 2020 · 64,255 次引用
- An Image is Worth 16x16 Words: Transformers for Image Recognition at ScaleAlexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn 等ICLR 2021 · 21,477 次引用
- Segment AnythingAlexander Kirillov, Eric Mintun, Nikhila Ravi, Hanzi Mao 等ICCV 2023 · 13,211 次引用
- FlashAttention: Fast and Memory-Efficient Exact Attention with IO-AwarenessTri Dao, Daniel Y. Fu, Stefano Ermon, Atri Rudra 等NeurIPS 2022 · 5,493 次引用
- Big Bird: Transformers for Longer SequencesManzil Zaheer, Guru Guruganesh, Kumar Avinava Dubey, Joshua Ainslie 等NeurIPS 2020 · 3,159 次引用
相关 Paper
- Provably Learning a Multi-head Attention LayerSitan Chen, Yuanzhi LiSTOC 2025 · 3 次引用
- Transformers, parallel computation, and logarithmic depthClayton Sanford, Daniel Hsu, Matus TelgarskyICML 2024 · 64 次引用
- Subquadratic Algorithms and Hardness for Attention with Any TemperatureShreya Gupta, Boyang Huang, Barna Saha, Yinzhan Xu 等ICLR 2026 · 5 次引用
- Poly-attention: a general scheme for higher-order self-attentionSayak Chakrabarti, Toniann Pitassi, Josh AlmanICLR 2026 · 3 次引用
- Representational Strengths and Limitations of TransformersClayton Sanford, Daniel J. Hsu, Matus TelgarskyNeurIPS 2023 · 162 次引用
