## Introduction to State-Tracking Linda: Welcome back to Mechanical Dreams, the podcast where we untangle the latest research in machine learning and natural language processing. I am your host, Linda, and as always, I am joined by the delightfully skeptical Professor Norris. Norris: Delightfully skeptical? I will take that as a compliment, Linda. Hello everyone. I prefer to think of myself as seasoned. I have seen architectures come and go, so when you brought in a paper today claiming linear RNNs are doing something magical yet again, my seasoned eyebrows naturally went up. Linda: I promise it is worth the raised eyebrows! Today we are discussing a really insightful paper titled 'Learning State-Tracking from Code Using Linear RNNs', by Siems, Grazzi, and colleagues from Microsoft Research and the University of Freiburg. Norris: Ah, state-tracking. It is the classic stress test for sequence models, is it not? For our listeners who might be deep in the optimization or vision side of things, state-tracking is essentially the model's ability to remember and update the state of the world as new information comes in. Think of tracking variable values during code execution, or updating the board configuration in a game of chess. Linda: Exactly! And theoretically, we have known for a while that there is a divide here. Transformers are notoriously amazing at associative recall, which means grabbing specific information from the context. But when it comes to true state-tracking, recurrent neural networks actually have the upper hand. Recently, there has been a massive resurgence of linear RNNs, like Mamba or DeltaNet, because they allow parallelization across the sequence length, fixing the old RNN bottleneck. Norris: Right, the holy grail. You get the parallel training efficiency of a Transformer, but the constant-time inference of an RNN. But here is my historical gripe, Linda. A lot of the formal literature testing these models on state-tracking relies on highly synthetic sequence-to-sequence tasks. They feed the model a long string of mathematical permutations, and then ask for the final cumulative state at the very end. Linda: And that is precisely why I love this paper! It calls out that exact discrepancy. Modern language models are not trained in a sequence-to-sequence setup. They are trained on next-token prediction. The authors point out that mapping abstract actions to states at the end of a sequence deviates significantly from the objective we actually use to train LLMs. Norris: I see. So, testing a model's state-tracking abilities using an objective it was never designed for is bound to give us misleading results about what foundation models can actually do in the wild. How do the authors propose we bridge this gap? Linda: They do something super clever. They convert classic permutation composition tasks, which are basically like a shell game where cups are shuffled around, into actual Python code. Specifically, they use REPL traces that interleave variable transformations with partial state-reveals using print statements. Norris: Oh, that is a fantastic workaround. So instead of just doing abstract math, the model is reading standard Python like 'a, b equals b, a' followed by a 'print(a)' statement. It makes the supervision sparse, much like actual code execution, but perfectly frames the problem as next-token prediction! Linda: You got it! It creates a highly realistic setting to test if these architectures can learn state-tracking naturally, rather than through dense, synthetic supervision. And as we will see, it completely changes how we evaluate the limits of Transformers versus linear RNNs. ## The Next-Token Prediction Testbed Linda: Let's dig into this REPL testbed because it is honestly such a clever experimental design. In a traditional sequence-to-sequence setup, like the one from Merrill and colleagues in 2024, the model sees a sequence of inputs, say, permutations of symmetric groups, and outputs the cumulative state at each position. Norris: Right, which effectively gives the model dense supervision. It gets a loss signal for the entire state at every single step. But as we established, that is a far cry from next-token prediction on natural code. Linda: Exactly. So, to adapt permutation groups for next-token prediction, they use these Python REPL traces. The paper uses the analogy of a shell game. Imagine cups being swapped to track object positions. The code equivalent is variable swapping. So you might see an input like 'a, b equals b, a' to swap their values. Norris: And instead of demanding the full state of all variables at the end, they interleave print statements. But, importantly, these are partial state reveals, correct? If they printed out the entire state every time, the model could just cheat by looking at the most recent printout and ignore all the prior swaps. Linda: You hit the nail on the head, Professor. Full reveals would trivialize the task. By only printing a single variable, like 'print(c)' and expecting the model to predict its value as the next token, the model is forced to keep track of the unrevealed variables, like 'a' and 'b', hidden inside its latent state across the sequence. Norris: That is very elegant. It mimics real-world software engineering perfectly. When we debug, we do not dump the entire memory state of the program. We log a few key variables and infer the rest. So, how do they turn the dial on the difficulty for the models? Linda: They vary what they call the 'reveal spacing'. They train the models on traces where the print statements happen every step, every two steps, every four steps, and so on. This progressively reduces the density of explicit state information available during training. Norris: Okay, so the million-dollar question: how do our beloved Transformers handle this? I imagine if you give a pretrained Transformer enough data, it might just brute-force the permutation patterns through its attention layers. Linda: You would think so! They actually fine-tuned a pretty capable model, a Qwen3-0.6B-Base model, using standard next-token prediction on these REPL traces. They tried both simple elementary swaps and full permutations, progressively increasing the reveal spacing. Norris: Let me guess. When the reveal spacing is one, meaning dense supervision, it does okay, but as soon as the supervision gets sparse, the performance falls apart? Linda: It drops off a cliff. As the reveal spacing increases, the Transformer's accuracy rapidly degrades. And when they used full permutations instead of just simple elementary swaps, the Transformer completely failed to learn the task, regardless of how dense the reveals were. Norris: That is a staggering result for a pretrained model of that size. It really exposes the vulnerability of the attention mechanism. Transformers are fantastic at routing information from the past to the present, but they struggle to maintain and update an implicit state bottleneck step-by-step without dense explicit supervision. Linda: Exactly! They rely critically on having that state explicitly spelled out in the context window. But when the state is latent and evolving over dozens of steps without being printed, the Transformer just loses track of the shell game. Norris: This sets the stage beautifully for recurrent architectures. If Transformers cannot maintain this implicit state under sparse supervision, this REPL testbed is the absolute perfect proving ground for linear RNNs. I am eager to hear how they fare. ## DeltaNet Triumphs Over Transformers Linda: So, since Transformers completely dropped the ball on tracking these latent states with sparse reveals, let's talk about the architecture that actually caught it: DeltaNet. Norris: Ah, DeltaNet. For those unfamiliar, it is a linear RNN that uses a generalized Householder transformation for its recurrence. It is highly efficient and parallelizable. But given what we know about RNNs, surely they did not just use a vanilla setup? Linda: Spot on, Professor! They specifically tested two variants of DeltaNet. The architecture determines the eigenvalue spectrum of the state-transition matrix. They tested one variant restricted to eigenvalues between zero and one, and another with an extended spectrum from minus one to one. Norris: That minus one is the magic number. It is a critical theoretical point. An eigenvalue of negative one allows the model's hidden state to flip signs back and forth. This gives it the capacity to track things like parity and compose complex permutations. If you restrict eigenvalues strictly between zero and one, the state can only decay or stay constant. Linda: Exactly! And the empirical results match the theory perfectly. The DeltaNet restricted to the zero-to-one range failed just like the Transformers. But the DeltaNet allowed to reach minus one? It learned to track the states flawlessly, even with the sparse supervision we talked about. Norris: Perfect performance on the training distribution is one thing. But did it extrapolate? That is the true stress test of whether a model has actually learned the underlying algorithm or just memorized the training data. Linda: It did extrapolate beautifully! They trained the models on a curriculum of sequences up to 64 commands. But during testing, they pushed it all the way out to 128 commands with a reveal spacing of 16. DeltaNet minus-one-to-one perfectly extrapolated across all random seeds. The Transformer and the restricted DeltaNet just flatlined at zero accuracy. Norris: Now that is what I call a clean architectural separation. The structure of the model literally dictates whether it can learn the algorithm. But Linda, you know I love to peek inside the black box. How do we know it actually learned the right mechanism and did not just find some bizarre, high-dimensional shortcut? Linda: The authors were one step ahead of you! They ran a really cool interpretability analysis using a tool called NNsight. DeltaNet parameterizes its recurrence using a beta value. Setting beta to two gives you that crucial eigenvalue of negative one. So, they looked at the distribution of these beta parameters across all the layers and attention heads during a forward pass. Norris: Let me guess. The network did not just spread this capability everywhere. It localized it? Linda: Yes! One specific head stood out from the rest. Layer 12, Head 3. While other heads had varying betas, Layer 12, Head 3 consistently set its beta values to exactly two. Furthermore, a PCA analysis showed the keys for this head live in a significantly lower-dimensional subspace compared to everything else. Norris: Layer 12, Head 3... the designated state-tracking head! I love it when a neural network delegates tasks so cleanly. It is almost biological. But correlation is not causation. Did they do an intervention to prove this head was doing the heavy lifting? Linda: They absolutely did. They artificially intervened during the forward pass by restricting the beta range back to zero-to-one for each head independently. Scaling any other head in the network did absolutely nothing to the accuracy. But the moment they restricted Layer 12, Head 3, the state prediction accuracy completely tanked. Norris: That is brilliant. It is like finding the exact gear in a pocket watch that keeps the time, pulling it out, and watching the hands stop. I am thoroughly impressed by DeltaNet here. But knowing you, Linda, you did not bring this paper just to sing its praises. We are halfway through the episode, which means there has to be a catch coming. ## The Catch: Partial Observability Norris: So, Layer 12, Head 3 is our state-tracking hero. But you warned me at the end of the last segment that there is a catch coming. The paper didn't just stop at praising linear RNNs, did it? Linda: Not at all. The authors actually use this success to highlight a massive idealization in their own testbed, and in most sequence-to-sequence benchmarks. In those REPL traces, every single variable swap was fully observable. The model saw exactly what happened at every step. Norris: Ah, and real code execution rarely gives us that kind of transparency. In a real software environment, you have control flow, random number generators, or external API calls. The model doesn't always know which branch the code actually took. Linda: Exactly! The paper categorizes this into three sources of transition uncertainty. The first is what you just mentioned: unobservable branching. Imagine a Python script that says 'if random choice is less than 0.5, swap variable A and B'. The model reading the code doesn't see the random seed, so it doesn't know if the swap actually happened. Norris: Right. What are the other two sources? Linda: The second is approximation. Language models often skip over expensive operations like deep recursion or massive loops to save computation, which introduces uncertainty about the intermediate states. And the third is inverse inference, like trying to deduce what input produced a specific output, which often has multiple valid solutions. Norris: So in all three of these scenarios, the model can no longer just confidently track 'the' state deterministically. It is forced to maintain a probability distribution over multiple possible states. A belief state. Linda: Precisely. The problem shifts from tracking a Deterministic Finite-State Automaton, a DFA, to what the authors formalize as a Probabilistic Finite-State Automaton with State Reveals. They call it PFSA-SR for short. Norris: PFSA-SR. That is quite the acronym. Conceptually, how does that differ from classical models of uncertainty, like Hidden Markov Models or POMDPs? Linda: It is closely related to those, but with a specific focus on how code works. The key difference is the 'State Reveals' part. In a POMDP, you get noisy, likelihood-weighted observations. But in code, an observation like a print statement or an assert is a hard constraint. Norris: I see the distinction. If a program prints that variable 'a' equals one, it is not a noisy signal. It is an absolute fact. Any hypothesis in your belief state where 'a' equals two is deterministically eliminated. It prunes the support of your probability distribution. Linda: Yes! So the model's belief updates in two stages. First, the transition step, where uncertainty might grow due to a probabilistic event like our random swap. Second, the reveal step, where a print statement zeros out all the states that are inconsistent with the observation. Norris: But wait a minute. If you zero out a bunch of inconsistent states in your probability vector, the remaining probabilities no longer sum to one. You have to re-normalize the vector to get a valid belief distribution. Linda: You are jumping right to the punchline, Professor! That is exactly the issue. Norris: It is inescapable math! Re-normalizing a vector requires dividing by the sum of its remaining elements. That is a highly non-linear operation. But our hero, the linear RNN, can only do matrix multiplications. It defers all non-linearities to the very end of the sequence. Linda: Which means it has to propagate an unnormalized state through time. And that leads to a catastrophic numerical failure when tracking probabilistic states, which we will dive into next. ## The Math of Norm Decay Norris: So we are left with this unnormalized state vector. Because the linear RNN cannot do the division required for renormalization at each step, what exactly happens to the math when it tries to track these probabilistic states? Linda: It leads to a fatal flaw called norm decay. The paper analyzes this using two different ways a model could theoretically represent its belief state inside its hidden dimension: the joint representation and the marginal representation. Norris: Let us start with the joint representation. That would mean explicitly tracking the probability of every possible full permutation of our variables, right? So for a list of 'n' elements, the state space is 'n' factorial. Linda: Exactly. It is massively inefficient to begin with. But even ignoring the sheer size of it, it is mathematically doomed under partial reveals. Every time a print statement prunes inconsistent states from the distribution, the survival probability acts as a multiplier strictly less than one. Norris: Ah, I see. Because the linear recurrence is just multiplying these fractions over and over without ever re-normalizing the sum to one, the vector's magnitude shrinks exponentially with every partial reveal. Linda: Precisely! And because floating-point precision is finite, eventually that vector just underflows to zero. The model completely loses its mind because the signal simply drowns in numerical noise. Norris: This is exactly why classic Bayesian filtering algorithms always use log-sum-exp tricks or per-step scaling to maintain numerical stability. But those are non-linear operations! Does the second method, the marginal representation, save the day? Linda: It tries its best! Instead of tracking the joint probability of the entire list, the marginal representation tracks the probability of each position independently. You can think of it as tracking an 'n' by 'n' doubly stochastic matrix where the entries are the probabilities of element 'j' being in position 'i'. Norris: That sounds much more tractable. And I suppose the linear recurrence can handle moving mass around within that matrix. But does this representation survive the dreaded norm decay? Linda: It actually survives the standard cases! Unlike the joint representation, the marginal representation can use the input injection term of the linear RNN, the 'B' matrix, to inject absolute certainty. If the code prints that position two contains element two, the model directly injects a one at that matrix entry. It acts as a targeted reset that replenishes the decayed probability mass. Norris: A targeted reset, what a clever use of the injection term. But you said it only survives the standard cases. I smell an adversarial counterexample coming. Linda: You have a great intuition for these things, Professor. The authors constructed an adversarial sequence where even the marginal representation fails. Imagine you continually swap elements two and three probabilistically, but you only ever reveal the state of element two. Norris: Oh, I understand! The matrix entry for element two gets that targeted reset back to one. But element three is never directly revealed; it can only be inferred by exclusion. So it never gets replenished by the injection term. Linda: Exactly! So the unrevealed mass for element three just gets multiplied by a half over and over. One half, one quarter, one eighth, and so on, until it vanishes entirely into floating-point nothingness. Norris: What a brilliant way to characterize the divide between linear and non-linear models. It proves a hard mathematical barrier: without either a non-linear renormalization inside the recurrence, or a guarantee of frequent full-state reveals to act as a hard reset, stable belief maintenance for probabilistic states is fundamentally impossible for linear RNNs. Linda: That is the exact takeaway. Linear RNNs are incredibly powerful for deterministic code, but the messy, probabilistic nature of real-world execution is their kryptonite. The authors suggest this might require hybrid architectures that mix linear efficiency with periodic non-linearities, like the recent Titans or TTT models. Norris: A fantastic conclusion to a highly rigorous paper. The quest for the ultimate sequence model is definitely far from over. Linda: It certainly is! Thank you for breaking down the math with me, Professor, and a huge thank you to all our listeners for tuning in to Mechanical Dreams. We will catch you next week!