AI State of the Art
SOTA/Advanced Attention Mechanisms/16 min
Section 83

ALiBi and Alternatives to RoPE

Listen as a podcast β†’

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 Extrapolation

ALiBi'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

Attention(Q,K,V)=softmax ⁣(QKTdk+mβ‹…B)V\text{Attention}(Q, K, V) = \text{softmax}\!\left(\frac{QK^T}{\sqrt{d_k}} + m \cdot B\right) V

Where:

  • BB is the distance bias matrix: Bi,j=βˆ’βˆ£iβˆ’j∣B_{i,j} = -|i - j|, that is, the distance between positions ii and jj, negative because we penalize distant tokens. Concretely, BB is 0 for a token with itself, βˆ’1-1 for the immediate neighbor, βˆ’10-10 for a token 10 positions away, βˆ’100-100 for a token 100 positions away.
  • mm 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 12,14,18,…,1256\frac{1}{2}, \frac{1}{4}, \frac{1}{8}, \dots, \frac{1}{256}: the kk-th head gets m=2βˆ’km = 2^{-k}. Each head therefore "sees" at a different distance: heads with a high mm strongly penalize distance (local attention), while heads with a tiny mm barely penalize it (near-global attention). The other symbols are the standard attention ones: QQ, KK, VV are the queries, keys and values, dkd_k the dimension of one head, and the softmax turns scores into weights that sum to 1.
Figure 3 from the ALiBi paper. On the left, the lower-triangular matrix of attention scores q_i . k_j for five tokens. In the middle, a plus sign. On the right, a second triangular matrix holding the negated distance: 0 on the diagonal, minus 1 next to it, down to minus 4 in the bottom-left corner. The whole thing is multiplied by a head-specific scalar m.
The entire method is this one addition. You keep the usual attention score matrix and simply add a matrix of negative distances, scaled by the head's slope m. Nothing else in the Transformer changes, and no positional encoding is added to the embeddings.Source : ALiBi paper, Press et al. 2021 (figure 3), via InterDB
The communication cost analogy

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:

HeadSlope mmBehavior
11/2=0.51/2 = 0.5Very local attention (strong distance penalty)
21/4=0.251/4 = 0.25
31/8=0.1251/8 = 0.125
......
81/256β‰ˆ0.0041/256 \approx 0.004Near-global attention (negligible penalty)

The formula βˆ’mΓ—βˆ£iβˆ’j∣-m \times |i-j| is a simple multiplication. It works for any value of ∣iβˆ’j∣|i-j|, 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.

Empirical results

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?

CriterionALiBiRoPE
ComplexityUltra-simple (a linear bias)More complex (multi-frequency rotations)
Native generalizationExcellentPoor (without extension techniques)
Short sequence performanceDecentBetter
AdoptionNiche (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's structural weakness

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.

Current trend

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's legacy

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.

Check your understanding0 / 4

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?