MIT's Transformer-PSM Beats Mamba on Sequences 10x Longer With Log Memory
MIT researchers unify Mamba, GLA, and softmax attention under one prefix-scan framework, then use it to build a model with linear-time inference and better length generalization.
ProTakeaways
- MIT and collaborators unify Mamba, GLA, Mamba2, mLSTM, RetNet under the classic Blelloch prefix scan.
- Prefix-Scannable Models (PSMs) generalize state-space models by allowing non-associative aggregators like softmax attention.
- An online binary-counter scan gives O(1) amortized compute per token and O(log N) memory at inference.
- Transformer-PSM generalizes S5 state tracking from length 18 up to 180, beating GPT-2 and 370M Mamba.
- On WikiText-103, perplexity drops from 24.12 to 22.45 as chunk size grows, near GPT-2's 22.28.
- Code released at github.com/muherng/hidden for reproducing all experiments.
A team from MIT CSAIL, TU Munich, and Harvard has proposed a mathematical framework that unifies most of the fast sequence models developed over the past few years, from Mamba to Gated Linear Attention (GLA) to mLSTM, under a single classic parallel algorithm: the Blelloch prefix scan. More importantly, the framework points at models that nobody had built yet, including a new architecture called Transformer-PSM that trains in linear time, decodes with logarithmic memory, and generalizes to sequences roughly ten times longer than what it was trained on.
The paper, titled Sequential-Parallel Duality in Prefix Scannable Models, tackles a question that has been quietly bugging the field: what exactly is the class of neural sequence models that can be trained in parallel and run sequentially in constant space? The answer turns out to be a much larger space than the models we currently have, and the paper both maps it and shows one useful new corner of it.
The quadratic tax nobody wants to pay
Transformers made sequence modeling parallel over the time axis, but they pay for it at inference. Each new token has to attend to every previous key and value, so memory grows linearly with context length and per-token latency grows with it. The alternative, a classical RNN like an LSTM, decodes in constant memory but cannot be trained in parallel because each hidden state depends on the previous one.
Modern architectures like Mamba, GLA, Mamba2, mLSTM in xLSTM, RetNet, DeltaNet, and RWKV all target this tension. Their inference compute is linear in time and constant in memory, just like a classic RNN, while retaining transformer-like parallelizability during training. The property has a name in this paper: sequential-parallel duality (SPD).
The problem is that each of these models was derived independently, with different tricks. There was no clean statement of what design choices are actually required to get SPD, and no way to know if we had exhausted the family.
A very old parallel algorithm, reused
The paper's central observation is that all these models are secretly running the Blelloch parallel prefix scan, a 1990-era algorithm for computing all running prefixes of a sequence under an associative operator. Given tokens combined by some binary operator, the scan computes every prefix in linear work and logarithmic depth using a perfect binary tree with an upsweep and a downsweep.
The authors show that every fast RNN in the current zoo is a Blelloch scan with a different choice of associative aggregator. They lay this out in a single table showing how Linear Attention, DeltaNet, RetNet, mLSTM, Gated RFA, S4, Mamba, and GLA all fit the same affine state-update template. Once you write your recurrence as an affine map on the state, the classic scan does the parallel training for free.
This gives a clean definition of the associative case. But then the paper does something more interesting.
Breaking the associativity rule
The Blelloch scan requires an associative operator to guarantee that the parallel tree gives the same answer as a sequential left-to-right loop. Softmax attention is not associative, which is why it has never fit into this picture.
The authors' key move is to drop the associativity requirement. If you commit to a fixed binary-tree parenthesization, the scan is still perfectly well-defined; it just computes a specific value that happens to differ from the sequential left-to-right one. The Blelloch scan resolves this by fixing a single full binary tree, hence a unique parenthesisation. They call this broader family Prefix-Scannable Models (PSMs).
The really clever part is how they run these non-associative scans at inference. They introduce an online binary-counter scan that maintains at most one intermediate root per block size of a power of two. Inserting a new token behaves exactly like adding one to a binary counter: each trailing 1-bit triggers a merge with the aggregator and a carry to the next bit. They prove this online procedure produces exactly the same value as the static parallel tree, while using only logarithmic memory.
The complexity story lands at O(1) amortized compute per token and O(log N) memory for a sequence of length N. That is strictly better than a transformer's linear KV cache growth, and only a log factor worse than pure state-space models.
Transformer-PSM: attention on chunks, scan on the outside
To validate the theory, the authors instantiate a concrete architecture called Transformer-PSM. It splits the sequence into chunks of size c and uses three learnable pieces:
- An
Encembedding layer that turns a chunk of tokens into a hidden representation. - An aggregation module
Agg, implemented as a small bidirectional GPT-2 block. Given two chunk states, it concatenates them, runs attention over the joint length-2c window, and returns the right half. - An inference module
Inf, a causal GPT-2 block that consumes the current prefix state and a token chunk to produce next-token logits.
The chunk size c becomes a dial. Small c makes the model behave like a state-space model with tight memory; large c makes it behave like a full-context transformer. The paper makes this smooth interpolation precise and shows it empirically.
Results that actually matter
The experiments are on small models but the tasks are diagnostic. On the S5 state tracking problem, essentially composing permutations and predicting the current state, which is known to be NC1-complete and famously hard for both transformers and linear RNNs, the model is trained on sequences of length 4 to 18 and evaluated up to length 180. Transformer-PSM keeps error rates near zero far beyond training length, while a 12-layer GPT-2 and a 370M-parameter Mamba both degrade quickly.
On multi-query associative recall (MQAR), a benchmark that constant-state RNNs typically fail, Transformer-PSM with chunk size 64 hits perfect accuracy like a full-context transformer, while a Mamba baseline collapses under the harder uniform-query sampling used in the paper.
On WikiText-103 language modeling, perplexity drops smoothly as chunk size grows: 24.12 at chunk 32, 22.45 at chunk 256, essentially matching a vanilla GPT-2 baseline at 22.28. Meanwhile, per-token latency measured over 40,000 tokens stays below roughly 0.008 seconds for Transformer-PSM, while GPT-2 with a KV cache climbs from about 0.002 seconds at the start to around 0.04 seconds at the end of the stream.
What it is good at, and what it is not
The results paint a specific picture of the tradeoff:
- Strong length generalization on algorithmic tasks. The scan structure appears to give the model an inductive bias that helps it extrapolate on state tracking, one of the hardest theoretical benchmarks.
- Transformer-quality associative recall. Unlike Mamba-style models, it does not lose the ability to look up arbitrary key-value pairs.
- Log-memory streaming inference. Per-token cost stays roughly flat regardless of context length, unlike a transformer's growing KV cache.
- Not yet a large-scale model. All experiments were run on a single V100 GPU with small architectures. The 130M-parameter Mamba and small GPT-2 baselines are the ceiling here, not modern frontier models.
- Chunk size is a real tradeoff. Larger chunks recover transformer-level quality but reintroduce quadratic cost within a chunk, so you cannot get language-modeling perplexity for free.
Why this is more than a taxonomy paper
The headline result is a unified view of Mamba, GLA, and friends, but the real breakthrough is the demonstration that non-associative aggregators can be scanned efficiently at inference with only logarithmic extra memory. That opens a design space where softmax attention, or any other non-associative token-mixing block, can be dropped into the scan and still yield a streaming-friendly model.
Concurrent work on log-linear attention by Guo et al. arrived at a related conclusion from a different direction, and the paper positions PSMs as a strict generalization that subsumes it. Together, these results suggest that log-memory streaming is becoming the natural sweet spot between constant-memory SSMs and linear-memory transformers.
The code for the experiments is released at github.com/muherng/hidden, along with instructions for reproducing the S5, MQAR, and WikiText-103 runs. For anyone working on long-context architectures, the more useful takeaway may be the framework itself: any binary operator with a well-defined identity is a candidate aggregator, and the online binary-counter scan gives you a streaming inference procedure almost for free.