UC Berkeley's M²RNN Drops Into Hybrid Models, Boosting Long-Context by 8 Points
A new non-linear RNN with matrix-valued hidden states beats Gated DeltaNet hybrids by up to 8 LongBench points while dropping into existing architectures.
ProTakeaways
- M²RNN introduces matrix-valued hidden states and non-linear transitions for scalable recurrent language modeling.
- Hybrid M²RNN beats Hybrid Gated DeltaNet by 0.4-0.5 perplexity points on a 7B MoE model.
- Adding one M²RNN layer to hybrids gives up to 8 LongBench points with 6% throughput cost.
- Outer-product state expansion makes GEMM shape independent of batch size, eliminating FlashRNN padding waste.
- Achieves perfect state-tracking generalization on S₃ permutation task at unseen sequence lengths.
- Triton kernels, training code, and 410M/7B checkpoints are available on Hugging Face.
A team from UC Berkeley, MIT-IBM Watson Lab, Princeton, and Together AI has released M²RNN, a non-linear recurrent layer designed to slot into hybrid language models next to attention and other linear RNNs like Mamba-2 and Gated DeltaNet. The pitch is unusual: instead of pushing linear recurrences harder, they revive non-linear RNNs, fix the two things that historically killed them (tiny state size and terrible hardware utilization), and show that even a single M²RNN layer inside an existing hybrid model produces measurable gains across language modeling, retrieval, and long-context benchmarks.
Why linear recurrences hit a ceiling
The motivation starts from a complexity-theory result that has become uncomfortable for modern architectures. Transformers lie in TC⁰, making them capable of solving only simpler tasks like parity, while many practical state tracking tasks such as tracking chess moves or evaluating programs reduce to problems at least as hard as the S₅ word problem, which sits in NC¹ and provably outside what a Transformer can express. Linear RNNs with diagonal or input-independent transitions inherit the same limitation.
Non-linear RNNs escape this box in theory. In practice they have been abandoned for three reasons:
- Small state. A vector-valued hidden state must compress the entire context into a fixed-size representation, and grows overloaded as sequences lengthen.
- Weak retrieval. That same bottleneck makes it hard to recover specific key-value associations from earlier in the context.
- Training inefficiency. The element-wise non-linearity breaks the associativity needed for parallel scan, forcing sequential computation along the sequence dimension, and existing block-wise workarounds like FlashRNN pad the batch dimension to 16 to use tensor cores, wasting 75% of recurrence FLOPs at batch size 4.
Matrix-valued state, outer-product writes
M²RNN keeps the non-linearity but swaps the vector hidden state for a matrix H_t ∈ R^(K×V). The recurrence is compact:
Z_t = tanh(H_{t-1} W + k_t v_t^T) # non-linear update with outer-product write
H_t = f_t * H_{t-1} + (1 - f_t) * Z_t # gated blend
y_t = H_t^T q_t + w_r * v_t # readout with residual
Three design choices matter. First, the k_t v_t^T outer product is borrowed from linear attention and Mamba-2, giving a large effective state without a quadratic parameter blow-up. Second, the forget gate f_t depends only on the input, not the previous state, so all pre-recurrence projections can be computed in parallel across the sequence. Third, a residual w_r * v_t around the recurrence helps gradient flow through the stacked tanh layers.
The authors prove that this construction is at least as expressive as vector-valued non-linear RNNs, so it can represent any regular language. Empirically, on the S₃ permutation state-tracking task, M²RNN and a GRU both hit ≥99.5% accuracy out to sequence length 512 after training only on length 128, while Gated DeltaNet with negative eigenvalues fails outright and Gated DeltaProduct degrades past 256.
Hardware trick: the GEMM shape stops depending on batch size
The subtler contribution is the tiling story. In a traditional non-linear RNN, each recurrent step is a W h_{t-1} GEMM whose shape depends on the batch dimension, which is why FlashRNN has to pad. In M²RNN, each GPU streaming multiprocessor executes an independent recurrence over a matrix-valued state of size K × V, with GEMM dimensions M, N, K = K, V, V. The GEMM shape is independent of the batch size B, so as long as K and V are multiples of 16, tensor cores stay fully utilized with zero padding overhead. The authors used K=64, V=16 throughout.
They implemented the forward and backward kernels in Triton. Because caching the full H_t ∈ R^(BNKV) at every step would blow through HBM, the backward pass recomputes the forward recurrence and streams cached states through global memory. Two tensor parallelism strategies are provided: a topology-aware grouped-value variant that adds no communication, and a topology-independent multi-value variant that preserves parameter count across TP configurations at the cost of a few extra AllReduces.
What the numbers look like
The team trained 410M dense models and 7B (1.1B active) MoE models on 100B tokens from Nemotron-CC-v2. The most interesting result is not homogeneous M²RNN, where the smaller state still lags Gated DeltaNet on Wikitext, but the hybrid setups.
| Model (7B MoE) | Wiki PPL | Avg Acc | Retrieval Avg | LongBench Avg |
|---|---|---|---|---|
| Hybrid Mamba-2 | 13.10 | 65.03 | 55.1 | 18.8 |
| Hybrid Gated DeltaNet | 13.51 | 64.64 | 51.4 | 23.1 |
| Hybrid M²RNN | 13.00 | 65.56 | 55.6 | 24.6 |
| Hybrid GDN + M²RNN-1 | 13.07 | 65.80 | 54.2 | 30.4 |
| Hybrid GDN + M²RNN-5 | 12.85 | 65.66 | 55.1 | 31.2 |
The headline numbers: Hybrid M²RNN beats Hybrid Gated DeltaNet by 0.4 and 0.5 perplexity points at 410M and 7B MoE scale on Wikitext, and dropping a single M²RNN layer into an existing Hybrid Gated DeltaNet gives up to 8 additional points on LongBench across summarization, coding, and few-shot tasks. On the RULER needle-in-a-haystack variants, the same one-layer swap improves multi-query, multi-key, and multi-value retrieval both at the 4k training length and out to 16k.
The state-size ablation that reframes the field
Buried in the ablations is a claim worth pulling out. Comparing a 406M vector-valued RNN, a 474M GRU, and a 410M M²RNN at matched training data, the M²RNN with its 86,016-dimensional state beats the RNN by more than 10 Wikitext perplexity points and 280 LAMBADA perplexity points, while the GRU still trails by 3 Wikitext points despite having 16% more parameters. The authors argue this means the historical gap between non-linear RNNs and Transformers was never really about non-linearity being a bottleneck; it was about state capacity. Gating helps at the margin, but expanding the hidden state from a vector to a matrix does the heavy lifting.
Where it hurts, and where to use it
M²RNN is not free. It has linear time complexity, but higher constants than Mamba-2 or Gated DeltaNet because the recurrence cannot be parallelized across the sequence and each step involves a V×V GEMM plus a tanh. Homogeneous M²RNN is measurably slower than linear-RNN baselines on 8×H100. The paper's practical recommendation is to use it sparingly: replacing only a single Mamba-2 or Gated DeltaNet layer with M²RNN in a hybrid architecture achieves the same accuracy improvements as the full hybrid M²RNN model, while keeping training throughput within 6% of the Hybrid Gated DeltaNet at both 4k and 16k context lengths.
That framing makes M²RNN more of a spice than a base ingredient. If you are already training a hybrid attention-plus-linear-RNN stack (a design used in production models like Jamba, Samba, Granite 4, and Nemotron Nano 2), swapping one recurrent layer for M²RNN appears to add non-linear state tracking and improved retrieval with negligible throughput cost. If you need aggressive homogeneous recurrence for maximum inference throughput, Mamba-2 or Gated DeltaNet are still faster.
Availability
Everything is open. Training code lives in the lm-engine repository, the Triton kernels are in the accelerated-model-architectures repo, and the trained checkpoints are published in the M²RNN Hugging Face collection. The 410M and 7B MoE variants across all the hybrid configurations reported in the paper are included, which is enough to reproduce both the RULER and LongBench comparisons directly.