Hybrid Architectures

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

Why Every Fixed-Size State Hits an In-Context Ceiling

Motivation

  • Pre-Query Compression Limit: A fixed recurrent state \mathbf{S}_t must compress all 64 prompt pairs before knowing which 20 keys will be queried.
  • Post-Query Attention Lookup: Full attention retains the raw KV table for exact random access at O(T) memory cost.
  • The Hybrid Principle: Interleave 1 sparse attention layer per 3–7 recurrent layers.

Limit 1: The Information-Theoretic Bit-Counting Bound

Pigeonhole Capacity Limit

M b \ge k \log_2 V \implies k_{\max} \le \frac{M b}{\log_2 V}

  • Abundant Raw Bits: Our 2-layer 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).
  • Linear-Algebraic Bottleneck: Matrix memories saturate rank d_k long before exhausting raw float bits.

Limit 2: Linear Independence and Welch’s Overlap Bound

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)

  • Rank-d_k Gram Deficit: \mathbf{G} = \sum_{i=1}^m \mathbf{k}_i \mathbf{k}_i^\top \in \mathbb{R}^{d_k \times d_k} has trace m and rank \le d_k, so Cauchy–Schwarz forces \|\mathbf{G}\|_F^2 \ge m^2 / d_k.
  • Universal Linear Floor: Applies to every linear matrix readout \mathbf{y} = \mathbf{S}\mathbf{q} (GLA, DeltaNet, Longhorn).

What Welch’s Bound Predicts for Trained Key Embeddings

Theory to Experiment

  • At d_k = 4, m = 64: Welch’s lower bound (0.2381) is 95.2\% of random overlap (1/4 = 0.2500), leaving gradient descent almost zero room to reduce cross-talk.
  • At d_k = 16, m = 64: Welch’s bound drops 5\times to 0.0476, predicting a 4\times capacity jump when head width quadruples at fixed model width d = 32.

Four 2-Block Architectures on Associative Recall

Controlled Experimental Design

  • Four Matched 2-Block Stacks (d = 32):
    1. GG (8 heads of 4 \times 4 = 128 floats/layer).
    2. GG, 4x state (2 heads of 16 \times 16 = 512 floats/layer, same params).
    3. AA (2 full causal attention layers).
    4. GA hybrid (GatedDeltaNet \to Attention, 50\% KV cache).

Multi-Query Associative Recall: 4 to 64 Key–Value Pairs

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

1 Attention Layer Lifts the Ceiling; 4x State Shifts It

Interpreting the Recall Sweep

  • 4× State Scaling (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.
  • Why Short Conv Matters: Adjacent tokens (k_i, v_i) require width-4 causal convolution so step t’s outer product \mathbf{v}_t \mathbf{k}_t^\top binds both tokens together.

Why the Width-4 Causal Convolution Is Essential

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
  • Why 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.
  • Width-4 causal convolution bridges adjacent tokens: Mixing 4 consecutive steps into (\mathbf{Q}, \mathbf{K}, \mathbf{V}) lets step t extract \mathbf{k}_t from position t-1 and \mathbf{v}_t from position t in a single outer-product write.

WikiText-103 Bytes: GGGG, GGGA Hybrid, and Attention

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

Loss by Position on 1,024-Byte Windows

Longer Context Separates the Memories

  • Setup: Batch 8 \times 1{,}024-byte windows for 8{,}000 steps (same bytes/step), averaged over two runs by position band [a, 2a).
  • Fixed states flatten: GRU leads up to byte 127, while both GRU and GGGG gain only \approx 0.03 past byte 128.
  • Hybrid keeps falling: Matches GGGG early, then leads it by \approx 0.05 and GRU by \approx 0.02 at bytes 512–1{,}023.
  • Attention: Reaches 1.03–1.04 in the final band once an induction head forms (roughly 1 in 5 runs stalls near 1.10, lifting the mean).

Pitfall: Short-Window Loss Masks Retrieval Deficits

Benchmarking Insight

  • Short-Window Loss (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.
  • Long-Range 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.

Inference Memory Scaling: GQA Cache vs. Fixed State

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}
  • Crossover at 512 tokens: By T = 128\text{K} tokens, a single GQA layer’s KV cache is 256\times larger than a recurrent matrix state (512\text{ MB} vs. 2\text{ MB}).

KV Cache Savings in Frontier Hybrid Architectures

32-Layer Memory Scaling

  • 32-layer Transformer at 256\text{K} tokens: 32 \times 1\text{ GB} = \mathbf{32\text{ GB}} of KV cache per sequence.
  • 1-in-8 Hybrid (Jamba, 4 attention + 28 Mamba layers): 4 \times 1\text{ GB} + 28 \times 2\text{ MB} \approx \mathbf{4.06\text{ GB}} (8\times reduction).
  • 1-in-4 Hybrid (Qwen3-Next & Kimi Linear, 3:1 Gated DeltaNet + Attention): Cuts KV cache by 4\times while retaining full in-context retrieval.

Master Comparison of Chapter 12 Sequence Mixers (1/2)

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})

Master Comparison of Chapter 12 Sequence Mixers (2/2)

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})

When to Choose Which Sequence Architecture

Design Guidelines

  • Unbounded Streaming & Edge (Mamba / S4D / GRU): Best for audio, robotics, and sensor streams requiring strictly constant O(1) memory and latency per step.
  • Long-Context Foundation Models (3:1 or 7:1 Hybrid): Interleaving chunked GatedDeltaNet / Mamba-2 with sparse GQA layers delivers fast prefill, 4\times–8\times smaller KV caches, and 100\% exact retrieval.

Concept Check: Welch’s Bound and Hybrid Memory

Check Your Understanding

Work out these three capstone calculations:

  1. According to Welch’s bound, what is the minimum possible average squared inner product among m = 33 unit keys in a head of dimension d_k = 8 versus random unit keys?
  2. An 80\text{ GB} GPU holds 16\text{ GB} of model weights, leaving 64\text{ GB} for inference caches. At T = 128\text{K} tokens (512\text{ MB} per GQA layer, 2\text{ MB} per recurrent layer), how many concurrent 128\text{K}-token sequences can a 32-layer Transformer serve versus a 32-layer hybrid with 4 attention layers?
  3. Why does a 1-layer matrix memory with conv_width=1 fail when keys and values arrive on consecutive tokens (t-1, t)?

Answers:

  1. Welch floor: \frac{33 - 8}{8 \times (33 - 1)} = \frac{25}{256} \approx \mathbf{0.0977} (compared to 1/8 = \mathbf{0.1250} for random unit keys).
  2. 32-layer Transformer: 32 \times 0.5\text{ GB} = 16\text{ GB/seq} \implies 64 / 16 = \mathbf{4\text{ sequences}}. 32-layer Hybrid (4 attention + 28 recurrent): 4 \times 512\text{ MB} + 28 \times 2\text{ MB} \approx 2.10\text{ GB/seq} \implies \lfloor 64 / 2.10 \rfloor = \mathbf{30\text{ sequences}} (7.5\times higher serving concurrency).
  3. With 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.

Summary: Hybrid Architectures and Fixed-State Limits

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