Hybrid Models & the Limits of Fixed-Size Memory
Why recall needs attention, and architectures that mix it with recurrence.
A transformer generating its 100,000th token consults a cache of 100,000 keys and values. A state space model consults a state of fixed size, the same at token 10 as at token 10 million. That difference has a price, and theorems can measure it: a fixed state cannot copy or recall beyond its capacity, and trained models fall short of even that. This lesson proves the limits, shows them in trained models, and examines the hybrids that keep a little attention to pay for them.
What you’ll learn
- Compare the inference memory of a KV cache with that of a fixed recurrent state, and state the trade-off between state size and recall.
- Prove that a model with a state of bits fails to copy uniformly random strings of more than about tokens, and sketch why two attention layers copy strings exponentially long in their width.
- Define multi-query associative recall, derive the linear-in- lower bound on state size for exact recall, and connect recall to the perplexity gap between attention and efficient models.
- Describe hybrid architectures (Griffin, Jamba, Mamba-2-Hybrid), what controlled comparisons show about how much attention they need, and what remains open, including state tracking.
Two kinds of memory
To generate token , a transformer reads its KV cache: the keys and values of all earlier tokens in every layer. Its memory and its cost per token grow with . A recurrent model (an LSTM, a state space model, linear attention) compresses the past into a state whose size is fixed in advance, so each token costs the same and memory never grows. Linear attention, for instance, keeps a matrix and reads , and delta-rule variants overwrite old associations instead of adding to them (Fast Weights & Test-Time Memory). For this lesson they are all the same kind of object: a fixed-size summary updated token by token.
A transformer has 32 layers of width 4,096 and stores keys and values in 2-byte floats, with no sharing of keys and values across heads. How many gigabytes does its KV cache need for a context of 100,000 tokens?
Show the answer
52.4 GB
Per token: bytes bytes, about MB; times tokens, about GB. A Mamba-style model with 64 blocks of inner width 8,192 and state size 16 keeps about million state numbers, plus small convolution buffers: roughly 20 MB in the same 2-byte floats, at any context length.
The same arithmetic appears in Jamba's report (Lieber et al., 2024): at a context of 256,000 tokens in 16-bit precision, a 7-billion-parameter transformer (Llama-2) needs a 128 GB cache, while Jamba, with attention in one layer out of eight, needs 4 GB. The question is what the fixed state gives up. Arora, Eyuboglu, Zhang et al. (2024) measured it by plotting models' state size against their accuracy at recalling information from the context: the models fall along a trade-off curve, with attention at one end (largest state, best recall) and small recurrent states at the other.
Copying needs memory
The copy task feeds , with drawn uniformly from (write ), and asks for back. It is the simplest task in which the answer is the whole input.
After reading the model's entire future output is a function of its state , since no further input arrives. So at most distinct output strings are possible, each correct for at most one input, and the inputs are equally likely:
If , then and the error exceeds one half. The bound is information-theoretic, so it holds however the model was trained and however expensive its update is.
For (b), the transformer copies by lookup, like an induction head generalized to -grams. The first layer hashes each window of tokens into a key at its position; the second, given the last tokens produced, attends to the earlier position holding the same -gram and outputs the token that followed it. It errs only if some -gram occurs twice, and for uniform strings a union bound over pairs of positions gives
The transformer's parameters grow only logarithmically in , while its cache grows linearly, bits, which (a) shows is optimal up to logarithmic factors. Copying is cheap for attention because the input is kept and searched, not compressed.
A recurrent model's state can take distinct values. It must copy uniformly random bit strings (). From which length on does the theorem guarantee an error above ?
- , since the state has 32-bit numbers
- Never: copying needs no memory if the model is deep enough
Show the answer
B.
bits, and the condition holds for . Up to that length the counting bound allows success; real models fall short much earlier, as the experiments show.
The counting bound alone is loose: a large model's state could, in principle, hold millions of tokens. The experiments show that trained models fall far short of it. At about 160 million parameters, transformers learned to copy with far fewer training examples than state space models, generalized far better to strings longer than those seen in training, and, as tests on strings with deliberately repeated -grams showed, copied by -gram lookup much as in the construction. Among pretrained models evaluated without fine-tuning, Pythia transformers retrieved a phone number from a "phone book" in their context much more reliably than Mamba models of the same sizes, although the Mamba models had lower perplexity (Jelassi et al., 2024). Good average prediction and exact retrieval are different skills.
Associative recall: where the gap in perplexity comes from
Copying an entire input is extreme; language needs something milder but constant, recalling what was said earlier. Zoology (Arora, Eyuboglu, Timalsina et al., 2024) pretrained 17 language models with 70 million to 1.4 billion parameters and found gated-convolution models (H3, Hyena, RWKV) up to 2.1 perplexity points behind attention on the Pile. By their measure 82% of that gap came from tokens predictable by recalling an association made earlier in the same context ("Hakuna Matata means no worries … Hakuna Matata, it means no" → "worries"). On such tokens a 70-million-parameter attention model beat a 1.4-billion-parameter gated-convolution model.
In Zoology's two-layer experiments, attention solved MQAR at every sequence length with width 64, whereas gated convolutions reached accuracy above 0.9 only when their width was at least the sequence length. Attention can recall at constant width because its cache holds every pair and one head can match a query to its key, the induction-head mechanism of Pointer, Copy & Monotonic Attention. A recurrent model must instead have written every pair that might be queried into its state before any query arrives, and that costs bits:
Take pairs with distinct keys, each value drawn independently from symbols, followed by one query for each key, so . After the last pair, every later output depends on the pairs only through the state at that boundary.
Two different assignments of values demand different answers to the same queries, so they must lead to different boundary states. The map from the assignments to states is injective:
A transformer pays the same bits, but in a cache that grows with the input rather than a state fixed in advance. Exact recall from contexts of unbounded length is therefore impossible for any fixed-state model; what designs can change is how close to the bound they come and how gracefully they degrade.
Arora et al. built Based to sit on the trade-off deliberately: linear attention, whose state size is set by its feature dimension, plus exact attention over a short sliding window. Varying the two traces the curve from small states to attention-like recall. At 1.3 billion parameters Based matched Mamba's perplexity and scored about 10 points higher on recall-intensive tasks.
State tracking is a different limit. Recurrence seems made for following a changing state, such as pieces on a chessboard or variables in a program. Yet Merrill, Petty and Sabharwal (2024) showed that S4, Mamba and similar models with logarithmic precision lie in the circuit class , as transformers do, so they cannot compose permutations of five elements, an -complete problem, unless , which is widely believed false. Nonnegative transitions are part of the cause: such linear recurrences cannot recognize parity at arbitrary lengths with finite precision (Sarrof, Veitsman & Hahn, 2024), and allowing negative eigenvalues restores it (Grazzi et al., 2025). What Recurrent Networks Can Compute has more.
Hybrids: a little attention, a lot of recurrence
If a little attention buys lookup, mix it in. A hybrid architecture interleaves a few attention layers, global or within a sliding window, with recurrent or state space layers. Griffin (De et al., 2024) uses a gated linear recurrence, the RG-LRU, whose gates depend on the input but not on the state, so it can be computed with a scan:
| Model | Mix | What the authors report |
|---|---|---|
| Griffin (De et al., 2024) | 2 RG-LRU blocks : 1 local attention block | matched Llama-2's reported performance despite training on over 6 times fewer tokens; extrapolated to longer inputs; but Griffin and Hawk did worse than transformers at copying and exact retrieval when pretrained models were evaluated without fine-tuning |
| Jamba (Lieber et al., 2024) | 1 attention : 7 Mamba layers, mixture of experts every other layer | 52 billion parameters, 12 billion active; contexts of 256,000 tokens with a 4 GB cache; pure Mamba failed to follow few-shot formats that the hybrid followed, and, as anecdotal evidence of an induction mechanism, heads in the hybrid's attention layers attended to the labels of the few-shot examples |
| Mamba-2-Hybrid (Waleffe et al., 2024) | 43% Mamba-2, 7% attention, 50% MLP layers | at 8 billion parameters and 3.5 trillion tokens, beat a matched transformer on all 12 standard tasks (2.65 points on average) and was predicted to generate up to 8 times faster; pure Mamba and Mamba-2 lagged on 5-shot MMLU, phone-book lookup and long-context reasoning |
The controlled comparison of Waleffe et al. is among the cleanest evidence available: the same data, the same budget, the same evaluation. It agrees with the theory of the previous steps. Pure state space models are competitive on tasks that reward good average prediction and fall behind where exact recall from context is needed, and a small fraction of attention layers (7% in their hybrid) closed that gap while keeping most of the inference savings.
Key takeaways
- A KV cache grows with the context (about 0.5 MB per token for 32 layers of width 4,096 in 16-bit), while a recurrent state is fixed (tens of megabytes for a large SSM); recall ability tracks state size along a trade-off curve.
- A model with a -bit state copies uniformly random strings with error above once , whatever its training; two attention layers copy strings exponentially long in their width by -gram lookup, using a cache that is optimal up to logarithmic factors.
- Exact multi-query recall needs bits of state; recall explains most of the perplexity gap between gated convolutions and attention (82% in Zoology), and trained fixed-state models fall short of even the information-theoretic capacity.
- Common SSMs, like transformers, lie in and cannot track permutations unless ; at finite precision, nonnegative transitions cannot even recognize parity at arbitrary lengths.
- Hybrids keep a few attention layers among many recurrent ones (Griffin, Jamba, Mamba-2-Hybrid); in a controlled comparison about 7% attention layers closed the recall gap while keeping most of the inference savings.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
As the context grows from 1,000 to 1,000,000 tokens, how do the inference memories of a transformer's KV cache and of a state space model's state change?
- Both stay constant
- Both grow linearly
- The KV cache grows linearly with the context; the state stays the same size
- The state grows linearly; the KV cache stays the same size
Show the answer
C. The KV cache grows linearly with the context; the state stays the same size
The cache stores keys and values for every earlier token in every layer, so it grows 1,000-fold; the recurrent state is fixed by the architecture. That is the efficiency of recurrence, and also the reason for its recall limits.
A causal recurrent model reads key–value pairs, with values drawn uniformly from symbols, and must then answer one query per key, all correctly. How many bits must its state hold at the boundary between pairs and queries?
- At least
- At least , enough to index the pairs
- A constant independent of , if the model is large enough
- At least , one bit per pair
Show the answer
A. At least
Different value assignments require different answers to the same queries, and the answers depend on the pairs only through the boundary state, so the assignments need distinct states: bits.
What makes multi-query associative recall (MQAR) a better probe of language models than single-query recall with a small vocabulary?
- It requires copying the entire input
- It requires arithmetic on the values
- It requires many recalls in one pass, at arbitrary positions, with more distinct tokens than the model has dimensions
- It requires positional encodings that extrapolate
Show the answer
C. It requires many recalls in one pass, at arbitrary positions, with more distinct tokens than the model has dimensions
Gated convolutions could solve single-query recall with tiny vocabularies, yet still lost to attention on real text. MQAR's many queries and large vocabulary force a model to keep many associations available at once, which exposes the state-size limit and matches the recall failures found in the Pile.
In Waleffe et al.'s controlled comparison at 8 billion parameters, what distinguished the Mamba-2-Hybrid from the pure Mamba-2 model?
- It replaced every Mamba-2 layer with attention
- About 7% of its layers were attention, and it beat the matched transformer on all 12 standard tasks, where pure Mamba-2 lagged on tasks such as 5-shot MMLU and phone-book lookup
- It was trained on six times fewer tokens
- It used local attention only, with a window of 1,024 tokens
Show the answer
B. About 7% of its layers were attention, and it beat the matched transformer on all 12 standard tasks, where pure Mamba-2 lagged on tasks such as 5-shot MMLU and phone-book lookup
The hybrid kept mostly Mamba-2 and MLP layers (43% and 50%) and added a few global attention layers (7%). That small amount of lookup closed the recall gap and was still predicted to generate up to 8 times faster than the transformer.
Further reading
- S. Jelassi, D. Brandfonbrener, S. M. Kakade & E. Malach, "Repeat after me: Transformers are better than state space models at copying," ICML (2024).
- S. Arora, S. Eyuboglu, A. Timalsina, I. Johnson, M. Poli, J. Zou, A. Rudra & C. Ré, "Zoology: Measuring and improving recall in efficient language models," ICLR (2024).
- S. Arora, S. Eyuboglu, M. Zhang, A. Timalsina, S. Alberti, D. Zinsley, J. Zou, A. Rudra & C. Ré, "Simple linear attention language models balance the recall-throughput tradeoff," ICML (2024).
- W. Merrill, J. Petty & A. Sabharwal, "The illusion of state in state-space models," ICML (2024).
- S. De, S. L. Smith, A. Fernando, A. Botev et al., "Griffin: Mixing gated linear recurrences with local attention for efficient language models," arXiv:2402.19427 (2024).
- O. Lieber, B. Lenz, H. Bata, G. Cohen et al., "Jamba: A hybrid Transformer-Mamba language model," arXiv:2403.19887 (2024).
- R. Waleffe, W. Byeon, D. Riach et al., "An empirical study of Mamba-based language models," arXiv:2406.07887 (2024).