[Paper Review] Gated Linear Attention Transformers with Hardware-Efficient Training
This paper proposes Gated Linear Attention (GLA), a hardware-efficient transformer variant that replaces standard softmax attention with a data-dependent, gated linear attention mechanism. By optimizing memory access patterns and introducing a novel I/O-aware algorithm called FLASHLINEARATTENTION, GLA achieves faster training than FlashAttention-2 even on short sequences (e.g., 1K), while maintaining linear-time inference. The GLA Transformer matches or exceeds strong baselines like LLaMA, RetNet, and Mamba in language modeling, particularly excelling in length generalization and recall-intensive tasks.
Transformers with linear attention allow for efficient parallel training but can simultaneously be formulated as an RNN with 2D (matrix-valued) hidden states, thus enjoying linear-time inference complexity. However, linear attention generally underperforms ordinary softmax attention. Moreover, current implementations of linear attention lack I/O-awareness and are thus slower than highly optimized implementations of softmax attention. This work describes a hardware-efficient algorithm for linear attention that trades off memory movement against parallelizability. The resulting implementation, dubbed FLASHLINEARATTENTION, is faster than FLASHATTENTION-2 (Dao, 2023) as a standalone layer even on short sequence lengths (e.g., 1K). We then generalize this algorithm to a more expressive variant of linear attention with data-dependent gates. When used as a replacement for the standard attention layer in Transformers, the resulting gated linear attention (GLA) Transformer is found to perform competitively against the LLaMA-architecture Transformer (Touvron et al., 2023) as well recent linear-time-inference baselines such as RetNet (Sun et al., 2023a) and Mamba (Gu & Dao, 2023) on moderate-scale language modeling experiments. GLA Transformer is especially effective at length generalization, enabling a model trained on 2K to generalize to sequences longer than 20K without significant perplexity degradations. For training speed, the GLA Transformer has higher throughput than a similarly-sized Mamba model.
Motivation & Objective
- To address the performance gap between linear attention and standard softmax attention in Transformers.
- To improve training efficiency of linear attention by designing an I/O-aware, hardware-optimized algorithm that reduces memory movement.
- To enhance expressiveness of linear attention through data-dependent gating, improving performance on long-context and recall-intensive tasks.
- To enable competitive performance with standard Transformers while maintaining linear-time inference complexity.
- To demonstrate strong generalization to longer sequence lengths without performance degradation.
Proposed method
- Proposes FLASHLINEARATTENTION, a hardware-efficient algorithm for linear attention that optimizes memory access and parallelism for modern GPUs.
- Introduces a chunkwise parallel training form that combines inter-chunk recurrence with intra-chunk parallel computation to balance I/O efficiency and training speed.
- Designs a gated linear attention mechanism where the hidden state update is modulated by data-dependent gates, improving modeling capacity.
- Derives closed-form gradients for learnable parameters α and β using cumulative sum tricks to avoid storing intermediate states in high-bandwidth memory.
- Generalizes the FLASHLINEARATTENTION algorithm to support the gated variant, enabling efficient training of GLA-Transformers.
- Employs a modified attention computation that maintains the RNN-like recurrence for linear-time inference while enabling parallel training via chunking.
Experimental results
Research questions
- RQ1Can a hardware-optimized implementation of linear attention outperform highly-tuned softmax attention implementations like FlashAttention-2 on short sequences?
- RQ2Does introducing data-dependent gating in linear attention significantly improve performance compared to fixed decay factors or vanilla linear attention?
- RQ3Can a GLA-Transformer achieve competitive performance with standard Transformers (e.g., LLaMA) while maintaining linear-time inference?
- RQ4How well does the GLA-Transformer generalize to sequences longer than its training length, especially in recall-intensive tasks?
- RQ5What is the training throughput of GLA-Transformers compared to state-of-the-art linear-time models like Mamba and RetNet?
Key findings
- FLASHLINEARATTENTION is faster than FlashAttention-2 even on short sequences (e.g., 1K tokens), demonstrating superior I/O efficiency.
- The GLA-Transformer achieves competitive performance on language modeling benchmarks, matching or exceeding LLaMA-architecture models and recent linear-time models like RetNet and Mamba.
- On 340M and 1.3B parameter models, the GLA-Transformer achieves an average accuracy of 48.0% and 55.5% respectively across 11 zero-shot tasks, outperforming Mamba and RetNet in several benchmarks.
- The GLA-Transformer generalizes effectively to sequences longer than 20K tokens, with minimal perplexity degradation when trained on 2K sequences.
- The GLA-Transformer achieves higher training throughput than a similarly sized Mamba model, indicating better scalability on large-scale pretraining.
- The model shows strong performance on recall-intensive tasks such as BoolQ and ARC, suggesting improved memory retention and long-range dependency modeling.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.