Mamba Selective State-Space Module
A sequence-mixing module that updates a compact recurrent state as each token arrives, using input-dependent parameters to decide what the state stores, forgets, and emits.
A selective state-space module (SSM) processes tokens in order while carrying a small hidden state forward through time. Mamba makes that state input-dependent so each step can selectively store, forget, and emit information instead of using fixed recurrence rules.
At a glance
Released
December 2023
Authors
Albert Gu, Tri Dao
Optimizes
- Sequence Scaling
- Long Context Inference
- Memory Bandwidth
Example models
What It Is
A state-space module is a sequence-mixing block that reads tokens one at a time and keeps a compact hidden state that summarizes what came before. At each position, the module combines the current token with that carried state to produce an output and an updated state for the next step. A selective state-space model (SSM) changes the update rules based on the current input rather than applying the same fixed transition at every position.Why It Exists
Long sequences strain attention because dense attention compares every token to every other token. State-space modules offer a different path: they propagate information through a fixed-size state as the sequence unfolds, which can scale more gently with length when the recurrence is implemented efficiently.How It Works
The module walks the sequence in order. For each token, it projects the input into input-dependent parameters that control the state transition and output. The previous hidden state is updated into a new state, and the module emits an output vector for that position. In Mamba, those transition parameters depend on the current token, so the block can decide what to remember, what to discard, and what to expose at each step. That selective behavior is the main change from earlier fixed-coefficient state-space designs.Sequence mixing over time
x_tStep t selective updateh_{t-1}Selective Δ, B, Ch_ty_tEarlier token inputsx_0x_1…x_{t-2}x_{t-1}x_{t-1} to h_{t-1}h_{t-1} to Selective Δ, B, Cx_t to Selective Δ, B, CSelective Δ, B, C to h_th_t to y_t
State carried across steps
Input-dependent update path
Current token input
Selective gate parameters
Math Or Compute Schema
Dense attention forms outputs from pairwise token scores. A selective state-space step instead updates a hidden state and projects an output from that state. The formulas below contrast multi-head attention against a selective state update and output projection at one time step.Compared To Nearby Modules
Multi-head attention mixes tokens by scoring every query against every key position. Linear attention keeps a running summary but still routes through attention-style feature maps. A Mamba-style state-space module does not build an explicit all-pairs score map; it compresses history into a recurrent state and lets input-dependent gates shape each update.| Comparison dimension | Mamba Selective State-Space | Multi-Head Attention | Linear Attention |
|---|---|---|---|
| Sequence mixing mechanism | Ordered recurrent state updates with input-dependent transition parameters | Softmax-weighted combination of value vectors from all key positions | Feature-map accumulation over keys without materializing full score matrix |
| Direct all-pairs token comparison | No explicit n-by-n attention map; history flows through a compact state | Every query token scores against every key token | Approximates dense attention through kernel-style summaries |
| History representation | Fixed-size hidden state carried across positions | Past tokens remain addressable through keys and values at each step | Running key-value summaries rather than a single recurrent state vector |