Attention with Linear Biases (ALiBi) removes positional embeddings from transformers entirely and adds a fixed distance penalty directly to query-key attention scores, letting a 1.3B-parameter language model trained on 1,024 tokens match a 2,048-token sinusoidal baseline at 2,048 tokens while training 11% faster with 11% less memory.
- Drop-in extrapolation at 1.3B scale: Trained for 50k updates on 461 GB (CC100 + RoBERTa), an
ALiBimodel withL = 1,024hits 8.92 validation perplexity atL_valid = 2,048using 26.2 GB per GPU, beating a time-matchedL = 2,048sinusoidal model (9.01 perplexity, 29.3 GB) while saving 3.1 GB of memory. - No sinusoidal explosion: On WikiText-103 (
L_train = 1,024), sinusoidal perplexity jumps from 19.34 at 1,024 tokens to 51.09 at 2,024 and 453.32 at 16,024; Rotary (RoPE) reaches 31.17 and 106.99;ALiBidrops to 18.05 and holds at 17.98. - Zero runtime tax vs. T5 bias:
T5relative position bias extrapolates up to ~2L(18.34 at 2,024 tokens) but slows GPU training by more than 2x (13.0k vs. 26.0k words/sec atL = 1,024) and runs out of 32 GB memory at 13,024 tokens;ALiBistays within 1% of sinusoidal training speed and adds 0% to 0.7% memory. - Train short, beat long: On WikiText-103,
ALiBitrained onL = 512(1.84x faster thanL = 3,072sinusoidal) extrapolates to 3,072 tokens at 18.40 validation perplexity, outperforming theL = 3,072sinusoidal model (18.67).
How ALiBi Scores Distance Without Embeddings
In the original Transformer, sinusoidal vectors are added to token embeddings at layer 1. Press, Smith, and Lewis found that sinusoidal models cannot extrapolate even a few dozen tokens past training length L (degrading past k = 50 extra tokens), while learned position tables cannot represent any position past L at all.
ALiBi drops position embeddings from the input and injects recency directly into every attention head’s pre-softmax logits: softmax(q_i K^T + m * [-(i - 1), ..., -2, -1, 0]). A query at position i penalizes key j proportionally to their distance i - j, multiplied by a fixed, non-learned head slope m.
For n heads, slopes follow a geometric progression starting at 2^(-8/n) with the same ratio. In an 8-head model, slopes span from 1/2 (0.5 per token, enforcing tight local focus) down to 1/256 (0.0039, allowing long-range context). For 16 heads, ALiBi interpolates geometric midpoints from 2^(-0.5) to 2^(-8). Making m trainable hurt extrapolation and slowed training by 3%. Because the bias tensor simply folds into the existing causal attention mask (n x L x L instead of L x L), it adds zero matrix-multiply operations and at most ~100 MB of mask overhead while saving gigabytes by enabling shorter L_train.
Key Findings and Why Perplexity Drops Past L
Without changing slopes across datasets (WikiText-103, Toronto BookCorpus, and CC100+RoBERTa), ALiBi matched sinusoidal perplexity at 1.3B scale when L_valid = L (8.84 vs. 8.83 at L = 2,048) and beat it on smaller corpora (17.60 vs. 18.67 on WikiText-103 L = 3,072).
Crucially, Appendix B.2 explains why perplexity keeps falling up to 2L during standard nonoverlapping evaluation: it is mostly the early token curse, not long-range synthesis. In nonoverlapping windows of length 1,000, 10% of predictions have 100 or fewer tokens of left context; doubling the window to 2,000 halves that starved fraction to 5%. When the authors re-ran WikiText-103 with stride S = 1 sliding-window evaluation (so every token already had L tokens of context), ALiBi stayed flat past L rather than improving further, whereas sinusoidal perplexity still exploded.
Caveats and Builder Takeaway
Flat perplexity under ALiBi proves the model does not collapse on long inputs, not that it reliably retrieves or reasons over facts 10,000 tokens back. Because linear penalties grow monotonically with distance, distant keys suffer steep logit suppression unless a head has a tiny slope. Modern long-context stacks typically pair RoPE position interpolation or YaRN context extension with brief long-context fine-tuning when exact needle-in-a-haystack retrieval matters. ALiBi remains an attractive, zero-parameter baseline whenever training sequence length is memory-bound and recent-context recency matches the workload.


