NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Learning State-Tracking from Code Using Linear RNNs

Julien Siems, Riccardo Grazzi, Korbinian Pöppel, Kirill Kalinin, Hitesh Ballani, Babak RahmaniarXiv 2026

TL;DR

This paper bridges the gap between synthetic state-tracking benchmarks and real-world language model training by framing state-tracking as executing code via Python REPL traces. It demonstrates that while advanced Linear RNNs excel at deterministic code execution where Transformers fail, they face a fundamental mathematical barrier—exponential norm decay—when dealing with the probabilistic uncertainty inherent in real-world code.

What Problem Does This Paper Address?

State-tracking—the ability to maintain an internal representation of a changing system, such as variable values during code execution or pieces on a game board—is a foundational capability for language models. While theoretical work shows that Recurrent Neural Networks (RNNs) are naturally suited for this task, standard evaluations rely on sequence-to-sequence setups (mapping a string of actions directly to a final state). This clashes with the Next-Token Prediction (NTP) paradigm used to train modern Large Language Models (LLMs).

Furthermore, real-world code execution isn't always perfectly transparent or deterministic. It often involves uncertainty driven by unobservable branching (e.g., random choices or hidden environment states), algorithmic approximations, and inverse inference tasks. This paper addresses two core questions: How can we effectively train and evaluate sequence models on state-tracking using next-token prediction? And why do linear architectures struggle when code execution introduces uncertainty?

Figure 1: The State-Tracking Hier- archy. Linear RNNs solve determinis- tic tasks (blue) but struggle with prob- abilistic automata (orange). Real-world code often requires belief-state tracking in the orange region.

Methods

To align state-tracking with next-token prediction, the authors convert the classic "permutation composition" problem into Python REPL (Read-Eval-Print Loop) traces. These traces interleave variable transformations (swaps) with partial state reveals via print statements, creating a realistic code-like training environment.

The authors evaluate Transformers against DeltaNet, a parallelizable linear RNN. Crucially, they utilize a variant of DeltaNet with an extended eigenvalue range ($[-1, 1]$ instead of the standard $[0, 1]$), which allows the network to model complex oscillatory behaviors like tracking permutations.

To analyze tracking under uncertainty, they introduce a formal framework called Probabilistic Finite-State Automata with State Reveals (PFSA-SR). Under this framework, they mathematically analyze how linear recurrences maintain "belief states" (probability distributions over possible states) using two distinct representations:

  1. Joint Representation: Explicitly enumerating all $n!$ possible configurations.
  2. Marginal Representation: Tracking the independent probability of each position using an $n \times n$ doubly stochastic matrix.

Datasets

The authors generated a synthetic dataset consisting of 15,000 Python REPL traces based on the symmetric group $S_5$ (permutations of 5 elements). To evaluate model robustness, they trained the architectures on a four-stage curriculum that progressively increased:

  • Trace Length ($L$): The number of execution commands (from 8 to 64).
  • Reveal Spacing ($S$): The number of intermediate steps between print statements (from 1 to 8), which controls the sparsity of the supervision signal.

Key Insights and Ideas

  • Transformers Need Constant Reassurance: Transformers rely heavily on dense supervision. As the spacing between print statements increases, their performance plummets because they struggle to compress historical state changes recurrently without explicit tokens to attend to.
  • The Linear RNN "State Head": Through mechanistic interpretability, the authors discovered that DeltaNet automatically dedicates a specific attention head (Layer 12, Head 3) to state-tracking. It achieves this by setting its decay parameters ($\beta$) to 2, effectively unlocking the negative eigenvalues required to compute permutations.
  • The Probabilistic Wall for Linear RNNs: The paper's most significant theoretical contribution proves that linear RNNs face an inherent stability crisis under partial observability. Because linear recurrences lack non-linear renormalization (like a Softmax layer) within their hidden state updates, tracking uncertain belief states causes the state vector's norm to decay exponentially. Under adversarial conditions, the tracking signal completely vanishes into numerical noise.

Key Results

  • DeltaNet Extrapolates Perfectly: DeltaNet with extended eigenvalues ($[-1, 1]$) achieved perfect state-tracking accuracy on the REPL traces and generalized flawlessly to longer sequences (up to 128 commands), whereas standard DeltaNet ($[0, 1]$) and Transformers failed to generalize.
  • Sparsity Breaker: As reveal spacing increased, Transformer performance degraded rapidly, failing completely on full permutations under any level of sparsity.
Transformer accuracy drops as reveal spacing increases
  • Intervention Verification: By manually scaling the eigenvalue range of the identified "state head" in DeltaNet back to $[0, 1]$, the authors observed an immediate drop in state prediction accuracy, confirming that negative eigenvalues are mathematically essential for tracking variable swaps.

Limitations and Future Work

The primary limitation is that the empirical evaluation relies entirely on synthetic permutation groups ($S_n$) rather than real-world codebases. The REPL traces simplify away complex programming realities such as syntax parsing, intricate control flow (loops, recursion), and dynamic memory management.

The authors suggest that exploring non-linear RNNs (like xLSTM) or hybrid architectures (like TTT or Titans) that interleave linear recurrences with periodic non-linear normalization layers represents the most promising path forward for robust, real-world code execution modeling.

Summary updated

BibTeX
@misc{siems2026learning,
  author = {Julien Siems and Riccardo Grazzi and Korbinian Pöppel and Kirill Kalinin and Hitesh Ballani and Babak Rahmani},
  title = {{Learning State-Tracking from Code Using Linear RNNs}},
  year = {2026},
  eprint = {2602.14814},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2602.14814},
}
Figure