Paper · 2023-12-01 · cs.LG, cs.AI
Mamba: Linear-Time Sequence Modeling with Selective State Spaces
Makes the SSM step size and input/output matrices functions of each token, so a state-space model can keep or drop each input. A fused, memory-aware parallel scan computes the resulting recurrence; blocks are stacked with no attention or MLP. Author-reported: best zero-shot results against open models of the same size, and about 5x inference throughput versus Transformers.
State-space model (SSM)Recurrent neural network (RNN)Self-attentionsequence-modelsstate-space-modelsselective-scanlanguage-modelinghardware-efficient-training
arXivPDFCodeMarkdown17 min read
AI-compiled by claude-haiku-5-5 on 2026-10-19, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.
In plain words
Most language models read text by letting every token look back at every earlier token. That works very well but gets expensive as the text grows. A cheaper family, state-space models, instead passes a small running memory along the sequence. The catch is that the memory update is the same for every token, so the model cannot decide, token by token, what to remember and what to ignore. It finds it hard to pick out one useful word among filler.
This paper makes the memory update depend on the current token. A "step size" decides how much of the old memory to keep and how much of the new token to write in, and the same idea controls what is read out. The catch is that this no longer lets the computation be written as one fixed filter, so the authors also wrote a GPU routine that runs the updates in parallel without storing the full memory for every step. The resulting model has no attention and no separate feed-forward block; one repeated block does the work. The authors report that it matches or beats open Transformers of the same size on language, and that it also works on audio and DNA.
TL;DR
- Mamba is a state-space sequence model whose step size, input matrix and output matrix depend on the current input (the "selection" mechanism) §3.2.
- The input-dependent recurrence cannot be computed as a convolution, so the authors give a fused, hardware-aware parallel scan with recomputation in the backward pass §3.3, app. D.
- The model is one homogeneous block, repeated, with no attention and no MLP §3.4.
- Author-reported: best zero-shot scores among open models at each size from 130M to 2.8B; about 5x inference throughput versus Transformers of similar size §4.2.2, §4.5.
- Released code is Apache-2.0 at
state-spaces/mamba; the file for this paper's Mamba-1 layer ismamba_simple.py[code].
Problem
Attention keeps the whole context, so inference must store every past key and value (the KV cache), and training cost grows with the square of the length §3.1. Recurrent models keep a fixed-size state and are cheap, but their effectiveness depends on how well the state compresses the context §3.1.
Earlier structured state-space models (S4 and its relatives) are linear time-invariant: their parameters are the same at every step. The authors argue that such models cannot select content, so they fail a Selective Copying task where the positions of the tokens to remember vary, while they solve the fixed-spacing Copying task §3.1. Making the parameters input-dependent removes the convolution form, which was the reason these models were efficient §3.2, §3.3.
The assumptions are: discrete data such as text and DNA, long sequences, and a GPU that is limited by memory bandwidth rather than by matrix multiplication §3.3, app. D.
Method
Background. A structured SSM maps a scalar input sequence to an output through a latent state of size N, using four parameters (Δ, A, B, C). In continuous time, h' = A h + B x and y = C h §2. Zero-order hold (ZOH) discretisation with step Δ gives Ā = exp(ΔA) and B̄ = (ΔA)^-1 (exp(ΔA) − I) · ΔB §2, eq. 4. The discrete system can be run as a recurrence h_t = Ā h_{t−1} + B̄ x_t, y_t = C h_t, or, when Δ, A, B, C are fixed, as a convolution with a kernel built from C B̄, C Ā B̄, and so on §2.
Selection. Let B, C and Δ be functions of the input x_t, and keep A fixed §3.2, alg. 2:
- B = Linear_N(x), C = Linear_N(x) §3.2;
- Δ = softplus(Parameter + Broadcast_D(Linear_1(x))) §3.2;
- A is kept time-invariant, because it only affects the model through Δ·A in Ā and the authors expect a selective A to give similar results §3.2, §3.5.
Because B, C and Δ now carry a time index, the model is time-varying, and the convolution equivalence is lost §3.2. The authors also show that for N = 1, A = −1, B = 1 and a linear Δ, the selective recurrence becomes a gated RNN, h_t = (1 − g_t) h_{t−1} + g_t x_t with g_t = σ(Linear(x_t)); this is their explanation of why Δ is the key parameter §3.5, eq. 5, app. C.
Hardware-aware scan. The naive method would materialise Ā and B̄ of shape (B, L, D, N) and the states in high-bandwidth memory app. D. The authors instead fuse three steps into one kernel: read Δ, A, B, C from slow memory, discretise and run a parallel associative scan in fast on-chip memory, then multiply by C and write an output of shape (B, L, D) §3.3, app. D. The backward pass recomputes the intermediate states instead of storing them §3.3, app. D. Long sequences are split into chunks; the scan state carries across chunks app. D.
Block. Each block expands the model width D by E = 2, projects the input into two branches, applies a short causal convolution and SiLU to one branch, runs the selective SSM on it, multiplies by SiLU of the other branch, and projects back to D §3.4, app. E.2.2. A normalisation layer and a residual connection wrap the block, and the blocks are stacked with no separate attention or MLP §3.4. Relative to H3, the block replaces the first multiplicative gate with an activation; relative to the gated MLP, it adds an SSM to the main branch §3.4.
# Selective SSM (S6) over one sequence [alg. 2] [§3.2]
# Input: x (B, L, D)
# Output: y (B, L, D)
# A is a fixed (D, N) parameter, with negative real values [§3.6]
def selective_ssm(x, A):
# Per-token SSM inputs; B and C are linear maps of x [§3.2]
B_sel = linear_N(x) # (B, L, N)
C_sel = linear_N(x) # (B, L, N)
# Per-token step size: 1-dim projection, broadcast to D channels,
# plus a learned per-channel bias, then softplus [§3.2]
delta = softplus(delta_bias + broadcast_D(linear_1(x))) # (B, L, D)
# Zero-order hold: A_bar = exp(delta A) and B_bar = (A_bar - 1) B / A
# (equal to (delta A)^-1 (A_bar - 1) delta B) [§2] [eq. 4]
A_bar = exp(delta[..., None] * A) # (B, L, D, N)
B_bar = (A_bar - 1) / A * B_sel[:, :, None, :] # (B, L, D, N)
# Recurrence over time; the GPU version is a parallel scan [§3.3]
h = zeros(B, D, N)
y = zeros(B, L, D)
for t in range(L):
h = A_bar[:, t] * h + B_bar[:, t] * x[:, t, :, None]
# Read out with C at this step [§2]
y[:, t] = sum_n(h * C_sel[:, t, None, :]) # (B, D)
return y# Mamba block [§3.4] [app. E.2.2]
# Input: hidden (B, L, D); expansion E = 2
# Output: (B, L, D)
def mamba_block(hidden):
# Two branches, each of width E * D [§3.4]
x, gate = linear_in(hidden).split(2) # (B, L, E*D) each
# Short causal convolution and SiLU on the SSM branch [app. E.2.2]
x = silu(causal_conv(x)) # (B, L, E*D)
y = selective_ssm(x, A) # (B, L, E*D)
# Multiplicative SiLU gate from the other branch [§3.4]
y = y * silu(gate) # (B, L, E*D)
return linear_out(y) # (B, L, D)Hyperparameters
Values in the first block are from the paper. Rows marked "code" are read from the released code at code_commit and are not stated in the paper.
| Name | Value | Where | Notes |
|---|---|---|---|
| State dimension N | 16 | §4.5, §4.6.2 | Used for the efficiency benchmark and the N ablation; the sweep goes 1 to 16 §4.6.2 |
| Expansion E | 2 | §3.4 | Fixed in all experiments §3.4 |
| Blocks per Transformer layer | 2 Mamba blocks match one MHA + MLP layer | §3.4, app. E.3.2 | Matched by parameter count |
| Causal conv width | not stated | app. E.2.2 | Code default d_conv=4 mamba_simple.py |
| Conv / linear bias | conv bias on; linear bias off | app. E.2.1 (no linear bias); code mamba_simple.py | |
| Δ projection rank R | "small fraction of D" | §3.6 | Code default ceil(D/16) mamba_simple.py |
| Δ init | τ⁻¹(Uniform([0.001, 0.1])) | §3.6 | Code samples log-uniformly, see Paper vs code |
| A init | S4D-Real, A_n = −(n+1) | §3.6 | Code: A_log = log(1..N) mamba_simple.py |
| Real vs complex | real, except audio | §3.6, §4.4.1 | Audio uses the complex S4 variant |
| Activation | SiLU | §3.4 | |
| Normalisation | LayerNorm optional; RMSNorm in LM recipe | §3.4, app. E.2.1 | Code: norm class set by config mixer_seq_simple.py |
| Discretisation | ZOH | §2, eq. 4 | Code uses a different B̄ approximation, see Paper vs code |
| Selective Copying | 2 layers, D = 64, seq 4096, 16 vocab, 16 data tokens, batch 64, 400K steps, constant LR 1e-4 | app. E.1 | |
| Induction Heads | Adam, no weight decay, batch 8, epoch 8192 steps; LR 2e-4 and 1e-3 tried, better one reported | app. E.1 | Mamba reported at LR 1e-3 for extrapolation |
| LM optimiser | AdamW, clip 1.0, weight decay 0.1, no dropout | app. E.2.1 | |
| LM betas | (0.9, 0.95) | app. E.2.1 | Improved recipe; default PyTorch is (0.9, 0.999) |
| LM LR schedule | linear warmup, cosine decay to 1e-5 | app. E.2.1 | Warmup length not stated |
| LM peak LR (improved recipe) | 5x the GPT-3 value | app. E.2.1 | Derived values: 3e-3 (125M), 1.5e-3 (350M), 1.25e-3 (760M), 1e-3 (1.3B); not listed in the paper |
| GPT-3 LM sizes | 125M: 12 layers, d 768, 4800 steps, 2.5B tokens; 350M: 24, 1024, 13500, 7B; 760M: 24, 1536, 29000, 15B; 1.3B: 24, 2048, 50000, 26B | app. E.2.1 | Batch 0.5M tokens (1.3B changed from 1M); GPT-3 peak LRs 6e-4, 3e-4, 2.5e-4, 2e-4 |
| Scaling data | The Pile, GPT-2 tokenizer | §4.2.1, app. E.2.1 | |
| Downstream pretraining | 300B tokens, GPT-NeoX tokenizer, context 2048; Mamba-1.3B batch 1M tokens | §4.2.2, app. E.2.3 | RWKV was trained at context 1024 §4.2.2 |
| DNA data | HG38, 34021 segments of 2^17 bp (about 4.5B tokens per epoch) | app. E.3.1 | |
| DNA optimiser | AdamW, betas (0.9, 0.95), weight decay 0.1, no dropout, cosine with 10% warmup | app. E.3.1 | |
| DNA LR sweep | {1e-3, 2e-3, 4e-3, 8e-3}; Mamba best at 8e-3; Transformer and HyenaDNA best at 2e-3 | app. E.3.2 | Single LR across sizes; upper edge of the sweep |
| DNA batch | 2^24 tokens per step at every length | app. E.3.3 | Sequence-length warmup: 2 epochs per power of two from 1024 app. E.3.3 |
| Species classification | 10 epochs x 1024 steps, batch 64; LR 1e-4 (Mamba), 4e-5 (Hyena); 5 warmup + 5 cosine epochs to 1e-6 | app. E.3.4 | |
| YouTubeMix | 3 blocks per stage, pool factor 16, D = 64, about 3.5M params; mu-law 8-bit; 200K steps; max LR 2e-3; 20K warmup; weight decay 0.1 | app. E.4.1 | Ablations: 6M params, 100K steps, LR 1e-3 |
| SC09 | AdamW, betas (0.9, 0.95), weight decay 0.1, clip 0.1, LR 2e-3, 200K steps, batch 16, warmup 10% | app. E.4.2 | Large model (24.3M): 15 layers per stage, D = 96, pool 4; ablation models (about 6M): 8 layers per stage, D = 64, pool 4; the 6.1M model's config is not stated |
| Efficiency benchmark | D = 1024, N = 16, batch 1, BF16, A100 80GB | app. E.5 | |
| Inference benchmark | prompt 2048, generation 128, batch 1 to 128, average of 3 runs | app. E.5 | Model is untrained for the 6.9B throughput test |
Results
Author-reported. Setup: Mamba models of 130M to 2.8B parameters, with baselines up to 7.4B; zero-shot models trained on 300B tokens, scaling runs on The Pile. Baselines are GPT-3 style Transformers, Transformer++ (rotary, SwiGLU, improved recipe), H3, Hyena, RWKV, RetNet, and Pythia §4.2, app. E.2. Hardware for speed numbers is one A100 80GB app. E.5.
Synthetic tasks §4.1. Selective Copying accuracy:
| Model | Arch. | Layer | Accuracy (%) |
|---|---|---|---|
| S4 | no gate | S4 | 18.3 |
| - | no gate | S6 | 97.0 |
| H3 | H3 | S4 | 57.0 |
| Hyena | H3 | Hyena | 30.1 |
| - | H3 | S6 | 99.7 |
| - | Mamba | S4 | 56.4 |
| - | Mamba | Hyena | 28.4 |
| Mamba | Mamba | S6 | 99.8 |
Induction Heads, trained at length 256: Mamba reaches perfect accuracy at all tested lengths up to 2^20 §4.1, app. E.1. The authors report that no other method goes beyond about 2x the training length §4.1. The appendix table lists the MHA variants as running out of memory from 2^15 onward, and H3 at 4.7–8.2% from 2^15 to 2^20 app. E.1.
Language modelling, scaling §4.2.1. Pile validation perplexity across 125M to 1.3B at the Chinchilla protocol and 2k and 8k context. The paper's figure shows Mamba as the first attention-free model to match Transformer++, mainly at longer context §4.2.1. No numbers are tabulated in the text.
Zero-shot evaluation §4.2.2. Pile perplexity is on the validation split and only compares with models using the same tokenizer and dataset (Pythia, RWKV). Accuracy on six tasks; the Average column is the mean of those six accuracies. Bold values are the best in each size class in the source.
| Model | Tok. | Pile ppl ↓ | LAMBADA ppl ↓ | LAMBADA acc ↑ | HellaSwag ↑ | PIQA ↑ | Arc-E ↑ | Arc-C ↑ | WinoGrande ↑ | Average ↑ |
|---|---|---|---|---|---|---|---|---|---|---|
| Hybrid H3-130M | GPT2 | — | 89.48 | 25.77 | 31.7 | 64.2 | 44.4 | 24.2 | 50.6 | 40.1 |
| Pythia-160M | NeoX | 29.64 | 38.10 | 33.0 | 30.2 | 61.4 | 43.2 | 24.1 | 51.9 | 40.6 |
| Mamba-130M | NeoX | 10.56 | 16.07 | 44.3 | 35.3 | 64.5 | 48.0 | 24.3 | 51.9 | 44.7 |
| Hybrid H3-360M | GPT2 | — | 12.58 | 48.0 | 41.5 | 68.1 | 51.4 | 24.7 | 54.1 | 48.0 |
| Pythia-410M | NeoX | 9.95 | 10.84 | 51.4 | 40.6 | 66.9 | 52.1 | 24.6 | 53.8 | 48.2 |
| Mamba-370M | NeoX | 8.28 | 8.14 | 55.6 | 46.5 | 69.5 | 55.1 | 28.0 | 55.3 | 50.0 |
| Pythia-1B | NeoX | 7.82 | 7.92 | 56.1 | 47.2 | 70.7 | 57.0 | 27.1 | 53.5 | 51.9 |
| Mamba-790M | NeoX | 7.33 | 6.02 | 62.7 | 55.1 | 72.1 | 61.2 | 29.5 | 56.1 | 57.1 |
| GPT-Neo 1.3B | GPT2 | — | 7.50 | 57.2 | 48.9 | 71.1 | 56.2 | 25.9 | 54.9 | 52.4 |
| Hybrid H3-1.3B | GPT2 | — | 11.25 | 49.6 | 52.6 | 71.3 | 59.2 | 28.1 | 56.9 | 53.0 |
| OPT-1.3B | OPT | — | 6.64 | 58.0 | 53.7 | 72.4 | 56.7 | 29.6 | 59.5 | 55.0 |
| Pythia-1.4B | NeoX | 7.51 | 6.08 | 61.7 | 52.1 | 71.0 | 60.5 | 28.5 | 57.2 | 55.2 |
| RWKV-1.5B | NeoX | 7.70 | 7.04 | 56.4 | 52.5 | 72.4 | 60.5 | 29.4 | 54.6 | 54.3 |
| Mamba-1.4B | NeoX | 6.80 | 5.04 | 64.9 | 59.1 | 74.2 | 65.5 | 32.8 | 61.5 | 59.7 |
| GPT-Neo 2.7B | GPT2 | — | 5.63 | 62.2 | 55.8 | 72.1 | 61.1 | 30.2 | 57.6 | 56.5 |
| Hybrid H3-2.7B | GPT2 | — | 7.92 | 55.7 | 59.7 | 73.3 | 65.6 | 32.3 | 61.4 | 58.0 |
| OPT-2.7B | OPT | — | 5.12 | 63.6 | 60.6 | 74.8 | 60.8 | 31.3 | 61.0 | 58.7 |
| Pythia-2.8B | NeoX | 6.73 | 5.04 | 64.7 | 59.3 | 74.0 | 64.1 | 32.9 | 59.7 | 59.1 |
| RWKV-3B | NeoX | 7.00 | 5.24 | 63.9 | 59.6 | 73.7 | 67.8 | 33.1 | 59.6 | 59.6 |
| Mamba-2.8B | NeoX | 6.22 | 4.23 | 69.2 | 66.1 | 75.2 | 69.7 | 36.3 | 63.5 | 63.3 |
| GPT-J-6B | GPT2 | — | 4.10 | 68.3 | 66.3 | 75.4 | 67.0 | 36.6 | 64.1 | 63.0 |
| OPT-6.7B | OPT | — | 4.25 | 67.7 | 67.2 | 76.3 | 65.6 | 34.9 | 65.5 | 62.9 |
| Pythia-6.9B | NeoX | 6.51 | 4.45 | 67.1 | 64.0 | 75.2 | 67.3 | 35.5 | 61.3 | 61.7 |
| RWKV-7.4B | NeoX | 6.31 | 4.38 | 67.2 | 65.5 | 76.1 | 67.8 | 37.5 | 61.0 | 62.5 |
HellaSwag and Arc-C use length-normalised accuracy app. E.2.3. The text's "Mamba-3B" claim is not a row in this table (see Pitfalls).
DNA §4.3, app. E.3. HG38 pretraining: Mamba scales better than HyenaDNA and Transformer++ with model size at context 1024, and improves with longer context while the baselines do not. Great Apes classification after fine-tuning (chance is 20%) app. E.3.4:
| Model | Params | 2^10 | 2^12 | 2^14 | 2^16 | 2^18 | 2^20 |
|---|---|---|---|---|---|---|---|
| HyenaDNA | 1.4M | 28.04 | 28.43 | 41.17 | 42.22 | 31.10 | 54.87 |
| Mamba | 1.4M | 31.47 | 27.50 | 27.66 | 40.72 | 42.41 | 71.67 |
| Mamba | 7M | 30.00 | 29.01 | 31.48 | 43.73 | 56.60 | 81.31 |
Audio §4.4. YouTubeMix (piano, 16 kHz) pretraining: Mamba beats the SaShiMi S4+MLP baseline at every context from 8192 to about 10^6, and the gap widens with length §4.4.1. SC09 speech generation (unconditional, 1-second clips, digits 0-9) §4.4.2:
| Model | Params | NLL ↓ | FID ↓ | IS ↑ | mIS ↑ | AM ↓ |
|---|---|---|---|---|---|---|
| SampleRNN | 35.0M | 2.042 | 8.96 | 1.71 | 3.02 | 1.76 |
| WaveNet | 4.2M | 1.925 | 5.08 | 2.27 | 5.80 | 1.47 |
| SaShiMi | 5.8M | 1.873 | 1.99 | 5.13 | 42.57 | 0.74 |
| WaveGAN | 19.1M | — | 2.03 | 4.90 | 36.10 | 0.80 |
| DiffWave | 24.1M | — | 1.92 | 5.26 | 51.21 | 0.68 |
| DiffWave + SaShiMi | 23.0M | — | 1.42 | 5.94 | 69.17 | 0.59 |
| Mamba | 6.1M | 1.852 | 0.94 | 6.26 | 88.54 | 0.52 |
| Mamba | 24.3M | 1.860 | 0.67 | 7.33 | 144.9 | 0.36 |
| Train data | — | — | 0.00 | 8.56 | 292.5 | 0.16 |
| Test data | — | — | 0.02 | 8.33 | 257.6 | 0.19 |
The SC09 architecture ablation at 6M parameters, outer and centre blocks §4.4.2:
| Outer | Centre | NLL ↓ | FID ↓ | IS ↑ | mIS ↑ | AM ↓ |
|---|---|---|---|---|---|---|
| S4+MLP | MHA+MLP | 1.859 | 1.45 | 5.06 | 47.03 | 0.70 |
| S4+MLP | S4+MLP | 1.867 | 1.43 | 5.42 | 53.54 | 0.65 |
| S4+MLP | Mamba | 1.859 | 1.42 | 5.71 | 56.51 | 0.64 |
| Mamba | MHA+MLP | 1.850 | 1.37 | 5.63 | 58.23 | 0.62 |
| Mamba | S4+MLP | 1.853 | 1.07 | 6.05 | 73.34 | 0.55 |
| Mamba | Mamba | 1.852 | 0.94 | 6.26 | 88.54 | 0.52 |
Speed and memory §4.5, app. E.5. The fused scan is up to 20–40x faster than a standard PyTorch scan and faster than FlashAttention-2 beyond sequence length 2K §4.5. Inference throughput: 4–5x that of a Transformer of similar size; the authors' abstract figure is 5x §4.5, §1. Training memory for 125M models, batch size vs GB:
| Batch | Transformer (FlashAttention-2) | Mamba |
|---|---|---|
| 1 | 4.6 GB | 4.8 GB |
| 2 | 5.2 GB | 5.8 GB |
| 4 | 6.9 GB | 7.3 GB |
| 8 | 11.5 GB | 12.3 GB |
| 16 | 20.7 GB | 23.1 GB |
| 32 | 34.5 GB | 38.2 GB |
The authors say Mamba's memory is comparable to a highly optimised Transformer, not lower app. E.5.
Ablations §4.6, 350M models at Chinchilla tokens, perplexity on the Pile:
| Model | Arch. | SSM layer | Ppl |
|---|---|---|---|
| Hyena | H3 | Hyena | 10.24 |
| H3 | H3 | S4 (complex) | 10.30 |
| - | H3 | S4 (real) | 10.34 |
| - | H3 | S6 | 8.95 |
| - | Mamba | Hyena | 10.75 |
| - | Mamba | S4 (complex) | 10.54 |
| - | Mamba | S4 (real) | 10.56 |
| Mamba | Mamba | S6 | 8.69 |
Which parameters are selective (350M models) §4.6.2:
| Δ selective | B selective | C selective | Ppl |
|---|---|---|---|
| no | no | no | 10.93 |
| no | yes | no | 10.15 |
| no | no | yes | 9.98 |
| yes | no | no | 9.81 |
| yes | yes | yes | 8.71 |
State dimension N, with B and C selective (bottom) or constant (top) §4.6.2:
| N | Params (M) | Ppl, constant B, C | Ppl, selective B, C |
|---|---|---|---|
| 1 | 367.1 | 9.88 | 9.73 |
| 2 | 367.4 | 9.86 | 9.40 |
| 4 | 368.0 | 9.82 | 9.09 |
| 8 | 369.1 | 9.82 | 8.84 |
| 16 | 371.5 | 9.81 | 8.71 |
Initialisation of A with a selective SSM §4.6.2: A_n = −(n+1) and a random exp-normal init both give 8.71; A_n = −1/2 gives 8.85; the complex S4D-Lin init gives 9.16.
Paper vs code
Code: official repository https://github.com/state-spaces/mamba, commit e9594ce1c732d97440f0332fdc43170a2294dbfa, Apache-2.0 LICENSE. The paper links this repository in its introduction §1. The repository's HEAD also contains later Mamba-2 and Mamba-3 modules (mamba2.py, mamba3.py); the Mamba-1 layer described in this card is mamba_ssm/modules/mamba_simple.py mamba_simple.py.
-
Δ initialisation. Paper: Δ is initialised as τ⁻¹(Uniform([0.001, 0.1])) §3.6. Code: Δ is sampled log-uniformly between 0.001 and 0.1 and floored at 1e-4, then the inverse softplus is applied mamba_simple.py. The two give different distributions. The paper's version is uniform in Δ itself; the code's is uniform in log Δ.
-
B discretisation. Paper: B̄ is the ZOH formula (ΔA)⁻¹(exp(ΔA) − I)·ΔB §2, eq. 4. Code: Ā = exp(ΔA) is used, but the input term is Δ·B·u, with no ZOH factor for B selective_scan_interface.py. For N = 1, A = −1, the paper's gate form is g = 1 − e^(−Δ) app. C, while the code's input weight is Δ. The two agree to first order in Δ only. The gating interpretation in §3.5 therefore describes the paper's discretisation, not the code path.
-
Δ projection. Paper's default: s_Δ(x) = Broadcast_D(Linear_1(x)) §3.2; the low-rank Linear_D(Linear_R(x)) is an alternative §3.6. Code: x_proj produces a rank-R vector (R = ceil(D/16)) that is projected to D by dt_proj, i.e. the low-rank form mamba_simple.py. The paper's ablation with Δ projection size 64 §4.6.2 is not the code default.
-
Skip term D. Paper: the algorithm and equations have no skip term §3.2, alg. 2, §2. Code: adds u·D inside the scan and multiplies by SiLU(z) after selective_scan_interface.py. The model in the code is therefore y = SSM(x) + D·x, gated.
-
Causal convolution. The paper mentions a short convolution on the SSM branch app. C, app. E.2.2 but does not state its width. Code: depthwise causal conv with width 4 and bias mamba_simple.py.
-
Gate. Paper: SiLU applied to the second branch, multiplied with the SSM output §3.4. Code: same, y·SiLU(z) mamba_simple.py. No discrepancy found.
-
A initialisation. Paper: S4D-Real, A_n = −(n+1) §3.6. Code: A = 1..N, stored as log, and A = −exp(A_log) mamba_simple.py. No discrepancy found.
-
State size. Paper's efficiency benchmark uses N = 16 §4.5, app. E.5. Code default
d_state = 16mamba_simple.py. Consistent.
Pitfalls
-
ZOH versus the code's B approximation. Implementing the paper's eq. 4 for B̄ will not match the released kernel. If the goal is the paper's math, implement eq. 4; if the goal is to match the released code, use Δ·B·u and the code's Δ init (see Paper vs code). Say which one the implementation follows.
-
Model size naming. The abstract and §1 say "Mamba-3B"; the zero-shot table has Mamba at 130M, 370M, 790M, 1.4B and 2.8B, with no Mamba row at 3B or 6.9B §4.2.2. The "matches a Transformer twice its size" claim rests on the text, not on a table row. Do not infer a 3B result from the table.
-
Tie on one task. The table bolds WinoGrande for both Pythia-160M and Mamba-130M (51.9). The "best in class on every result" claim §4.2.2 therefore has a tie at 130M.
-
Throughput test uses untrained weights. The 6.9B inference throughput comparison uses an untrained Mamba model; the Transformer baseline is the Hugging Face Transformers implementation app. E.5. Throughput also depends on the batch size that fits in memory §4.5.
-
No variance. The paper does not report seeds, error bars or the number of runs for the training results (only three runs for inference timing) app. E.5. Treat small gaps in ablations (for example 8.69 vs 8.71) as within noise until replicated. This is a gap in the paper, not something the card can fill.
-
Selection hurts raw audio. On YouTubeMix, Mamba-S6 is worse than Mamba-S4 (LTI) in every block; keeping LTI layers in the outer U-Net stages and using S6 only in the centre closes most of the gap app. E.4.1. The paper's advice is to keep layers next to raw signal LTI. Use S6 for discrete tokens such as text and DNA §5, app. E.4.1.
-
Real vs complex. The paper uses real A everywhere except the audio experiment, where it switches to complex S4-style A §3.6, §4.4.1. The complex audio model is still better than the real one in that setting app. E.4.1.
-
Learning rates. For DNA the swept LR is at the top of its range (8e-3 for Mamba), which the authors say may leave results suboptimal app. E.3.2. For the species task, Mamba uses 1e-4 and Hyena 4e-5 app. E.3.4.
-
Hardware dependence. All speed and memory numbers are on A100 80GB GPUs with BF16 app. E.5. The fused scan is a CUDA kernel; the paper's own reference (
selective_scan_ref) is a Python loop over the sequence length selective_scan_interface.py and is for testing, not speed. -
Memory cost. The paper estimates about 16 bytes of activation per token per selective SSM layer, against 12 for attention and 20 for an MLP, assuming mixed-precision training app. D. The memory table in app. E.5 shows Mamba using more memory than the FlashAttention-2 Transformer at every tested batch size.
-
Inference state. Decoding keeps a convolution state of size D_inner x d_conv and an SSM state of size D_inner x N per layer, updated in place mamba_simple.py. Memory per sequence does not grow with the context; the paper credits this for the larger batch sizes behind its throughput claim §4.5.
-
Sequence length in DNA. Sequence-length warmup and batch-size scheduling are part of the DNA recipe; the paper did not test turning warmup off app. E.3.3.
Lineage
- Builds on: structured state-space models S4 and its diagonal variants (S4D, S5), HiPPO initialisation, and the H3 architecture, which Mamba simplifies §2, §3.4, app. B.
- Compared against: GPT-3 style Transformer, Transformer++ (rotary, SwiGLU), H3, Hyena, RetNet, RWKV, Pythia, SaShiMi (audio), HyenaDNA (DNA), FlashAttention-2 (speed) §4, app. E.
- Follow-up in this wiki: Mamba-2 (Structured State Space Duality), which relates SSMs to masked attention and gives a chunked algorithm for the same model family.
Source and license
Adapted from “Mamba: Linear-Time Sequence Modeling with Selective State Spaces” by Albert Gu, Tri Dao (arXiv:2312.00752), used under CC BY 4.0. Changes: condensed and restructured for implementation, with tables, equations and algorithms taken from the paper and its code, each cited to its source. Not affiliated with or endorsed by the authors. Code citations refer to https://github.com/state-spaces/mamba at commit e9594ce1c732 (Apache-2.0). Any quoted code is shown under that license.