Not All Memories are Created Equal: Learning to Expire

Sainbayar Sukhbaatar, Da Ju, Spencer Poff, Stephen Roller, Arthur Szlam, Jason E Weston, Angela Fan

TL;DR

Transformers struggle with long-term memory due to the quadratic cost of self-attention. This paper introduces "Expire-Span," a novel mechanism that allows Transformer models to learn which past information is irrelevant and "expire" it, enabling efficient scaling to tens of thousands of timesteps while maintaining performance.

What Problem Does This Paper Address?

Modern deep learning models, particularly Transformers, excel at sequence modeling tasks. However, their core self-attention mechanism has a computational and memory cost that grows quadratically with the sequence length. This makes it prohibitively expensive to process very long sequences, limiting their ability to capture truly long-term dependencies. While existing methods have focused on making attention more efficient (e.g., sparse attention, linear attention) or compressing memories, they often treat all past information equally. This paper argues that, much like human memory, not all past information is equally important, and models should learn to selectively forget irrelevant details to focus on what truly matters for the task at hand.

Methods

The core innovation is the Expire-Span mechanism. For each past "memory" (hidden state) at timestep i, the model learns an "expire-span" value e_i. This value, derived from a learned linear transformation of the hidden state and passed through a sigmoid, determines how long that memory should remain accessible. Specifically, a memory h_i is considered "expired" at time t if e_i - (t - i) becomes negative.

To enable training, a smooth, differentiable masking function m_{t,i} is used instead of a hard cutoff. This function transitions from 1 to 0 as the memory expires, allowing gradients to flow back. The expire-span values are learned by adding an L1-norm penalty to the loss function, encouraging the model to reduce the effective memory span.

Expire-Span is integrated into Transformer layers, with the expire-span computation shared across attention heads within a layer. The authors also propose practical considerations for training, including:

  • Block Parallelism: Leveraging existing caching mechanisms for efficiency.
  • Position Embedding Handling: Removing position embeddings for older memories to manage computational cost.
  • Loss Computation: Carefully designing the auxiliary loss to avoid vanishing gradients.
  • Regularization: Introducing a "structured dropout" by randomly shortening the memory during training to prevent overfitting to specific span sizes.

Datasets

The paper evaluates Expire-Span on a variety of tasks and datasets:

  • Language Modeling:
    • PG-19 (character-level)
    • enwiki8 (character-level)
    • Wikitext-103 (word-level)
  • Reinforcement Learning:
    • Corridor Task (gridworld)
    • Portal Task (multi-room gridworld)
  • Algorithmic/Sequence Tasks:
    • Colliding Objects (frame-by-frame)
    • Copy Task (long sequence recall)
    • Instruction Task (dialogue-based story generation)

Key Insights and Ideas

  • Selective Forgetting is Crucial for Long Context: The paper strongly advocates that simply increasing memory size isn't enough; learning to discard irrelevant information is key to efficient and effective long-term memory in neural networks.
  • Human Memory as Inspiration: The analogy to human memory, where vivid and remarkable memories are retained while others fade, provides a strong conceptual basis for the Expire-Span approach.
  • Layer Specialization: Different layers within the Transformer can learn to specialize in expiring information at different time scales, with some layers focusing on short-term details and others on very long-term context.
  • Scalability Beyond Fixed Spans: Expire-Span demonstrably scales to much longer effective memory spans than fixed-span or adaptive-span methods, achieving significant performance gains on tasks requiring very long context.

Key Results

  • State-of-the-Art Performance: Expire-Span achieves state-of-the-art results on several long-context language modeling benchmarks (PG-19, enwiki8) and shows strong performance on RL and algorithmic tasks.
  • Significant Memory Savings: Models using Expire-Span require substantially less GPU memory and achieve faster training times per batch compared to baselines like Transformer-XL and Adaptive-Span, especially when dealing with very long sequences. For instance, on the Colliding Objects task, an Expire-Span model with a 64k span used 44% less memory and was 2.8x faster than an Adaptive-Span model with a 16k span.
  • Effective Long-Context Handling: On tasks requiring memory of tens of thousands of timesteps (e.g., character-level PG-19, Colliding Objects), Expire-Span significantly outperforms baselines. For example, on the Colliding Objects task, increasing the Expire-Span to 64k led to a test error of 26.7%, a substantial improvement over other methods.
  • Improved Accuracy on Long-Range Dependencies: In the Instruction Task, Expire-Span was much more successful than baselines in focusing on specific instruction lines amidst thousands of distractor tokens.

Limitations and Future Work

  • Overfitting with Large Memory: The paper acknowledges that exceptionally long memory can lead to overfitting. They propose structured dropout as a regularization technique, but further exploration might be beneficial.
  • Hyperparameter Tuning: While Expire-Span is designed to be adaptive, the ramp length R and the loss coefficient α are hyperparameters that require tuning.
  • Future Work: The authors suggest that Expire-Span has strong potential for more challenging, human-like tasks that inherently require selective memory and expiration. Further research could explore more sophisticated expiration strategies or integrate Expire-Span with other efficiency mechanisms.

Summary updated

BibTeX
@inproceedings{sukhbaatar2021not,
  author = {Sainbayar Sukhbaatar and Da JU and Spencer Poff and Stephen Roller and Arthur Szlam and Jason E Weston and Angela Fan},
  title = {{Not All Memories are Created Equal: Learning to Expire}},
  booktitle = {International Conference on Machine Learning},
  year = {2021},
}
Figure