Paper · 2024-05-31 · cs.LG
Transformers are SSMs: Generalized Models and Efficient Algorithms Through Structured State Space Duality
A state-space model with one scalar decay per head and masked linear attention are dual forms of one matrix family. Derives SSD, a chunked algorithm that mixes quadratic blocks with a linear state recurrence, and the Mamba-2 block built on it. Author-reported: SSD is 2-8x faster than Mamba's scan at state size 64; Mamba-2 2.7B averages 60.2 zero-shot vs 59.9 for Mamba-2.8B.
State-space model (SSM)Linear attentionSelf-attentionMulti-query attention (MQA)sequence-modelsstate-space-modelslinear-attentionstructured-matriceshardware-efficient-training
arXivPDFCodeMarkdown17 min read
AI-compiled by claude-haiku-5-5 on 2026-10-18, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.
In plain words
Transformers handle sequences by letting every token look at every earlier token, which gets expensive as the text grows. A newer family, state-space models, instead carries a compact running memory from token to token, which scales well but has been harder to train quickly on modern GPUs. This paper shows that the two families are closely related. Once you write a state-space model as one big structured matrix, you can compute it either token by token (cheap in memory, slow to train) or as a set of matrix products (fast on GPUs, costly for long sequences).
The paper's answer is to split the sequence into chunks. Inside a chunk it uses the matrix-product form. Between chunks it passes a small state along with the recurrent form. The result is a layer, SSD, that is fast on GPUs, and a block design, Mamba-2, that is built around it. The authors report that it trains faster than the earlier Mamba layer and remains competitive on language modelling. These numbers come from the authors' own experiments.
TL;DR
- The paper links state-space models (SSMs) and a masked form of linear attention through "structured matrices", and calls the link state space duality (SSD) §1, §5.
- SSD restricts the SSM so that its state decay is one scalar per head. Under that restriction, the recurrent form and the quadratic form are dual §5.1–§5.3.
- The chunked SSD algorithm uses matrix multiplications inside chunks and a small recurrence across chunks. The authors state linear training cost, linear-in-length inference and matmul-dominated work §6, Theorem 6.1.
- Author-reported: SSD is 2–8× faster than Mamba's fused scan at state size 64, and faster than FlashAttention-2 from sequence length 2K §9.3, fig. 10.
- Use this card if you implement Mamba-2 or a scalar-decay SSM. Read the Pitfalls section first: the paper omits discretisation and several implementation details that the code fills in.
Problem
Softmax attention costs quadratic time in sequence length during training and needs a cache that grows with length during generation §1. Structured SSMs cost linear time in length and keep a constant-size state during generation §1, but the authors say their development had become disconnected from the work on Transformers. Training SSMs as efficiently as Transformers was described as an open problem from both the algorithmic and the systems side §1.
The paper's own limit is that SSD only covers the case of a scalar state decay per head. General diagonal SSMs such as Mamba's selective scan are not covered by the SSD algorithm §5, §7.2. The main results are stated for the scalar case.
Method
1. SSMs as matrices. A selective SSM with recurrence h_t = A_t h_{t-1} + B_t x_t and output y_t = C_t^T h_t is a linear map y = M x with M_ji = C_j^T A_{j:i} B_i §2, §3. Here A_{j:i} is the product of the state matrices from i+1 to j. The matrix M is lower-triangular and N-semiseparable, so it has a sequential semiseparable (SSS) representation §3. The paper omits discretisation from these equations and says the main models use the same parameterisation as Mamba §2, remark.
2. Scalar-identity SSMs. If each A_t is a scalar times the identity, A_t = a_t I, the matrix becomes M = L ∘ (C B^T). Here L is a 1-semiseparable mask built from cumulative products of the scalars a_t §5.1. Written as tensor contractions, this is the same computation as masked kernel attention, with C playing the role of queries, B of keys and X of values §5.1, §5.3, fig. 4.
3. 1-semiseparable masks. A 1-SS matrix 1SS(a) has entries a_{j:i} for j ≥ i. Multiplying by it is the scalar recurrence y_t = a_t y_{t-1} + x_t [§3, eq. for 1SS]. Standard causal linear attention is the special case a_t = 1 §5.2. Structured masked attention with a 1-SS mask is therefore a diagonal SSM with one scalar decay §5.2, corollary. The paper also proves that any autoregressive attention with bounded order must have a semiseparable mask §5.2, theorem; proof in app. C.
4. Structured state space duality. The paper identifies the two forms. The SSM view computes the linear recurrence with state size N. The attention view computes the quadratic masked form with kernel feature dimension N §5.3, fig. 4. The two are exact duals on the scalar-identity case §5.3.
5. Chunked SSD algorithm. Split the length-T sequence into blocks of length Q and write M as a grid of (T/Q) × (T/Q) blocks §6. The four pieces are:
- Diagonal blocks: the outputs within each chunk, computed with the quadratic form and a zero starting state §6, "Diagonal Blocks".
- Right factors: the state at the end of each chunk, assuming zero state at its start. This is one batched matrix product per chunk §6, "Right Factors".
- Centre factors: a scalar recurrence over the
T/Qchunk states, which gives the true state at each chunk boundary §6, "Center Factors". - Left factors: the contribution of the carried-in state to the outputs of each chunk, again one batched matrix product §6, "Left Factors".
The reference listing for the whole layer is [listing 1] in §6 (PyTorch, about 40 lines). The following pseudocode restates it with the chunk recurrence written as a loop. Shapes are given in comments.
# Chunked SSD for scalar-decay SSMs [§6] [listing 1]
# Input: X (T, H, P); log_decay (T, H), values <= 0
# B, C (T, H, N); Q chunk length, T divisible by Q
# Output: Y (T, H, P); final state (H, P, N)
def ssd_chunked(X, log_decay, B, C, Q):
# Cut the sequence into K = T / Q chunks [§6] [listing 1]
X, log_decay, B, C = chunk(X, log_decay, B, C, Q) # (K, Q, ...)
# Cumulative log decay, restarted in each chunk [§5.1] [listing 1]
decay_cumsum = cumsum(log_decay, over_axis=1) # (K, Q, H)
# Diagonal block: outputs from inputs in the same chunk [§6]
within_mask = exp(segsum(transpose(log_decay))) # (K, H, Q, Q)
Y_within = einsum(C, B, within_mask, X) # (K, Q, H, P)
# Right factor: state at each chunk end, zero state at chunk start [§6]
decay_to_end = exp(decay_cumsum[:, -1] - decay_cumsum) # (K, Q, H)
chunk_states = einsum(B, decay_to_end, X) # (K, H, P, N)
# Centre factor: carry states across chunks [§6]
# Each chunk decays the carried state by exp of its total log decay
chunk_decay = exp(decay_cumsum[:, -1]) # (K, H)
state = zeros(H, P, N)
for chunk_index in range(K):
# Save the state that enters this chunk [§6]
start_states[chunk_index] = state # (H, P, N)
state = chunk_decay[chunk_index] * state + chunk_states[chunk_index]
# Left factor: effect of earlier chunks on each output [§6]
decay_from_start = exp(decay_cumsum) # (K, Q, H)
Y_carry = einsum(C, start_states, decay_from_start) # (K, Q, H, P)
Y = reshape(Y_within + Y_carry, (T, H, P))
return Y, stateTwo notes on the sketch. The loop over chunks is the paper's centre-factor step, which can be replaced by any scan algorithm for the scalar recurrence §6, "Center Factors"; app. B. The chunk_states line sums over positions inside each chunk; the listing gives the explicit einsum [listing 1].
6. Mamba-2 block. The block moves all data-dependent projections to the start, so that A, X, B and C come from one projection §7.1. The paper also adds one extra normalisation layer before the output projection, following NormFormer §7.1. The B and C projections use one head shared across all X heads §7.1, fig. 6. Mamba's original selective SSM is described as a multi-input SSM with head dimension 1 §7.2. Head patterns are defined as in attention: MHA, multi-query, multi-key and multi-value analogues §7.2. The authors find that the multi-value pattern, the one Mamba uses, performs best §9.4.2, tab. 5.
The code gives more detail than the paper for this block. The following sketch follows the reference implementation mamba2_simple.py. Items marked (code) are not described in the paper text. batch is the batch size; B and C are the SSM input and output matrices.
# Mamba-2 block forward [§7.1] [code: mamba_ssm/modules/mamba2_simple.py#L131]
# Input: u (batch, T, D); H heads of size P; state size N; one B/C group
# Output: (batch, T, D)
def mamba2_block(u):
# One projection gives the gate, the SSM inputs and the step sizes [§7.1]
z, x, B, C, dt_raw = split(in_proj(u)) # z, x: (batch, T, H*P)
# Depthwise causal conv, kernel 4, over x, B and C (code, not in paper)
x, B, C = silu(causal_conv1d(concat(x, B, C))) # (code)
# Per-head step size from the raw value and a learned bias (code)
dt = softplus(dt_raw + dt_bias) # (batch, T, H)
# Per-head scalar decay a_t = exp(dt * A) with A < 0 (code)
log_decay = dt * (-exp(A_log)) # (batch, T, H), <= 0
# Scale the input by dt and run chunked SSD [§6] [§5.1]
x_heads = reshape(x, (batch, T, H, P)) * dt[..., None]
y, _ = ssd_chunked(x_heads, log_decay, B, C, chunk_len)
# Skip connection with a learned per-head weight (code, not in paper)
y = y + D[None, None, :, None] * reshape(x, (batch, T, H, P))
# Gate first, then normalise: the extra norm layer of §7.1 [§7.1]
gated = reshape(y, (batch, T, H * P)) * silu(z) # (code)
return out_proj(rms_norm(gated)) # (code)7. Discretisation. The paper omits discretisation in its equations and defers to Mamba §2, remark. The reference code applies a step size dt = softplus(raw + bias), takes the discrete decay as exp(dt · A) with A = -exp(A_log) < 0, and scales the input by dt mamba2_simple.py. This is the usual Mamba convention. It is not in the paper text.
8. Costs. With state size N, head size P = N, and chunk length Q = N, the authors state training FLOPs O(T N²), memory O(T N), and work dominated by N × N matrix products §6, Theorem 6.1; §6.3. The cost table gives N² FLOPs per inference step for SSD, the same as a plain SSM, with state size N §6.3, table. Attention costs T²N total training FLOPs and a cache of size T §6.3.
Hyperparameters
Values are as written in the paper. "not stated" means the paper text I read does not give a value. The code column is separate and says where it comes from.
| Name | Value | Where | Notes |
|---|---|---|---|
State size N, head size P for language models | not stated | tab. 8 | The table's n_heads / d_head column applies only to Transformers. |
State size N, head size P in ablations | N = 64, P = 64 | §9.4, tab. 5 | All ablation models use these. |
State size N in the SSD speed benchmark | N = 64 (fused-scan comparison) | fig. 10 | Also sweeps state size at sequence length 4K fig. 10. |
Chunk length Q | not stated | §6 | The paper's listing defaults to 64 [listing 1]. Code defaults differ, see Paper vs code. |
Kernel feature map ψ | Swish (SiLU) by default | §7.3 | Ablated against other maps in tab. 6, tab. 7. |
| Hybrid attention layers, 350M model | 48 layers, 7B tokens, GPT-2 tokenizer | §9.2.3, tab. 2 | Attention share about 10% is best. |
| Hybrid attention layers, 2.7B model | 64 layers: 58 SSD + 6 attention at indices 9, 18, 27, 36, 45, 56 | §9.2.3, footnote | Location of attention layers reported as not critical when spaced out. |
| Hybrid 2.7B training | 300B tokens on the Pile, same hyperparameters and data order as other variants | §9.2.3 | Compared against Transformer++ and Mamba-2 variants tab. 3. |
| Scaling-law model: 125M | 12 layers, d_model 768, 4800 steps, peak LR 6e-4, batch 0.5M tokens, 2.5B tokens | tab. 8 | Pile, GPT-2 tokenizer app. D.2. |
| Scaling-law model: 350M | 24 layers, d_model 1024, 13500 steps, peak LR 3e-4, batch 0.5M tokens, 7B tokens | tab. 8 | As above. |
| Scaling-law model: 760M | 24 layers, d_model 1536, 29000 steps, peak LR 2.5e-4, batch 0.5M tokens, 15B tokens | tab. 8 | As above. |
| Scaling-law model: 1.3B | 24 layers, d_model 2048, 50000 steps, peak LR 2e-4, batch 0.5M tokens, 26B tokens | tab. 8 | Batch size changed from 1M to 0.5M for uniformity app. D.2. |
| Optimiser | AdamW, β = (0.9, 0.95) | app. D.2 | Default PyTorch β is (0.9, 0.999) and was not used. |
| Gradient clipping | 1.0 | app. D.2 | |
| Weight decay | 0.1 | app. D.2 | |
| Dropout | none | app. D.2 | |
| LR schedule | linear warm-up, cosine decay to 1e-5 | app. D.2 | Warm-up length not stated. |
| Peak LR, improved recipe | 5× the GPT-3 value for that size | app. D.2 | |
| Architecture changes from GPT-3 | no linear biases, RMSNorm, rotary/gated MLP for Transformer++ | app. D.2, §9.2.1 | Mamba-2 uses the same recipe. |
| Downstream training | 300B tokens; 1M batch for 1.3B and 2.7B; 2.7B has 32 layers and d_model 2560; LR 5× GPT-3 | app. D.3 | GPT-NeoX tokenizer. |
| Downstream evaluation | EleutherAI LM evaluation harness; 7 tasks (LAMBADA, HellaSwag, PIQA, ARC-E, ARC-C, WinoGrande, OpenBookQA) | app. D.3 | Zero-shot. |
| MQAR sequence lengths | T ∈ {256, 512, 1024}; T/4 key-value pairs; vocab 8192 | app. D.1 | Harder than the original Based setup. |
| MQAR curriculum | key-value counts (T/32, T/16, T/8, T/4); 2^18 examples each; 8 epochs per dataset | app. D.1 | Batch 2^18 tokens. |
| MQAR model and sweep | 2 layers; model dimension in {32, 64, 128, 256}; LR in {10^-3.5, 10^-2, 10^-2.5}; linear decay dropping each epoch | app. D.1 | Attention baseline also gets positional embeddings. |
| Kernel ablation sizes | 130M models with N = 64; 380M models with N = 256 | tab. 7, app. D.4 | Based and ReBased project B, C to 8 and 16 dims; total state 64 and 73 at 130M. |
| SSD speed benchmark hardware | not stated | §9.3 | No GPU model in the text. |
Results
Author-reported. Setup: Pile validation perplexity and zero-shot accuracy on seven standard tasks, models trained on the Pile for up to 300B tokens §9.2.2, tab. 1. Compared with Pythia (same tokenizer and data) and Mamba-1 (same recipe) §9.2.2.
Table 1: zero-shot results, main text (from tab. 1; markings from source omitted).
| Model | Tok. | Pile ppl ↓ | LAMBADA ppl ↓ | LAMBADA acc ↑ | HellaSwag ↑ | PIQA ↑ | Arc-E ↑ | Arc-C ↑ | WinoGrande ↑ | OpenbookQA ↑ | Avg ↑ |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Pythia-1B | NeoX | 7.82 | 7.92 | 56.1 | 47.2 | 70.7 | 57.0 | 27.1 | 53.5 | 31.4 | 49.0 |
| Mamba-790M | NeoX | 7.33 | 6.02 | 62.7 | 55.1 | 72.1 | 61.2 | 29.5 | 56.1 | 34.2 | 53.0 |
| Mamba-2-780M | NeoX | 7.26 | 5.86 | 61.7 | 54.9 | 72.0 | 61.0 | 28.5 | 60.2 | 36.2 | 53.5 |
| Hybrid H3-1.3B | GPT2 | — | 11.25 | 49.6 | 52.6 | 71.3 | 59.2 | 28.1 | 56.9 | 34.4 | 50.3 |
| Pythia-1.4B | NeoX | 7.51 | 6.08 | 61.7 | 52.1 | 71.0 | 60.5 | 28.5 | 57.2 | 30.8 | 51.7 |
| RWKV4-1.5B | NeoX | 7.70 | 7.04 | 56.4 | 52.5 | 72.4 | 60.5 | 29.4 | 54.6 | 34.0 | 51.4 |
| Mamba-1.4B | NeoX | 6.80 | 5.04 | 65.0 | 59.1 | 74.2 | 65.5 | 32.8 | 61.5 | 36.4 | 56.4 |
| Mamba-2-1.3B | NeoX | 6.66 | 5.02 | 65.7 | 59.9 | 73.2 | 64.3 | 33.3 | 60.9 | 37.8 | 56.4 |
| Hybrid H3-2.7B | GPT2 | — | 7.92 | 55.7 | 59.7 | 73.3 | 65.6 | 32.3 | 61.4 | 33.6 | 54.5 |
| Pythia-2.8B | NeoX | 6.73 | 5.04 | 64.7 | 59.3 | 74.0 | 64.1 | 32.9 | 59.7 | 35.2 | 55.7 |
| RWKV4-3B | NeoX | 7.00 | 5.24 | 63.9 | 59.6 | 73.7 | 67.8 | 33.1 | 59.6 | 37.0 | 56.4 |
| Mamba-2.8B | NeoX | 6.22 | 4.23 | 69.2 | 66.1 | 75.2 | 69.7 | 36.3 | 63.5 | 39.6 | 59.9 |
| Mamba-2-2.7B | NeoX | 6.09 | 4.10 | 69.7 | 66.6 | 76.4 | 69.6 | 36.4 | 64.0 | 38.8 | 60.2 |
Smaller sizes (130M to 370M) and larger baselines (Pythia-6.9B, RWKV4-7.4B, GPT-J-6B, OPT) are in tab. 9 in app. D.3. Headline claims from the text:
| Setting | Metric | Baseline | This paper | Source |
|---|---|---|---|---|
| 2.7B, zero-shot average | acc ↑ | Pythia-6.9B: 58.3 tab. 9 | Mamba-2-2.7B: 60.2 | tab. 1, tab. 9 |
| 2.7B, Pile validation | ppl ↓ | Mamba-2.8B: 6.22 | Mamba-2-2.7B: 6.09 | tab. 1 |
| Hybrid, 2.7B, Pile validation | ppl ↓ | Transformer++: 6.13; Mamba-2: 6.09 | Mamba-2-Attention (6 attention layers): 5.95 | tab. 3 |
| Hybrid, 2.7B, zero-shot average | acc ↑ | Transformer++: 60.2; Mamba-2: 60.2 | Mamba-2-Attention: 61.0; Mamba-2-MLP-Attention: 60.7 | tab. 3 |
| Attention-layer count, 350M, 48 layers | ppl ↓ | 0 attention (Mamba-2): 8.60; Transformer++: 8.68 | 6 attention layers: 8.26 (best); 24 layers: 8.50 | tab. 2 |
| SSD vs Mamba fused scan, state size 64 | speed | Mamba fused scan | SSD 2–8× faster | fig. 10, §9.3 |
| SSD vs FlashAttention-2 | speed | FlashAttention-2 | SSD faster from sequence length 2K; about 6× faster at 16K | fig. 10, §1 |
| Block ablation (scale not stated in caption) | ppl ↓ | Mamba-1 block, sequential projections, no extra norm: 11.76 | Mamba-2 block: 11.49 (126.5M vs 129.3M parameters) | tab. 4 |
| MQAR associative recall | qualitative | Mamba-1 struggles; attention baseline | Mamba-2 performs well across all settings; no numbers in text | fig. 8, §9.1 |
Head-pattern ablation. Multi-input (MVA-style) is best in both settings. At 125M and 2.5B tokens: MIS 11.66, MCS 12.62, MES 12.59, MHS 12.06, MSS 12.00. At 360M and 7B tokens: MIS 8.73, MCS 9.33, MES 9.36, MHS 9.01, MSS 9.04 tab. 5.
Kernel ablation (130M, perplexity). None 11.58; Swish 11.66; Exp 11.62; ReLU 11.73; ReLU+normalisation 11.64; cosFormer 11.97; Random Feature Attention 11.57; Performer 12.21 tab. 6. Based and ReBased variants: Swish 11.67; Swish+Taylor 12.19; LayerNorm 11.50; LayerNorm+Square 11.84 (130M); at 380M with N = 256: Swish 8.58; Swish+Taylor 8.71; LayerNorm 8.61; LayerNorm+Square 8.63 tab. 7. The authors conclude that the kernel variants do not beat a plain pointwise activation §9.4.3.
Scaling laws. Models from about 125M to about 1.3B were trained with the Chinchilla token budget. Mamba-2 matches or beats Mamba and a Transformer++ recipe in perplexity and wall-clock time §9.2.1, fig. 9.
Paper vs code
Searched: the paper links https://github.com/state-spaces/mamba as the code and checkpoint location §1. This repository is by the authors' organisation. Cloned at git rev-parse HEAD = e9594ce1c732d97440f0332fdc43170a2294dbfa. The LICENSE file is Apache License 2.0.
The repository is newer than the paper: its tree includes a mamba3.py module that the paper does not describe. The paper's exact code state is not known from the text. The citations below are to this commit.
- Activation on the convolution output. The paper applies the feature map
ψ(default Swish) to theBandCbranches, and says it may also be applied toX"for simplicity and symmetry" §7.3. The code applies SiLU to the whole convolution output, which containsx,BandCmamba2_simple.py. Paper:Xoptional. Code:Xalways. - Causal convolution. The code has a depthwise causal convolution with kernel 4 over
x,BandCbefore the SSD mamba2_simple.py. The paper's architecture section does not describe a convolution §7.1. Treat it as an implementation detail not in the paper. - Skip term
D. The code adds a learned per-head skipD · xmamba2_simple.py. None of the equations in the paper include it. - Default state and head size.
Mamba2Simpledefaults tod_state = 64,headdim = 128mamba2_simple.py.Mamba2defaults tod_state = 128,headdim = 64mamba2.py. The ablations in the paper use 64 and 64 §9.4.2, tab. 5. The paper does not state which values were used for the language-model runs. - Chunk length. The reference layer defaults to
chunk_size = 256mamba2_simple.py. The paper's listing defaultsblock_len = 64[listing 1], and the repository's minimal test uses 64 ssd_minimal.py. The paper gives no value forQin its experiments. - Segment sum. The paper's listing uses a direct cumulative-sum difference with a
-infmask [listing 1]. The repository keeps that form assegsum_unstablessd_minimal.py and uses a differentsegsumssd_minimal.py. Its docstring still says the file is "the same as Listing 1" ssd_minimal.py. The two versions are intended to compute the same values. - Discretisation. The paper's listing takes discrete
A(log-decays) as input and does not show howdtenters [listing 1]. The repository foldsdtintoXand intoAin its test,ssd_minimal_discrete(x*dt, A*dt, B, C, ...)ssd_minimal.py. The fused path takesdtanddt_biasand applies softplus internally mamba2.py. The paper states none of this. - Initialisation and parameter groups.
Ais initialised uniformly in[1, 16]and stored asA_log, withA = -exp(A_log)mamba2_simple.py.dtis sampled log-uniformly in[0.001, 0.1]with floor1e-4mamba2_simple.py.dt_bias,A_logandDare excluded from weight decay mamba2_simple.py. The paper states none of these. - Normalisation type. The paper allows LayerNorm, GroupNorm or RMSNorm §7.1. The code uses a gated RMSNorm with
eps = 1e-5andnorm_before_gate = False, so the gate is applied before the norm mamba2_simple.py. - Groups. The code supports
ngroups(G) sharingBandCacross head groups mamba2_simple.py. The paper describes grouped-value attention and omits the details §7.2. Ablations do not cover it.
No discrepancies were found in the core SSD algorithm itself: the block-decomposition steps in the paper's listing and in the repository's minimal implementation compute the same four terms [listing 1; code: mamba_ssm/modules/ssd_minimal.py#L53-L74].
Pitfalls
- Scalar decay per head is the restriction that makes SSD work. SSD does not cover Mamba's per-channel diagonal
A. Mamba-2 uses oneAper head mamba2_simple.py. Results from this paper do not show that a per-channel SSM can use the same algorithm. - Discretisation is missing from the paper. Implement it from the code (Paper vs code, items 7–8), or from Mamba-1, which the paper says it follows §2, remark. The paper's listing takes already-discretised decays as input and does not show how the step size scales the input [listing 1].
- Chunk length
Qis not given. The paper's listing and the reference layer use different defaults (64 vs 256). Memory and speed both depend onQ. Choose it and state it. - The chunk-level decay matrix grows as
(T/Q)². The reference listing builds a(K+1) × (K+1)decay matrix for the chunk recurrence ssd_minimal.py. The paper says the scan cost is negligible §6.3. This holds for moderateT/Q. For very long sequences with smallQ, use a scan instead. - The diagonal-block mask costs memory.
exp(segsum(...))materialises aQ × Qmask per chunk and head [listing 1]. The memory isO(T · Q · H), not theO(T N)in the theorem. The theorem assumesQ = N§6, Theorem 6.1. - Mask before
exp. Upper-triangular cumulative-sum differences are positive and can overflow if they are exponentiated before masking. The listing masks with-inffirst [listing 1]. Keep this order. - Dtype must match. The listing and the repository both assert that
X,A,BandCshare one dtype [listing 1; code: mamba_ssm/modules/ssd_minimal.py#L44]. Cast the decays to the input dtype before calling the layer. - Inference cost is stated two ways. Theorem 6.1 gives
O(TN)inference FLOPs §6. The cost table givesO(N²)per step §6.3. The paper does not reconcile these. A per-step recurrence with stateP × Ncosts aboutN²FLOPs whenP = N, so the per-step figure is the one to use. - Some benchmark claims lack detail. The speed comparisons do not give the GPU model or the precision §9.3. The associative-recall results are qualitative: figure only, no numbers in the text fig. 8.
- Ablation differences are small and have no variance estimate. Some kernel-table gaps are about 0.1 perplexity (for example ReLU 11.73 vs Swish 11.66). The paper does not report seeds or repeats tab. 6.
- Two Swish values differ. The 130M Swish row is 11.66 in tab. 6 and 11.67 in tab. 7. The paper does not explain the difference.
- Hybrid results are single comparisons. The attention-layer gains are small (about 0.1 perplexity) and the paper does not state repeats tab. 3.
- The arXiv version may differ from later releases. The repository has moved on (
mamba3.py). Pin the commit incode_commitand do not assume later behaviour matches this card.
Lineage
- Builds on:
- Mamba, the selective SSM with a hardware-aware scan, arXiv:2312.00752 §1, §2, §7.2. Mamba-2 keeps the selective form but restricts
Ato one scalar per head. - The structured SSM family S4 and its diagonal variants §2.
- Linear attention (Katharopoulos et al., ICML 2020), whose recurrent form the paper extends §1, §4.
- Multi-query and grouped-query attention, which define the multi-contract and grouped head patterns §7.2.
- NormFormer, which motivates the extra normalisation layer §7.1.
- Mamba, the selective SSM with a hardware-aware scan, arXiv:2312.00752 §1, §2, §7.2. Mamba-2 keeps the selective form but restricts
- Compared against:
- Mamba-1's selective scan, in speed and in model quality §9.3, §9.2.
- FlashAttention-2 §9.3.
- Transformer++, Pythia, RWKV-4 and GPT-J, as zero-shot baselines §9.2.2, tab. 9.
- Based, ReBased, cosFormer, Random Feature Attention and Performer, as kernel variants §9.4.3.
- Superseded by: not stated in this wiki's content.
Source and license
Adapted from “Transformers are SSMs: Generalized Models and Efficient Algorithms Through Structured State Space Duality” by Tri Dao, Albert Gu (arXiv:2405.21060), 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.