Memory Caching: RNNs with Growing Memory

Ali Behrouz, Zeman Li, Yuan Deng, Peilin Zhong, Meisam Razaviyayn, Vahab Mirrokni

Introduction: The Sequence Modeling Trade-off

In the current landscape of sequence modeling, architectures face a strict trade-off between memory capacity and computational efficiency. On one end of the spectrum, Transformers utilize an associative memory that grows with sequence length. While this enables exceptional performance on retrieval and long-context tasks, it incurs a quadratic computational complexity ($O(L^2)$) and massive KV-cache memory usage during inference.

Conversely, Recurrent Neural Networks (RNNs) and their modern sub-quadratic variants—such as State Space Models and Linear Attention—compress all past information into a fixed-size hidden state. This design achieves highly efficient linear scaling ($O(L)$) but creates a severe "compression bottleneck." As sequences grow, the model is forced to overwrite or forget older information, leading to significant degradation in recall-intensive tasks like the Needle-in-a-Haystack (NIAH) test.

To bridge this gap, researchers introduce Memory Caching (MC), a novel framework that allows RNNs to scale their memory capacity with sequence length while maintaining sub-quadratic efficiency.

The Memory Caching Framework

The core mechanism of Memory Caching is straightforward yet powerful: as an RNN processes a sequence, it divides the input into discrete segments. At the end of each segment, the model caches its final hidden state, effectively saving a "memory checkpoint." When processing subsequent tokens, the model does not rely solely on its current "online" memory; instead, it queries this bank of cached historical states.

From a meta-learning perspective, RNN recurrence can be viewed as a test-time optimization process. Caching hidden states is akin to saving checkpoints of this optimization, allowing the model to retrieve specific points in its learning history. By adjusting the segment size, MC acts as an interpolator: a segment size of 1 mimics gated attention, while a segment size equal to the full sequence length reverts to a standard RNN. This flexibility allows for hardware-aware tuning of the memory-compute trade-off, resulting in an overall complexity of $O(NL)$, where $N$ is the number of segments.

Architectural Variants

To effectively integrate these cached states, the authors propose four aggregation strategies:

  1. Residual Memory: A baseline approach that simply sums the current state with all past cached states.
  2. Gated Residual Memory (GRM): Introduces input-dependent gating to dynamically determine the contribution of each cached segment to the current output. This is crucial for preventing "linear collapse," where a simple sum of memories in strictly linear RNNs mathematically collapses back into a fixed-size state.
  3. Memory Soup: Inspired by weight souping, this variant averages the parameters of the memory modules themselves, proving particularly effective for deep memory architectures like Titans.
  4. Sparse Selective Caching (SSC): Employs a Mixture-of-Experts (MoE) style routing mechanism to select only the top-$k$ most relevant cached memories for a given query. This drastically reduces computational overhead for ultra-long sequences.

Empirical Results

The researchers trained 760M and 1.3B parameter models on up to 100B tokens from FineWeb and Long-Data-Collections, evaluating them across standard benchmarks, long-context suites (LongBench), and in-context retrieval tasks.

Closing the Recall Gap: On in-context recall tasks, MC-enhanced models significantly outperformed state-of-the-art recurrent baselines. In the Needle-in-a-Haystack evaluation at a 16k context length, the base Deep Linear Attention (DLA) model struggled, dropping to approximately 44% accuracy. In contrast, the MC-enhanced DLA maintained a robust 82.4% accuracy.

Computational Efficiency: Training throughput analyses demonstrated that the Sparse Selective Caching (SSC) variant remains exceptionally efficient. As context length scales, SSC maintains a near-constant cost per token, avoiding the sharp throughput decline characteristic of Transformers.

General Performance: Beyond long-context tasks, adding MC provided a consistent +0.8% to +1.2% average improvement across ten common-sense reasoning and language modeling benchmarks.

Limitations and Future Directions

While Memory Caching successfully narrows the performance gap, Transformers still retain a slight edge in pure, high-precision recall tasks. The authors hypothesize that more expressive routing mechanisms—beyond simple dot-product similarity—may be required to fully match Transformer retrieval capabilities.

Additionally, MC performance is sensitive to the segment size hyperparameter; while constant-size segments generally outperform logarithmic ones, identifying the optimal size for specific hardware remains an open challenge. Future work will explore more sophisticated cache pooling methods and the scaling behavior of MC in 10B+ parameter regimes.

Summary updated

BibTeX
@inproceedings{behrouz2026memory,
  author = {Ali Behrouz and Zeman Li and Yuan Deng and Peilin Zhong and Meisam Razaviyayn and Vahab Mirrokni},
  title = {{Memory Caching: RNNs with Growing Memory}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=B5SkWFRE8U},
}
Figure