The dominant paradigm in natural language processing and modern foundation models relies almost exclusively on the Transformer architecture. While standard multi-head self-attention delivers strong expressivity and in-context learning capabilities, its computational requirements present fundamental scaling bottlenecks: training complexity scales quadratically with sequence length , and autoregressive token generation requires storing key-value pairs in high-bandwidth memory (HBM), creating a linear KV cache memory footprint per active sequence.
To circumvent these computational limits, researchers developed Structured State Space Sequence Models (SSMs), culminating in architectures such as S4, Mamba, and Mamba-2. State space models originate from classical control theory, mapping a continuous input signal to an output signal through an implicit latent state. By introducing input-dependent parameter selection and hardware-aware associative scan kernels, modern selective SSMs achieve linear time complexity during training, constant time complexity per generated token during inference, and competitive performance against standard Transformers across dense language modeling benchmarks.
Continuous-Time State Space Representations
At their core, continuous-time state space models define a linear mapping from a 1D continuous sequence to an output via an -dimensional latent state . The continuous system is governed by a pair of linear differential equations:
h'(t) = A h(t) + B x(t)
y(t) = C h(t) + D x(t)In this formulation:
- represents the state transition matrix, governing how internal latent representations evolve over continuous time.
- is the input projection vector, modulating the continuous input signal into the latent state space.
- is the output projection vector, mapping the latent state back to the scalar output space.
- represents a direct feedthrough connection (often omitted or parameterized as a skip connection).
In deep learning implementations, models operate over multi-dimensional feature vectors with hidden dimension . The state space transformation is applied independently across each feature channel, resulting in a latent state dimension of .
Discretization Mechanics: Bridging Continuous Systems to Discrete Sequences
Because digital language models process discrete sequences of tokens rather than continuous analog signals, the continuous differential system must be discretized using a timescale step size parameter .
The standard discretization method in modern SSMs is the Zero-Order Hold (ZOH) transformation, which assumes that the continuous input signal remains constant over each discrete interval . Applying ZOH yields the discrete-time state space formulation:
h_t = A_bar * h_{t-1} + B_bar * x_t
y_t = C_bar * h_t + D * x_tThe discrete transition matrices and are derived mathematically from continuous parameters , , and timescale :
A_bar = exp(Delta * A)
B_bar = (Delta * A)^(-1) * (exp(Delta * A) - I) * (Delta * B)In first-order Taylor approximations, can be simplified as . The output matrix remains invariant during discretization: .
Alternative discretization strategies include the Bilinear (Tustin) transform and Euler discretization:
- Bilinear Transform: , preserving frequency-domain properties and stability along the imaginary axis.
- Euler Discretization: , which offers simpler arithmetic but suffers from numerical instability when is large.
The timescale parameter acts as a dynamic gating mechanism:
- When , and , causing the system to reset its latent state and focus entirely on the current input token .
- When , and , causing the model to preserve its existing memory state while ignoring current input perturbations.

From Linear Time-Invariant (LTI) Systems to Selective SSMs
Early structured SSMs, including S4 (Structured State Space for Sequences) and H3 (Hungry Hungry Hippos), enforced Linear Time-Invariance (LTI). In an LTI system, parameters remain constant across all time steps .
LTI systems possess a dual representation:
- Linear Recurrence for autoregressive inference: , requiring compute per token.
- Global Convolution for parallel training: Expanding the unrolled recurrence reveals that is computed as a 1D convolution of the entire sequence with an explicit SSM kernel :
K_bar = (C * B_bar, C * A_bar * B_bar, C * A_bar^2 * B_bar, ..., C * A_bar^{L-1} * B_bar)
y = x * K_barUsing the Fast Fourier Transform (FFT), this convolution can be computed across sequence length in time.
The Fundamental Limitation of LTI Models
Despite their training efficiency, LTI models cannot solve foundational sequence processing primitives required for natural language reasoning:
- Selective Copying: Remembering relevant tokens while filtering out irrelevant filler tokens across variable sequence intervals. Because the convolution kernel is static and input-independent, it allocates identical weights to tokens regardless of semantic content.
- Induction Heads: Detecting repeated patterns and retrieving the associated follower token. LTI systems cannot dynamically reallocate attention or modify state transitions conditioned on observed context.
The Mamba Selection Mechanism
Mamba resolves the LTI limitation by making the parameters , , and explicit functions of the input token at each time step:
B_t = Linear_N(x_t)
C_t = Linear_N(x_t)
Delta_t = Softplus(Linear_D(x_t) + Parameter_Delta)
A_bar_t = exp(Delta_t * A)
B_bar_t = (Delta_t * A)^(-1) * (exp(Delta_t * A) - I) * (Delta_t * B_t)By parameterizing , , and dynamically based on input embeddings, Mamba acts as a content-aware filter. The model dynamically flushes obsolete context from the state or amplifies salient tokens for indefinite retention.
Hardware-Aware Parallel Scan and Memory Hierarchy Optimization
Making parameters input-dependent breaks the convolutional representation because the convolution kernel can no longer be precomputed. Evaluating the recurrence sequentially across sequence length on modern GPU accelerators would severely degrade training throughput due to memory bandwidth constraints.
Standard deep learning frameworks materialize intermediate tensors of shape in High-Bandwidth Memory (HBM). For batch size , sequence length , model dimension , and state dimension , intermediate tensors require tens of gigabytes of HBM read/write traffic per layer.
To eliminate memory bottlenecks, Mamba implements a hardware-aware parallel scan kernel using GPU SRAM:
- Kernel Fusion in SRAM: The model loads input projections, , , , and directly into high-speed on-chip SRAM cache (operating at over 15 TB/s on modern architectures).
- Parallel Prefix Scan: The sequential recurrence is computed using a parallel associative scan (Blelloch algorithm) with an associative operator :
(A_i, B_i * x_i) o (A_{i-1}, B_{i-1} * x_{i-1}) = (A_i * A_{i-1}, A_i * B_{i-1} * x_{i-1} + B_i * x_i)- Work-Efficient Tree Reduction: The parallel scan executes in total work and parallel depth across thread blocks.
- Intermediate Gradient Recomputation: During the backward pass, intermediate latent states are not saved to HBM. Instead, they are recomputed on-the-fly in SRAM when evaluating gradients, reducing peak memory usage to the level of standard Transformer layers.
Structured State Space Duality (SSD) and Mamba-2
In 2024, researchers introduced Structured State Space Duality (SSD), establishing a direct mathematical equivalence between selective state space models and structured linear attention mechanisms.
SSD demonstrates that when state transition matrix is structured as a scalar-times-identity matrix (), the SSM transformation is equivalent to a 1-semiseparable matrix multiplication:
Y = (L o (Q * K^T)) * VWhere:
- , , and .
- represents a strictly causal decaying mask matrix.
- denotes Hadamard (element-wise) multiplication.
This duality enables Mamba-2 to formulate state space computation through chunked matrix multiplications. A sequence of length is partitioned into non-overlapping chunks of size (typically 64 or 128 tokens):
- Within each chunk, computations are executed as dense matrix multiplies on Tensor Cores ().
- Across chunk boundaries, state representations are propagated using a recurrence over chunk-level summary states.
By reformulating state space updates into matrix multiplies, Mamba-2 achieves 2x to 8x higher training throughput compared to Mamba-1 while supporting larger state expansion dimensions ( or ).
Architectural Comparison: Mamba vs Multi-Head Attention
The differences in computational complexity, memory scaling, and serving properties between standard Transformer attention, Linear Attention, and Selective SSMs can be summarized across core dimensions:
Computational Complexity
- Transformer Multi-Head Attention: training compute; per step inference compute.
- Linear Attention: training compute; per step inference compute.
- Selective SSM (Mamba-1 / Mamba-2): training compute; per step inference compute.
State Memory Footprint During Generation
- Transformer Multi-Head Attention: dynamic KV cache in HBM; scales linearly with generated sequence length.
- Linear Attention: fixed-size recurrent state; constant memory.
- Selective SSM: fixed-size latent state ; constant memory regardless of sequence length.
Induction and Associative Recall
- Transformer Multi-Head Attention: Exact retrieval via explicit pair-wise query-key dot products.
- Linear Attention: Degraded retrieval due to unnormalized feature map decay and kernel approximations.
- Selective SSM: High retrieval accuracy via input-dependent gating () and expanded state representations.
Serving Economics and Latency Dynamics
In production deployment environments, the memory and computational profiles of Mamba provide several practical advantages:
- Elimination of Memory-Bound Decoding: Autoregressive decoding in large Transformers is typically memory-bandwidth bound because reading the KV cache requires transferring gigabytes of memory per token generated. Mamba maintains a small, fixed-size hidden state per layer, allowing decoding to run compute-bound at substantially higher batch sizes.
- Linear Long-Context Scaling: For document processing, codebase ingestion, and multi-turn agent sessions exceeding 100,000 tokens, Mamba processes prompt context with linear time and memory scaling, avoiding the out-of-memory errors and quadratic slowdowns inherent to standard attention.
- Hybrid Architectures: Modern production models such as Jamba and Bamba integrate interleaved layers of Mamba SSM blocks and Multi-Head Attention blocks (e.g. 1 attention layer for every 7 Mamba layers). This hybrid topology preserves exact associative recall across complex multi-document reasoning tasks while reducing total KV cache size by over 80 percent.
Sources
- Gu, A., & Dao, T. (2023). Mamba: Linear-Time Sequence Modeling with Selective State Spaces. arXiv:2312.00752. https://arxiv.org/abs/2312.00752
- Dao, T., & Gu, A. (2024). Transformers are SSMs: Generalized Models and Efficient Algorithms Through Structured State Space Duality. ICML 2024. arXiv:2405.21060. https://arxiv.org/abs/2405.21060
- Gu, A., Goel, K., & Re, C. (2021). Efficiently Modeling Long Sequences with Structured State Spaces. ICLR 2022. arXiv:2111.00396. https://arxiv.org/abs/2111.00396
- Lieber, O., et al. (2024). Jamba: A Hybrid Transformer-Mamba Language Model. arXiv:2403.19887. https://arxiv.org/abs/2403.19887



