Introduction
Standard Transformers rely on softmax attention, which scales quadratically—$O(L^2)$—relative to sequence length. This computational bottleneck makes them prohibitively expensive for processing very long sequences. Linear attention offers an elegant theoretical solution by reducing complexity to $O(L)$, effectively acting like a Recurrent Neural Network (RNN) with a matrix-valued hidden state.
However, linear attention has historically faced two major hurdles:
- The Performance Gap: It typically underperforms softmax attention in language modeling accuracy. This is largely because it lacks the ability to "forget" or selectively attend to information—a critical feature provided by the "gates" in traditional RNNs like LSTMs.
- The Hardware Gap: Despite being theoretically faster, current implementations of linear attention are often slower in practice than highly optimized softmax attention algorithms (like FlashAttention-2). They lack "I/O awareness," meaning they spend too much time moving data between slow GPU memory (HBM) and fast on-chip cache (SRAM).
This paper introduces Gated Linear Attention (GLA), an architecture that bridges the performance gap between efficient linear attention and standard softmax attention. Paired with a hardware-aware algorithm called FlashLinearAttention, the authors achieve training speeds that surpass FlashAttention-2 and Mamba, while delivering a model capable of generalizing from 2K to 20K tokens with minimal performance loss.
Methods: Architectural and Algorithmic Innovation
The authors tackle the limitations of linear attention through a combination of hardware-algorithm co-design and architectural improvements.
FlashLinearAttention
To overcome the hardware gap, the authors propose a hardware-efficient algorithm based on a chunkwise parallel form. Instead of processing the sequence purely step-by-step (recurrent) or all-at-once (parallel), the sequence is divided into manageable chunks:
- Intra-chunk: Computations within a chunk are performed in parallel using high-speed matrix multiplications.
- Inter-chunk: The hidden state is passed between chunks recurrently.
- I/O Awareness: By carefully "tiling" the computation, the algorithm keeps the matrix-valued hidden states in SRAM as much as possible, drastically reducing memory traffic to and from the HBM.
Gated Linear Attention (GLA)
To address the accuracy gap, the authors introduce a data-dependent forget gate ($\alpha_t$). This gate allows the model to selectively discard outdated or irrelevant information from its hidden state.
To ensure this addition remains hardware-friendly, they employ a low-rank parameterization for the gates and a two-level tiling strategy. This clever structuring allows the model to use half-precision Tensor Cores for the bulk of the matrix math, resorting to full precision only for the numerically sensitive log-space gating calculations.
Key Insights
- The "Matrix RNN" Perspective: Linear attention can be viewed as an RNN where the hidden state is a $d \times d$ matrix. Adding a gate transforms it into a "Gated Matrix RNN." This larger state capacity (compared to the vector state of models like Mamba) allows it to store and recall significantly more complex information.
- Hardware-Algorithm Co-design: The breakthrough insight is that complex, data-dependent gating does not require sacrificing hardware efficiency. By structuring the math into a two-level chunking system, linear-time models can fully utilize GPU Tensor Cores.
Experiments and Key Results
The models were trained on the massive open-source SlimPajama dataset (up to 1.3B parameters on 100B tokens) and evaluated across various benchmarks including WikiText-103, LAMBADA, and several downstream tasks (PIQA, HellaSwag, WinoGrande).
Speed and Efficiency
FlashLinearAttention proves to be faster than FlashAttention-2 as a standalone layer, even at relatively short sequence lengths like 1K. At the full model level, the GLA Transformer achieves higher training throughput than a similarly sized Mamba model.
Accuracy and Recall
The 1.3B GLA model performs competitively with the LLaMA-style "Transformer++" and outperforms other linear-time baselines like RetNet and Mamba on several downstream tasks. Notably, on the Multi-Query Associative Recall (MQAR) task—a synthetic benchmark designed to test information retrieval from long contexts—GLA significantly outperforms Mamba and RetNet, likely due to its larger matrix-valued recurrent state.
Length Generalization
Because GLA is fundamentally recurrent, it exhibits strong "extrapolation" capabilities. Standard Transformers often fail immediately when exceeding their training window. In contrast, a GLA model trained on 2,048 tokens can generalize to sequences of 20,000+ tokens during inference with virtually no perplexity degradation, as demonstrated on the PG19 dataset.
Limitations and Future Work
While the results are highly promising, the authors note a few limitations:
- Scale: Due to compute constraints, experiments were limited to 1.3B parameters. Future work will need to verify if these advantages hold at the 7B, 70B, or 400B parameter scales.
- Modality: The current paper focuses exclusively on language modeling. The authors suggest that GLA could be highly effective for other modalities with long-range dependencies, such as video or audio, but this remains untested.
- Parameter Overhead: The gating mechanism introduces slightly more parameters compared to vanilla linear attention. However, the authors successfully mitigate this using low-rank parameterization to keep the overall parameter count comparable to standard Transformers.
Summary updated