Abstract
Standard Transformer-based Large Language Models (LLMs) face a "quadratic wall" where memory and computational costs scale quadratically with sequence length. We present Infini-attention, a novel mechanism that enables Transformers to process infinitely long sequences with bounded memory and computation. By integrating a compressive memory into the standard attention layer, Infini-attention combines local high-resolution attention with global long-term memory. Our experiments demonstrate that a 1B model equipped with Infini-attention can scale to 1-million-token contexts and achieve state-of-the-art results on long-context tasks such as 500K-length book summarization.
Introduction
The "Quadratic Wall" of standard Transformers is a well-known bottleneck in AI. In a vanilla Transformer, the memory and computational cost of the attention mechanism grows quadratically with the length of the input sequence. For instance, storing the Key-Value (KV) states for a 500B parameter model with a 2048-token context requires approximately 3TB of memory. Scaling this to 1 million tokens is financially and technically prohibitive with standard architectures. While previous attempts like Transformer-XL or Compressive Transformers tried to mitigate this by caching or compressing old segments, they often discarded older information or suffered from massive memory footprints. The challenge remains: providing a model with "infinite" memory without requiring infinite hardware.
Infini-attention Architecture
The proposed Infini-attention is a hybrid attention layer that lives within a single Transformer block. It integrates two distinct processing flows:
- Local Attention: A standard masked causal dot-product attention for the current segment of tokens, handling high-resolution, short-range dependencies.
- Global Compressive Memory: An associative matrix that stores KV states of previous segments using a form of Linear Attention.
Key Innovations
- State Reuse: The model reuses the same Query, Key, and Value (QKV) states for both local attention and global memory retrieval/update, making it a "plug-and-play" addition for existing LLMs.
- Learned Gating: Each attention head utilizes a learned scalar ($\beta$) to gate the balance between long-term memory and immediate local context.
- The Delta Rule: To prevent memory saturation and noise, a "Delta rule" is used for updates. The model retrieves existing information and subtracts it before adding new, "surprising" data to the memory.
Experimental Evaluation
The researchers evaluated Infini-attention across several demanding long-context benchmarks, including PG19 (books), Arxiv-math (scientific papers), and specialized tasks:
- 1M-length Passkey Retrieval: A "needle in a haystack" test requiring the retrieval of a 5-digit number hidden within 1 million tokens.
- BookSum: A dataset for summarizing entire books, tested at a 500K token length.
Key Results
- Extreme Extrapolation: A 1B model fine-tuned on only 5K-length inputs successfully solved the passkey retrieval task at 1M-length context, demonstrating robust generalization.
- Summarization Performance: The 8B Infini-Transformer reached a new State-of-the-Art (SOTA) on BookSum. ROUGE scores consistently improved as input length increased from 32K to 500K tokens.
- Efficiency: Infini-attention achieved a 114x compression ratio in memory parameters compared to "Memorizing Transformers."
Conclusion and Future Work
Infini-attention demonstrates that LLMs can effectively utilize extremely long contexts with bounded memory. While the compressive memory is inherently lossy, its performance on retrieval and summarization tasks is superior to existing baselines. Future research will focus on scaling these efficiencies to 100B+ parameter models and investigating the impact of compression loss on high-precision tasks like complex code debugging.
Summary updated