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

Scaling Transformer to 1M tokens and beyond with RMT

Aydar Bulatov, Yuri Kuratov, Mikhail S. BurtsevarXiv 2023 · DOI

Abstract

Standard Transformer architectures face a significant bottleneck due to the quadratic computational complexity of self-attention, limiting their ability to process long-form content. This paper introduces the Recurrent Memory Transformer (RMT), a "plug-and-play" mechanism that scales Transformers to handle contexts of up to 2 million tokens. By processing text in segments and utilizing special memory tokens to pass information across them, RMT achieves linear computational scaling and constant memory usage during inference.

The Challenge of Long Contexts

The primary limitation of the standard Transformer is its self-attention mechanism, where computational cost grows quadratically ($O(N^2)$) with input length. Doubling the text length quadruples the required processing power, making the analysis of entire books, large codebases, or extensive legal documents technically and economically challenging. While sparse attention methods exist, they often introduce memory bottlenecks or require architectural modifications.

Recurrent Memory Transformer (RMT)

RMT addresses these limitations by breaking the input into smaller segments (e.g., 512 tokens) and processing them sequentially. The core innovation is the use of memory tokens.

RMT architecture for BERT and GPT models showing how memory tokens facilitate information flow across segments.

Architecture and Recurrence

RMT acts as a wrapper around existing pre-trained models like BERT or GPT. It adds a set of learned memory vectors to the input sequence. As the model processes segment $N$, it updates these memory tokens, which are then passed as input to segment $N+1$. This recurrence allows information to persist across segments, effectively turning the Transformer into a long-range recurrent network without altering its internal weights.

Curriculum Learning

To train the model to manage this memory effectively, the authors employed "Curriculum Learning." The training begins with single segments and gradually increases the number of segments, allowing the model to learn how to store and retrieve information over progressively longer distances.

Key Insights and Scaling Efficiency

The most significant advantage of RMT is its linear scaling ($O(N)$). Processing 2 million tokens with RMT is only twice as computationally intensive as processing 1 million tokens, a stark contrast to the quadratic growth of standard models.

Computational efficiency (FLOPs) of RMT compared to standard quadratic scaling across various model sizes.

Furthermore, RMT is a "plug-and-play" solution. It requires zero changes to the underlying architecture of pre-trained models, making it highly adaptable. During inference, it maintains a constant memory footprint because the GPU only needs to hold one segment and the associated memory tokens at any given time.

Experimental Results

The researchers evaluated RMT on several challenging tasks:

  • Synthetic Memorization: RMT maintained high accuracy on retrieval tasks for sequences up to 2,048,000 tokens, setting a record for deep neural networks.
  • Natural Language Modeling: Fine-tuning on ArXiv documents showed consistent improvements in perplexity as context length increased, indicating that the memory tokens successfully capture long-term dependencies.
  • Efficiency Gains: For extremely long sequences, RMT reduced required floating-point operations (FLOPs) by up to 295x compared to non-recurrent baselines.

Limitations and Future Directions

Despite its success, RMT faces challenges. Training remains computationally expensive due to Backpropagation Through Time (BPTT). Additionally, compressing long-range information into a limited number of memory tokens may lead to a loss of granularity compared to full-attention or retrieval-augmented systems. Future work will focus on applying RMT to real-world tasks like massive code generation and long-form summarization, where standard benchmarks are currently lacking.

Summary updated

BibTeX
@misc{bulatov2023scaling,
  author = {Aydar Bulatov and Yuri Kuratov and Mikhail S. Burtsev},
  title = {{Scaling Transformer to 1M tokens and beyond with RMT}},
  year = {2023},
  eprint = {2304.11062},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2304.11062},
}
Figure