Dive into Deep Learning · §12.8
Hybrid Architectures: Combining Recurrence with Global Attention
information & Welch capacity bounds · Gated DeltaNet + attention hybrids · local convolution binding · KV-cache scaling
Motivation
Pigeonhole Capacity Limit
M b \ge k \log_2 V \implies k_{\max} \le \frac{M b}{\log_2 V}
GG model (8 heads of 4 \times 4) holds 8{,}192 float32 bits, whereas 64 four-valued answers carry just 128 bits (>30\times smaller).Geometric Capacity Limit
\operatorname{mean}_{i \neq j}\,(\mathbf{k}_i^\top \mathbf{k}_j)^2 \ge \frac{m - d_k}{d_k\,(m - 1)} \quad (m > d_k)
GLA, DeltaNet, Longhorn).Theory to Experiment
Controlled Experimental Design
GG (8 heads of 4 \times 4 = 128 floats/layer).GG, 4x state (2 heads of 16 \times 16 = 512 floats/layer, same params).AA (2 full causal attention layers).GA hybrid (GatedDeltaNet \to Attention, 50\% KV cache).Recall Sweep Results
Mean recall across two training runs (2{,}000 AdamW updates cycling across pair loads n \in \{4, 8, 16, 32, 64\}; chance = 0.25):
pairs 4 8 16 32 64
Gated DeltaNet 1.00/0.99 0.98/0.94 0.87/0.82 0.70/0.64 0.56/0.51
attention 1.00/1.00 1.00/1.00 1.00/1.00 1.00/1.00 1.00/1.00
hybrid 1.00/1.00 1.00/1.00 1.00/1.00 1.00/1.00 1.00/1.00
Gated DeltaNet, 4x state 1.00/1.00 1.00/1.00 1.00/1.00 1.00/0.99 0.97/0.97
Interpreting the Recall Sweep
GG vs. GG, 4x state): Quadrupling head entries from 128 to 512 floats/layer lifts 64-pair recall from \approx 0.5 to between 0.8 and 1.0 at equal parameter count.Local Token Binding Ablation
What happens if we remove the width-4 depthwise causal convolution in front of GatedDeltaNet by setting conv_width=1?
pairs 4 8 16 32 64
Gated DeltaNet 1.00/0.99 0.98/0.94 0.87/0.82 0.70/0.64 0.56/0.51
without the convolution 0.81/0.84 0.64/0.69 0.51/0.55 0.42/0.45 0.36/0.38
conv_width=1 fails even at 4 pairs: In our sequence format, key token k_i arrives at step t - 1 and its value token v_i arrives at step t. Without local receptive-field mixing (conv_width=1), step t’s linear projections (\mathbf{k}_t, \mathbf{v}_t) see only the value token v_i and cannot bind it to the preceding key token k_i inside a single layer.Language Modeling Benchmark
Comparing 4-block width-256 Gated DeltaNet (GGGG), a 3-to-1 hybrid (GGGA, attention in block 4), pure causal attention (AAAA), and attention behind the same width-4 causal convolution (CCCC) on 128-byte WikiText-103 windows, trained for 8{,}000 steps:
validation 0-15 16-63 64-127 ms/step
Gated DeltaNet 3,573,536 1.161/1.158 1.397/1.399 1.132/1.128 1.124/1.120 48/50
hybrid 3,501,848 1.153/1.154 1.399/1.398 1.123/1.124 1.114/1.114 44/43
attention 3,286,784 1.182/1.185 1.410/1.412 1.152/1.155 1.146/1.151 21/21
attention, conv 3,302,144 1.150/1.154 1.397/1.397 1.121/1.124 1.110/1.116 26/26
Longer Context Separates the Memories
GRU leads up to byte 127, while both GRU and GGGG gain only \approx 0.03 past byte 128.GGGG early, then leads it by \approx 0.05 and GRU by \approx 0.02 at bytes 512–1{,}023.Benchmarking Insight
T = 128, 8{,}000 steps): GGGG (\approx 1.16 nats/byte), GGGA and attention with the convolution (both \approx 1.15) finish together; plain AAAA trails at 1.18 only for lack of local mixing. The loss barely changes after byte 16 and says nothing about recall.m = 64 pairs, 2 blocks): GG (d_k = 4) saturates at \approx 50\%, whereas the hybrid GA achieves 100\% recall. On 1{,}024-byte windows the 3:1 GGGA (1.07–1.08 nats/byte) leads GGGG (1.11–1.12) at 25\% of the KV cache.Serving & Generation Footprint
During autoregressive decoding at scale (16-bit float16 / bfloat16), per-sequence memory determines maximum batch size and memory-bandwidth latency:
| Layer Type (Width d = 4{,}096, 16-bit Floats) | Per-Layer Memory Formula | At T = 512 | At T = 128\text{K} | At T = 256\text{K} |
|---|---|---|---|---|
| Grouped-Query Attention (8 KV heads \times 128) | 2 \times 8 \times 128 \times 2\text{ B} \times T = 4\text{ KB} \times T | 2\text{ MB} | 512\text{ MB} | 1{,}024\text{ MB} |
| Mamba-2 / Gated DeltaNet (8{,}192 \times 128 state) | 8{,}192 \times 128 \times 2\text{ B} = \mathbf{2\text{ MB}} | 2\text{ MB} | 2\text{ MB} | 2\text{ MB} |
32-Layer Memory Scaling
Architectural Synthesis
| Sequence Mixer | Generation State / Layer | Parallel Training Method | Key Synthetic Benchmark Result | WikiText-103 (d=256) |
|---|---|---|---|---|
| LSTM / GRU (§12.1) | 2d / d | Sequential (T steps) | 1.00 at T=200 recall with +5 keep-gate bias | 1.29–1.30 (4.3\text{M} / 3.8\text{M}) |
| minGRU (§12.3) | d | Associative scan | 1.00 at T=1000 recall with S4D timescales | 1.34–1.35 (2.8\text{M}) |
| S4D (§12.4) | dN | FFT conv or scan | 1.00 at T=1000 fixed delay; \le 0.20 selective copy | — |
| Mamba (§12.5) | HN (H=2d) | Scan + adjoint scan | 0.98+ on 1{,}024-step selective copying | 1.30 (4.0\text{M}) |
Architectural Synthesis
| Sequence Mixer | Generation State / Layer | Parallel Training Method | Key Synthetic Benchmark Result | WikiText-103 (d=256) |
|---|---|---|---|---|
| Gated Linear Attn (§12.6) | d^2 / h | Chunked GEMM + scan | Recall scales \propto d^2/h; superposes rebound keys | — |
| Gated DeltaNet (§12.7) | d^2 / h | Chunked solve + scan | 0.96+ on short-gap rebound keys; saturates at n \gg d_k | 1.16 at 8{,}000 steps (3.6\text{M}) |
| Causal Attention | 2dT | Flash / fused GEMMs | 1.00 at all pair loads; O(T^2) compute & O(T) cache | 1.38–1.39; at 8{,}000 steps 1.18, 1.15 with conv (3.3\text{M}) |
Hybrid (GA / GGGA, §12.8) |
Fixed states + sparse 2dT | Chunked + attention | 1.00 at all pair loads with 4\times–8\times smaller cache | 1.15 at 8{,}000 steps (3.5\text{M}) |
Design Guidelines
Mamba / S4D / GRU): Best for audio, robotics, and sensor streams requiring strictly constant O(1) memory and latency per step.GatedDeltaNet / Mamba-2 with sparse GQA layers delivers fast prefill, 4\times–8\times smaller KV caches, and 100\% exact retrieval.Check Your Understanding
Work out these three capstone calculations:
conv_width=1 fail when keys and values arrive on consecutive tokens (t-1, t)?Answers:
conv_width=1, \mathbf{k}_t and \mathbf{v}_t at step t are functions of x_t (the value token) alone, so \mathbf{v}_t \mathbf{k}_t^\top never sees the key token x_{t-1}; a width-4 causal convolution mixes (x_{t-1}, x_t) into the same step.Key Takeaways
| Principle / Component | Mathematical / Architectural Result | Practical Implication |
|---|---|---|
| Bit-Counting Bound | M b \ge k \log_2 V \implies k_{\max} = O(M) | Fixed-state recall capacity is independent of context length T |
| Welch’s Overlap Bound | \operatorname{mean}_{i \neq j}(\mathbf{k}_i^\top \mathbf{k}_j)^2 \ge \frac{m - d_k}{d_k(m - 1)} for m > d_k | Linear matrix readout degrades once stored keys outnumber head width d_k |
| State Width Scaling | h heads of d_h \times d_h hold d \cdot d_h entries | Quadrupling head dimension d_h at fixed width d quadruples pair recall capacity |
| Short Causal Convolution | Width-4 depthwise causal Conv1d before QKV |
Essential for binding adjacent key and value tokens into a single matrix write |
| Recurrent–Attention Hybrid | 3:1 or 7:1 GatedDeltaNet / Mamba-2 + GQA |
Restores 100\% associative recall while cutting 128\text{K}–256\text{K} KV caches by 4\times–8\times |