The problem: positions don't generalize
Imagine you train a model to read texts of 1024 words. Everything goes well. Then one day, you give it a text of 4000 words. Panic: the model completely loses its footing. This is the position extrapolation problem.
Why? Because classical positional encodings (sinusoidal or learned) work like an address book with 1024 entries. As long as you stay within known addresses, everything is fine. But at address 2000, there's nothing in the book. The model doesn't know what to do with this unknown position.
Train Short, Test Long: Attention with Linear Biases Enables Input Length ExtrapolationALiBi's idea: don't encode position at all
Most approaches add position information to token embeddings: "you're at position 42, here's your postal code." ALiBi (Attention with Linear Biases) proposes something radically simpler: forget about positional encodings. Instead, directly penalize distant tokens in the attention computation.
The formula
Where:
- is the distance bias matrix: , that is, the distance between positions and , negative because we penalize distant tokens. Concretely, is 0 for a token with itself, for the immediate neighbor, for a token 10 positions away, for a token 100 positions away.
- is a scalar different for each attention head (a simple slope, one single number), fixed in advance and never learned. For 8 heads, the paper takes the geometric sequence : the -th head gets . Each head therefore "sees" at a different distance: heads with a high strongly penalize distance (local attention), while heads with a tiny barely penalize it (near-global attention). The other symbols are the standard attention ones: , , are the queries, keys and values, the dimension of one head, and the softmax turns scores into weights that sum to 1.

It's like a phone system: talking to your office neighbor is free, calling someone in the next building costs a little, and international calls are expensive. Nearby tokens hear each other easily, distant tokens have to "pay" to be heard. The more relevant the distant content is (high QK^T score), the more it can "pay" that cost.
Why does it generalize so well?
The beauty of ALiBi is that the slopes m are fixed in advance (not learned) and follow a geometric progression: each head's slope is half the previous one's. For 8 heads:
| Head | Slope | Behavior |
|---|---|---|
| 1 | Very local attention (strong distance penalty) | |
| 2 | ||
| 3 | ||
| ... | ... | |
| 8 | Near-global attention (negligible penalty) |
The formula is a simple multiplication. It works for any value of , whether it's 10, 1000, or 100000. There's nothing to "learn" for new positions: the penalty is computed mechanically. That's why a model trained on 1024 tokens can generalize to 4000-8000 tokens without any modification.
In the paper, a model trained with ALiBi on 1024-token sequences maintains stable perplexity when tested on far longer sequences, hence the paper's title, "Train Short, Test Long." In comparison, classical sinusoidal positional encodings fail catastrophically as soon as you exceed the training length. The large multilingual model BLOOM later adopted ALiBi at scale.
ALiBi vs RoPE: why did RoPE win the battle?
| Criterion | ALiBi | RoPE |
|---|---|---|
| Complexity | Ultra-simple (a linear bias) | More complex (multi-frequency rotations) |
| Native generalization | Excellent | Poor (without extension techniques) |
| Short sequence performance | Decent | Better |
| Adoption | Niche (BLOOM, MPT) | Dominant (LLaMA, Mistral, virtually all LLMs) |
RoPE encodes much richer positional information through its multi-frequency rotations. The model can learn subtle positional patterns that ALiBi's simple linear bias can't capture. And RoPE's extrapolation problem has been largely solved by techniques like YaRN and NTK-aware. Result: RoPE offers better performance on short sequences (the dominant case) while being extensible to long sequences.
ALiBi imposes a systematic bias toward recent tokens. If your system prompt is at position 1 and you're generating at position 800, the system prompt receives a penalty of 800 * m. Even with the most "global" head (m β 0.004), that's a penalty of β3.2 on the attention score (800 Γ 0.004). Information at the beginning of the sequence is mechanically disadvantaged, which can be problematic for system instructions or long prompts.
Models that use ALiBi
- BLOOM (BigScience): the flagship model of the ALiBi approach
- MPT (MosaicML): popularized ALiBi in the open-source ecosystem
- Falcon (initial versions, before switching to RoPE)
Lesser-known alternatives
NoPE: zero positional encoding
Surprising studies show that causal Transformers can learn to infer positions solely from the causal mask. No positional encoding at all. Positions emerge implicitly from the fact that token i can only see tokens 0 to i-1. It's minimalist and works better than you'd imagine.
CoPE (Meta): contextual positions
Positions are no longer fixed integers but depend on the content. Your "position 2" isn't the same depending on the tokens around you. The model learns to weight distance based on semantic context.
FIRE: learned biases
A learned function (instead of a simple linear bias) maps relative distances to attention biases. More flexible than ALiBi while preserving the property of generalization to unknown distances.
Today, the standard is RoPE + YaRN/NTK for context extension. ALiBi remains confined to a few existing models and researchers exploring alternatives. But its founding ideas (simplicity, bias instead of encoding, generalization by design) continue to influence new architectures.
Why it works at a deeper level
ALiBi creates an exponential decay of attention with distance (softmax transforms the linear bias into exponential decay). This is formally similar to State Space Models (Mamba and friends) which progressively forget past tokens via a decay factor. Two very different architectural paths, but the same fundamental intuition: progressive forgetting is a powerful inductive bias that regularizes and generalizes.
The spectrum of positional approaches:
- Rigid: ALiBi (fixed bias, perfect generalization, limited expressiveness)
- Flexible: RoPE (rotations, rich expressiveness, generalization requiring extensions)
- Very flexible: Learned encodings (maximum expressiveness, zero generalization)
ALiBi demonstrated that positional information doesn't need to be encoded in the embeddings. A simple bias in the right place (the attention matrix) is enough to give the model a sense of order and distance. This lesson in elegance persists, even in a world dominated by RoPE.
1. What does ALiBi do instead of a positional encoding?
2. Why does an ALiBi model trained on 1024 tokens still work at 4000, where classic encodings collapse?
3. Your system prompt sits at position 1 and generation has reached position 800. What happens with ALiBi?
4. Why does each attention head get a different slope m?