Robots Atlas>ROBOTS ATLAS
Architecture

ALiBi

2021ActivePublished: 9 June 2026Updated: 9 June 2026Published
Key innovation
Replaces classical positional encoding (sinusoidal, learned, RoPE) with a static, non-learned linear bias added to attention logits, proportional to the distance between query and key — enabling sequence-length extrapolation far beyond the training length ("train short, test long").
Category
Architecture
Abstraction level
Building block
Operation level
ModelTrainingInference
Use cases
LLMs designed from scratch for length extrapolation (BLOOM, MPT, Replit Code, BloombergGPT)Training on short sequences with the intent of inferring on longer ones — saves pretraining costCode models operating on entire files/repositories without long-context fine-tuningDomains where typical inference lengths are unpredictable at training time

How it works

In a standard Transformer, positional encoding is added to each input embedding and attention is computed from query·key dot products alone. In ALiBi positional embeddings are removed — instead, a static bias of the form -m·|i-j| is added to the attention logit matrix, where i,j are query and key positions and m is a head-specific constant slope. The slopes m form a geometric sequence (e.g. for 8 heads: 1/2, 1/4, 1/8, …, 1/256), so different heads "look" at different context ranges — near heads see locally, far heads cover the whole context. The bias is static, with no learned position parameters. As a result, a model trained on sequences of length L correctly extrapolates to 2L, 4L, and beyond, because the bias is well-defined for any distance |i-j|.

Problem solved

Classical positional encodings — sinusoidal, learned, and to a lesser extent RoPE — extrapolate poorly to lengths longer than seen in training. Positions outside the pretraining range are "new" to the model and quality drops sharply. Earlier approaches required either longer training or fine-tuning (Position Interpolation, YaRN). ALiBi solves the problem structurally: the bias is a function of distance, not absolute position, so it works for arbitrarily long sequences without model modification.

Implementation

Implementation pitfalls
Combining ALiBi with a separate positional embeddingHigh

ALiBi by design replaces positional embeddings. Keeping sinusoidal/learned/RoPE together with ALiBi produces a double position signal and worsens results.

Fix:Completely remove positional encoding when ALiBi is enabled.
Wrong slopes for a non-standard number of headsMedium

The 2^(-8/n) geometric pattern assumes n = power of two. For non-standard n the authors provide specific formula extensions — skipping them lowers quality.

Fix:Use slopes computed per the procedure in the official Press et al. repository.
Assuming ALiBi always beats RoPE+YaRN/LongRoPELow

ALiBi yields strong extrapolation "for free", but on long-context benchmarks (NIAH, RULER, LongBench) RoPE + YaRN/LongRoPE based models typically score higher at comparable scale.

Fix:Choose ALiBi when simplicity and low long-inference cost are the priority. For maximum long-context quality prefer RoPE + YaRN/LongRoPE.

Evolution

Original paper · 2021 · arXiv:2108.12409 (later ICLR 2022) · Ofir Press
Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
Ofir Press, Noah A. Smith, Mike Lewis
2017
Sinusoidal positional encoding (Vaswani et al.)

The original Transformer introduces sinusoidal positional encoding as an additive embedding. Extrapolates poorly to lengths longer than in training — the starting point for all later alternatives.

2021
RoPE (Su et al.)

Rotary Position Embeddings — an alternative method of encoding positions via rotation of dimension pairs. Better than sinusoidal but also with limited extrapolation without PI/YaRN-style modifications.

2021
ALiBi — Press et al. paper
Inflection point

Press, Smith, Lewis publish ALiBi (arXiv:2108.12409). They show that a static linear bias in attention replaces positional embeddings and yields strong length extrapolation ("train short, test long").

2022
ICLR 2022 acceptance

ALiBi is accepted at ICLR 2022. The idea starts being adopted in new open LLMs.

2022
BLOOM (BigScience) uses ALiBi

BLOOM-176B — the first large open multilingual LLM — chooses ALiBi as its positional encoding, popularising the method in the open-source community.

2023
MPT (MosaicML) and BloombergGPT — production deployments of ALiBi

MosaicML releases the MPT family (7B/30B) with ALiBi, marketing the "context length flexibility" capability. BloombergGPT-50B also relies on ALiBi. ALiBi becomes an established alternative to RoPE.

2024
RoPE dominance in newer models

Most new large LLMs (Llama 2/3, Qwen, DeepSeek, Mistral) choose RoPE + YaRN/LongRoPE as the standard long-context path. ALiBi remains chosen mainly where simplicity of deployment and "free" extrapolation matter more than absolute benchmark quality.

Hyperparameters (configurable axes)

Per-head slopes (m)Critical

Vector of bias slopes, one per attention head. In the original paper this is a geometric sequence with base 2^(-8/n), where n is the number of heads.

8 głów: 1/2, 1/4, …, 1/256
16 głów: 1/√2, 1/2, …, 1/256
Training context length (L)High

Sequence length used during pretraining. Thanks to ALiBi extrapolation, the model performs well on sequences of 2L–4L without fine-tuning.

Use of positional embeddingCritical

ALiBi by design REPLACES classical positional encoding (sinusoidal/learned/RoPE) — the model is trained WITHOUT positional embeddings. Mixing ALiBi with RoPE is not a standard configuration.

none

Execution paradigm

Primary mode
Dense

ALiBi only modifies the attention weight — it remains a fully dense, deterministic mechanism without routing or conditional activation.

Activation pattern
All paths active

Parallelism

Parallelism level
Fully parallel

Adding the bias is a cheap vectorised operation on the attention logit matrix. No additional sequential dependencies — parallelism is identical to a standard Transformer.

Scope
TrainingInferenceAcross tokens

Hardware requirements

Primary

ALiBi is a purely algorithmic attention modification — adding a static bias to the logit matrix. It requires no special kernels or hardware instructions.

Good fit

Works well with FlashAttention (ALiBi kernel is supported out of the box). The bias can be precomputed once and reused across all layers.