What ALiBi is
Attention by itself does not know where tokens are: the scores depend only on the vectors. GPT-2 adds a learned position vector to each input, Qwen2.5 rotates queries and keys (the GQA tab). ALiBi, attention with linear biases, adds no position information to the vectors at all. Instead each head subtracts from every score a penalty proportional to the distance between query and key. Press et al. designed it so that a model trained on short sequences still works on longer ones, which learned and sinusoidal position embeddings do poorly.
This page records BLOOM-560m: 24 blocks, of which 7 are recorded (1, 5, 9, 13, 17, 21 and 24), 16 heads of 64 dimensions, one ALiBi slope per head, on the prompts Repeated words, Counting and Two names.
The bias
Head has a fixed slope and adds to the score of key for query ; since , the bias is 0 for the token itself and more negative the further back the key is:
The slopes are not learned. For heads they form the geometric sequence ; with 16 heads that is , from 0.707 for head 1 to for head 16. A steep slope makes a head local: with head 1's slope, a key ten tokens back already loses 7 from its score. A shallow one barely discounts distance at all. The Slopes panel shows all 16 and picks a head, and the m · (j − i) matrix beside the head card shows its bias, the same in every block.
One score, two terms
Below the bias matrix the selected query's score is split into its parts: the content term , the bias , and their sum, the score the softmax sees. The row popup lists the same numbers for every key.
BLOOM's code adds rather than . The two differ by , the same constant for every key of a row, and a softmax does not change when a constant is added to all its inputs:
No positions in the input
Because BLOOM adds no position embedding, a token enters block 1 with the same vector wherever it stands. The caption under the page checks this on the recording: in block 1 every repeated token, such as “ the” or “ cat”, has exactly the same input at each occurrence (max |Δ| = 0). Only the bias tells a head that one “ the” is nearer than another. From block 2 on the vectors differ, because attention has mixed different contexts into them, but position still enters the scores only through each head's bias.
Extrapolation
A learned position table has no rows beyond the training length, and sinusoidal embeddings, though defined everywhere, did not let the models Press et al. tested extrapolate well. ALiBi's bias is defined for any distance and behaves the same at distances the model has seen. The paper reports a 1.3B model trained on sequences of 1,024 tokens that extrapolates to 2,048 with the same perplexity as a sinusoidal model trained on 2,048, while training 11 % faster and using 11 % less memory. Its built-in preference for recent tokens also helped on WikiText-103, where it beat several strong position methods.
Where it came from
Shaw et al. (2018) first made attention depend on relative position, with learned vectors for each distance; T5 (2019) simplified that to one learned scalar bias per distance bucket and head (its self-attention does this; its cross-attention, on the Cross tab, has no position term). ALiBi (2021) fixed those biases to a straight line. BigScience compared position methods in ablations at the billion-parameter scale before training BLOOM (Le Scao et al.) and chose ALiBi. Rotary embeddings became the more common choice afterwards, and Kazemnejad et al. showed that a causal decoder with no position encoding at all can still represent positions and, on their tasks, generalised to longer inputs better than ALiBi or RoPE.
Papers
- Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation Introduces ALiBi: no position embeddings, a fixed linear distance penalty per head, and extrapolation to longer inputs.
- BLOOM: A 176B-Parameter Open-Access Multilingual Language Model The model family this page records, trained with ALiBi.
- What Language Model to Train if You Have One Million GPU Hours? The BigScience ablations, position embeddings among them, that settled BLOOM's architecture.
- Self-Attention with Relative Position Representations The first relative position method for self-attention, with learned vectors per distance.
- Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer T5, whose learned scalar bias per distance bucket is ALiBi's closest relative.
- RoFormer: Enhanced Transformer with Rotary Position Embedding Rotary position embeddings, the main alternative to ALiBi in later models.
- The Impact of Positional Encoding on Length Generalization in Transformers Compares ALiBi, RoPE and others with no position encoding at all on length generalisation.