NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

ReAttention: Training-Free Infinite Context with Finite Attention Scope

Xiaoran Liu, Ruixiao Li, Zhigeng Liu, Qipeng Guo, Yuerong Song, Kai Lv, Hang Yan, Linlin Li, Qun Liu, Xipeng Qiu

Introduction

As we increasingly rely on Large Language Models (LLMs) to process entire codebases, massive document repositories, or series of books, the demand for expansive context windows has skyrocketed. However, extending the context length of existing models is notoriously difficult. ReAttention introduces a training-free method that allows LLMs to process effectively infinite context windows. By utilizing a "think before you act" approach—retrieving relevant context chunks using position-agnostic semantic search before applying standard attention—it successfully extends models like LLaMA-3 and Qwen2 to handle up to 4 million tokens without any fine-tuning or added latency.

The Length Extrapolation Problem

Standard Transformer models hit a hard wall known as the "length extrapolation" problem. If a model is trained on 8,000 tokens, asking it to process 100,000 tokens breaks its self-attention mechanism for two primary reasons:

  1. Out-of-Distribution (OOD) Positions: The model encounters positional embeddings (the mathematical representations of word order) it has never seen during training, which often causes it to output gibberish.
  2. Attention Entropy: As the context grows, the model's attention becomes "watered down" across too many tokens, causing it to lose focus on critical information.

Existing solutions typically require expensive retraining, drop the middle of the text entirely (like StreamingLLM), or chunk the text in ways that destroy semantic meaning. The authors needed a way to let an LLM search an infinite context while keeping the actual mathematical attention computation strictly within the model's original, finite training limits.

Methods: The ReAttention Architecture

The authors propose a plug-and-play architecture that splits the attention process into two distinct steps:

ReAttention Architecture
  1. Position-Agnostic Cache Selection: At each generation step, the model does not look at the entire document. Instead, it retains the very beginning of the prompt (global context) and the very end (local context). For the massive middle section, it performs a top-$k$ search to find the most relevant chunks of the Key-Value (KV) cache. Crucially, it does this without positional embeddings, relying purely on the semantic similarity (dot product) between the current query and past context.
  2. Training-Free Integration: ReAttention takes the global, local, and retrieved middle chunks, stitches them together into a short sequence, and then applies positional embeddings sequentially. Finally, it runs standard self-attention on this shortened sequence.

Under the hood: To prevent this extra search step from slowing down the model or blowing up GPU memory, the authors wrote a custom Triton GPU kernel. This fuses the top-$k$ search operations, keeping memory I/O low and making ReAttention as fast as standard FlashAttention.

Key Insights

  • Positional embeddings can be a distraction: The authors discovered that when searching a massive context for a specific fact, pure semantic vectors (without position data) actually do a better job of finding the "needle" than position-aware vectors. Positional data can sometimes mislead the attention heads during retrieval.
  • Bypassing the OOD problem entirely: Because ReAttention only passes a short, concatenated sequence to the final self-attention step, the model's positional embeddings never exceed their pre-trained limits. The model never realizes it is reading a multi-million-token document; it computes attention as if it were reading a standard, short prompt.
  • The Manifold Hypothesis of Natural Language: Through t-SNE visualizations, the authors show that natural language forms a continuous, linear manifold in the KV cache space. ReAttention relies on this natural coherence to successfully grab and stitch together relevant chunks without losing semantic meaning.

Key Results

ReAttention was rigorously tested across standard long-context benchmarks (LongBench, L-Eval), extreme context suites (InfiniteBench), and retrieval tests (Needle-In-A-Haystack).

Needle-In-A-Haystack Results
  • Massive Context Scaling: ReAttention expanded the context window of LLaMA3.2-3B-chat and Qwen2-1B to a staggering 4 million tokens (a 128x increase) in Needle-In-A-Haystack tests, maintaining near-perfect retrieval accuracy.
  • Mainstream Model Support: It successfully pushed mainstream models like LLaMA3.1-8B and Mistral-v0.3-7B to 1 million tokens without any fine-tuning.
  • Downstream Performance: On InfiniteBench (128K context), ReAttention on LLaMA3-8B achieved an average score of 24.38, outperforming both StreamingLLM (17.55) and InfLLM (20.28).
  • Efficiency: Thanks to the custom Triton kernel, ReAttention maintains a Time-To-First-Token (TTFT) comparable to standard implementations, but continues to function at 256k+ sequence lengths where standard PyTorch implementations run out of memory.

Limitations and Future Work

While highly effective for natural language, ReAttention does have limitations. It struggles with highly synthetic benchmarks (like RULER's MultiKey3 task, which uses repeating, unnatural UUID patterns). Because synthetic text lacks the natural semantic flow of real language, the position-agnostic retrieval can grab disconnected, confusing chunks.

Additionally, while ReAttention limits the computation scope of attention, it still requires storing the full KV cache in GPU memory to perform the top-$k$ selection. Future work could combine ReAttention with KV cache eviction or compression techniques (like H2O or SnapKV) to reduce memory overhead even further.

Summary updated

BibTeX
@inproceedings{liu2025reattention,
  author = {Xiaoran Liu and Ruixiao Li and Zhigeng Liu and Qipeng Guo and Yuerong Song and Kai Lv and Hang Yan and Linlin Li and Qun Liu and Xipeng Qiu},
  title = {{ReAttention: Training-Free Infinite Context with Finite Attention Scope}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=KDGP8yAz5b},
}
Figure