Papers › Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation

Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation

27 Aug 2021ICLR 2022 4arXiv:2108.12409archive 2025-07-28

Ofir Press, Noah A. Smith, Mike Lewis

Since the introduction of the transformer model by Vaswani et al. (2017), a fundamental question has yet to be answered: how does a model achieve extrapolation at inference time for sequences that are longer than it saw during training? We first show that extrapolation can be enabled by simply changing the position representation method, though we find that current methods do not allow for efficient extrapolation. We therefore introduce a simpler and more efficient position method, Attention with Linear Biases (ALiBi). ALiBi does not add positional embeddings to word embeddings; instead, it biases query-key attention scores with a penalty that is proportional to their distance. We show that this method trains a 1.3 billion parameter model on input sequences of length 1024 that extrapolates to input sequences of length 2048, achieving the same perplexity as a sinusoidal position embedding model trained on inputs of length 2048 but training 11% faster and using 11% less memory. ALiBi's inductive bias towards recency also leads it to outperform multiple strong position methods on the WikiText-103 benchmark.

PaperPDFConference PDFCodeCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2108.12409")

Code

Syntology Ran 13 of 16 code samples harvested from 5 repositories linked to this paper; 3 have no recorded run. Of those that ran: 4 ran · honoured contract; 1 ran · our draft was wrong; 1 ran · fixture could not drive it; 7 ran with no contract checked.

By repository: official repository: 4 samples from 1 repository, 1 ran; community (archive-listed): 12 samples from 4 repositories, 12 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

ofirpress/attention_with_linear_biases officialmentioned in paperpytorchMIT report
answerdotai/modernbert mentioned on GitHubpytorchApache-2.0 report
baichuan-inc/baichuan-13b mentioned on GitHubpytorchApache-2.0 report
brkkaya/a_linear_attention_with_biases mentioned on GitHubpytorch report
jaketae/alibi mentioned on GitHubpytorch report
lucidrains/PaLM-jax mentioned on GitHubjax report
vinairesearch/phogpt mentioned on GitHubpytorchBSD-3-Clause report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

16 samples harvested; 13 ran; 4 honoured the contract we drafted; 3 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

4ran · honoured contract
1ran · our draft was wrong
1ran · fixture could not drive it
7ran
3unverified

Licence: 5 of the 16 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from 5 repositories linked to this paper, official or community; each sample names its own and says which. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

safe_readline ofirpress/attention_with_linear_biases/fairseq/binarizer.py official repository ran MIT recorded; this copy not marked cleared · pointer only · 82bdf940665aeeb4 · report
GatedLinear ofirpress/attention_with_linear_biases/fairseq/modules/downsampled_multihead_attention.py official repository unverified MIT recorded; this copy not marked cleared · pointer only · ca6cbbd64821d7fa · report
Linear ofirpress/attention_with_linear_biases/fairseq/modules/downsampled_multihead_attention.py official repository unverified MIT recorded; this copy not marked cleared · pointer only · 77d359c7acb72d6a · report
augmented_memory ofirpress/attention_with_linear_biases/fairseq/models/speech_to_text/modules/augmented_memory_attention.py official repository unverified MIT recorded; this copy not marked cleared · pointer only · 1769a89f798d0556 · report
ALiBiConfig jaketae/alibi/alibi/attention.py community (archive-listed) ran MIT (permissive) · 678123248e9a2d53 · report
ALiBiMultiHeadAttention jaketae/alibi/alibi/attention.py community (archive-listed) ran MIT (permissive) · 8099385f6961bb81 · report
AliBiAttention brkkaya/a_linear_attention_with_biases/models/alibi_attn.py community (archive-listed) ran · metamorphic tier: deterministic fingerprinted no licence file found · pointer only · 12ef66be25ef338d · report
BertAlibiUnpadSelfAttention answerdotai/modernbert/src/bert_layers/attention.py community (archive-listed) ran · metamorphic tier: deterministic Apache-2.0 (permissive) · 201cc87ee9341bc1 · report
IndexFirstAxis answerdotai/modernbert/src/bert_layers/attention.py community (archive-listed) ran Apache-2.0 (permissive) · 06c2a55caabae8b8 · report
IndexPutFirstAxis answerdotai/modernbert/src/bert_layers/attention.py community (archive-listed) ran Apache-2.0 (permissive) · 1760a9fa00a33980 · report
calc_alibi_bias lucidrains/PaLM-jax/palm_jax/palm_lite.py community (archive-listed) ran · honoured contract MIT (permissive) · 076a228889dcba7c · report
get_alibi_slope jaketae/alibi/alibi/attention.py community (archive-listed) ran · honoured contract MIT (permissive) · aa08d318b01ec8ef · report
get_alibi_slopes lucidrains/PaLM-jax/palm_jax/palm_lite.py community (archive-listed) ran · honoured contract fingerprinted MIT (permissive) · 0e4286158fe03dff · report
get_relative_positions jaketae/alibi/alibi/attention.py community (archive-listed) ran · honoured contract MIT (permissive) · 69e643285942e484 · report
pad_input answerdotai/modernbert/src/bert_layers/attention.py community (archive-listed) ran · fixture could not drive it Apache-2.0 (permissive) · 802fa8542c8445f9 · report
unpad_input_only answerdotai/modernbert/src/bert_layers/attention.py community (archive-listed) ran · our draft was wrong fingerprinted Apache-2.0 (permissive) · 4e534e11984c06b5 · report

Tasks

Inductive BiasPlaying the Game of 2048Word Embeddings

1 archive task tag without a task page not shown.

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

Introduced by this paper: ALiBi

ALiBi

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections