Part IV · Integration Week 14 Published

Hybrid architectures and gating mechanisms

Hybrids read through the two-timescale lens — attention as the boundary layer (exact on fast, token-local structure), the decaying state as the slow manifold (compressed carried context), and composition and gate granularity as the design variables; with the production lineup as of May 2026, the MAD methodology, and the two-timescale benchmark seed for pilot B.

On this page
  1. 14.1 Two limits of sequence modeling
  2. 14.2 The two-timescale lens
  3. 14.3 The composition design space
  4. 14.4 The gating design space
  5. 14.5 The production lineup, as of May 2026
  6. 14.6 MAD and the two-timescale benchmark seed
  7. 14.7 What’s next
  8. 14.8 Exercises
  9. Exercise 14.1 (short)
  10. Exercise 14.2 (short, code)
  11. Exercise 14.3 (short)
  12. Exercise 14.4 (theory) — solution in §14.9
  13. Exercise 14.5 (theory) — solution in §14.9
  14. Exercise 14.6 (theory) — solution in §14.9
  15. 14.9 Full solutions to theory exercises
  16. Solution to Exercise 14.4
  17. Solution to Exercise 14.5
  18. Solution to Exercise 14.6
  19. 14.10 Companion code

Hybrid architectures and gating mechanisms

14.1 Two limits of sequence modeling

Part of this book’s argument has been that attention and state-space models are not rival species but two corners of one family. Chapter 9 made that literal: a selective SSM is a masked linear-attention computation (Theorem 9.5). Chapter 11 priced the recurrent corner: a finite additive state can hold only so many associations before interference swamps retrieval (Proposition 11.4), and Chapter 12’s delta-rule lineage bought back capacity with smarter writes at the cost of a genuine stability analysis (Theorem 12.4). The attention corner has the opposite ledger: retrieval is exact at any range it can see, and the price is a cache that grows linearly with what it has seen.

The trade is not hypothetical; it is the explicit organizing axis of the recall-throughput frontier mapped by Based Arora et al. (2024) : architectures that fix state size give up recall, architectures that keep recall give up the O(1)O(1)-per-token decode that makes long generation cheap. Pure designs sit at the frontier’s ends. The production systems of §14.5 sit deliberately in the middle, and the question this chapter equips you to ask is why the middle is the right place — not as an engineering compromise but as a statement about the sequences being modeled.

The statement is statistical. Real token streams mix two kinds of structure: fast, token-local dependence — syntax, local copying, the bigram-scale texture a short context pins down — and slow latent structure — topic, style, the document-level regime that changes rarely but conditions everything. (This decomposition-by-capability is also field practice: it is the premise of the synthetic-probe methodology of Poli et al. (2024) and Arora et al. (2024) that §14.6 takes up.) A layer that is exact over a short window serves the first; a compressed state that persists serves the second. Neither serves both: the window forgets the regime the moment it scrolls past the evidence, and the compressed state cannot reproduce exact local interactions it never stored. That intuition — two statistical timescales, two architectural resources — is the chapter’s lens. The next section gives it a theorem in the continuous prototype, and §14.6 an exactly computable discrete counterpart.

14.2 The two-timescale lens

The continuous prototype for “fast and slow living together” is a singularly perturbed linear system: a slow variable xx and a fast variable yy whose own dynamics relax on a timescale ε1\varepsilon \ll 1,

x˙  =  Ax+By,εy˙  =  Cx+Dy,\dot{x} \;=\; A x + B y, \qquad \varepsilon\,\dot{y} \;=\; C x + D y ,

with DD Hurwitz (every eigenvalue in the open left half-plane — a stable fast subsystem, the timescale separation that defines the stiff regime Chapter 6 tamed with implicit methods; Proposition 6.1). Setting ε=0\varepsilon = 0 formally gives y=D1Cxy = -D^{-1}C x: the slow manifold, the surface on which the fast variable has equilibrated to whatever the slow variable is doing. What happens off the surface is the boundary layer: a transient, of duration O(ε)O(\varepsilon), in which yy collapses onto the manifold.

Theorem 14.1 (Slow-manifold tracking, linear fast–slow systems).

Let x˙=Ax+By\dot{x} = Ax + By, εy˙=Cx+Dy\varepsilon\dot{y} = Cx + Dy with DD Hurwitz, so that eDtMeβt\|e^{Dt}\| \le M e^{-\beta t} for some M1M \ge 1, β>0\beta > 0. Define the deviation from the slow manifold η=y+D1Cx\eta = y + D^{-1}Cx. Then for every fixed horizon TT and every bounded initial condition, as ε0\varepsilon \to 0:

  1. Boundary layer. η(t)Meβt/εη(0)+O(ε)\|\eta(t)\| \le M e^{-\beta t/\varepsilon}\,\|\eta(0)\| + O(\varepsilon) — the fast variable reaches an O(ε)O(\varepsilon) neighbourhood of the manifold in time O(εlog(1/ε))O(\varepsilon\log(1/\varepsilon)).
  2. Reduced dynamics. The slow variable tracks the reduced system x˙r=(ABD1C)xr\dot{x}_r = (A - BD^{-1}C)\,x_r, xr(0)=x(0)x_r(0) = x(0), with suptTx(t)xr(t)=O(ε)(1+η(0))\sup_{t \le T}\|x(t) - x_r(t)\| = O(\varepsilon)\,(1 + \|\eta(0)\|).

The proof is a change of variables and one Grönwall estimate. Differentiating η\eta along trajectories,

εη˙  =  εy˙+εD1Cx˙  =  Dη  +  εD1C(Ax+By),\varepsilon\,\dot{\eta} \;=\; \varepsilon\,\dot{y} + \varepsilon\,D^{-1}C\,\dot{x} \;=\; D\eta \;+\; \varepsilon\,D^{-1}C\,(Ax + By),

since Cx+Dy=D(y+D1Cx)=DηCx + Dy = D(y + D^{-1}Cx) = D\eta. The first term contracts at rate β/ε\beta/\varepsilon; the second is a bounded forcing of size O(ε)O(\varepsilon) on bounded trajectories. Variation of constants gives claim 1. For claim 2, substitute y=D1Cx+ηy = -D^{-1}Cx + \eta into the slow equation: x˙=(ABD1C)x+Bη\dot{x} = (A - BD^{-1}C)\,x + B\eta, so the difference e=xxre = x - x_r obeys e˙=(ABD1C)e+Bη\dot{e} = (A - BD^{-1}C)\,e + B\eta with e(0)=0e(0) = 0, and Grönwall bounds e(t)\|e(t)\| by a constant times 0tη\int_0^t \|\eta\|, which claim 1 bounds by Mη(0)ε/β+O(ε)TM\|\eta(0)\|\,\varepsilon/\beta + O(\varepsilon)\,T. Exercise 14.4 carries the scalar case through explicitly; the nonlinear generalization is Tikhonov’s theorem Kokotović et al. (1986) .

The theorem licenses a reading of the hybrid division of labour — the reading Chapter 12’s closing section previewed:

  • Attention is boundary-layer machinery. Within its window it computes pairwise interactions exactly — no compression, no model of how the past decays — which is precisely what fast, token-local structure needs, and exactly what a regime transient needs at the moment the slow context shifts.
  • A decaying state is slow-manifold machinery. It carries a compressed, O(1)O(1)-size summary forward — the manifold parameterization — and its forgetting rate plays the role of the timescale assumption: Chapter 9’s selectivity and Chapter 11’s decay masks (Theorem 11.2) are mechanisms for making that rate fit the data’s slow rate.
  • A hybrid is a matching construction. Sequential stacks, parallel gated blocks, and interleaved layers (§14.3) are different ways of joining the two descriptions — different matching conditions, in the asymptotics vocabulary.

What this lens does and does not claim. The theorem above is a statement about linear fast–slow ODEs, and in §14.6 an exact discrete counterpart is proved for a filtering task. The architectural reading — attention \approx boundary layer, decaying state \approx slow manifold, hybrid \approx matched expansion — is an interpretive map between idealized computations, not a theorem about trained networks: nothing here claims that a trained hybrid implements a matching condition, and no such result exists. The map earns its keep where it is testable: it predicts which restriction fails on which statistics, and §14.6 measures exactly that. Its third leg is weaker, and we say so: the lens supplies the two specialists, not yet a theory of the joint — it does not by itself predict which matching condition (sequential, parallel, gated) wins where. The one careful cross-vendor comparison available — Lee et al.’s finding that sequential hybrids win at short context and parallel hybrids at long context Lee et al. (2025) — is consistent with components that specialize as the map says, and it is precisely the kind of data a theory of the joint would have to explain. Consistency is evidence for a lens, not proof of a mechanism; we will say “the lens predicts,” never “the network performs asymptotic matching.”

14.3 The composition design space

Fix the two primitives the rest of the chapter mixes, in the exact form the companion implements: sliding-window attention — causal softmax attention in which position tt attends to positions tw+1,,tt-w+1, \dots, t — and a gated-decay SSM, the per-channel EMA recurrence

ht  =  gtht1  +  (1gt)xt,gt[0,1]d,h_t \;=\; g_t \odot h_{t-1} \;+\; (1 - g_t) \odot x_t, \qquad g_t \in [0,1]^d,

the diagonal skeleton of Chapter 11’s gated linear attention, kept minimal so that every composition claim below is checkable to machine precision. Three composition patterns cover the production space:

  1. Sequential: one primitive feeds the other within a block, attn(ssm(x))\mathrm{attn}(\mathrm{ssm}(x)) or ssm(attn(x))\mathrm{ssm}(\mathrm{attn}(x)) — the in-series pairing every stacked hybrid uses locally.
  2. Parallel-gated: both read the same input and a gate blends them, gattn(x)+(1g)ssm(x)g \odot \mathrm{attn}(x) + (1-g) \odot \mathrm{ssm}(x) — the Hymba Dong et al. (2024) /GMU-style pattern, and the carrier of §14.4’s granularity question.
  3. Interleaved at ratio r ⁣: ⁣1r\!:\!1: a residual stack in which every (r+1)(r{+}1)-th block is attention and the rest are SSM — the layer-ratio pattern, the design variable Chapter 12 deferred here from Kimi Linear’s 3:1 choice Kimi Team (2025) .

One boundary needs drawing, because the literature cuts this space twice. Sequential here is a within-block statement (primitives composed directly, no residual between them); a repeating block pattern — Griffin’s two recurrent blocks then one local-attention block, Jamba’s one attention block per eight — is an interleave in this vocabulary, whatever its authors call it. Lee et al.’s sequential-vs-parallel dichotomy Lee et al. (2025) is the coarser cut: their “sequential” covers every design in which information passes through the primitives in series — all interleaves included — against parallel-branch designs. We keep the finer three-way split and map their finding onto it where it is used (§14.5).

The companion pins the algebra that makes these well-posed objects of study (measured printouts; the tests pin each identity below 101210^{-12}): the band-masked windowed attention equals its per-position oracle to 4.4×10164.4 \times 10^{-16}; window wLw \ge \seqlen is full causal attention (identical outputs, exactly); under constant input xˉ\bar{x} the EMA matches its closed form ht=(1gt)xˉh_t = (1 - g^t)\bar{x} to 8.9×10168.9 \times 10^{-16}; and the parallel gate’s endpoint reductions are exact — g=1g = 1 returns the attention branch bitwise, g=0g = 0 the SSM branch.

Why does the ratio — rather than, say, the window alone — carry so much design weight? Because decode-time memory is the binding constraint at production context lengths, and the ratio sets it:

Proposition 14.2 (Decode-state accounting).

A stack of nn mixing blocks of width dd, of which nan_a are sliding-window-attention blocks (window ww) and nnan - n_a are gated-decay SSM blocks, carries decode-time state

state(f)  =  na2wd  +  (nna)d  =  nd(1+f(2w1))floats,f=na/n,\mathrm{state}(f) \;=\; n_a \cdot 2wd \;+\; (n - n_a)\,d \;=\; n\,d\,\bigl(1 + f\,(2w - 1)\bigr) \quad \text{floats}, \qquad f = n_a/n,

independent of the sequence length L\seqlen. A pure full-attention stack carries n2Ldn \cdot 2\seqlen d, growing linearly in L\seqlen. Per block, the hybrid budget is linear in the attention fraction ff.

The proof is counting: each attention block holds a rolling w×dw \times d key buffer and a w×dw \times d value buffer; each SSM block holds its dd-float state. The companion refuses to leave it at arithmetic — it materializes the buffers and asserts the formula against their actual sizes. At a production-shaped configuration (n=24n = 24, d=w=1024d = w = 1024), the measured totals are 12,601,34412{,}601{,}344 floats at ratio 3 ⁣: ⁣13\!:\!1 and 6,312,9606{,}312{,}960 at 7 ⁣: ⁣17\!:\!1, against 3,221,225,4723{,}221{,}225{,}472 for full attention at L=65,536\seqlen = 65{,}536 — factors of 255.6255.6 and 510.3510.3.

Log-scale plot of decode state per block in millions of floats versus attention fraction from 0 to 1. A solid curve rises from about a thousand floats at fraction 0 to about 2 million at fraction 1, far below a dashed full-attention reference line at 134 million. Five production models are marked as dots on the curve between fractions 0.085 and 0.5.
The decode-state budget per mixing block as a function of the attention fraction $f$ ($d = w = 1024$), with the full-attention reference at context length $65{,}536$. Production attention fractions, as of May 2026, cluster at the low end: Nemotron-H at $f = 0.085$ ($751.2\times$ below full attention), Bamba $0.094$ ($679.5\times$), Jamba $0.125$ ($510.3\times$), Kimi Linear $0.25$ ($255.6\times$), Samba $0.5$ ($127.9\times$). Curve and points are computed from the same audited cost function. Produced by companions/ch14/jax/hybrid_block.py; the formula is pinned against materialized buffers in tests/test_hybrid_block.py.

Two structural notes close the composition story. First, interleaving is the pattern that preserves trainability: every layer in the stack remains chunkwise-parallelizable — the SSM blocks by Chapter 11’s recurrent↔parallel duality and the delta-rule blocks by the WY machinery of Theorem 12.5 — so the ratio is a pure budget dial, not a training-throughput sacrifice. Second, the window and the ratio are not interchangeable: ww buys reach for the exact path, ff buys how often the exact path appears in depth. The two-timescale lens says their jobs differ in kind — ww must cover the fast structure’s correlation length, while the slow signal needs some carried state at some depth — and §14.6 measures exactly that asymmetry.

14.4 The gating design space

Composition decides where the two paths sit; gating decides, position by position and channel by channel, how much each path contributes. The production designs of §14.5 differ more in their gates than in anything else, and the differences organize cleanly along two axes.

Granularity — what shape the gate is:

Proposition 14.3 (Gate granularity is an expressivity ordering).

Fix the two branch maps and consider parallel-gated blocks y=gattn(x)+(1g)ssm(x)y = g \odot \mathrm{attn}(x) + (1 - g) \odot \mathrm{ssm}(x). The families

Gscalar={g[0,1]}    Gvector={g[0,1]d}    Ginput={g=g(x)[0,1]d}\mathcal{G}_{\mathrm{scalar}} = \{\,g \in [0,1]\,\} \;\subsetneq\; \mathcal{G}_{\mathrm{vector}} = \{\,g \in [0,1]^d\,\} \;\subsetneq\; \mathcal{G}_{\mathrm{input}} = \{\,g = g(x) \in [0,1]^d\,\}

are nested as sets of realizable input–output maps, and each inclusion is strict under its own non-degeneracy condition: the first whenever the branches differ on at least two channels at some input; the second whenever the branches differ at two distinct inputs. Endpoints reduce exactly: g1g \equiv 1 gives the attention branch, g0g \equiv 0 the SSM branch; a {0,1}\{0,1\}-valued vector gate routes each channel to its branch.

The first strictness is a two-line argument: a {0,1}\{0,1\} vector gate that sends channel 11 to attention and channel 22 to the SSM would force a scalar gate to satisfy g=1g = 1 and g=0g = 0 simultaneously wherever the branches disagree on both channels. The second — input-dependent gates are genuinely stronger than constant ones — needs its two-input condition (a constant vector gate can already realize any single-input behaviour) and is Exercise 14.6. Both conditions hold generically for the actual attention/EMA branches. The companion pins the reductions and the channel-routing witness exactly (differences of 0.00.0, not merely small). The lineup also uses one coarser point on the same axis: block granularity, where the “gate” is the structural choice of which block type occupies which position — a {0,1}\{0,1\} routing decision made once, at design time, for a whole block.

The ordering is the cheap part; the design question is where on it to sit. A scalar gate costs one number and one design meeting; a vector gate is Chapter 11’s decay-mask vocabulary (Theorem 11.2) applied to branch mixing; input-conditioned vector gates are exactly the move selective SSMs made in Chapter 9, now steering the blend rather than the state. Production examples, as of May 2026: Nemotron-H mixes with a fixed schedule and no per-channel gate NVIDIA (2025) . Gated DeltaNet’s decay gate is the scalar γt\gamma_t per head Yang et al. (2025) — input-dependent but coarse — and Kimi’s KDA is precisely the per-channel (vector) refinement of it Kimi Team (2025) , the granularity class Griffin’s RG-LRU also occupies De et al. (2024) . SambaY’s Gated Memory Unit is an element-wise (vector) gate whose value is computed from a shared memory stream — input-dependent — while its placement across decoder layers is a fixed structural choice Ren et al. (2025) ; the trigger axis below classifies the value, not the wiring.

Trigger — what the gate responds to. A gate can be set by position (a fixed schedule: every (r+1)(r{+}1)-th block, Hunyuan TurboS’s macro-block patterns Tencent Hunyuan Team (2025) ), by the input (every selective/gated recurrence above), or — the 2026 frontier — by the model’s own output state: AMOR invokes attention only at positions where prediction entropy crosses a threshold, reporting attention on roughly 22% of tokens with long-context stability Zheng & Shani (2026) . The trigger axis has a sharp theoretical caution attached: Basu’s analysis of content-based routing argues that mechanisms which avoid pairwise token comparison cannot route precisely (1–29% routing accuracy across recurrent, memory-bank, and bandit-style gates) — high-precision routing needs pairwise machinery, the representational ingredient cheap gates omit, though not necessarily full attention: the same paper constructs a 99.7%-accurate router from a rank-one pairwise projection at linear cost Basu (2026) .

Categorical scatter plot with gate granularity on the horizontal axis (scalar, vector, block) and gate trigger on the vertical axis (fixed schedule, input-dependent, output-triggered). Nine architectures are placed as labeled dots: Nemotron-H and Jamba and Hunyuan TurboS along the fixed-schedule row, Gated DeltaNet and SambaY and Griffin and Kimi Linear and Hymba on the input-dependent row, AMOR alone on the output-triggered row.
The gating design space, as of May 2026: granularity (scalar / vector / block) against trigger (fixed schedule / input-dependent / output-triggered), with nine named designs placed per their papers' descriptions (the trigger classifies the gate's value, not its wiring). The lower rows are crowded and the top row is nearly empty — output-triggered gating (AMOR) is the frontier, and Basu's routing bound says filling it honestly requires pairwise machinery. Schematic placement (no measured quantity); produced by companions/ch14/jax/hybrid_block.py.

Two families that belong to this design space by shape are treated elsewhere: xLSTM’s exponential gates (granularity: vector; trigger: input; plus a stabilizer state the sigmoid families do not need) and the test-time memory writes of the Titans line (trigger: the loss, a fourth trigger class) are Chapter 13’s subjects, where their matrix-memory context lives.

14.5 The production lineup, as of May 2026

The lens and the design space were built to read a real lineup, so here it is.

Mix pattern uses §14.3’s vocabulary; gate class uses §14.4’s.

| Model | Mix pattern (attention fraction ff) | Gating | Reported headline (paper’s own) | |---|---|---|---| | Griffin De et al. (2024) | interleaved, 2 RG-LRU : 1 local attention (f=1/3f = 1/3) | vector, input-dep. | matches Llama-2 quality with faster long-sequence inference | | Samba Ren et al. (2024) | interleaved 1:1 Mamba + sliding window (f=1/2f = 1/2) | vector (Mamba’s) | linear-time training at 4K, length extrapolation to 256K context | | Jamba Lieber et al. (2024) | interleaved 1:7 attention:Mamba, MoE FFNs (f=1/8f = 1/8) | block-structural | 256K context at 12B-active scale | | Bamba (IBM, HF blog) Bamba Team (IBM, Princeton, CMU, UIUC) (2024) | interleaved 3:29 attention:Mamba-2 (f0.09f \approx 0.09) | block-structural | fully open data recipe; ~2.5× vLLM decode throughput vs comparable transformers | | Nemotron-H NVIDIA (2025) | interleaved, 10 attention of 118 layers (f0.08f \approx 0.08) | scalar schedule | ~3× faster inference than similarly sized transformers at comparable accuracy | | SambaY / Phi-4-mini-flash Ren et al. (2025) | Samba self-decoder + GMU cross-decoder, single full-attention layer | vector (GMU) | ~10× decoding throughput on long-generation reasoning | | Hunyuan TurboS Tencent Hunyuan Team (2025) | AMF/MF macro-blocks (attention–Mamba–FFN), MoE | block schedule | top-10 LMSYS arena placement at 56B activated | | Kimi Linear Kimi Team (2025) | interleaved 3:1 KDA:full attention (MLA) (f=1/4f = 1/4) | vector, input-dep. | 75% KV-cache reduction, up to ~6× decode at 1M context |

Read the table against Proposition 14.2 and the figure that draws it: every row sits low on the attention-fraction curve, exactly where the budget argument says the cheap exactness should be spent. The within-family motion is also informative: Samba → SambaY replaces cross-attention with a gate (GMU) and gains its throughput from the gating design space, not from a new mixing pattern; Jamba → Bamba → Nemotron-H is a march down the attention fraction as the slow-path layers improved (Mamba-1 → Mamba-2 Dao & Gu (2024) ); Kimi reaches the same neighbourhood from the delta-rule side, with Chapter 12’s gated-delta machinery as the slow path.

One cross-vendor regularity deserves its own sentence. Lee et al., comparing sequential against parallel mixing across vendors and scales, find sequential hybrids stronger at short context and parallel hybrids stronger at long context Lee et al. (2025) — the single most design-relevant empirical fact in the lineup. (Their dichotomy is the coarser cut §14.3 reconciled: “sequential” there spans the interleaves above.) Per §14.2’s flag, it is a consistency check for the matching lens — the kind of regularity a theory of the joint would have to explain — not a verification of it.

14.6 MAD and the two-timescale benchmark seed

How should claims like the table’s be tested? Full-scale training runs answer with averages over everything at once. The mechanistic-architecture- design (MAD) methodology Poli et al. (2024) answers with small, synthetic, capability-isolating tasks — in-context recall, compression, copying — chosen so that performance on the probe predicts scaling behaviour of the full architecture; the MQAR family Arora et al. (2024) did the same for associative recall specifically, and Chapter 11 already used it to measure the capacity wall. This section contributes the probe the two-timescale lens calls for, and it is pilot B’s seed.

The task. A hidden Markov model with the two timescales built in:

  • a slow regime zt{1,,K}z_t \in \{1, \dots, K\} with sticky transition T(ε)=(1ε)I+εK1(JI)T(\varepsilon) = (1-\varepsilon)\,I + \tfrac{\varepsilon}{K-1}(J - I) — stay with probability 1ε1 - \varepsilon, else jump uniformly (JJ the all-ones matrix);
  • a fast process: given the regime, tokens follow a regime-specific bigram table, P(xt+1zt+1=j,xt)=Bj[xt,]P(x_{t+1} \mid z_{t+1} = j, x_t) = B_j[x_t, \cdot] on a vocabulary of size VV;
  • an overlap dial η(0,1]\eta \in (0,1]: the tables interpolate between a shared table and regime-specific ones, Bj=(1η)C+ηDjB_j = (1-\eta)C + \eta D_j, controlling how hard the regimes are to tell apart locally — measured by the mean per-token discrimination ıˉ\bar{\imath} (the average pairwise KL between regime rows).

Because the model is known, every predictor below is exact — no training, no approximation other than the stated information restriction — so every claim is a computation, checkable to machine precision. The Bayes-optimal predictor is the HMM forward filter, and the companion validates it against a brute-force enumeration over every regime path — Kt+1K^{t+1} paths for the prediction at position tt, an independent code path that is only feasible on short validation instances (L=7\seqlen = 7): maximum prediction difference 1.1×10161.1 \times 10^{-16}.

Three restrictions mirror the architectural resources:

  • window-ww (the attention idealization): the same Bayes computation, restricted to the last ww tokens with a uniform regime prior at the window edge — exact pairwise machinery, zero carried state. With wLw \ge \seqlen it reproduces the full filter exactly (difference 0.00.0).
  • fixed-decay (the state idealization): the filter run with the mixing-to-uniform prior update M(λ)=(1λ)I+λKJM(\lambda) = (1-\lambda)I + \tfrac{\lambda}{K}J — a compressed state forgotten toward uniform at a fixed rate, the EMA of §14.3 wearing filtering clothes.
  • unigram (the slow-manifold-only idealization): regime tracking with each bigram row replaced by the regime’s stationary unigram — carried state, no fast structure.

The fixed-decay restriction is the one with a theorem in it:

Theorem 14.4 (The matched decay is exactly Bayes-optimal).

For every K2K \ge 2 and ε(K1)/K\varepsilon \le (K-1)/K,

T(ε)  =  M(λ)atλ  =  εKK1,T(\varepsilon) \;=\; M(\lambda^\star) \qquad \text{at} \qquad \lambda^\star \;=\; \frac{\varepsilon K}{K - 1},

entrywise. Consequently the fixed-decay filter with rate λ\lambda^\star is the exact Bayes filter for the two-timescale task: a fixed-decay state model is optimal when its forgetting rate matches the regime’s switching rate, and every other fixed λ\lambda is the Bayes filter for a misspecified switching rate — strictly costly whenever the regimes are distinguishable at all (the measured V-shape below; in the degenerate identical-tables limit every λ\lambda ties).

The proof is two lines of algebra on the diagonal and off-diagonal entries (Exercise 14.5). The companion measures the identity at 1.1×10161.1 \times 10^{-16} entrywise and the resulting prediction agreement between the matched-decay filter and the optimal filter at 3.3×10163.3 \times 10^{-16}. This is the chapter’s sharpest statement of the slow-manifold half of the lens: gating is timescale matching. Chapter 9’s selectivity and Chapter 11’s decay masks let a model learn λ\lambda; the theorem says what the target of that learning is, and the V-shaped mistiming cost below says what missing it costs.

What each restriction costs, measured. At the committed reference configuration (K=4K = 4, V=12V = 12, η=0.4\eta = 0.4, ε=0.02\varepsilon = 0.02, L=8192\seqlen = 8192, burn-in 128128, ıˉ=0.534\bar{\imath} = 0.534 nats/token), the optimal filter achieves 1.92891.9289 nats. The window-8 predictor pays an excess of 0.02460.0246 nats; a fixed decay matched to the wrong rate (λ(0.2)\lambda^\star(0.2) where the truth is ε=0.02\varepsilon = 0.02) pays 0.05120.0512; the unigram predictor pays 0.49650.4965 — twenty times the window’s tax. Dropping the fast structure is catastrophic; carrying the wrong-decay state or a modest window is merely costly.

Two stacked panels sharing a log-scale switch-probability axis. Top panel: excess cross-entropy of the window-8 predictor falls from 0.058 nats at the slowest regimes toward zero at fast regimes; window-64 sits at zero throughout; the fixed-decay curve is V-shaped, touching zero at the matched switch rate 0.05 and rising on both sides. Bottom panel, on a ten-times larger scale: the unigram predictor's excess stays between 0.41 and 0.55 nats across all switch rates.
Excess cross-entropy over the exact filter as the regime speed $\varepsilon$ varies (overlap $\eta = 0.4$, $\seqlen = 8192$). Top: the window-8 predictor's tax is largest for the slowest regimes — carried state is worth most exactly when the latent moves slowest — while window-64 is indistinguishable from optimal here, and the fixed-decay filter (rate matched at $\varepsilon = 0.05$) shows the V-shaped mistiming cost that vanishes only at its matched point, the measured face of the matched-decay theorem. Bottom (note the scale): discarding fast structure costs ~0.5 nats regardless of regime speed. Differences below about $2 \times 10^{-4}$ nats are at the single-sequence Monte-Carlo floor. Produced by companions/ch14/jax/two_timescale.py; the reference-configuration values are pinned in tests/test_two_timescale.py.

The third timescale, and the benchmark design lesson. The window curves above collapse to zero by w=64w = 64. Why so small? Because with η=0.4\eta = 0.4 the regimes are still locally distinguishable enough that a few dozen tokens identify the current regime — the identification timescale τid\tau_{\mathrm{id}} is short. The overlap dial exists to control exactly this, and the crossover figure sweeps it:

Excess cross-entropy versus window size on a log-2 axis from 2 to 256, one curve per overlap value. The sharp-regime curve starts highest at window 2 but plunges to zero by window 8. The intermediate-overlap curve crosses it, decaying to zero near window 32. The low-overlap curve starts lowest but decays slowest, still positive at window 64.
The window a local predictor needs tracks identification difficulty, not regime speed ($\varepsilon = 0.005$ fixed). With sharply distinct regimes ($\eta = 1.0$, $\bar{\imath} = 3.04$ nats/token) a window of 8 is already near-optimal; at $\eta = 0.4$ ($\bar{\imath} = 0.53$) the tax persists to $w \approx 32$; at $\eta = 0.2$ ($\bar{\imath} = 0.21$) it persists past $w = 64$. The curves cross: harder identification lowers the value of regime knowledge but stretches how long a window must be to acquire it. Produced by companions/ch14/jax/two_timescale.py; the legend's discrimination values and the $\eta$-monotonicity are pinned in tests/test_two_timescale.py.

The design lesson is the section’s payload, and it is a constraint on benchmarks rather than on architectures: a two-timescale task separates fast-path from slow-path machinery only when the three timescales are ordered wτid1/εw \ll \tau_{\mathrm{id}} \ll 1/\varepsilon. Make the regimes too distinguishable (η1\eta \to 1) and a sliding window solves everything — the benchmark measures nothing about carried state. Make them too similar and even the optimal filter gains little — there is nothing to measure at all. Pilot B’s benchmark must therefore report ıˉ\bar{\imath} (or place τid\tau_{\mathrm{id}} directly) as a task parameter alongside ε\varepsilon, exactly as this companion does. One measurement is deliberately deferred with the protocol: the composite restriction — a window-ww filter seeded at its edge with a decayed carried prior instead of the uniform one — is the idealized matched expansion itself, the natural probe of §14.2’s third leg, and it belongs with B’s protocol work rather than this chapter’s seed. What else does not transfer to Chapter 16 from here: the per-layer probing protocol that asks where a trained hybrid stores the regime posterior, the evaluation tiers around real benchmarks, and B’s five-axis decomposition — that is Chapter 16’s subject.

14.7 What’s next

This chapter mixed the layer families of Chapters 9–12 into hybrids and read the mixture through a fast–slow lens with one continuous theorem (Theorem 14.1) and one discrete one (Theorem 14.4) holding the interpretation to account. Its sibling beyond-SSM chapter, Chapter 13 (already behind you if reading in order), lives inside the gates themselves: exponential gating with its stabilizer states (xLSTM) and the generalized delta rule (RWKV-7) extend Chapter 12’s lineage to matrix memories with their own stability questions. Chapter 15 plays prosecution — the counter-evidence file on what SSM-heavy designs provably cannot do, and the diagnostic toolkit for detecting it. Chapter 16 builds the evaluation methodology this chapter’s benchmark seed feeds into — the protocol around the task, the per-layer probes, and the point where pilot B’s book-side prerequisites close.

14.8 Exercises

Three short problems (solutions inline) and three longer ones (solutions in §14.9).

Exercise 14.1 (short)

A 32-block hybrid has width d=2048d = 2048, window w=2048w = 2048, and ratio 7 ⁣: ⁣17\!:\!1 (so na=4n_a = 4). Using Proposition 14.2, compute the decode state in floats, the same stack’s full-attention cache at L=131,072\seqlen = 131{,}072, and the ratio. At what context length L\seqlen^\star does full attention’s cache equal the hybrid’s?

Solution

State =4220482048+282048=33,611,776= 4 \cdot 2 \cdot 2048 \cdot 2048 + 28 \cdot 2048 = 33{,}611{,}776 floats. Full attention: 322131,0722048=17,179,869,18432 \cdot 2 \cdot 131{,}072 \cdot 2048 = 17{,}179{,}869{,}184 — a factor of 511.1511.1. Setting 322Ld=33,611,77632 \cdot 2\seqlen d = 33{,}611{,}776 gives L=256.4\seqlen^\star = 256.4: past a few hundred tokens of context, this hybrid already stores less than full attention ever would.

Exercise 14.2 (short, code)

Run companions/ch14/jax/two_timescale.py. Report the reference-configuration excesses (window-8, mistimed decay, unigram), then change _FIG_OVERLAP to 1.01.0 and to 0.20.2 and report how the window-8 excess at ε=0.005\varepsilon = 0.005 moves. One sentence: why does the hardest-to-identify task show the smallest window-8 excess?

Solution

Reference: 0.02460.0246 (window-8), 0.05120.0512 (decay mistimed by a factor 10), 0.49650.4965 (unigram). From the script’s printed crossover sweep, the window-8 excess at ε=0.005\varepsilon = 0.005 is 0.00380.0038 at η=1.0\eta = 1.0, 0.04960.0496 at η=0.4\eta = 0.4, 0.02400.0240 at η=0.2\eta = 0.2. Identification difficulty cuts both ways: at η=0.2\eta = 0.2 the regimes are hard to identify in a window, but knowing the regime is also worth less (the tables nearly coincide), so the achievable excess shrinks even as the window needed to remove it grows.

Exercise 14.3 (short)

Let a=attn(x)a = \mathrm{attn}(x) and s=ssm(x)s = \mathrm{ssm}(x) be the two branch outputs at one position, and suppose asa \ne s in every channel. Show that the set of outputs reachable by a scalar gate is a line segment in Rd\mathbb{R}^d, that the vector-gate reachable set is the full axis-aligned box with corners aa and ss, and conclude the dimension counts (11 versus dd) behind Proposition 14.3.

Solution

Scalar: {ga+(1g)s:g[0,1]}\{g a + (1-g) s : g \in [0,1]\} is the segment from ss to aa. Vector: channel jj of the output is gjaj+(1gj)sjg_j a_j + (1-g_j) s_j, which ranges over the interval with endpoints sj,ajs_j, a_j independently of other channels — the product of dd nondegenerate intervals, i.e. the box. A segment is one-dimensional; the box is dd-dimensional, so for d2d \ge 2 the inclusion is strict — and the {0,1}\{0,1\} corners of the box are exactly the channel-routing witnesses the companion pins.

Exercise 14.4 (theory) — solution in §14.9

Prove Theorem 14.1 in the scalar case x˙=ax+by\dot{x} = ax + by, εy˙=cx+dy\varepsilon\dot{y} = cx + dy with d<0d < 0: solve the η=y+(c/d)x\eta = y + (c/d)x dynamics exactly, exhibit the boundary layer, and bound xxr|x - x_r| on [0,T][0, T] explicitly, identifying where each hypothesis (d<0d < 0, fixed TT, bounded initial data) is used.

Exercise 14.5 (theory) — solution in §14.9

Prove Theorem 14.4, then compute the spectrum of T(ε)T(\varepsilon) and of M(λ)M(\lambda), the stationary distribution of each, and the mixing time of the regime chain. Conclude that for large KK the matched rate λε\lambda^\star \approx \varepsilon: forgetting toward uniform at the switching rate.

Exercise 14.6 (theory) — solution in §14.9

Complete the second strictness in Proposition 14.3: construct two inputs x(1),x(2)x^{(1)}, x^{(2)} and a target map realizable by an input-dependent vector gate but by no constant vector gate. Then explain why a gate computed from another layer’s state (the GMU pattern) sits in the input-dependent class.

14.9 Full solutions to theory exercises

Solution to Exercise 14.4

With η=y+(c/d)x\eta = y + (c/d)x the fast equation becomes, exactly as in the matrix case,

εη˙  =  dη  +  εcd(ax+by),\varepsilon\dot{\eta} \;=\; d\,\eta \;+\; \varepsilon\,\frac{c}{d}\,(ax + by),

a scalar linear ODE with constant contraction rate d/ε|d|/\varepsilon (here d<0d < 0 is used — without it η\eta grows and there is no layer). Variation of constants:

η(t)  =  edt/εη(0)  +  cd0ted(ts)/ε(ax+by)(s)ds.\eta(t) \;=\; e^{dt/\varepsilon}\eta(0) \;+\; \frac{c}{d}\int_0^t e^{d(t-s)/\varepsilon}\,(ax + by)(s)\,ds .

On [0,T][0, T] the trajectory (x,y)(x, y) is bounded uniformly in ε\varepsilon, say by RR — and this is where d<0d < 0 earns its keep a second time. Fixed horizon and bounded data alone give only an ε\varepsilon-dependent bound (the system matrix has O(1/ε)O(1/\varepsilon) entries); with d<0d < 0, the contraction keeps η(t)η(0)+O(εR)|\eta(t)| \le |\eta(0)| + O(\varepsilon R), hence yc/dx+η(0)+O(εR)|y| \le |c/d|\,|x| + |\eta(0)| + O(\varepsilon R), the slow equation then bounds x|x| by an ε\varepsilon-independent Grönwall constant, and a standard bootstrap (pick RR dominating both estimates; continuity keeps the trajectory inside) closes the loop. Without d<0d < 0 the fast variable blows up as ε0\varepsilon \to 0 and no uniform RR exists. With RR in hand, (ax+by)(s)(a+b)R|(ax + by)(s)| \le (|a| + |b|)R, so the integral term is at most cd(a+b)Rεd(1edt/ε)c(a+b)Rd2ε\tfrac{|c|}{|d|}(|a| + |b|) R \cdot \tfrac{\varepsilon}{|d|}(1 - e^{dt/\varepsilon}) \le \tfrac{|c|(|a| + |b|) R}{d^2}\,\varepsilon: the boundary-layer estimate η(t)edt/εη(0)+O(ε)|\eta(t)| \le e^{-|d| t/\varepsilon}|\eta(0)| + O(\varepsilon), with the layer over by tεlog(1/ε)t \sim \varepsilon\log(1/\varepsilon). Substituting y=(c/d)x+ηy = -(c/d)x + \eta into the slow equation gives x˙=(abc/d)x+bη\dot{x} = (a - bc/d)x + b\eta, so e=xxre = x - x_r obeys e˙=(abc/d)e+bη\dot{e} = (a - bc/d)e + b\eta, e(0)=0e(0) = 0, and

e(t)    beabc/dT0Tη(s)ds    beabc/dT(εdη(0)+c(a+b)Rd2εT)  =  O(ε),|e(t)| \;\le\; |b|\,e^{|a - bc/d|\,T} \int_0^T |\eta(s)|\,ds \;\le\; |b|\,e^{|a - bc/d|\,T}\Bigl(\frac{\varepsilon}{|d|}|\eta(0)| + \frac{|c|(|a| + |b|) R}{d^2}\,\varepsilon\,T\Bigr) \;=\; O(\varepsilon),

where the fixed horizon TT is used to keep the Grönwall factor a constant. Each piece of the theorem’s statement appears with explicit constants. \blacksquare

Solution to Exercise 14.5

The identity. Diagonal entries: T(ε)ii=1εT(\varepsilon)_{ii} = 1 - \varepsilon and M(λ)ii=1λ+λ/KM(\lambda)_{ii} = 1 - \lambda + \lambda/K; equality forces λ(11/K)=ε\lambda(1 - 1/K) = \varepsilon, i.e. λ=εK/(K1)\lambda^\star = \varepsilon K/(K-1). Off-diagonal: Tij=ε/(K1)T_{ij} = \varepsilon/(K-1) and Mij=λ/KM_{ij} = \lambda/K, and at λ\lambda^\star indeed λ/K=ε/(K1)\lambda^\star/K = \varepsilon/(K-1). Both matrices are row-stochastic, so matching all entries matches the matrices; the constraint λ1\lambda^\star \le 1 is ε(K1)/K\varepsilon \le (K-1)/K. Since the Bayes filter’s only use of the regime chain is the prior update ppT(ε)p \mapsto p\,T(\varepsilon), replacing TT by M(λ)M(\lambda^\star) changes nothing at any step: the fixed-decay filter at the matched rate is the Bayes filter, identically. \blacksquare

Spectra and mixing. Both matrices are of the form αI+βJ\alpha I + \beta J: eigenvalues α+Kβ\alpha + K\beta on the all-ones vector and α\alpha on its (K1)(K-1)-dimensional complement. For T(ε)T(\varepsilon): eigenvalue 11 (stochasticity) and 1εε/(K1)=1λ1 - \varepsilon - \varepsilon/(K-1) = 1 - \lambda^\star with multiplicity K1K - 1; for M(λ)M(\lambda): 11 and 1λ1 - \lambda. The stationary distribution of each is uniform (both are doubly stochastic). The regime chain forgets its initial condition at geometric rate 1λ1 - \lambda^\star per step — mixing time 1/λ\sim 1/\lambda^\star — which is the precise sense in which 1/ε1/\varepsilon is the slow timescale. As KK \to \infty, λ=εK/(K1)ε\lambda^\star = \varepsilon K/(K-1) \to \varepsilon: forget toward uniform at exactly the switching rate. \blacksquare

Solution to Exercise 14.6

Take d=1d = 1 (one channel suffices) and any two inputs with a(1):=attn(x(1))ssm(x(1))=:s(1)a^{(1)} := \mathrm{attn}(x^{(1)}) \ne \mathrm{ssm}(x^{(1)}) =: s^{(1)} and likewise a(2)s(2)a^{(2)} \ne s^{(2)}. Define the target map to output the attention branch on x(1)x^{(1)} and the SSM branch on x(2)x^{(2)}. A constant gate g[0,1]g \in [0,1] must satisfy ga(1)+(1g)s(1)=a(1)g a^{(1)} + (1-g) s^{(1)} = a^{(1)}, forcing g=1g = 1, and ga(2)+(1g)s(2)=s(2)g a^{(2)} + (1-g) s^{(2)} = s^{(2)}, forcing g=0g = 0 — contradiction. An input-dependent gate with g(x(1))=1g(x^{(1)}) = 1, g(x(2))=0g(x^{(2)}) = 0 realizes the target, so the inclusion is strict. (With d2d \ge 2 the same argument runs per channel.)

A GMU-style gate is computed from the hidden state of another layer — a deterministic function of the network input — so as an input–output map it is exactly an input-dependent vector gate: g=g(x)g = g(x), with the cross-layer sharing changing where the gate’s information comes from (a memory stream computed once and reused) but not the function class. That is why SambaY’s throughput gain is a systems gain — fewer recomputations of expensive context — while its expressivity class is the one already characterized here. \blacksquare

14.10 Companion code

The companions live in companions/ch14/{jax,torch} and are float64 throughout. The JAX modules are canonical and produce all four figures; the torch modules mirror the hybrid block and the filter family with cross-framework parity pinned to <109< 10^{-9} (tokens drawn once and fed to both implementations). No Julia module this chapter: the numerical core is filtering linear algebra, not the integrator analysis that earned Julia its seat in Chapters 10 and 12.

# JAX (canonical; emits the four figures to public/figures/ch14/)
PYTHONPATH=. python companions/ch14/jax/hybrid_block.py
PYTHONPATH=. python companions/ch14/jax/two_timescale.py

# Tests: JAX identities (< 1e-12), torch parity (< 1e-9)
.venv/bin/pytest companions/ch14 -q
  • hybrid_block.py — sliding-window attention with its per-position oracle, the gated-decay EMA and its closed form, the three composition patterns with exact gate reductions, the r ⁣: ⁣1r\!:\!1 schedule, and the decode-cost accounting audited against materialized buffers; produces the cost-frontier and design-space figures (§§14.3–14.5).
  • two_timescale.py — the two-timescale HMM with the overlap dial, the exact forward filter validated against brute-force path enumeration, the window / fixed-decay / unigram restrictions, the matched-decay identity at machine precision, and the discrimination diagnostic ıˉ\bar{\imath}; produces the two-timescale-error and window-crossover figures (§§14.2, 14.6). This module is pilot B’s seed artifact.
  • torch/ — eager mirrors of both modules plus the buffers-vs-Parameters distinction in a minimal gated-mix layer (the learned blend is a Parameter; the fixed decay rates are a buffer).