## Welcome & Introduction
Norris: Welcome back to Mechanical Dreams, the podcast where we explore the algorithms, the architectures, and the occasional hallucinations of modern machine learning. I'm Professor Norris, your resident skeptic. Linda: And I'm Linda! Welcome back, everyone. Dr. Norris, I hope you're ready for a blast from the past, because today we are going back to the future. Norris: Oh no. Please don't tell me we're doing symbolic logic and Expert Systems again. I packed all those textbooks into the attic back in the 90s. Linda: Not quite that far back! Today, we're talking about Recurrent Neural Networks. But specifically, we are looking at the unexpected comeback of non-linear RNNs. Norris: Non-linear RNNs? You mean like LSTMs and GRUs? Linda, I thought the Transformer, and more recently, linear models like Mamba and Gated DeltaNet, essentially sent those to the retirement home. The conventional wisdom is that non-linear RNNs just can't scale or parallelize well enough for modern foundation models. Linda: That is exactly the conventional wisdom! But the paper I brought in today completely challenges that assumption. It's called 'M2RNN: Non-Linear RNNs with Matrix-Valued States for Scalable Language Modeling.' It's from a fantastic team spanning UC Berkeley, Learning Machine, MIT-IBM Watson Lab, Princeton, and Together AI. Norris: M2RNN... Matrix-to-Matrix RNN, I presume? So, they are taking the classic non-linear recurrence but fundamentally changing the hidden state. I have to admit, I'm highly skeptical. Training a non-linear RNN at the scale of billions of parameters sounds like an absolute nightmare for GPU memory and utilization. Linda: It definitely used to be! But they've figured out a way to make the state capacity massive using matrix-valued states and outer product expansions, all while keeping hardware utilization incredibly high. In fact, they show it outperforming some of the best hybrid linear attention architectures out there today. Norris: Well, you've certainly set a high bar. A non-linear RNN taking on modern linear attention and Mamba architectures? I'll believe it when I see the benchmarks. Lead the way, Linda.
## The Expressivity Gap: Linear vs. Non-Linear RNNs
Linda: To understand why we're bringing non-linear RNNs back from the dead, we have to talk about why we abandoned them in the first place, and what we lost when we did. Norris: Well, we abandoned LSTMs and GRUs because of efficiency! LSTMs were a sequential bottleneck. When Transformers came along, we could parallelize training across the entire sequence. And more recently, with linear RNNs like Mamba or Gated DeltaNet, we figured out how to make RNNs parallelizable too, using algorithms like parallel scan. Linda: Exactly. Because linear RNNs remove the non-linear activation function from the recurrent step, the operations become associative. That allows us to chunk the computations and train super fast. But the authors point out a fatal flaw in this tradeoff: the expressivity gap. Norris: Right, I suspect we are wading into computational complexity theory here. Let me guess, TC0 versus NC1? Linda: Spot on, Dr. Norris. Standard Transformers and linear RNNs with diagonal or input-independent transitions belong to the TC0 complexity class. That means they can be simulated by constant-depth threshold boolean circuits. They are great at simple state tracking, but provably fail at harder tasks. Norris: Tasks like the S5 permutation group problem, if I recall the Merrill paper correctly. But let me play devil's advocate: who cares about abstract math group permutations if the model can write decent Python code or summarize a document? Linda: The problem is that practical tasks like tracking chess moves, rigorously tracking entities in a long story, or accurately evaluating code branches actually reduce to problems that are at least as hard as that S5 permutation task. They require a deterministic finite-state automaton, which linear RNNs struggle to simulate. Norris: I see. But haven't there been attempts to fix linear RNNs? I think some recent papers showed that if you allow the transition matrices in models like Mamba or DeltaNet to have negative eigenvalues, they gain some expressivity. Linda: Yes, theoretically! Some researchers showed that by using negative eigenvalues or Householder matrices, linear RNNs can solve simpler permutation tasks like S3. But the authors of the M2RNN paper actually put that to the test. They trained a Gated DeltaNet with negative eigenvalues on the S3 task for a sequence length of 128. Norris: And let me guess... it overfit to the training length? Linda: It completely fell apart. As soon as they evaluated it on context lengths longer than 128, the accuracy degraded massively. But when they tested a classic, non-linear GRU? It generalized perfectly to unseen context lengths, maintaining over 99.5% accuracy up to a sequence length of 512. Norris: Fascinating. So theoretical expressivity doesn't guarantee robust state tracking in practice. The non-linearity—applying that tanh activation at every single time step—really does force the model to learn a much more robust state representation. Linda: Exactly. Because non-linear RNNs don't rely on associative tricks, they can simulate arbitrary deterministic finite-state automata. They actually 'track' the state properly. Norris: I concede the point on expressivity, Linda. But that brings us to the elephant in the room. If LSTMs and GRUs are so mathematically expressive, why did they always get crushed by Transformers and Mamba on actual language modeling leaderboards? If they are so smart, why were their perplexity scores so bad? Linda: That is the million-dollar question! Everyone, including us, assumed it was the non-linearity that was holding their performance back. But this paper proves that it wasn't the non-linearity at all.
## The Real Bottleneck: State Capacity
Norris: Alright Linda, don't keep me in suspense. If the non-linearity wasn't the anchor dragging down classic RNNs, what was? Linda: It was the state capacity! Traditional non-linear RNNs, like your classic Elman networks, LSTMs, and GRUs, rely on a vector-valued hidden state. The entire memory of the sequence is compressed into a single one-dimensional vector, usually denoted as h_t. Norris: Right, a hidden state vector of dimension d. But if the problem is just that the vector is too small, why didn't we just make d larger? Surely we have enough compute nowadays to just scale up the hidden dimension. Linda: You would think so, but it mathematically hits a wall. The transition matrix in a standard non-linear RNN, let's call it W, projects the previous hidden state to the next. That matrix is of size d by d. So the number of parameters grows quadratically with the state size. Norris: Ah, I see. If you try to make the state size large enough to hold the same amount of information as a modern linear RNN, that dense transition matrix explodes in size. Linda: Exactly! If you scale d up to match modern state capacities, that d-by-d matrix becomes so massive it can no longer fit into the shared memory of a single streaming multiprocessor on an NVIDIA GPU. You completely lose the ability to do on-chip reuse, which kills your hardware efficiency. Norris: So you are stuck. You either have a fast model that forgets everything, or a model with a good memory that takes a century to train. And I imagine this tiny vector state is exactly why old RNNs were notoriously bad at in-context retrieval. Linda: Spot on. As the sequence length grows, that single vector becomes completely overloaded. If you try to do a needle-in-a-haystack retrieval task, the RNN has likely overwritten the key-value association you need. Transformers don't have this problem because they explicitly keep all past tokens in a Key-Value cache. Norris: And linear RNNs like Mamba bypass this by using matrix-valued states. So the authors of this paper essentially set out to prove that if you give a non-linear RNN a matrix-valued state, it suddenly becomes competitive again? Linda: They proved it beautifully in their ablation studies. They trained a classic vector-valued RNN and their new M2RNN model, both sitting at around 410 million parameters. But because of how M2RNN is structured, its effective state size was over 86,000, compared to just 1,360 for the classic RNN. Norris: Let me guess the punchline. The perplexity difference was staggering? Linda: Incredible, really. The matrix-valued M2RNN outperformed the vector-valued RNN by over 10 perplexity points on WikiText, and a massive 280 points on the LAMBADA benchmark. They also tested a GRU with the same parameter count, and M2RNN still easily beat it. Norris: Well, a 280-point improvement in perplexity is not something you can ignore. You have successfully diagnosed the bottleneck, Linda. But now you have to explain the cure. How exactly do they manage to give a non-linear RNN a massive matrix-valued state without blowing up the parameter count and melting the GPUs?
## Enter M²RNN: Matrix-Valued States
Norris: Alright, so if scaling up the vector size d gives us a transition matrix that's too big to fit in GPU shared memory, how does the M2RNN paper solve this? How do you get a massive state without a massive parameter explosion? Linda: They borrow a brilliant trick from linear attention and State Space Models like Mamba. Instead of a single vector, they use an outer product state expansion. The hidden state is no longer a vector; it's a matrix, which we can call H_t, with dimensions K by V. Norris: A matrix-valued state. So the architecture is literally Matrix-to-Matrix... M2RNN. That explains the name! But wait, if the state is a K by V matrix, how do the inputs interact with it? Linda: Just like in an attention mechanism, they take the input token x_t and project it into Keys and Values—k_t and v_t. Then, they take the outer product of the key and the value. This creates a matrix of the exact same size as the hidden state, K by V. Norris: Ah, I see! So instead of a dense d-by-d transition matrix mapping the whole state, the transition matrix W just needs to operate on the V dimension. The parameter count stays completely manageable. Linda: Exactly! The core recurrent equation is beautiful. You take the previous state matrix H_t-1, multiply it by the transition matrix W, add that key-value outer product, and then—here is the crucial part—you wrap the whole thing in a tanh non-linearity. Norris: So the non-linear update is tanh applied to (H_t-1 * W + k_t * v_t transpose). You get the massive K by V capacity of linear attention, but you force the model to learn a highly expressive, non-linear state transition. But Linda, applying tanh at every single step... what about the vanishing gradient problem? Backpropagation through time on that must be brutal. Linda: You are absolutely right to worry about that. To stabilize the gradients, they bring back a classic tool from the LSTM era: the forget gate. But they make a vital modern tweak to it. Norris: Let me guess... if it's like an LSTM, the forget gate depends on the previous hidden state, which forces you to compute it sequentially. Did they decouple it? Linda: Spot on, Dr. Norris. In M2RNN, the forget gate is only a function of the current input x_t. It doesn't look at the previous state at all. Because of that, they can compute the forget gates, queries, keys, and values for the entire sequence in parallel before the recurrence even starts! Norris: That's a massive optimization. So the final state at time t is just a weighted sum? The forget gate decides how much of the old state to keep, and the rest is filled in by that new, non-linear tanh update. Linda: Exactly. H_t equals f_t times H_t-1, plus (1 - f_t) times the new non-linear update. They also apply per-step gradient clipping during training to keep the transition matrix W from causing gradients to explode. It's a very stable setup. Norris: And then, to get the output, I assume they project the input into a Query vector and multiply it against this massive state matrix? Linda: Yes, just like linear attention! The Query vector reads out the relevant information from the hidden state. And to squeeze even more capacity out of the parameter budget, they adopt the multi-value attention formulation from Mamba-2. They share a single query and key head across multiple value heads. Norris: Okay, I have to admit, the math is incredibly elegant. They’ve successfully grafted the expressivity of non-linear RNNs onto the high-capacity, outer-product chassis of modern linear models. But elegant math doesn't always run fast on a GPU. Doing a matrix-to-matrix multiply inside a sequential loop at every time step sounds like a recipe for terrible hardware utilization. Linda: It definitely could be! But the systems engineering behind M2RNN is just as impressive as the math. The way they tile the computations for the Tensor Cores is fascinating, and it completely bypasses a major flaw in previous non-linear RNN implementations.
## Hardware Utilization & Systems Engineering
Norris: Alright, so we left off with a major systems engineering question. You've got this elegant K by V matrix state, but doing a matrix-to-matrix multiply at every single sequence step sounds like a great way to stall a GPU. Tensor Cores are notoriously picky about matrix dimensions. Linda: They are, and that actually used to be a massive bottleneck for older vector-valued RNNs! To use NVIDIA Tensor Cores, you need your matrix dimensions to be multiples of 16. Previous works, like FlashRNN, tried to solve this by parallelizing the recurrence over the batch dimension. Norris: Ah, let me guess. If your per-GPU batch size is small, say 4, you have to pad it out to 16 just to use the WMMA instructions. That means you are throwing away a huge percentage of your compute on padding. Linda: Exactly! At a batch size of 4, you are wasting 75 percent of your FLOPs. But because M2RNN uses an outer product expansion, its recurrent state is already a matrix. The GEMM computation at each step has dimensions K, V, and V. Norris: Oh, that is incredibly clever. So they just set K and V to be multiples of 16? Linda: Yes! They use K equals 64 and V equals 16. The matrix dimensions themselves satisfy the Tensor Cores. The GEMM shape becomes completely independent of the batch size, so there is zero padding waste. They can utilize the WGMMA instructions on Hopper GPUs at maximum hardware efficiency. Norris: That is a beautiful piece of engineering. The batch size is decoupled from the compute geometry. But wait, what about multi-GPU training? We are talking about billion-parameter foundation models here. You have to use Tensor Parallelism to partition these layers across multiple accelerators. Since you mentioned earlier they share a single Query and Key head across multiple Value heads, partitioning must be a nightmare. Linda: It's definitely tricky! You can't just slice the heads evenly across GPUs. To handle this, the authors propose two different Tensor Parallelism strategies. The first is a 'Topology-Aware' approach. They simply set the number of Query and Key heads to exactly match the Tensor Parallelism world size. Norris: It's fast, because it requires zero extra communication across the GPUs, but... you've just coupled your model architecture to your training cluster size. If I train on an 8-GPU node, I have 8 Query heads. If I want to serve that model later on a single GPU, I'm stuck carrying around those inflated projections. Linda: Exactly, which is why they also built a 'Topology-Independent' strategy. They keep the single Query and Key head, but shard the RMSNorm and the Value heads across the GPUs. It requires introducing a few custom AllReduce operations during the forward and backward passes to synchronize the normalization and gradients. Norris: A classic systems trade-off! You burn a little bit of network bandwidth with those AllReduces, but you keep your model parameter count completely pristine and independent of your cluster topology. Linda: Precisely. They even wrote custom Triton kernels to ensure each sequence-head pair gets its own Streaming Multiprocessor. It’s a very robust, end-to-end training pipeline. Norris: Well, Linda, you've convinced me that they have solved the math, and they have solved the hardware. The only thing left to see is if this Frankenstein's monster of non-linear state tracking and matrix expansion actually performs on the benchmarks.
## Empirical Wins & The Power of Hybrids
Norris: Alright, the moment of truth. We've established that the math works and the hardware optimization is pristine. But you promised me this Frankenstein's monster of non-linear state tracking and matrix expansion actually performs. How does it stack up against the modern heavyweights like Mamba-2 and Gated DeltaNet? Linda: It doesn't just stack up; it throws punches! They trained models at the 410 million parameter dense scale, and also a 7 billion parameter Mixture-of-Experts scale. On pure language modeling, M2RNN essentially matched Mamba-2 on WikiText perplexity, and actually beat both Mamba-2 and Gated DeltaNet on the LAMBADA benchmark. Norris: Impressive. But let me put my systems hat back on for a second. Even with zero padding waste, doing that K-by-V matrix recurrence has to be computationally heavier than a pure linear model. What's the catch on training throughput? Linda: You caught them. You're absolutely right. While M2RNN has linear time complexity, its constant factors are higher. A purely homogeneous M2RNN model is slower to train than a pure Mamba-2 model. But that is exactly where the authors introduce their masterstroke: Hybrid architectures. Norris: Hybrids. Right. We've seen this trend lately in production models, mixing standard attention with linear RNNs to get the best of both worlds. The standard recipe is usually one attention layer for every seven recurrent layers. Linda: Exactly! The authors took that standard 2-way hybrid recipe and turned it into a 3-way hybrid. They took a Hybrid Gated DeltaNet model, and replaced just *one* single recurrent layer with an M2RNN layer. Norris: Just one layer? Out of, what, 24 or 40 layers depending on the scale? Surely injecting one non-linear layer can't move the needle that much. Linda: It moved the needle massively! On the 7B MoE model, swapping just that one layer dropped the WikiText perplexity by almost half a point. But the real shocker was on the RULER benchmark, which tests long-context retrieval. Think Multi-Query and Multi-Value Needle in a Haystack. Norris: Ah, the exact tasks where linear RNNs typically overwrite their states and forget the keys. Linda: Exactly. Because linear RNNs struggle with hard state tracking, that one single M2RNN layer acts like an anchor for the model's memory. It gave them huge accuracy improvements on those retrieval tasks. And the best part? Replacing just one layer only reduced the training throughput by about 6 percent. Norris: A 6 percent throughput hit for a near state-of-the-art boost in long-context retrieval and reasoning. That is an incredibly pragmatic trade-off. It’s like adding a highly specialized turbocharger to a very efficient engine. Linda: It really is. They also tested adding 3 to 5 M2RNN layers in the 7B model for even better performance. On LongBench, which tests long-context summarization and coding, this hybrid approach outperformed the state-of-the-art hybrid linear attention architectures by up to 8 points! Norris: 8 points on LongBench! Okay, Linda, I officially surrender. The non-linear RNN isn't just a nostalgia trip. By solving the state capacity bottleneck and injecting it surgically into modern hybrids, they've created a highly effective tool for next-generation foundation models.
## Conclusion & Wrap-Up
Norris: Well Linda, I have to admit, when you first brought up non-linear RNNs at the top of the episode, I was ready to go into the attic and dust off my 1990s floppy disks. Linda: But now you're ready to start swapping M2RNN layers into your latest foundation models, right? Norris: I just might! The way they solved the state capacity bottleneck with matrix outer products, while keeping the Tensor Cores perfectly fed without padding waste, is just phenomenal systems engineering. Linda: And seeing how a single non-linear layer can act as a memory anchor in a hybrid architecture, boosting long-context retrieval by 8 points on LongBench, really proves that theoretical expressivity matters in practice. Norris: It certainly does. It is a great reminder to all our graduate students and professionals listening: sometimes the old algorithms aren't dead, they just need a modern, hardware-aware makeover. Linda: Exactly! Thank you all for joining us this week on Mechanical Dreams. We will leave a link to the M2RNN paper in the show notes for those who want to dive deeper into the math and the Triton kernels. Norris: Until next time, keep your gradients stable, your state matrices large, and your Tensor Cores fully utilized. Goodbye everyone!