Mechanistic evaluation of Transformers and state space models

Aryaman Arora, Neil Rathi, Nikil Roashan Selvam, Róbert Csordás, Dan Jurafsky, Christopher Potts

TL;DR

This paper uses causal interventions to reveal that while Transformers and State Space Models (SSMs) like Mamba can both successfully solve associative retrieval tasks, they do so using completely different internal mechanisms. Crucially, the authors discover that Mamba's retrieval success relies heavily on its short convolution layers to mimic transformer-like induction, rather than the core SSM block itself.

What Problem Does This Paper Address?

State Space Models (SSMs) are rapidly emerging as efficient, linear-time alternatives to quadratic-attention Transformers. However, SSMs frequently struggle with in-context retrieval—the basic ability to find and copy information from earlier in a prompt.

Traditionally, researchers evaluate retrieval capabilities using "behavioral metrics" like accuracy on synthetic tasks (e.g., Associative Recall). But behavioral metrics only tell you if a model works, not how it works or why it fails. This paper bridges the gap by opening the black box, using mechanistic interpretability to see how different architectures actually route and store information under the hood.

Methods

The authors employ interchange interventions (a form of causal intervention) using the open-source pyvene library to map out the information flow inside the models.

Figure 2: An example interhcange intervention where we corrupt the key (A) and attempt to restore it by intervening at the value token in an intermediate representation. We evaluate the downstream effect on the next-token prediction at the query (which should ideally predict the answer).

The experimental setup is elegant:

  1. They run a "clean" input sequence through the model.
  2. They run a "corrupted" version of the same sequence where a critical key token is changed (which normally causes the model to fail).
  3. During the corrupted run, they overwrite specific internal activations (at a chosen layer, component, or token position) with the corresponding activations from the clean run.

If swapping in the clean activation at a specific component restores the model's ability to output the correct answer, that component is causally verified as playing a vital role in the retrieval mechanism.

Datasets

The models were evaluated on two synthetic tasks:

  • Associative Recall (AR): The standard benchmark for context retrieval. The model is fed a sequence of random key-value pairs followed by a query key, and it must predict the matching value (e.g., A 2 C 3 F 9 D 1 C → 3).
  • Associative Treecall (ATR): A novel hierarchical retrieval task introduced in this paper. Generated using a probabilistic context-free grammar (PCFG), ATR forces models to associate keys and values that are not adjacent in the text, better mimicking the complex, non-positional structures found in natural language.

Key Insights and Ideas

Figure 1: Associative mechanisms in Attention, Based, and Mamba: Key results from applying mechanistic metrics to understand how Attention and SSMs solve AR and our new retrieval task, Associative Treecall (ATR). Attention and Based both implement induction, but with different architectural components (§4.2 and §5.2). Mamba instead uses a single layer for both association and retrieval, but uses short convolution for association just like Based (§4.3 and §4.4). When convolutions are removed, Mamba implements induction, but only on ATR (§5.3).
  • Same Accuracy, Different Mechanics: Transformers and the Based SSM solve retrieval via a two-layer induction mechanism (storing key-value associations at the value token position). Most other SSMs use direct retrieval, a single-layer mechanism that writes the association directly to the query token.
  • Mamba's Secret Weapon is Convolution: Mamba's ability to solve Associative Recall isn't driven by its core state-space model block, but by its short convolution layers. The convolutions handle the key-value association step, while the SSM block merely handles retrieval.
  • Latent Induction Capabilities: When short convolutions are removed, Mamba fails completely at standard AR. However, on the new hierarchical ATR task, a convolution-less Mamba successfully falls back to learning an Attention-like, two-layer induction mechanism. This proves SSMs can perform induction, but their architectural priors bias them toward simpler positional shortcuts if available.

Key Results

  • AR Performance: Attention and Based achieve 100% accuracy/likelihood at model dimensions $d \ge 32$. Mamba and DeltaNet follow closely behind (~90.3% likelihood at $d=256$), while other SSMs like H3 and Hyena fail.
  • The Convolution Threshold: Ablation experiments showed that reducing Mamba's convolution kernel size below 2 completely destroys its performance on AR, proving that local context mixing via short convolutions is strictly necessary for its standard retrieval mechanism.
  • ATR Superiority: On the new hierarchical ATR task, Mamba actually matches or outperforms all other architectures across all model dimensions. Even without short convolutions, Mamba achieves 93.4% accuracy at $d=256$, outperforming Based (92.2%) and BaseConv (89.7%).

Limitations and Future Work

  • Synthetic Focus: The study is strictly limited to synthetic tasks (AR and ATR) trained from scratch at small scales.
  • Scaling to Real-World Models: Future work is required to validate whether these exact mechanistic circuits (like Mamba's reliance on convolutions for induction) hold true in large-scale, production-grade language models trained on natural language text.
  • Complementary Metrics: The authors note that behavioral metrics are still necessary to properly contextualize these mechanistic findings, as interpretability tools alone do not capture overall task performance.

Summary updated

Abstract

State space models (SSMs) for language modelling promise an efficient and performant alternative to quadratic-attention Transformers, yet show variable performance on recalling basic information from the context. While performance on synthetic tasks like Associative Recall (AR) can point to this deficiency, behavioural metrics provide little information as to \textit{why} -- on a mechanistic level -- certain architectures fail and others succeed. To address this, we conduct experiments on AR, and find that only Transformers and Based SSM models fully succeed at AR, with Mamba and DeltaNet close behind, while the other SSMs (H3, Hyena) fail. We then use causal interventions to explain why. We find that Transformers and Based learn to store key-value associations in-context using induction. By contrast, the SSMs seem to compute these associations only at the last state using a single layer. We further investigate the mechanism underlying the success of Mamba, and find novel evidence that Mamba \textit{does} implement induction: not via the SSM, but instead via short convolutions. Further experiments on a new hierarchical retrieval task, Associative Treecall (ATR), show that all architectures learn the same mechanism as they did for AR. Furthermore, we show that Mamba can learn Attention-like induction on ATR when short convolutions are removed. These results reveal that architectures with similar accuracy may still have substantive differences, motivating the adoption of mechanistic evaluations.
BibTeX
@inproceedings{arora2025mechanistic,
  author = {Aryaman Arora and Neil Rathi and Nikil Roashan Selvam and Róbert Csordás and Dan Jurafsky and Christopher Potts},
  title = {{Mechanistic evaluation of Transformers and state space models}},
  booktitle = {MechInterp @ NeurIPS},
  year = {2025},
  url = {https://openreview.net/forum?id=F62dVLJ8wk},
}
Figure