Extending LLM Context via Associative Recurrent Memory
This paper proposes the Associative Recurrent Memory Transformer (ARMT) as an efficient solution for extending LLM context lengths with constant memory scaling, validated through new domain-specific datasets, a comprehensive training recipe, and experimental results showing superior generalization and a 30% reduction in FLOPs without performance degradation.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
Technical Summary: Extending LLM Context via Associative Recurrent Memory
Problem Statement
Large Language Models (LLMs) are increasingly required to process inputs spanning hundreds of thousands or millions of tokens for tasks such as technical report analysis, software development, and multi-document reasoning. However, standard Transformer architectures face a fundamental bottleneck: the computational and memory costs of self-attention scale quadratically with sequence length (). Furthermore, performance often degrades as context length increases, even within the model's nominal window. While recurrent architectures (e.g., Mamba, RWKV) offer linear scaling, they typically require training from scratch, preventing the leverage of existing pre-trained LLMs, and often struggle with complex algorithmic tasks and instruction following compared to Transformers.
Methodology
The authors propose the Associative Recurrent Memory Transformer (ARMT) as a practical solution to extend context length while maintaining constant memory scaling and efficiency. ARMT acts as a wrapper around a pre-trained base LLM, enabling segment-wise processing of input.
Core Architecture
ARMT divides long-context inputs into non-overlapping segments of fixed length. Within each segment, the model utilizes full self-attention (short-term/working memory). Crucially, it introduces a layerwise associative memory module that propagates information between segments (long-term memory). The mechanism operates in three stages:
- Memory Extraction: Each transformer layer compresses an input segment into memory embeddings.
- Memory Consolidation: These embeddings are consolidated into a per-layer associative matrix as key-value pairs.
- Association: Embeddings in subsequent segments are transformed into query vectors and multiplied by the associative matrix to retrieve relevant information from previous segments.
Training Recipe
The paper outlines a comprehensive training strategy to adapt pre-trained LLMs to ARMT:
- Continued Pre-training: Uninitialized associative memory parameters are initialized via unsupervised language modeling on long contexts (e.g., 19B tokens from FineWeb-Edu) to learn effective memory propagation before task-specific fine-tuning.
- Curriculum Learning: To address the difficulty of learning long-range dependencies from scratch, the model is fine-tuned by progressively increasing the number of segments (e.g., from 2 to 4 to 8) and annealing the learning rate.
- Synthetic Data Generation: To overcome data scarcity in long-context scenarios, the authors generate synthetic training instances by concatenating short passages from long documents and generating QA pairs for each, creating large bins of specific context lengths.
- Layer Pruning and Selection: The study investigates whether associative memory is needed in every layer. It proposes a strategy to retain associative memory only in a subset of layers (e.g., specific middle and final layers), reducing trainable parameters and computational cost without significant performance loss.
Key Contributions
- Domain-Specific Datasets: The construction of two new datasets, ManyTypes-long (MT) for variable type prediction in code and GovReport-long (GR) for long-document question answering, designed to evaluate realistic, narrow-domain workloads.
- Training Recipe: A novel framework for extending LLM context using ARMT, combining continued pre-training, synthetic data generation, curriculum learning, and selective layer integration.
- Empirical Validation: An extensive experimental study demonstrating that ARMT-augmented models:
- Process inputs well beyond original context limits (up to 64k tokens) without performance degradation relative to in-limit baselines.
- Exhibit superior generalization to out-of-distribution (OOD) context lengths compared to base models.
- Require approximately 30% fewer FLOPs while preserving baseline performance within the original context window.
Experimental Results
The authors evaluated ARMT using Gemma-3-1B-IT and SmolLM-2-360M-IT backbones on the MT and GR datasets.
- Performance: ARMT models maintained stable performance across context lengths up to 65k tokens. In contrast, base models (even when fine-tuned) showed sharp performance drops beyond their native context windows (e.g., 8k or 32k). ARMT outperformed base models significantly in Long-OOD regimes (32k–65k).
- Efficiency: ARMT demonstrated constant GPU memory usage regardless of context length, whereas base models' memory usage grew linearly. For a 32k token sequence, ARMT allowed for a 4x increase in batch size (32 vs. 8) under the same memory budget.
- FLOPs Reduction: Theoretical analysis and empirical inference time measurements confirmed a reduction in global attention FLOPs by a factor of (sequence length divided by segment size), leading to an overall ~30% reduction in total FLOPs compared to full-attention models.
- Ablation Studies:
- Layer Pruning: Models with associative memory in only ~20% of layers (specifically pre-selected middle and final layers) achieved performance comparable to or better than full ARMT models.
- Pre-training: Continued pre-training was found essential for initializing associative memory, significantly improving both in-domain and OOD performance.
- Baselines: ARMT outperformed other long-context baselines, including Mamba-2, DeltaNet, and xLSTM, particularly in long-context generalization, while requiring less extensive pre-training than models trained from scratch.
Significance and Claims
The paper positions ARMT as a practical, compute-efficient approach for enabling long-context processing in small- to medium-sized LLMs (up to 1B parameters). The authors claim that this approach bridges the gap between the strong short-context performance of Transformers and the linear scaling of recurrent models.
Key claims regarding significance include:
- Privacy and Local Deployment: By enabling efficient long-context processing on smaller models, ARMT facilitates privacy-preserving applications that do not rely on remote, large-scale API-based LLMs.
- Scalability: The method allows for the processing of arbitrarily long contexts with constant memory, a critical requirement for real-world document analysis.
- Efficiency: The combination of constant memory scaling and reduced FLOPs makes ARMT a viable alternative for resource-constrained environments.
- Generalization: The proposed training recipe effectively addresses the "lost in the middle" phenomenon and performance degradation seen in standard Transformers when handling long sequences.
The authors acknowledge limitations, noting that experiments were restricted to models up to 1B parameters and a specific set of tasks (code and document QA), and that the underlying mechanisms of associative memory interaction with transformer representations remain partially understood. However, they argue that the demonstrated ability to extend context in small models is a significant step toward practical, local long-context AI.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.