LAYOUTS = {'linear': 'GGGG', 'attention': 'AAAA', 'hybrid': 'GGAG'}Dive into Deep Learning · §12.7
Hybrid Architectures
fixed-state capacity · attention-cache growth · recall with one attention layer · deployed configurations
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 cache equals the attention fraction times the transformer cache.
| 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; otherwise, recurrent-block outputs dominate the residual stream before it reaches the downstream attention layer.
Same three stacks as character LMs on The Time Machine:
model val loss bits/char
linear 1.78 2.57
attention 1.83 2.65
hybrid 1.76 2.54
The hybrid matches attention recall while retaining one quarter of the attention stack’s context-dependent state.
AI21 tested Mamba-2 in Jamba — the better standalone model — and rejected it.
Evaluate the recurrent component together with the attention component. Once quality saturates, choose the less expensive configuration.
| 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.