[Paper Review] Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
The paper introduces ALiBi, a simple attention bias that enables transformer language models to extrapolate to longer input sequences than seen during training without adding positional embeddings or slowing runtime.
Since the introduction of the transformer model by Vaswani et al. (2017), a fundamental question has yet to be answered: how does a model achieve extrapolation at inference time for sequences that are longer than it saw during training? We first show that extrapolation can be enabled by simply changing the position representation method, though we find that current methods do not allow for efficient extrapolation. We therefore introduce a simpler and more efficient position method, Attention with Linear Biases (ALiBi). ALiBi does not add positional embeddings to word embeddings; instead, it biases query-key attention scores with a penalty that is proportional to their distance. We show that this method trains a 1.3 billion parameter model on input sequences of length 1024 that extrapolates to input sequences of length 2048, achieving the same perplexity as a sinusoidal position embedding model trained on inputs of length 2048 but training 11% faster and using 11% less memory. ALiBi's inductive bias towards recency also leads it to outperform multiple strong position methods on the WikiText-103 benchmark.
Motivation & Objective
- Investigate why transformers struggle to extrapolate to longer sequences than training.
- Evaluate existing position methods (sinusoidal, rotary, T5 bias) for extrapolation.
- Propose a simple, efficient alternative (ALiBi) that biases attention by distance.
- Demonstrate that ALiBi enables training on short sequences with reliable long-sequence inference.
- Show applicability across domains and model sizes, including large-scale settings.
Proposed method
- Replace bottom-position embeddings with a linear distance-based bias added to attention scores.
- Set head-specific slopes in a fixed geometric progression to control extrapolation behavior.
- Train Transformer LMs on short sequences and evaluate perplexity on longer sequences without changing model parameters.
- Compare ALiBi against sinusoidal, rotary, and T5 bias baselines in terms of speed, memory, and perplexity.
- Demonstrate extrapolation performance up to several times the training length (e.g., 2x–3x) and beyond on WikiText-103 and CC100+RoBERTa domains.
Experimental results
Research questions
- RQ1Can extrapolation to longer input lengths be achieved by modifying only the position method without additional training on longer sequences?
- RQ2How does ALiBi compare to sinusoidal, rotary, and T5 bias in terms of perplexity, speed, and memory across different model sizes and datasets?
- RQ3Does ALiBi maintain performance when extrapolating to very long sequences (e.g., 10,000 tokens) and across diverse domains?
- RQ4Is ALiBi easy to implement with negligible runtime cost and memory overhead?
Key findings
- ALiBi enables training on short sequences while achieving perplexities comparable to or better than sinusoidal baselines when evaluated on longer sequences.
- A 1.3B parameter model trained on L=1024 with ALiBi attains the same perplexity as a sinusoidal model trained on L=2048 at 2048-token evaluation, with 11% faster training and 11% less memory usage.
- ALiBi maintains strong performance even when extrapolating to sequences of length up to 10,000 tokens.
- On WikiText-103, ALiBi models trained with L=512–3072 outperform the sinusoidal baseline across extrapolation ranges, with notable speed and memory advantages.
- On CC100+RoBERTa, ALiBi achieves similar perplexities to sinusoidal baselines while using 6%–11% less memory and 7% faster training in large-scale settings.
- ALiBi shows transferability to different domains (books) and scales well without retuning the hyperparameters (slopes).
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.