Paper deep-dive series · 2
Key takeaways
- S4-style state-space models carry a fixed-size state but treat every token the same. Mamba makes \(\Delta\), \(B\) and \(C\) functions of the input, so the model decides token by token what to keep — filtering at write time.
- Small \(\Delta\) → \(\bar{A} \approx 1\): skip the token, keep the memory. Large \(\Delta\) → \(\bar{A} \approx 0\): wipe the state and let the new input take over.
- The recurrence is linear and associative, so a parallel scan trains it in \(O(\log L)\) sequential steps with \(O(L)\) total work; generation needs a constant-size state instead of a growing KV cache.
- Mamba-2 recast the layer as structured matrix multiplication (SSD); Mamba-3 (ICLR 2026) refines it for inference.
The field of Artificial Intelligence has been defined by a single architecture for nearly a decade: the Transformer. While it has powered revolutions like ChatGPT and Claude, it hides a structural flaw that no amount of scaling can simply “fix.”
Transformers suffer from a quadratic bottleneck. As the length of the input sequence (\( L \)) grows, the computational cost grows by \( L^2 \). This makes processing massive sequences — like entire human genomes (millions of base pairs) or raw audio waveforms — prohibitively expensive. Furthermore, Transformers use Read-Time Filtering. They store the entire history of the sequence (the Key-Value Cache) and only filter out irrelevant information when they “read” it back via attention. This forces the memory footprint to grow linearly with every new token generated.
Enter Mamba.
Many LLMs are moving towards hybrid architectures that combine linear-time layers with a few full-attention layers — take Nemotron 3, which interleaves Mamba-2 layers with a handful of attention layers.
Mamba is not just an optimization; it is a paradigm shift. It replaces the memory-heavy attention mechanism with a Selective State Space Model (SSM). By introducing a dynamic “gate” (Delta), Mamba learns to selectively remember or forget information token-by-token. The result is a model that matches the Transformer’s accuracy but scales linearly (\( O(L) \)), unlocking infinite-context possibilities.
Here is the complete technical story of how Mamba works, from the physics of its memory to the engineering of its parallel algorithms.
The Foundation: State Space Models (SSMs)
Mamba is built on State Space Models (S4), a concept borrowed from control theory (used to describe physical systems like robotic arms or circuits).
An SSM describes a system using a single, compact “hidden state” (\( h \)) that evolves over time. Unlike an attention cache, it doesn’t store the history; it stores the current state of the history.
In continuous time, the system is defined by two equations:
$$h'(t) = A\,h(t) + B\,x(t)$$
$$y(t) = C\,h(t)$$
- The State Equation (\( h'(t) \)): This tells us how the memory changes. The new memory is a mixture of the old memory \( A\,h(t) \) and the new input \( B\,x(t) \).
- \( A \) (The Dynamics Matrix): This is the Retention Filter. It acts on the past. It dictates how long information persists in the state. If \( A \) is small, the memory decays quickly. If \( A \) is stable, the memory persists.
- \( B \) (The Input Matrix): This is the Input Modulator. It acts on the present. It determines how strongly the new input \( x(t) \) influences the system.
The Fatal Flaw of the Past (S4):
Previous Deep Learning SSMs, like S4, had a critical weakness: the matrices \( A \) and \( B \) were static. They were fixed learned parameters shared across the entire sequence.
This meant the model treated every token exactly the same. It used the same retention rate for a crucial proper noun as it did for a filler words like “um.” It was content-agnostic, making it fast but poor at complex language tasks.
The Core Innovation: The Dynamic Delta Gate (Δ)
Mamba’s breakthrough is the Selective SSM (S6). It makes the system content-aware by making the parameters input-dependent.
For every input token \( x_k \), Mamba calculates a dynamic parameter called Delta (\( \Delta \)). This \( \Delta \) effectively represents the “step size” or “importance” of the current token.
From Continuous to Discrete (The Discretization):
Computers can’t process continuous time (\( t \)), so they process discrete steps (\( k \)). We must “discretize” the continuous matrices \( A \) and \( B \) using \( \Delta \). Mamba uses the Zero-Order Hold (ZOH) method to create dynamic, discrete gates:
$$\begin{aligned}\bar{A} &= f_A(\Delta, A)\\[2pt] \bar{B} &= f_B(\Delta, B)\end{aligned}$$
This transformation is where the magic happens. By varying \( \Delta \), the model fundamentally changes the physics of its memory.
This dynamic \( \Delta \) effectively acts as a time-step parameter. Let’s see how its value translates into the “forget” and “update” decisions — the gates of Mamba.
The discretization process transforms the continuous-time matrices (\( A \) and \( B \)) into discrete-time matrices (\( \bar{A} \) and \( \bar{B} \)) based on the calculated \( \Delta \).
- The transformed matrix \( \bar{A} \) serves as the forget gate.
- The transformed matrix \( \bar{B} \) serves as the input (or update) gate.
The Physics of Selection: How Mamba “Skips” and “Resets”
The value of Delta acts as a gatekeeper. We can mathematically prove how it allows Mamba to either preserve memory (skip noise) or overwrite memory (focus on signal).
Scenario A: The “Skip” (Small Delta):
Imagine the model reads a stop word like “the”. It predicts a small \( \Delta \) (Close to 0) which makes \( \bar{A} \) close to identity matrix.
What do you predict happens to the retention of the old state (\( \bar{A} \)) when the time step is very small? Does the memory fade quickly or is it strongly preserved?
The Result: The previous state is multiplied by 1. It is preserved perfectly. The new input is largely ignored. The model effectively skips this token, retaining its context for later.
Scenario B: The “Reset” (Large Delta):
Imagine the model reads a major context shift, like “Chapter 2”. It predicts a large \( \Delta \) (\( \Delta \to \infty \)) making \( \bar{A} \) close to 0.
What do you predict happens to the influence of the current input (\( \bar{B} \)) when \( \Delta \) is large?
The Result: The old memory is multiplied by 0 (erased). The new input dominates the state. The model overwrites the history to focus entirely on the new, critical information.
This Write-Time Filtering allows Mamba to compress massive amounts of information into a fixed-size state without losing the signal in the noise.
Interactive figure — needs JavaScript. Drag Δ to move between skipping a token and resetting on it.
The flow of information in a Mamba block follows this structure:
- Input Projection: The input token vector \( x_k \) is projected into a higher-dimensional space.
- Split and Gates: This projected vector is split into two paths
- One path feeds into the Selective SSM layer. Inside it, \( x_k \) is used to compute the dynamic parameters: \( \Delta_k \), \( B_k \), and \( C_k \).
- The second path, called the gating mechanism, bypasses the SSM and later multiplies its output (see the block anatomy below).
- Discretization: The model uses the input-dependent \( \Delta_k \) to transform the static, learned matrices \( A \) and \( B \) into the dynamic forget gate (\( \bar{A} \)) and input gate (\( \bar{B} \)).
- State Update: The discrete state equation below is executed, producing the new memory state \( h_k \) and the output \( y_k \).
$$h_k = \bar{A}_k\, h_{k-1} + \bar{B}_k\, x_k, \qquad y_k = C_k\, h_k$$
$$\bar{A}_k = \exp(\Delta_k A), \qquad \bar{B}_k = (\Delta_k A)^{-1}\big(\exp(\Delta_k A) - I\big)\,\Delta_k B_k$$
\( \bar{A}_k \) decides how much of \( h_{k-1} \) survives, \( \bar{B}_k \) how strongly \( x_k \) is written, and both move together with \( \Delta_k \). Step through it on one channel:
Interactive figure — needs JavaScript. It steps through the recurrence one token at a time, showing Δ, Ā, B̄ and the new state for each word.
The Engineering Miracle: The Parallel Scan
We established that Mamba uses a recurrent state (\( h_k \) depends on \( h_{k-1} \)). In traditional RNNs, this is a disaster for training speed because you cannot calculate step 100 until you have calculated step 99. GPUs hate this; they want to process everything at once (parallelism).
Mamba solves this with the Parallel Scan Algorithm — the selective scan.
The Associative Property:
The researchers observed that the linear update operation of an SSM is associative.
This mathematical property means that even though the process is sequential, we don’t have to calculate it strictly left-to-right. We can group operations together.
The Up-Sweep and Down-Sweep:
Mamba uses a tree-based algorithm (similar to the Blelloch scan):
- Up-Sweep (Parallel Reduction): The model groups adjacent tokens (pairs) and computes their partial updates in parallel. It effectively calculates “what happens from step 1 to 2” and “step 3 to 4” simultaneously.
- Down-Sweep: It combines these partial chunks to distribute the correct cumulative state to every position.
The Impact: This reduces the number of sequential steps — the depth of the computation — from \( O(L) \) to \( O(\log L) \). The total work stays \( O(L) \); what changes is that it is spread across thousands of GPU threads instead of waiting in line.
Animated figure — needs JavaScript. It walks through the up-sweep and down-sweep of the parallel scan.
This allows Mamba to train just as fast as a Transformer, removing the primary bottleneck that held back previous RNNs.
The Full Anatomy: Inside the Mamba Block
The Selective SSM is the core, but the full “Mamba Block” wraps this engine in a modern neural network architecture designed for performance.
Interactive figure — needs JavaScript. A diagram of the Mamba block: input projection, then a convolution + SiLU + selective SSM branch and a SiLU gate branch, multiplied and projected back out.
Local Feature Extraction (1D Convolution):
Before the sequence enters the SSM, it passes through a standard 1D Convolution layer.
Why? SSMs are great at global context (the whole book). Convolutions are great at local context (the current sentence). This gives Mamba a “dual focus,” ensuring it doesn’t miss short-range patterns like bigrams.
SiLU Gating (The MLP Replacement):
Mamba replaces the Transformer’s Multi-Layer Perceptron (MLP) with a gating mechanism. It runs a parallel path alongside the SSM and combines them using the SiLU (Sigmoid Linear Unit) activation function.
Why? This provides the necessary non-linearity, allowing the model to learn complex functions that a purely linear SSM cannot.
What Came Next: Mamba-2 and Mamba-3
Mamba-2 (Dao & Gu, 2024) restricts \( \bar{A} \) to a scalar times the identity in each head. That small loss of flexibility buys a big result — State Space Duality (SSD): the same layer can be computed either as a recurrence or as a masked, attention-like matrix multiplication. Training runs as chunkwise matmuls on tensor cores, and the paper reports a core layer 2–8× faster than Mamba’s selective scan. It also makes the link to linear attention explicit, which is why Mamba-2 and Gated DeltaNet show up as the linear layers of production hybrids (Nemotron 3 uses Mamba-2; Qwen3-Next uses Gated DeltaNet).
Mamba-3 (Lahoti et al., ICLR 2026) takes an inference-first view. It adds a more expressive “exponential-trapezoidal” discretization (expressive enough that the short convolution above can be dropped), a complex-valued state update computed as RoPE-like rotations for state tracking, and a multi-input multi-output (MIMO) form that does more work per decoding step without raising latency. At 1.5B parameters the authors report +0.6 points of average downstream accuracy over Gated DeltaNet (+1.8 with MIMO), and Mamba-2-level perplexity with half the state size.
All three live under one node of the Architecture Atlas.
Conclusion: The Linear Future
Mamba represents a “best of both worlds” breakthrough.
By solving the “Selectivity” problem with dynamic Delta gates and solving the “Training Speed” problem with Parallel Scans, Mamba has proven that we don’t need quadratic attention to model language. We just need a smarter, selective memory.
This architecture opens the door to million-token context windows, allowing AI to read entire genomes, process hours of audio, or memorize whole codebases without running out of memory.
References
- Gu, A., Goel, K., & Ré, C. (2021). Efficiently Modeling Long Sequences with Structured State Spaces (S4). arXiv:2111.00396.
- 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 (Mamba-2). arXiv:2405.21060.
- Lahoti, A., Li, K. Y., Chen, B., et al. (2026). Mamba-3: Improved Sequence Modeling using State Space Principles. ICLR 2026. arXiv:2603.15569.
- NVIDIA (2025). NVIDIA Nemotron 3: Efficient and Open Intelligence. arXiv:2512.20856.
Until next time folks…
El Psy Congroo