# Landmark Attention: Random-Access Infinite Context Length for Transformers

Source: [Landmark Attention: Random-Access Infinite Context Length for Transformers](<https://www.sota2.com/research/paper/68fa71411e209131cea50284>)

Collection index: [llms.txt](<https://www.sota2.com/research/llms.txt>)

Data updated: 2025-10-28T13:57:02.559Z

Authors: Amirkeivan Mohtashami, Martin Jaggi

Published: 2023-05-25T17:53:42.000Z

## Abstract

While Transformers have shown remarkable success in natural language processing, their attention mechanism's large memory requirements have limited their ability to handle longer contexts. Prior approaches, such as recurrent memory or retrieval-based augmentation, have either compromised the random-access flexibility of attention (i.e., the capability to select any token in the entire context) or relied on separate mechanisms for relevant context retrieval, which may not be compatible with the model's attention. In this paper, we present a novel approach that allows access to the complete context while retaining random-access flexibility, closely resembling running attention on the entire context. Our method uses a landmark token to represent each block of the input and trains the attention to use it for selecting relevant blocks, enabling retrieval of blocks directly through the attention mechanism instead of by relying on a separate mechanism. Our approach seamlessly integrates with specialized data structures and the system's memory hierarchy, enabling processing of arbitrarily long context lengths. We demonstrate that our method can obtain comparable performance with Transformer-XL while significantly reducing the number of retrieved tokens in each step. Finally, we show that fine-tuning LLaMA 7B with our method successfully extends its context length capacity to over 32k tokens, allowing for inference at the context lengths of GPT-4. We release the implementation of landmark attention and the code to reproduce our experiments at https://github.com/epfml/landmark-attention/.

## Recorded benchmark results

A research result applies to its stated dataset, split, metric and evaluation configuration. Compare like-for-like settings, preserve the metric's unit and direction, and distinguish paper-reported results from independent reproduction. The best result recorded here is not a claim of exhaustive, current global coverage.

- [Long-context retrieval and tracking on RULER 32K](<https://www.sota2.com/research/sota/long-context-retrieval-and-tracking-on-ruler-32k.md>): Long-context retrieval and tracking; RULER 32k; S-N Score: 83.

- [Long-context retrieval and tracking on RULER 4K](<https://www.sota2.com/research/sota/long-context-retrieval-and-tracking-on-ruler-4k.md>): Long-context retrieval and tracking; RULER 4k; S-N Score: 83.

- [Long-context retrieval and tracking on RULER 128K](<https://www.sota2.com/research/sota/long-context-retrieval-and-tracking-on-ruler-128k.md>): Long-context retrieval and tracking; RULER 128k; S-N Score: 0.

## Original sources and implementation

[Original paper](<https://arxiv.org/abs/2305.16300>)

[PDF](<https://arxiv.org/pdf/2305.16300.pdf>)
