State Space Models

Dive into Deep Learning · §12

State Space Models and Modern Recurrent Architectures
gated recurrences · parallel associative scans · structured & selective SSMs · matrix memories · delta rule · hybrids

The Long-Context Dilemma: KV Cache vs. Fixed State

Motivation

  • Causal Attention (O(T) KV Cache): Stores 4 KB/token (8 KV heads \times 128 fp16), growing to 512\text{ MB}/layer at T = 128\text{K} with O(T^2 d) score FLOPs.
  • Recurrent State (O(1) Memory): Compresses history into a fixed 2\text{ MB} state (Mamba-2 at d=4{,}096), crossing the KV cache at T = 512 tokens.
  • Central Question: Can an O(1) state train in parallel on GPUs and match Transformer recall?

Two Obstacles to Modernizing Recurrent Networks

Core Challenges

  • Obstacle 1 — O(T) Sequential Depth: Nonlinear \tanh(\mathbf{W}_{\textrm{hh}}\mathbf{h}_{t-1}) blocks GPU parallelism; affine transitions (§12.3–12.5) run in O(\log_2 T) parallel scan rounds.
  • Obstacle 2 — Fixed-Vector Decay: A 1D state \mathbf{h}_t \in \mathbb{R}^d blurs facts; multi-timescale \Delta_t, matrix states \mathbf{S}_t \in \mathbb{R}^{d_v \times d_k}, and the delta rule (§12.4–12.7) add key-value addressing.
  • Unifying State-Space View: Every mixer has a state, a write update, and a readout.

Architectural Progression Across Chapter 12

Chapter Roadmap

  • From Gates to Linear Scans (§12.1–12.5): Progresses from sequential LSTM/GRU gates and Seq2Seq bottlenecks to parallel minGRU scans, multi-timescale S4D, and selective Mamba.
  • From Vectors to Matrix Memories (§12.6–12.7): Expands the state into an outer-product key–value matrix (GLA) sharpened by online read-before-write error correction (GatedDeltaNet).
  • Sparse Attention Hybrids (§12.8): Interleaves 1 full attention layer per 3 recurrent layers to break the Welch overlap ceiling.

Synthetic Stress Tests and the Language Benchmark

Empirical Methodology

  • Five Targeted Capability Probes: Delayed Recall (half-life horizon), String Reversal (bits/float capacity), Selective Copying (token-dependent \Delta_t), Associative Recall (Welch rank limit), and Key Rebinding (delta rule erasure).
  • Unified Language Benchmark (SeqLM): Every sequence mixer is evaluated inside the exact same 4-block pre-norm residual stack on byte-level WikiText-103.

How to Navigate Chapter 12

Study Guide

  • Core architectural line: Follow §12.1 (Gates) \to §12.3 (Linear Recurrences & Parallel Scans) \to §12.5 (Selective SSMs / Mamba) \to §12.6–12.7 (Matrix Memories & DeltaNet) \to §12.8 (Hybrid Architectures).
  • Historical & information-theoretic foundation (§12.2): Revisits the 2014 encoder–decoder and translation metrics (chrF, BLEU) to measure how rapidly a single state vector saturates as input length grows.
  • Mathematical derivations that can wait on first reading: Continuous-time zero-order-hold discretization in §12.4 and the block-semiseparable chunked algorithms in §12.6–12.7.
  • Controlled code comparisons: Every mixer plugs into the identical pre-norm residual SeqLM backbone with LeCun initialization so differences reflect the sequence mixer alone.

Up next (§12.1 Gated Recurrent Networks): How sigmoid gates create a learned elementwise decay path—and why gate bias initialization decides whether training discovers long-range memory.