ALiBi

ALiBi injects position into attention by adding a head-specific linear distance penalty to attention logits instead of adding positional embeddings to token representations.

Metadata

FieldValue
PaperTrain Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
AuthorsOfir Press, Noah A. Smith, Mike Lewis
Year2021 preprint; 2022 ICLR paper
VenueICLR 2022
arXiv2108.12409
Statusfull note started

One-Line Takeaway

ALiBi turns positional information into an additive bias on attention scores:

where is a fixed slope for head and is a distance-based bias. In causal language modeling, distant past tokens get a larger penalty.

Question

Plain self-attention has no order signal unless position is injected somewhere:

The usual Transformer route adds positional encodings to token embeddings:

That works, but long-context extrapolation raises a sharper question:

ALiBi asks whether position should enter the attention logit directly rather than the token embedding.

Main Claim

The paper’s architecture claim is:

Instead of learning or tabulating one position vector per index, ALiBi uses a fixed monotonic bias:

in the attention score before softmax.

For a causal query at position attending to a key at position , define distance:

Then a simplified ALiBi logit is:

The slope differs across heads, giving some heads a strong recency bias and others a weaker long-range bias.

Architecture Contract

ItemContract
Inputordered token sequence
Target blockself-attention logits
Position operationadd fixed head-specific linear bias by relative distance
Token embeddingno added positional embedding required by ALiBi
Parametersno learned position table
Main usedecoder-only language modeling and long-context extrapolation
Main claimtrain on shorter sequences and test on longer sequences
Main riskbias shape is fixed and may not fit every task or attention pattern

ALiBi is not a new backbone. It is a positional mechanism for attention.

Attention Logit View

For a batch and one head, standard attention logits are:

With a causal mask :

ALiBi adds a relative-position term:

For causal attention:

Then:

The value mixing is unchanged:

ALiBi only changes the logit geometry before softmax.

Why Linear Bias Helps Extrapolation

Learned absolute embeddings usually define parameters only for positions seen during training:

Extrapolating to a longer sequence requires some strategy for:

ALiBi avoids this lookup-table issue. The distance penalty is defined for any distance:

So the same rule extends beyond the training length:

This does not guarantee perfect long-context behavior, but it removes one hard length boundary from the architecture.

Head Slopes

ALiBi uses different slopes for different heads:

The architecture intuition:

Head BiasEffect
large slopestrong preference for nearby tokens
small slopeweaker distance penalty and more long-range access

This creates a spread of attention distance priors across heads without learning a position table.

Relation to Other Position Methods

MethodWhere Position EntersExtrapolation Story
sinusoidal positionadd fixed vector to token embeddinganalytic but still mixed into token state
learned absolute positionadd learned vector to token embeddingtied to trained position range
relative position biasadd learned or bucketed bias to logitsdepends on buckets and maximum distance
RoPErotate query/key vectorsrelative phase, later often scaled for longer context
ALiBiadd fixed linear distance bias to logitsdistance rule naturally extends

The key distinction:

Both are position mechanisms for Attention, but their implementation and extrapolation behavior differ.

Evidence to Read

ClaimEvidence TypeWhat It SupportsCaveat
train-short test-long workslanguage modeling perplexity at longer test lengthsALiBi can extrapolate beyond training contextresult depends on task and model setup
memory and speed improvecomparison against training at longer context lengthshorter training sequences can reduce training costnot a free serving-time long-context method
recency bias helpscomparison with position methods on WikiText-103fixed distance prior is useful for language modelingrecency prior may not fit every modality
implementation is smalllogit-bias additioneasy to add to existing attention codekernel and mask code must handle bias correctly

Implementation Reading

An implementation should make these decisions explicit:

  • Is the model causal, bidirectional, or cross-attentional?
  • Are distances , , or another relation?
  • Are slopes fixed exactly as in the paper or changed?
  • Is the ALiBi bias added before softmax and before masking is finalized?
  • Does the attention kernel support additive bias without materializing a huge dense matrix?
  • Are train and test context lengths reported separately?

For causal language models, the simplified logit update is:

Limitations

  • ALiBi is a fixed inductive bias; it is not universally optimal for every sequence task.
  • It helps remove positional-table length limits, but attention compute still scales with context length unless paired with efficient attention or sparsity.
  • Extrapolation claims should report both training length and evaluation length.
  • Some later long-context systems prefer RoPE variants or position interpolation/scaling, so ALiBi is one branch of the design space rather than the final answer.

Common Misreadings

MisreadingCorrection
”ALiBi makes attention linear time.”It changes position bias, not dense attention complexity.
”ALiBi is a new Transformer architecture.”It is a positional mechanism inside attention.
”No positional embeddings means no position information.”Position enters through the logit bias.
”Length extrapolation is solved completely.”The paper shows a useful route; evaluation still depends on task, data, model size, and context range.

What to Remember

ALiBi is the cleanest example of position as an attention-logit prior:

For the architecture shelf, keep it near RoPE, Transformer-XL, Performer, and FlashAttention because it changes how Transformers handle sequence length without changing the whole backbone.