PreprintCited by 4Topic ModelingNatural Language Processing TechniquesMultimodal Machine Learning Applications

Landmark Attention: Random-Access Infinite Context Length for Transformers

Open access
Mohtashami, Amirkeivan, Jaggi, Martin·2023·arXiv

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/.

Integrity signals

Registry

DataCite · 10.48550/arxiv.2305.16300

Cites

Statistics

Recomputing p-values needs the paper’s full text.

Claims the paper makes

We couldn’t retrieve this paper’s full text, so its claims and self-check weren’t run. The registry and citation checks still apply.

Claims other papers make about this one

Each is checked against this paper’s own text: does it say what the citing paper says it does?

  • Two of the 12 tasks in ∞Bench are derived from existing literature.

    “Two of these tasks are derived from existing literature(Mohtashami and Jaggi, 2023; Liu et al., 2024).”

    From ∞Bench: Extending Long Context Evaluation Beyond 100K Tokens (2024) · cites this paper as Mohtashami and Jaggi, 2023

  • Previous works commonly adopt synthetic tasks such as passkey retrieval and NIAH to evaluate long-context LMs.

    “Previous works (AI21, 2024; X.AI, 2024; Reid et al., 2024; Anthropic, 2024) commonly adopt synthetic tasks, such as passkey retrieval (Mohtashami & Jaggi, 2023) and needle-in-ahaystack (Kamradt, 2023) to evaluate long-context LMs.”

    From RULER: What's the Real Context Size of Your Long-Context Language Models? (2024) · cites this paper as Mohtashami & Jaggi, 2023

The citation lists haven’t been fetched yet

Cited by 4

Authors
Mohtashami, A., & Jaggi, M.
Affiliations
École Polytechnique Fédérale de Lausanne (CH)
Venue
arXiv
Publisher
arXiv
Published
2023
ISSN
2331-8422 (ISSN-L)
OpenAlex
W4378505330
Cited by
4
References
0
Citations by year
2025: 3 · 2024: 1
Type
posted content
Language
en
Open access
Locations
  • arXiv (Cornell University) (submittedVersion)
  • arXiv (Cornell University)
Funders
Schweizerischer Nationalfonds zur Förderung der Wissenschaftlichen Forschung
Topics
  • Physical Sciences › Computer Science › Artificial Intelligence › Topic Modeling
  • Physical Sciences › Computer Science › Artificial Intelligence › Natural Language Processing Techniques
  • Physical Sciences › Computer Science › Computer Vision and Pattern Recognition › Multimodal Machine Learning Applications
Keywords
attention mechanism, Transformer-XL, LLaMA fine-tuning, memory hierarchy, long-range dependencies

About these checks

Registry, retraction, Cites and statistics results are computed, not judged, with one exception: a printed reference that no index lists is read once by a model before it counts as a citation error. Claims are extracted by a model and kept only when their quote appears verbatim in the text; each cited source is then checked, with a model’s help, for whether it says what the claim relies on. Those verdicts can be wrong — read the claim’s quote and the cited source before relying on one.

Statistics and arithmetic are recomputed, not judged.

Confidence bands are shown only for fields calibrated on our annotated test set. None is calibrated yet, so no band is shown.

What counts as a claim ›How we measure confidence ›How we check this ›

Are you an author, or do you see a problem with this page? Request a review