[Paper Review] Unlimiformer: Long-Range Transformers with Unlimited Length Input
Unlimiformer augments pretrained encoder-decoder transformers with a single k-nearest-neighbor index for cross-attention, enabling unlimited input length at test time without extra training, and improving long-document and book-summarization performance.
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 .
Motivation & Objective
- Motivate and enable processing of extremely long inputs beyond standard context windows without retraining from scratch.
- Propose a generic, non-parametric retrieval mechanism to substitute full cross-attention over all input tokens.
- Show that a single k-NN index suffices to approximate attention masses for all decoder layers and heads.
- Demonstrate improvements on long-document and book-summarization benchmarks across multiple base models and training regimes.
Proposed method
- Insert a k-NN retrieval step before cross-attention in every decoder layer, selecting top-k keys per head.
- Encode long inputs by chunking with overlap, and index the middle-half of each chunk’s hidden states.
- Rewrite attention computation to allow a single index of encoder hidden states accessed via per-head projections QWqWk^T, enabling one shared index across layers/heads.
- Query the index at decoding time to attend only to the top-k retrieved keys, with the dot-product distances serving as attention scores.
- Use 16-bit hidden states to bound memory (e.g., 2 GB for 1,000,000 tokens) and offload the index to CPU/GPU as needed.
- Offer low-cost test-time variants (+test Unlimiformer, +early stop w/ Unlimiformer) and longer-range training approaches (Random-encoded, Retrieval, Alternating).
- Provide a codebase and model release compatible with LLaMA-2 and HuggingFace Transformers.
Experimental results
Research questions
- RQ1Can cross-attention in encoder-decoder transformers be offloaded to a k-NN index to support unbounded input lengths at test time?
- RQ2Does a single shared k-NN index across all decoder layers/heads suffice for effective retrieval and preserve most attention mass?
- RQ3Can we augment existing pretrained models without additional learned parameters to handle unlimited input lengths?
- RQ4What are the trade-offs in accuracy and computation when using Unlimiformer on long-range summarization and related tasks?
Key findings
- Unlimiformer improves baseline models on long-document summarization without extra training (e.g., BART_base +test Unlimiformer yields higher ROUGE/L and BERTScore than standard finetuning).
- Early stopping with Unlimiformer provides substantial gains without additional training cost (e.g., GovReport: ROUGE-1 from 48.7 to 51.0).
- When trained with Unlimiformer, models like PRIMERA surpass or match larger long-range baselines, and Unlimiformer can further improve them (e.g., PRIMERA +test Unlimiformer improves ROUGE/L and EntMent over standard PRIMERA).
- BookSum results show EntMent gains with Unlimiformer (e.g., Unlimiformer+PRIMERA raises EntMent to 25.5 from 11.6 in baseline PRIMERA).
- Retrieval-focused training variants (Retrieval, Random-encoded, Alternating) yield competitive gains across datasets, with the best method varying by model and data.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.