Unlimiformer: Long-Range Transformers with Unlimited Length Input

Amanda Bertsch, Uri Alon, Graham Neubig, Matthew R. Gormley
2/12/2026

No official code found. Best implementation: abertsch72/unlimiformer (1,062 stars, MIT, last commit 2024-03-07).

Abstract

Since the proposal of transformers, these models have been limited to bounded input lengths, because of their need to attend to every token in the input. In this work, we propose Unlimiformer: a general approach that wraps any existing pretrained encoder-decoder transformer, and offloads the cross-attention computation to a single k-nearest-neighbor (kNN) index, while the returned kNN distances are the attention dot-product scores. This kNN index can be kept on either the GPU or CPU memory and queried in sub-linear time; this way, we can index practically unlimited input sequences, while every attention head in every decoder layer retrieves its top-k keys, instead of attending to every key. We evaluate Unlimiformer on several long-document and book-summarization benchmarks, showing that it can process even 500k token-long inputs from the BookSum dataset, without any input truncation at test time. We demonstrate that Unlimiformer improves pretrained models such as BART and Longformer by extending them to unlimited inputs without additional learned weights and without modifying their code. We make our code and models publicly available at https://github.com/abertsch72/unlimiformer .

View on arXivView PDF

Code Implementations(1)

MIT

Public repo for the NeurIPS 2023 paper "Unlimiformer: Long-Range Transformers with Unlimited Length Input"

1,06278PythonMay 3, 20232 years agoMIT

Similar Papers

Cite this paper

@article{bertsch2026unlimiformer,
  title  = {Unlimiformer: Long-Range Transformers with Unlimited Length Input},
  author = {Amanda Bertsch and Uri Alon and Graham Neubig and Matthew R. Gormley},
  year   = {2026},
  eprint = {2305.01625},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/pdf/2305.01625},
  journal = {NEURIPS 2023 2023}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2305.01625.svg)](https://codeofpaper.com/paper/2305.01625)

Discussion