Understanding and Improving Length Generalization in Recurrent Models

Ricardo Buitrago Ruiz, Albert Gu · DOI

Introduction

Recurrent architectures such as Mamba and Gated Linear Attention (GLA) are designed with linear complexity, theoretically enabling them to process sequences of infinite length. However, a persistent "length generalization" gap exists: models trained on short contexts (e.g., 2,048 tokens) often experience catastrophic performance collapse when evaluated on longer sequences. This paper investigates the root causes of this failure and proposes efficient interventions to unlock long-context capabilities.

The Unexplored States Hypothesis

The authors identify the "unexplored states hypothesis" as the primary driver of length generalization failure. During standard training, models are typically initialized from a zero state and only encounter hidden state distributions characteristic of the first few thousand tokens. As a sequence extends beyond the training window, the recurrent state evolves into regions of the state space never seen during optimization. This distribution shift leads to unpredictable model behavior and exploding perplexity.

Diagnostic Metric: Effective Remembrance

To quantify this phenomenon, the researchers introduce Effective Remembrance (EffRem). This metric measures the degree to which a model's current output depends on specific historical tokens. In failing models, EffRem reveals a "distraction" effect, where the model incorrectly maintains high sensitivity to tokens from the very beginning of a long sequence that should have become irrelevant, indicating a failure in state management.

Training Interventions: State Passing

To bridge the gap between short-context training and long-context inference, the authors propose State Passing (SP). In this approach, a training sequence is initialized with the final hidden state of a previous, unrelated sequence. This simple technique exposes the model to "deep" state distributions during training without requiring the computational overhead of processing extremely long contiguous sequences. Other interventions tested include adding Gaussian noise to the initial state and Truncated Backpropagation Through Time (TBTT).

Key Results

The interventions, particularly State Passing, demonstrate remarkable efficiency and effectiveness. With as little as 500 additional training steps (approximately 0.1% of the original pre-training budget), models achieve stable performance on sequences up to 128k tokens and beyond.

Figure 3: Position-wise perplexity and Effective Remembrance across Mamba-1, Mamba-2, and GLA architectures. The dashed lines represent models with State Passing (SP) interventions, showing stable performance far beyond the training context.

As shown in the figure, base models (solid lines) exhibit a sharp rise in perplexity once the sequence length exceeds the training threshold (indicated by the vertical dotted line). In contrast, models fine-tuned with State Passing (dashed lines) maintain low perplexity and stable Effective Remembrance across massive context windows. Beyond perplexity, these models also excel on long-range benchmarks:

  • BABILong: Mamba-2 models with SP maintained high accuracy on reasoning tasks up to 256k tokens, whereas base models failed immediately.
  • Passkey Retrieval: Intervened models achieved near-perfect accuracy at depths far exceeding their original training context.

These results are consistent across Mamba-1, Mamba-2, and GLA, suggesting that the "unexplored states" issue is a general property of recurrent architectures that can be solved with minimal compute.

Conclusion

Length generalization in recurrent models is a distribution shift problem rather than a fundamental capacity limit. By utilizing State Passing to expose models to a broader range of hidden state distributions, researchers can enable long-context reasoning in linear-time models with minimal additional training cost. This work provides a scalable path toward truly infinite-context sequence modeling.

Summary updated

BibTeX
@inproceedings{ruiz2025understanding,
  author = {Ricardo Buitrago Ruiz and Albert Gu},
  title = {{Understanding and Improving Length Generalization in Recurrent Models}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=2OEb20dy7B},
}
Figure