Sub-Quadratic & Hybrid Architectures

Sub-Quadratic & Hybrid Architectures

The self-attention operator is the computational engine of modern foundation models, yet it carries a fundamental structural flaw: because every token attends to every preceding token explicitly, prefill compute scales quadratically as and the autoregressive KV-cache grows linearly as without bound.

Sub-quadratic sequence architectures—led by Structured State Space Models (S4), Selective State Spaces (Mamba-1 & Mamba-2), Gated Linear Attention, and Hybrid SSM-Transformer topologies (Jamba, Zamba)—replace the expanding key-value history with a fixed-dimensional recurrent state that compresses arbitrary sequence lengths into training time and inference memory.

Operator / RecurrenceTime & State ComplexityMathematical & Architectural Role
Continuous-Time LTI State Space (S4 / HiPPO): Maps 1D input signal through an -dimensional orthogonal polynomial memory state .
Zero-Order Hold (ZOH) Discretization: Converts continuous parameters into discrete step transitions governed by input-dependent step size .
/ StateSelective State Space (Mamba, Gu & Dao 2023): Makes functions of token , enabling content-aware gating in fixed memory.
Structured State Space Duality (Mamba-2 SSD): Proves that scalar-identity selective SSMs are mathematically isomorphic to -semiseparable masked linear attention.

Selective State Space Recurrence (Mamba O(1) State) vs. Quadratic Transformer KV-Cache

Input Token xtxt∈ RdLinear ProjectionsWΔ, WB, WCSelective ZOH Gate (Content-Aware)Δt→ ∞ (Focus on Salient xt)exp(ΔtA) → 0: Resets prior state ht-1Δt→ 0 (Ignore Filler / Noise)exp(ΔtA) → I: Preserves state ht-1Fixed-Size Recurrent State htht= Ātht-1+ B̄txt∈ Rd×NSRAM-fused Blelloch Parallel Prefix ScanConstant O(1) Inference Stateyt= Ctht(Zero T-dependent KV Cache)
Figure 1 (Selective State Compression): Unlike time-invariant SSMs that apply fixed convolution kernels to every token, Mamba projects step size from the current token . Large flushes old state and writes into ; small bypasses irrelevant tokens while maintaining a constant-size state independent of sequence length .

1. Continuous-to-Discrete State Space Foundations

A classical Linear Time-Invariant (LTI) State Space Model maps a 1D continuous scalar input signal to an output via an -dimensional latent state vector :

where is the state transition matrix initialized via HiPPO (High-Order Polynomial Projection Operators) to compress continuous history into orthogonal Legendre polynomials, and are projection vectors.

Zero-Order Hold (ZOH) Discretization

To apply this continuous differential equation to a discrete token sequence , we hold the input value constant over a continuous step size . Integrating the linear ODE over yields the exact Zero-Order Hold (ZOH) discrete parameters :

where the first-order Euler approximation holds when is small. The discrete system can then be evaluated in two dual modes:

  1. Linear Recurrence ( Autoregressive Decode):
  2. Global Convolution ( Parallel Training for LTI S4): Because are constant across time , unrolling the recurrence yields a 1D causal convolution with kernel .

2. Selective State Spaces (Mamba) & Associative Scans

While LTI models (S4, H3) achieve scaling, their time-invariant matrices cannot perform content-based reasoning (such as selective copying or induction heads): the transition weights are identical regardless of whether token is a critical entity name or an irrelevant punctuation mark.

Gu and Dao (2023) solved this limitation in Mamba by making the step size and projection matrices explicit functions of the input token :

The Information-Theoretic Meaning of Δₜ

When we restrict with , the selective ZOH recurrence becomes an adaptive continuous-time gating mechanism analogous to an LSTM forget/input gate:

  • (Salient Token Focus): and grows large. The model flushes its old recurrent state and writes the current token into memory.
  • (Noise / Filler Bypass): and . The model ignores the current token completely and persists its prior memory state unchanged across arbitrary distractors.

Because now varies with , the FFT convolution trick no longer applies. Instead, Mamba fuses the discretization and recurrence inside GPU SRAM using a work-efficient Blelloch Parallel Associative Scan. Because the first-order affine composition is strictly associative, all recurrent states are computed in parallel tree depth without materializing intermediate state tensors in HBM.


3. Worked Numerical Walkthrough: Selective ZOH Step & Associative Scan

Let us trace a -dimensional selective state space coordinate with continuous decay parameter over a -token sequence starting from .

  1. Token 1 (, Salient Entity): Suppose the selection network outputs , , .

  2. Token 2 (, Irrelevant Filler): The selection network suppresses the step size to , .

    Notice that of Token 1’s state survives across the distractor token.

  3. Token 3 (, New Salient Fact): The selection network spikes , .


4. Structured State Space Duality (Mamba-2 SSD) & Hybrid Architectures

In Mamba-2, Dao and Gu (2024) proved Structured State Space Duality (SSD): when the diagonal matrix is simplified to a scalar identity multiplier per head, unrolling the selective SSM recurrence is mathematically identical to multiplying the input by a -semiseparable causal mask in linear attention:

By partitioning the sequence into blocks of size , SSD computes intra-block transitions using dense Tensor Core matrix multiplications (, exactly like FlashAttention) while passing the recurrent state between blocks in time—achieving higher training throughput than Mamba-1’s elementwise scan.

Long-Context Scaling Wall: Dense Transformer vs. Hybrid Jamba vs. Pure Mamba-2

Sweep sequence length from to tokens and adjust the Hybrid Attention-to-SSM layer ratio to compare KV/state memory footprint and prefill FLOP scaling.

Context (T): 128K
Hybrid Attn Ratio: 1 : 8 (12.5%)
0 GB40 GB80 GB120 GB160 GB4K128K256K384K512KSequence Context Length T (Tokens)Dense Transformer (64 Attn Layers)Hybrid Jamba (Attn + Mamba-2)Pure Mamba-2 (Constant O(1) State)State & KV Audit (64 Layers)Dense Attn KV Cache:42.9 GBPure Mamba-2 State:0.13 GBIn-Context Recall:99.2%Hybrid State Memory:5.48 GBKV Reduction:8.0× SmallerFits Single 80GB H100
1:8 Jamba Topology
Context T: Attn Layers:

Why Hybrid Architectures (Jamba / Zamba) Win in Practice

Despite their memory efficiency, pure fixed-state models face a fundamental information-theoretic bottleneck on exact in-context copying and multi-needle associative recall: a fixed state of cannot losslessly store arbitrary random key-value pairs.

Frontier hybrid architectures (AI21 Jamba, Zyphra Zamba, NVIDIA Nemotron-H) resolve this by interleaving 1 full GQA Self-Attention layer for every 7 State Space (Mamba-2) layers ( ratio):

Architectural FamilyPrefill ComputeState / KV Memory at Exact Multi-Needle RecallRepresentative Models
Dense GQA Transformer (100% KV Cache)Exact ()LLaMA-3, Qwen-2.5
Pure Selective SSM ( Fixed)Degrades on dense random keysMamba-1, Mamba-2
Gated Linear / RNN ( Matrix)Moderate ()RWKV-6, RetNet, GLA
Hybrid SSM-Attention (1:8) ( smaller)Exact ()Jamba-1.5, Zamba-2, Falcon-Mamba

Key Papers & References