Attention has an O(N²) ceiling. At 1M tokens, just the attention matrix is the entire compute budget — which is why every frontier transformer caps out somewhere between 200K and 2M context. Mamba, RWKV, and Jamba bet on a completely different architecture: compress the past into a fixed-size state, never quadratic. Albert Gu's 2023 Mamba paper was the first SSM to match transformer quality at language modeling, and 2024–2026 hybrid models (Jamba, Zamba, Samba) are now serving million-token contexts at fractions of transformer cost.
Learning Objectives
After this lesson, you will be able to:
Explain why attention's O(N²) cost is the architectural ceiling that motivates linear-time alternatives — and what 'linear time' actually buys you in training and inference
Walk through the discretization that turns a continuous state space x'(t) = Ax + Bu into the Mamba selective scan you can actually run on a GPU
Pick the right architecture for a workload — pure transformer for retrieval-heavy tasks, pure SSM for streaming low-memory inference, or hybrid (Jamba/Zamba) for long-context cost-sensitive deployments
Recognize the strengths and weaknesses of Mamba, RWKV, RetNet, and Hyena well enough to read a 2025 paper without getting lost in the alphabet soup
Don't worry if "state space" sounds like control theory — that is exactly where it came from, and the connection back to Kalman filters and signal processing is part of why these models work. The math looks daunting but the core idea is just "an RNN you can train in parallel."
The convolutional view rewrites the recurrence as a global convolution with a structured kernel:
y=u∗K,K=(CBˉ,CAˉBˉ,CAˉ2Bˉ,…,CAˉN−1Bˉ)
The trick that made S4 work — and that Mamba inherited — is the HIPPO initialization of A. HIPPO comes from approximation theory: it is the matrix that produces the best polynomial reconstruction of past inputs. Random initialization fails badly; HIPPO-initialized SSMs train cleanly and capture long-range dependencies up to 16K tokens on the long-range arena benchmark.
S4 was elegant but linear and time-invariant — the matrices A, B, C are fixed, not data-dependent. So an S4 state forgets at the same rate whether the input is "remember this password" or "irrelevant filler". Mamba's contribution: make B, C, and Δ a function of the current input, breaking time-invariance.
Aˉt,Bˉt,Ct,Δt=fθ(ut)
The cost is that the convolutional view no longer applies — the kernel changes every step. Mamba solves this with a hardware-aware parallel scan (Blelloch scan) implemented as a custom CUDA kernel that does the recurrence in O(log N) parallel passes per chunk, using shared memory aggressively. The result: training as fast as a comparable transformer, inference O(1) per token with constant memory.
Step a token through both pipelines to contrast SSM's fixed-size rolling state with attention's growing all-to-all lookup.
Hybrid 2024–2025 systems typically use ~1 attention layer per 7–8 Mamba layers — enough to handle in-context learning and copy/recall tasks, while keeping most of the cost on the linear path.
What Do You Think?
You have to serve 10M-token contexts (e.g. lifetime medical history) on commodity hardware. Pure transformer is impossible — KV cache alone exceeds VRAM. Which architecture earns the slot?
Pure Mamba sounds right — and it works for many tasks — but production teams overwhelmingly pick the hybrid because real workloads include in-context learning, copying, and few-shot patterns where pure SSMs underperform. The hybrid pays a small cost relative to pure Mamba but recovers most of attention's recall ability. Jamba and Zamba both ship this design. Sliding-window transformer with 4K is a non-answer for 10M tokens; Linformer's fixed-length projection loses too much information at extreme lengths.
Tests · The model should produce output shape (1, 4096, 64) and use roughly the same VRAM as a 64-dim shape regardless of sequence length, while a same-d_model attention model would balloon.
State space models are linear-time alternatives to attention. They compress the past into a fixed-size state and update it each step. Inference is O(1) per token with constant memory; training is O(N) parallelizable via convolution or scan.
HIPPO initialization is what made S4 work. Random init fails badly. The structured initialization is non-negotiable; modern selective SSMs (Mamba) inherit HIPPO-style structure even after making A partly learnable.
Selectivity is what made Mamba match transformers. Input-dependent B_t, C_t, Δ_t let the state forget aggressively when the input is filler and remember strongly when it is informative. This breaks time-invariance and requires a hardware-aware parallel scan.
Hybrids beat purity in production. Pure SSMs underperform on copying, recall, and in-context learning. Jamba and Zamba intersperse a few attention layers among many Mamba layers; this hybrid is the practical default for cost-sensitive long-context deployment.
The architecture race is not over. Transformers are not the final answer; they are the current local optimum that combines content-based retrieval with hardware-friendly matmul. SSMs, RWKV, RetNet, and Hyena are all credible alt-architectures with active research traction.
What is the asymptotic inference cost per token for a selective SSM (Mamba) vs a vanilla transformer (without KV cache)?
State space models are the most credible challenger transformers have faced. Whether they win, lose, or merge into hybrids by 2030, an ML engineer in 2026 needs to recognize them on sight. Next up: how transformers got into vision in the first place — Vision Transformers, where image patches became the new tokens.
O(N) parallel
O(1) per token
Open source, multilingual focus
Hyperparameter sensitivity
RetNet (2023)
Retention with three modes (parallel/recurrent/chunkwise)