LAYOUTS = {'linear': 'GGGG', 'attention': 'AAAA', 'hybrid': 'GGAG'}Dive into Deep Learning · §12.7
Hybrid Architectures
what a fixed state cannot do · only attention pays rent · one layer rescues recall · the shipped recipes
Five upgrades this chapter — gate, linearize, select, edit, learn — and none changed the state’s size.
Measured: a 410M transformer beats a 2.8B Mamba on phone-book lookup past ~70 entries.
Where the wall bites in real text (Zoology, Arora et al. 2024):
Production symptom: fuzzy recall — MMLU 29 vs 46 at matched 8B; ablate a hybrid’s few attention layers and needle-in-a-haystack drops to ~0.
Per layer, at production width (16-bit):
The hybrid’s bill = attention fraction × the transformer’s.
| model | KV cache |
|---|---|
| Llama-2-70B-class | 128 GB |
| Mixtral | 32 GB |
| Jamba (4 attn of 32 layers) | 4 GB |
Recurrence removes the growing term; the constant state can still be quantized, but nothing grows. The surviving attention cache takes GQA / MLA / quantization on top.
Same depth, width, heads, MLPs, embeddings — only the mixer string differs:
'G' = ScalarGatedMixer: scalar-per-head decay, Mamba-2’s rung of the decay ladder (not GLA’s per-coordinate gate), trained via the quadratic dual.'A' = the causal attention of ch. 11, through d2l.TransformerBlock’s attn_factory hook.A fresh gate must retain. Default init → a \approx 0.5: state half-life of one token, chance recall at every load. Bias -4.5 → a \approx 0.99. (S4D, Mamba, Gated DeltaNet all ship this trick.)
Mask before exp. The dual’s \exp(\textrm{cum}_i - \textrm{cum}_j) is large and positive above the diagonal; trained decays → 0 make it overflow: inf * 0 = nan. Mask with -\infty in log space first — only the LM panel triggers it, never the recall task.
Normalize the read-out. \mathbf{S}^\top \mathbf{q} grows with what the state has accumulated (\sqrt{T} at init); per-head RMSNorm before W_o, or the recurrent blocks flood the residual stream and the attention layer downstream never sees the tokens.
Same three stacks as character LMs on The Time Machine:
model val loss bits/char
linear 1.76 2.54
attention 1.84 2.66
hybrid 1.77 2.55
Recalls like attention, pays like recurrence, plus a quarter of the rent.
AI21 tested Mamba-2 in Jamba — the better standalone model — and rejected it.
Judge the recurrent half in the presence of the attention half; where quality saturates, economics decides.
| model | layers | attention | recurrence | context |
|---|---|---|---|---|
| Jamba | 32 | 4 full, GQA | Mamba-1 | 256K |
| Nemotron-H | 52 | 4 full, GQA | Mamba-2 | 8K |
| Granite 4.0-H | 40 | 4 full, NoPE | Mamba-2 | 128K |
| Qwen3-Next | 48 | 12, GQA 16{:}2 | gated DeltaNet | 262K |
| Kimi Linear | 27 | 7 MLA, NoPE | KDA | 1M |
Every row: evenly spread, none first; the surviving attention wears every compression of ch. 11.
Duality is exact for linear attention only; softmax attention is not a recurrence in disguise. Conversion is a learned approximation:
Per layer: decode work / persistent state / training depth / exact?
| architecture | decode | state | depth | exact? |
|---|---|---|---|---|
| LSTM/GRU | O(d^2) | O(d) | T | no parallel form |
| S4D, Mamba-1 | O(dN) | dN | O(\log T) | yes |
| SSD / GLA / DeltaNet | O(h d_k d_v) | h d_k d_v | T/C | yes |
| softmax attention | O(td) ↑ | 2td ↑ | O(1) | by definition |
| 1-in-4 hybrid | mix | const + cache/4 | mix | per component |
The fixed state lost exact recall (a counting bound, plus our measured collapse) and won the economics (by a factor that grows with context). Production stopped choosing. Kernels → Computational Performance; pretrained stacks → the Language Models part.