Manifest AI - Linear Transformers Are Faster After All
It is well-known that removing the exponential from the attention layer of a transformer allows for a recurrent reformulation, with computational cost that is linear instead of quadratic on context length [1]. One would expect that such an architecture would be far faster to train, especially when the context size is large. However, when training deep neural networks on hardware accelerators (e.g. GPUs), reductions in FLOPs do not always straightforwardly translate into practical speedups. Initial empirical experiments showed that large language models based on linear transformers train more slowly than classic transformers, and led many to dismiss the approach as nice-in-theory but unhelpful-in-practice [2]. At the moment, the conventional wisdom in the field is that a quadratic-cost algorithm with highly optimized hardware utilization (e.g. FlashAttention) gives the best training throughput [3]. But this is mistaken. In this post, we explain several different ways of implementing lin
Linear Transformers Are Faster After All – Manifest AI \[ \newcommand{\R}{\mathbb{R}} \newcommand{\Z}{\mathbb{Z}} \newcommand{\N}{\mathbb{N}} \newcommand{\sft}{\text{softmax}} \newcommand{\List}{\text{List}} \newcommand{\Seq}{\text{Seq}} \newcommand{\SeqT}{\text{SeqT}} \newcommand{\CSeqT}{\text{CSeqT}} \newcommand{\Dist}{\text{Dist}} \newcommand{\SM}{\text{SM}} \newcommand{\Fn}{\text{Fn}} \newcommand{\Tok}{\text{Tok}} \newcommand{\Aij}{ A_{[i,j]}} \] It is well-known that removing the exponential from the attention layer of a transformer allows for a recurrent reformulation, with computational
saved by
related reading
- Transformer Math 101 | EleutherAI Blogblog.eleuther.ai
- The Illustrated Transformer – Jay Alammar – Visualizing machine learning one concept at a time.jalammar.github.io
- Linear Attention Fundamentals | Hailey Schoelkopfhaileyschoelkopf.github.io
- transformer_attention.pdfarxiv.org
- Transformers Inference Optimization Toolset | AstraBlogastralord.github.io
- Transformer Inference Arithmetic | kipply's blogkipp.ly
- The Annotated Transformernlp.seas.harvard.edu
- Transformers are RNNs: Fast Autoregressive Transformers with Linear Attentionarxiv.org
- Log-Linear Attentionarxiv.org
- Linear Attention Is All You Need | Towards Data Sciencetowardsdatascience.com
- [2205.14135] FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awarenessarxiv.org
- Tensor-Transformer Variants are Surprisingly Performant — LessWronglesswrong.com