State Space Models (SSMs) and their modern selective formulations, most notably Mamba-1 and Mamba-2, represent a foundational alternative to the standard Transformer architecture for sequence modeling. While multi-head self-attention scales quadratically with sequence length () and requires an ever-expanding Key-Value (KV) cache during autoregressive generation (), State Space Models achieve linear time complexity () during training and constant memory footprint () per step during inference.
Originating from continuous-time dynamical systems in classical control theory, SSMs were historically limited by time-invariance, preventing them from performing content-dependent reasoning. The development of Selective State Spaces (Gu and Dao, 2023) and Structured State Space Duality (Dao and Gu, 2024) bridged this gap, enabling subquadratic models to match or exceed Transformer performance across language, audio, and genomic modeling while unlocking up to 5x higher inference throughput.

Theoretical Foundations: Continuous and Discrete State Spaces
A continuous-time State Space Model maps a 1-dimensional continuous input signal through an -dimensional latent state to produce an output signal . The system is governed by a set of linear ordinary differential equations (ODEs):
where:
- is the state transition matrix, determining how the internal state evolves over time.
- is the input projection matrix, mapping the scalar input into the latent state space.
- is the output projection matrix, mapping the latent state back to the output space.
- is a direct feedthrough (skip connection) parameter, typically omitted or handled as a separate residual connection.
Continuous-to-Discrete Discretization
Because digital computers process discrete token sequences rather than continuous signals, the continuous system must be discretized over a continuous timescale parameter (the step size or sample resolution).
Using the standard Zero-Order Hold (ZOH) discretization rule, which assumes the input signal remains constant over each time interval , the continuous parameters are transformed into discrete parameters :
The discrete state space formulation is then expressed as:
The Duality of Inference and Training in Linear Time-Invariant SSMs
When the parameters are constant over time (known as a Linear Time-Invariant or LTI system), the model possesses a dual representation:
- Linear Recurrence (Inference Mode): Tokens are processed sequentially step-by-step. Generating token requires only updating the fixed -dimensional vector from in memory and operations per step, completely eliminating the linear memory growth of a Transformer KV cache.
- Global Convolution (Training Mode): Expanding the recurrence from yields:
The entire output sequence can be computed as a discrete 1D convolution:
Using the Fast Fourier Transform (FFT), this global convolution computes the entire sequence in parallel in time, enabling efficient training on modern GPUs.
The LTI Expressivity Bottleneck and HiPPO
Early structured SSM architectures such as S4 (Gu et al., 2021) addressed numerical stability and long-range memory by structuring using the HiPPO (High-order Polynomial Projection Operator) framework. HiPPO derives closed-form continuous transition matrices that maintain an optimal continuous orthogonal polynomial projection (e.g., Legendre polynomials) of historical input signals.
However, LTI SSMs suffered from a fundamental theoretical limitation: time-invariance. Because the convolutional filter is static and independent of input tokens, an LTI model cannot dynamically change its attention or memory based on sequence context. It cannot solve basic associative recall tasks, such as copying dynamic key-value pairs or filtering out irrelevant filler tokens based on content.
Mamba-1: Selective State Spaces and Hardware-Aware Scans
To overcome the expressivity ceiling of LTI models while retaining linear computational scaling, Mamba-1 (Gu and Dao, 2023) introduced Selective State Spaces (S6).
The Selection Mechanism
Mamba makes the discretization parameters dynamic functions of the current input token :
where , , and . The transition matrix is parameterized as a diagonal matrix. The discretized parameters become time-dependent:
The dynamic step size acts as a continuous, input-dependent gating mechanism:
- When , and , causing the model to ignore the current token and retain its accumulated historical state .
- When , , resetting the historical state and focusing computational capacity entirely on the new token .
+-------------------------------------------------------------------------+
| Mamba-1 Block Layer |
| |
| Input Vector x_t in R^D |
| / \ |
| Linear Expansion (E=2) Linear Projection |
| | | |
| 1D Conv (k=4) + SiLU | |
| | | |
| Selective SSM (S6 Engine) | |
| Delta_t, B_t, C_t = f(x_t) | |
| h_t = A_t h_{t-1} + B_t x_t | |
| y_t = C_t h_t | |
| \ / |
| Multiplicative Gating (SiLU) |
| | |
| Linear Projection Out |
+-------------------------------------------------------------------------+Breaking the Convolutional Constraint
Because vary with each token , the system loses time-invariance. The global convolution operator can no longer be parameterized as a fixed filter, making FFT-based parallel convolution mathematically impossible.
A naive sequential implementation of the recurrence on a GPU would require materializing the intermediate state tensor in High-Bandwidth Memory (HBM) at each token position. For batch size , sequence length , model dimension , and state expansion , materializing requires transferring gigabytes of intermediate data across the memory bus at every layer, resulting in severe GPU memory bandwidth starvation.
Hardware-Aware Parallel Associative Scan
Mamba-1 resolves this memory bottleneck through a dedicated GPU kernel utilizing a parallel associative scan:
- Kernel Fusion in SRAM: Parameters are loaded from GPU HBM into fast local on-chip Shared Memory (SRAM) once per block.
- On-Chip Discretization: The discretization step is computed directly in SRAM without writing intermediate discretized matrices back to HBM.
- Associative Scan Tree: The recurrence is formulated as an associative binary operation:
Using a parallel prefix sum (Blelloch scan tree) executed across GPU thread warps, the sequential recurrence over length is computed in parallel across the sequence dimension in parallel step depth.
- Direct Output Projection: The state is multiplied by inside SRAM, and only the final output tensor is written back to HBM. Intermediate states are recomputed during the backward pass rather than saved to memory.
Mamba-2 and Structured State Space Duality (SSD)
While Mamba-1 established competitive empirical scaling against Transformers, its execution model exposed a hardware utilization limitation on modern GPU architectures (such as NVIDIA A100 and H100). Modern AI accelerators achieve high theoretical FLOPS primarily through specialized matrix-multiplication units (Tensor Cores).
Mamba-1’s selective scan operates predominantly on matrix-vector products and point-wise state updates. These operations are memory-bandwidth bound and cannot fully exploit Tensor Core Matrix Multiply-Accumulate (MMA) pipelines.
Mamba-2 (Dao and Gu, 2024) resolved this hardware mismatch by introducing the framework of Structured State Space Duality (SSD).
The SSD Theoretical Equivalence
Dao and Gu proved that when the continuous transition matrix is structured as a scalar-times-identity matrix (), linear time-varying state space models are mathematically equivalent to a structured form of masked linear attention.
Consider an SSM with input , scalar transitions , and projection vectors . The input-to-output mapping can be expressed in closed matrix form:
where the transformation matrix is a 1-semiseparable matrix whose elements are defined by:
By factoring through the lens of attention operators, this transformation can be written as:
where:
- Queries:
- Keys:
- Values:
- Mask matrix: for , representing a 1-semiseparable causal decay mask.
- denotes the Hadamard (element-wise) product.
This formulation demonstrates that SSMs and Attention are two computational expressions of the same underlying algebraic structure:
- Attention view: Compute (matrix multiplication), multiply by mask , and multiply by .
- State space view: Maintain hidden state and project .
+-------------------------------------------------------------------------+
| Chunk-Wise SSD Computation Pipeline |
| |
| Sequence divided into chunks of length Q (e.g., Q = 64 tokens) |
| |
| 1. Intra-Chunk Computation (Tensor Cores / Dense GEMM): |
| Y_intra = (L_chunk o (Q_chunk * K_chunk^T)) * V_chunk |
| |
| 2. Inter-Chunk State Recurrence (Linear SSM Scan): |
| H_k = a_k * H_{k-1} + K_k^T * V_k (State size N x P) |
| |
| 3. Output Aggregation: |
| Y_chunk = Y_intra + Q_chunk * H_{k-1} |
+-------------------------------------------------------------------------+The Chunk-Wise SSD Algorithm
To maximize hardware throughput on Tensor Cores, Mamba-2 implements a chunk-wise decomposition algorithm:
- The sequence of length is divided into non-overlapping chunks of size (typically or ).
- Diagonal Blocks (Intra-Chunk): Within each chunk, tokens interact via dense matrix multiplications using Tensor Cores: .
- Off-Diagonal Blocks (Inter-Chunk): Interaction between different chunks occurs strictly through boundary state vectors. Each chunk summarizes its token representations into an end-of-chunk state .
- A recurrent SSM scan propagates the states across chunks: .
- The accumulated state is projected into the current chunk via matrix multiplication () and added to .
This chunk-wise algorithm achieves up to 8x faster training speed over Mamba-1 by mapping the vast majority of FLOPs to Tensor Core GEMM operations, while allowing the state dimension to be expanded from (in Mamba-1) to , or without incurring memory bandwidth penalties.
Multi-Head State Space Layers
Mamba-2 restructures the block architecture to match standard Multi-Head Attention (MHA) and Grouped-Query Attention (GQA) conventions. In Mamba-2:
- Hidden dimension is split into heads, each of dimension ().
- Projections for and are computed in a single unified matrix multiplication at the block entrance.
- Multi-head configurations allow sharing and representations across heads, mirroring Multi-Query Attention (MQA) and Grouped-Query Attention (GQA) parameter efficiencies.
Architectural Comparison: Mamba vs. Transformer
The mathematical differences between Multi-Head Self-Attention, Linear Attention, Mamba-1, and Mamba-2 translate into distinct computational and memory profiles:
| Dimension | Standard Transformer (MHA) | Linear Attention | Mamba-1 (Selective SSM) | Mamba-2 (SSD) | | :--- | :--- | :--- | :--- | :--- | | Training Time Complexity | | | | | | Inference Step Compute | | | | | | Inference Memory (KV Cache) | (Grows linearly) | (Constant) | (Constant) | (Constant) | | Hardware Core Affinity | Tensor Cores (GEMM) | Vector ALUs / Mixed | Memory Bandwidth (Scan) | Tensor Cores (Chunk GEMM) | | Associative Recall | Exact (Full Softmax Matrix) | Degraded (Kernel Decay) | High (Selective Gating) | High (Multi-Head SSD) | | State Expansion () | Implicitly | Typically | Constrained () | Scalable () |
Inference Throughput and Memory Scaling
In standard autoregressive Transformer decoding, each step must load the historical KV cache from GPU HBM to compute attention weights. As context length reaches tens of thousands of tokens, the memory bandwidth required to transfer the KV cache exceeds the compute time of the matrix multiplications, creating an I/O bottleneck.
In contrast, Mamba models maintain a constant state representation . For a model with and , the state footprint per sequence is strictly fixed at approximately 512 KB per layer, regardless of whether the prompt is 1,000 tokens or 1,000,000 tokens long. This allows inference engines to support batch sizes up to an order of magnitude larger on identical GPU hardware.
The Trade-Off: Associative Recall and Hybrid Architectures
While selective state spaces solve the content-blindness of LTI models, pure SSMs compress historical information into a fixed-capacity vector state . For tasks requiring exact arbitrary lookups across long contexts, such as needles in a haystack or complex multi-hop variable tracing across 100K+ tokens, softmax attention preserves an uncompressed, lossless memory representation.
To achieve an optimal balance between throughput and arbitrary associative recall, modern production systems increasingly deploy Hybrid Architectures:
- AI21 Jamba: Interleaves Mamba-1/2 layers with standard Transformer Attention layers and Mixture-of-Experts (MoE) routing, achieving up to 3x higher throughput on long prompts while retaining Transformer-grade retrieval fidelity.
- NVIDIA Nemotron-4 / Samba: Utilizes alternating blocks of Mamba and sliding-window attention to optimize training efficiency and long-context reasoning.
Sources
- Gu, A., & Dao, T. (2023). Mamba: Linear-Time Sequence Modeling with Selective State Spaces. arXiv:2312.00752
- Dao, T., & Gu, A. (2024). Transformers are SSMs: Generalized Models and Efficient Algorithms Through Structured State Space Duality. arXiv:2405.21060
- Gu, A., Goel, K., & Ré, C. (2021). Efficiently Modeling Long Sequences with Structured State Spaces. arXiv:2111.00396



