Recurrence Returns: xLSTM & Parallel RNNs
Exponential gating, matrix memories and recurrent networks that train in parallel.
Transformers won the late 2010s by training in parallel; recurrent networks keep the advantage at inference, with a fixed cost per token. A truce arrived in the 2020s: if the state update is linear in the state, a parallel scan trains the recurrence in logarithmic depth, and gates computed from the input alone keep much of the expressive power. Here you derive the scan, meet the minimal gated RNNs, take apart xLSTM's exponential gates and matrix memory, and see what is given up.
What you’ll learn
- Compare the training and inference costs of nonlinear RNNs, transformers and linear recurrences, and identify the property that permits parallel training.
- Derive the associative operator for , prove associativity, and analyze the depth and work of the Hillis–Steele and Blelloch scans.
- Explain QRNNs, SRUs and the minimal gated RNNs minGRU and minLSTM as recurrences whose gates ignore the state.
- Write xLSTM's sLSTM and mLSTM cells, prove that their stabilizer leaves the output unchanged, relate RWKV and the RG-LRU to them, and state what is lost relative to nonlinear recurrence.
The trade-off
An LSTM layer must compute in order, because each gate reads through a nonlinearity: dependent steps per layer, each a small matrix product that leaves most of a GPU idle. A transformer computes all positions of a training sequence at once, but at inference it attends to a KV cache that grows with the context, so each new token costs more than the last. A recurrence that trains like a transformer and runs like an RNN needs one property: the new state must be an affine function of the old one, with coefficients that may depend on the input but not on the state.
| Model | Training: sequential steps per layer | Inference cost per token | State kept at inference |
|---|---|---|---|
| Nonlinear RNN (LSTM, GRU) | constant | fixed size | |
| Transformer (causal) | none: all positions in parallel | grows with the context | KV cache, grows with the context |
| Linear recurrence with a parallel scan | about | constant | fixed size |
Linear does not mean ungated. In the decay can be a sigmoid gate computed from , and a gated candidate computed from ; only the dependence on must stay linear. The nonlinearity moves between layers instead of within the recurrence, and depth supplies what the recurrence gives up.
Parallel scans
Each step of applies an affine map , which we represent by the pair . Computing every means computing every prefix composition : a prefix scan. Scans parallelize whenever the combining operation is associative (Blelloch, 1990).
Apply first and second. The composition is again an affine map, which defines the operator:
Check associativity by expanding both groupings; elementwise products commute, so the results agree:
With , the state is the second component of the prefix composition. The identity element is . (Composition of affine maps is associative in general, so matrix-valued transitions also scan, at the cost of matrix products.)
Hillis–Steele (Hillis & Steele, 1986): in round , every position combines its pair with the pair positions earlier. After rounds every position holds its full prefix, at total work. Blelloch's work-efficient scan uses an up-sweep and a down-sweep over a balanced tree: work in about rounds.
import torch
def linear_scan(a, b):
"""All states of h_t = a_t * h_{t-1} + b_t with h_0 = 0, in ceil(log2 T) rounds.
a, b: tensors of shape (T, ...); returns h of the same shape."""
T, shift = a.shape[0], 1
while shift < T:
a_prev = torch.cat([torch.ones_like(a[:shift]), a[:-shift]]) # identity map
b_prev = torch.cat([torch.zeros_like(b[:shift]), b[:-shift]])
b = a * b_prev + b # earlier segment first, then this one
a = a * a_prev
shift *= 2
return bA Hillis–Steele scan in a few lines: each round is a handful of elementwise operations over the whole sequence. Martin & Cundy (2018) implemented a work-efficient blocked scan as a CUDA kernel (each processor scans its own block of steps, and only the block summaries are combined across processors) and sped up the training of QRNN and SRU layers by up to 9×. Products of many gates below 1 can underflow, so practical kernels often work in log space.
How many rounds does a Hillis–Steele scan need for a sequence of steps?
Show the answer
12 rounds
, against 4,095 sequential applications of the recurrence. The total work is larger: combinations, of order . Blelloch's scan brings it down to combinations over about 24 rounds. Either way, depth grows only logarithmically with length.
Gates that ignore the state
Several architectures took the step of computing every gate from the input alone. The quasi-recurrent neural network (QRNN; Bradbury, Merity, Xiong & Socher, 2017) computes candidates and gates with causal convolutions over a few past inputs, all positions at once, and keeps only a minimal recurrent "pooling", for example , with output- and input-gated variants. The simple recurrent unit (SRU; Lei, Zhang, Wang, Dai & Artzi, 2018) keeps a sliver of state dependence, but only elementwise:
Minimal gated RNNs. Feng, Tung, Ahmed, Bengio & Hajimirsadeghi (2024) strip the GRU and the LSTM down until a scan applies: gates and candidates depend on only. With the state gone from the gates, they also drop the candidate's tanh, as a further simplification. Written with for the share of the new candidate (in the GRU convention of LSTMs & GRUs, ):
A minGRU layer needs about parameters against the GRU's , and a minLSTM about against . Trained with a log-space scan, they reported training steps 175 (minGRU) and 235 (minLSTM) times faster than the sequential GRU and LSTM at length 512 on a T4 GPU, with the gap widening for longer sequences, and performance competitive with recent sequence models on their benchmarks. The recipe shared by all these models: compute gates and candidates from the input (often with a short convolution), run an elementwise linear recurrence, and stack layers with nonlinear mixing in between.
Why can a minGRU layer be trained with a parallel scan while a GRU layer cannot?
- The minGRU has fewer parameters
- The minGRU has no gates
- The minGRU uses a ReLU instead of a tanh
- The GRU's gates and candidate read through sigmoids and a tanh, so is a nonlinear function of ; the minGRU's coefficients depend only on , so is affine in
Show the answer
D. The GRU's gates and candidate read through sigmoids and a tanh, so is a nonlinear function of ; the minGRU's coefficients depend only on , so is affine in
A scan needs each step to be an element of an associative family, here affine maps with known in advance. Computing all from the inputs first makes that possible.
xLSTM: exponential gates and matrix memory
xLSTM (Beck et al., 2024), from Hochreiter's group, revisits the LSTM with two changes: exponential gating, which lets a new, strongly gated input outweigh everything stored before, and new memory structures. It defines two cells. The scalar sLSTM keeps recurrent connections from into its gates ("memory mixing", restricted to blocks or heads) and adds a normalizer state:
Unroll from : the cell is a weighted sum of past inputs and the normalizer the sum of the same weights, so is a weighted average of the , however large the exponential input gates become:
Exponential gates can still overflow. Track a stabilizer and rescale both gates by it:
Run the recurrence with . By induction and , since . The common factor cancels in the ratio, so the output, and every gradient, is unchanged while all stored numbers stay bounded:
The mLSTM gives each head a matrix memory written with the covariance update rule, which is a fast-weight write (Fast Weights & Test-Time Memory), gated by scalar input and forget gates per head and read with a query:
xLSTM stacks residual blocks built around the two cells, mixing mLSTM and sLSTM blocks in chosen ratios. The authors report that it performs favorably against transformers and state space models of similar size, both in performance and in how it scales; as with every architecture comparison at this scale, such results depend on training recipes and are best read as of 2024.
Relatives, and what is lost
RWKV (Peng et al., 2023) mixes information over time with a linear-attention-like operator whose contributions decay at a learned rate per channel, so the same model can be written as a transformer for parallel training or as an RNN for inference; it was scaled to 14 billion parameters and reported on par with similarly sized transformers. The RG-LRU of Griffin (De et al., 2024) is a gated diagonal linear recurrence in which, in the authors' words, "neither gate depends on the recurrent state":
Mamba belongs to the same family, with for an input-dependent step size (Selective State Spaces: Mamba). All of these models buy parallel training by giving up one thing: the nonlinear dependence of the update on the previous state. The sLSTM keeps it and pays with sequential training. What it costs in power is concrete. A nonlinear RNN with saturating units can simulate any finite automaton, while diagonal linear recurrences with positive decays cannot even compute parity and, like transformers, cannot solve hard state-tracking problems unless (What Recurrent Networks Can Compute). A fixed-size state also limits exact recall, the subject of Hybrid Models & the Limits of Fixed-Size Memory.
Can nonlinear recurrences be parallelized directly? DEER (Lim, Zhu, Selfridge & Kasim, 2024) treats the whole trajectory as the solution of a fixed-point equation and solves it with Newton's method. Each Newton step linearizes the recurrence around the current guess, with the Jacobian at the guess: a linear recurrence, solved by a parallel scan over matrices, with quadratic convergence near the solution. Dense Jacobians make each step cubic in the state size and the iteration can be unstable; Gonzalez, Warrington, Smith & Linderman (2024) use diagonal Jacobian approximations (quasi-DEER) and trust-region damping linked to Kalman smoothing (ELK) to scale it and stabilize it.
Key takeaways
- Parallel training of a recurrence needs the update to be affine in the state, , with input-dependent coefficients; inference keeps a fixed-size state and constant cost per token.
- The pairs compose by the associative rule , so a scan computes all states in rounds (Hillis–Steele, work) or about rounds with work (Blelloch).
- QRNN, SRU, minGRU and minLSTM compute gates from the input alone; minimal gated RNNs need far fewer parameters than GRUs and LSTMs and train orders of magnitude faster on long sequences.
- xLSTM's sLSTM uses exponential input gates with a normalizer, so is a weighted average of past inputs, and a stabilizer that rescales cell and normalizer by the same factor; the mLSTM's matrix memory has no memory mixing and trains in parallel.
- RWKV, the RG-LRU (with its variance-preserving ) and Mamba share the recipe. The price is the loss of nonlinear state dependence, with provable limits on state tracking; Newton-based methods such as DEER attack nonlinear recurrences directly.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Pairs stand for the maps . Which operation, combining applied first and second, makes a parallel scan compute ?
Show the answer
C.
Applying then gives . The operation is associative, which is all a scan needs, though it is not commutative: order matters.
For a sequence of length , how do the Hillis–Steele and Blelloch scans compare?
- Hillis–Steele: depth and work of order ; Blelloch: depth about and work of order
- Both need sequential steps, like the recurrence itself
- Hillis–Steele: depth and work
- Blelloch has lower depth and lower work than Hillis–Steele
Show the answer
A. Hillis–Steele: depth and work of order ; Blelloch: depth about and work of order
Hillis–Steele halves the remaining distance every round but makes every position work in every round; Blelloch's up-sweep and down-sweep do linear work at about twice the depth. Which is faster in practice depends on how much parallel hardware is available relative to .
xLSTM replaces its exponential gates by stabilized versions and . Why does this not change the output ?
- Because is always zero in practice
- Because the stabilized gates are clipped to 1, which never matters
- Because the output gate compensates for the rescaling
- Because, by induction, the cell and the normalizer are both multiplied by the same factor , which cancels in the ratio
Show the answer
D. Because, by induction, the cell and the normalizer are both multiplied by the same factor , which cancels in the ratio
if , and the same holds for . The output depends only on the ratio, so values and gradients are unchanged while every stored number stays bounded.
What do minGRU-, RG-LRU- and Mamba-style recurrences give up, compared with a GRU, in exchange for parallel training?
- Gating: their decay is a fixed constant
- The nonlinear dependence of the state update on the previous state, which limits what one layer can compute, for example tracking state through long sequences of permutations
- Constant-cost inference: they must reread the whole context for each new token
- Differentiability: they must be trained without backpropagation
Show the answer
B. The nonlinear dependence of the state update on the previous state, which limits what one layer can compute, for example tracking state through long sequences of permutations
Their gates depend on the input only, so each update is affine in the state. Depth and nonlinear layers in between recover much, but single-layer expressivity drops: diagonal linear recurrences with positive decays cannot do parity, and linear recurrences generally lie in .
Further reading
- G. E. Blelloch, "Prefix sums and their applications," Technical Report CMU-CS-90-190, Carnegie Mellon University (1990).
- E. Martin & C. Cundy, "Parallelizing linear recurrent neural nets over sequence length," ICLR (2018).
- L. Feng, F. Tung, M. O. Ahmed, Y. Bengio & H. Hajimirsadeghi, "Were RNNs all we needed?," arXiv:2410.01201 (2024).
- M. Beck, K. Pöppel, M. Spanring, A. Auer, O. Prudnikova, M. Kopp, G. Klambauer, J. Brandstetter & S. Hochreiter, "xLSTM: Extended long short-term memory," NeurIPS (2024).
- B. Peng et al., "RWKV: Reinventing RNNs for the transformer era," Findings of EMNLP (2023).
- S. De, S. L. Smith, A. Fernando, A. Botev, G. Cristian-Muraru, A. Gu et al., "Griffin: Mixing gated linear recurrences with local attention for efficient language models," arXiv:2402.19427 (2024).