On the Importance of Gating: Memorization vs. In-Context Learning in State Space Models

William Lingxiao Tong, Aryo Lotfi, Emmanuel Abbe, Konstantinos Vaggelakos, Vishnu Banna, Etai Littwin, Joshua M. Susskind, Eran MalachNeurIPS 2026

TL;DR

State Space Models (SSMs) like Mamba process long sequences far faster than Transformers, yet they mysteriously stumble when asked to retrieve exact details from a prompt. It turns out this isn't just a fundamental memory-capacity limit—it's a training trap caused by gating (the mechanism that decays old memories). Strong gating tricks the model into taking a lazy "memorization" shortcut in its weights instead of learning how to read the context, though that exact same gating is essential to keep long prompts from drowning in noise.

What Problem Does This Paper Address?

If you have processed a massive document with an LLM, you have felt the pain of the Transformer's quadratic compute scaling: double the text length, quadruple the work. State Space Models (SSMs) solve this by compressing past text into a fixed-size running state, giving us linear compute and constant memory.

Despite their speed, pure SSMs haven't dethroned Transformers at scale because they lag behind at in-context learning (ICL) and precise retrieval—looking up exact facts or rules provided on the fly in a prompt. The prevailing wisdom blames an expressivity gap: cramming a huge prompt into a fixed-size state must inevitably lose information. The authors test a very different hypothesis: What if the model can hold the information, but its optimization dynamics actively discourage it from learning how?

Methods

To isolate how an SSM learns, the authors construct tasks with a deliberate tension between two strategies: in-weights memorization (relying on static patterns seen during training) and in-context retrieval (actually reading the prompt). They assign static default labels to inputs, but flip those labels in the prompt with probability $\epsilon$. Memorizing the defaults gets you decent accuracy quickly, while achieving 100% requires true retrieval.

They pair this setup with a multi-tiered investigation:

  1. Theoretical Analysis: They analyze the gradient descent dynamics of a simplified, single-head Mamba-2 layer controlled by a global gating parameter $\lambda$, which sets how aggressively past tokens decay.
  2. Initialization & Scaling Interventions: In full Mamba architectures, they systematically shift or scale the gating strength at initialization—or right after pretraining, just before supervised fine-tuning (SFT)—to steer the model toward or away from memorization without changing the architecture itself.

Datasets

The authors progress from clean mathematical sandboxes to realistic agentic benchmarks:

  • Synthetic Vector & Multi-Token Retrieval (New): Custom tasks using random vectors and 8-token key-value dictionaries (up to 512 pairs during training, evaluated out to 2,048) with noisy values ($\epsilon = 0.1$) to cleanly separate memorization plateaus from retrieval.
  • Logical Rules Retrieval (New): A synthetic proxy for multi-step agentic tool use. Models chain together logical Horn clauses (e.g., $R \to T$) by retrieving randomly reassigned numeric clause names from the context.
  • Modified BFCL & Pretraining/SFT Corpora: 1.5B Mamba and 2B Transformer models are pretrained on 300B tokens of Nemotron-CC-HQ and fine-tuned on the Nemotron Agentic tool-calling split. They are evaluated on an extended Berkeley Function Calling Leaderboard (BFCL) python simple split, modified using a BM25 retriever to inject variable-sized pools of distractor tools (trained on up to 24 tools, tested up to 72).

Key Insights and Ideas

  • Gating creates a "memorization trap": When gating is strong (fast memory decay), gradient signals from earlier tokens in the prompt are heavily dampened. Because learning static associations in the weights is unaffected by decay, gradient descent greedily latches onto memorization first.
  • The plateau is escapable, but brutally slow: Strong gating doesn't make retrieval impossible—the model isn't out of memory—it just traps it on a "memorization plateau." Escaping this plateau takes training time that grows exponentially with the distance to the relevant token (and double-exponentially with the initial log-decay parameter $\lambda_0$).
Validation of theoretical predictions showing critical decay thresholds, escape times from the memorization plateau, and long-context accuracy.
  • The Fundamental Gating Tradeoff: Why not just turn off gating so the model learns to retrieve immediately? Because without decay, every irrelevant "distractor" token in a long sequence adds variance to the hidden state, eventually drowning out the signal. Weak gating wins at learning short-context retrieval; strong gating wins at length generalization by enforcing locality and filtering out old noise.

Key Results

  • Exact theoretical match: In simplified SSMs, the transition between memorizing and retrieving at initialization occurs right at the predicted critical decay factor ($\alpha^* \approx 0.158$ in their test setup), and plateau escape times scale inversely with decay ($\propto \frac{1}{\alpha_0 \log(1/\alpha_0)}$).
  • Multi-token & Logical Retrieval: Under standard/strong gating, Mamba models get stuck at the ~43% memorization accuracy baseline on multi-token retrieval, whereas weaker gating converges rapidly to 100%. Conversely, when extending logical rule pools from $k=8$ (training) to $k=128$ (testing), weakly gated models collapse while strongly gated models maintain near-perfect accuracy.
  • Better Real-World Tool Calling for Free: Simply scaling down a pretrained 1.5B Mamba model's gating decay rate (e.g., by $0.06\times$ to $0.25\times$) right before SFT improves accuracy on BFCL and noticeably reduces tool hallucinations. Furthermore, all Mamba variants generalized far better than the 2B Transformer baseline once tool pools exceeded the training limit of 24 (where Transformer hallucination rates spiked above 75%).

Limitations and Future Work

This paper is a diagnostic study rather than a silver-bullet architectural fix. Because of the fundamental tradeoff uncovered here, you cannot simply delete gating or universally initialize it near zero without wrecking long-context noise control. Furthermore, strong gating induces strict locality—long-context generalization only works if the relevant information sits relatively close to the query (within an effective window of roughly $\tau \log(d/\tau)$). To achieve true, position-independent retrieval over massive contexts, the authors suggest moving beyond simple scalar decay gates toward higher-dimensional linear operators or non-linear state transitions capable of selective memory management.

Summary updated

Abstract

State Space Models (SSMs) have emerged as a compelling alternative to Transformers, enabling sequence modeling with constant memory and linear compute. While SSMs excel in certain settings like length generalization, they continue to lag behind Transformers on tasks that require in-context learning and precise retrieval, slowing their adoption for large-scale language modeling. In this work, we demonstrate that both the success and failure of SSMs in these domains can be explained by studying the role of the gating mechanism, a prevalent component in modern recurrent networks. Specifically, we show through theory and experiments that this gating mechanism causes SSMs to first learn an in-weights ``memorization'' solution, while delaying, or even preventing, convergence to a correct in-context learning solution. Importantly, this happens even in cases where there are no fundamental limitations due to the architecture or its memory capacity. On the other hand, we find that gating is often beneficial for improving generalization to long sequence lengths. Our results illuminate the crucial role of the gating mechanism in shaping both the training dynamics and generalization of SSMs, and provide a basis for understanding and improving linear-time models.
BibTeX
@inproceedings{tong2026importance,
  author = {William Lingxiao Tong and Aryo Lotfi and Emmanuel Abbe and Konstantinos Vaggelakos and Vishnu Banna and Etai Littwin and Joshua M. Susskind and Eran Malach},
  title = {{On the Importance of Gating: Memorization vs. In-Context Learning in State Space Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=XsNfjnUeWl},
}
Figure