Paper commentary
Mamba: Linear-Time Sequence Modeling with Selective State Spaces
Mamba makes state space models select inputs and match Transformers on language
- Problem Fast subquadratic sequence models have trailed attention on language. Their fixed dynamics cannot choose which tokens to keep, so content-based reasoning fails.
- Method Mamba makes the state space model parameters depend on each input token. This lets the model selectively keep or forget information along the sequence, instead of using fixed dynamics.
- Results Mamba-2.8B averages 63.3 on zero-shot tasks, compared to 59.1 for Pythia-2.8B.

Figure 4 : ( Scaling Laws.) Models of size ≈ 125𝑀 to≈ 1.3𝐵 parameters, trained on the Pile. Mamba scales better than all other attention-free models and is the first to match the performance of a very strong “Transformer++” recipe that has now become standard, particularly as the sequence length grows.
Original paper · CC BY 4.0 · Albert Gu, Tri Dao · Mamba: Linear-Time Sequence Modeling with Selective State Spaces · Original paper figure · Extracted the figure area from page 11 of the original PDF.Why fast sequence models lag on text
Transformers power most foundation models because attention routes information densely within a context window. That same design brings two costs: it can't reach past a finite window, and its work grows quadratically with window length. Recurrent models avoid the quadratic cost by compressing history into a fixed-size state, so each inference step takes constant time.
The catch is that such a state holds only as much of the context as the model manages to compress into it.
Structured state space models (SSMs) had worked well on continuous signals such as audio and vision, but less well on discrete, information-dense data such as text. The underlying reason is that their dynamics stay fixed at every time step, so they can't choose which tokens to keep. Selective Copying makes the failure concrete: the spacing of the tokens to keep varies, and a static convolution kernel can't follow it.
Letting the input steer the recurrence
The key idea is to let the parameters that control how information moves along the sequence depend on the current input. In the selective SSM, B, C and the step size Δ are computed from each token, while the state matrix A stays a learned parameter. B and C are linear projections to the state size N, and Δ comes from a one-dimensional projection that is broadcast across the D channels and passed through softplus.
Because these parameters now vary along the length dimension, the model is no longer time-invariant, and its convolution form is lost.
Before the recurrence runs, the continuous parameters are converted with the zero-order hold rule. The discrete A is the matrix exponential of ΔA, and the discrete B is (ΔA) to the power -1, times (exp(ΔA) minus I), times ΔB.\[\bar{A}=\exp(\Delta A),\qquad \bar{B}=(\Delta A)^{-1}(\exp(\Delta A)-I)\,\Delta B\] The model then runs the recurrence on these discrete parameters.\[h_t=\bar{A}h_{t-1}+\bar{B}x_t,\qquad y_t=Ch_t\] Since Δ, B and C depend on the input, the discrete A and B are also computed for each token.
The authors show that the selection mechanism generalizes the gating of RNNs. With N = 1, A = -1, B = 1 and a softplus Δ, the update becomes \[h_t=(1-g_t)h_{t-1}+g_t x_t,\qquad g_t=\sigma(\mathrm{Linear}(x_t))\] A large Δ resets the state toward the current input, while a small Δ keeps the state and ignores the input. This is the mechanism that lets the model forget irrelevant context when it needs to.
Keeping the time-varying recurrence fast on GPUs
Losing the convolution form is costly, because a naive implementation would write the full expanded state to GPU memory. That state has shape batch, length, D, N, which is N times larger than the input, so the authors avoid materializing it. Instead, the discretization and recurrence run in fast SRAM, with the parameters loaded from slow HBM and only the outputs written back.
The recurrence isn't linear, yet a work-efficient parallel scan still computes it. Intermediate states aren't stored for backpropagation; they are recomputed in the backward pass, which keeps memory on par with an optimized FlashAttention Transformer. For long sequences and modest N, the recurrent form can need fewer operations than the convolution, \(O(BLDN)\) against \(O(BLD\log L)\), according to the authors.
A single homogeneous block
The authors merge the H3-style SSM path and the MLP path into one repeated block, instead of alternating two block types. The block expands the model dimension D by a factor E, which is fixed at 2 in the experiments. Most parameters sit in linear projections, about 3ED² in total, while the SSM adds comparatively few. Two stacks of this block roughly match the 12D² parameters of a Transformer's attention and MLP pair.
The activation is SiLU, or Swish, and the gated branch resembles a SwiGLU MLP. Blocks are interleaved with normalization and residual connections, and LayerNorm is the chosen normalization.
Synthetic tasks: does selection fix content recall?
The authors test two tasks that motivated the selection mechanism: Selective Copying and Induction Heads. Selective Copying needs content-aware reasoning to keep the coloured tokens and drop the rest, while Induction Heads needs context-aware recall. Constant-spacing copying is easy for time-invariant models, so the random spacing is what breaks them.
Mamba reaches 99.8 accuracy on Selective Copying, compared to 18.3 for an S4 model with no gate. The inner layer matters more than the outer architecture: Mamba with an S4 layer drops to 56.4, while H3 with an S6 layer reaches 99.7. So the selective layer carries most of the gain on this task.
On Induction Heads, models are trained at sequence length 256 and tested up to 1048576. The authors report that Mamba extrapolates to million-length sequences, about 4000× longer than training, while no other method they compared goes beyond 2×.
Language modeling against Transformer baselines
Language is the hard test, and the authors pretrain on the Pile with model sizes that mirror GPT3. The baselines include the standard GPT3-style Transformer and a stronger Transformer++ recipe built on PaLM and LLaMa choices.
The scaling curves show Mamba below the other attention-free models across these sizes. Full results at context length 8k are missing for RWKV and RetNet, because those baselines lacked efficient implementations.
On zero-shot tasks, Mamba-2.8B averages 63.3, compared to 59.1 for Pythia-2.8B. Both were trained on 300B tokens with the same tokenizer, though Mamba and Pythia used context length 2048 while RWKV used 1024. The authors say Mamba generally matches baselines at twice its size.
Audio and DNA results
For audio, the authors compare Mamba-UNet to SaShiMi, which alternates S4 and MLP blocks inside a U-Net. On YouTubeMix, Mamba is better than SaShiMi at every context length, and the gap widens at longer lengths. The metric is bits per byte, a constant factor log(2) times the standard negative log-likelihood.
The authors say this small model beats the much larger GAN and diffusion baselines. In the ablation, Mamba beats S4+MLP in the outer blocks, and in the center blocks the order is Mamba, then S4+MLP, then MHA+MLP.
The authors state that Mamba beats SaShiMi, Hyena and Transformers on audio waveforms and DNA sequences.
Speed and throughput
The fused scan is faster than FlashAttention-2 beyond sequence length 2K. It is also 20-40× faster than a standard PyTorch scan. The introduction reports up to 3× speedup on A100 GPUs over previous methods.
The gain comes from skipping the KV cache, which lets Mamba use much larger batches. An untrained Mamba-6.9B would out-throughput a Transformer-1.3B that is 5× smaller, but that is a measurement-only variant, not one of the accuracy-trained models.
Ablations and open limits
Projecting Δ from the input to dimension 1 cuts perplexity from 9.12 to 8.97, and dimension 64 reaches 8.71.
The authors describe a continuous-discrete trade-off: selection helps discrete text and DNA, but can hurt audio waveforms, where LTI SSMs do well. Whether Transformer affordances such as fine-tuning, in-context learning and quantization carry over to SSMs is left open. The authors also note that scaling SSMs may bring engineering challenges that the paper does not cover.
Paper info
- Authors
- Albert Gu, Tri Dao
- Venue
- arXiv · Preprint
- First published
- 2023-12-1
- Added
- 2026-10-20
- Updated
- 2024-5-31
- Version
- v2
- arXiv
- 2312.00752
- Category
- cs.LG · cs.AI
- Original paper terms
- CC BY 4.0
- What we show
- Paper info, commentary and permitted figures from the original paper
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
Abstract
Foundation models, now powering most of the exciting applications in deep learning, are almost universally based on the Transformer architecture and its core attention module. Many subquadratic-time architectures such as linear attention, gated convolution and recurrent models, and structured state space models (SSMs) have been developed to address Transformers' computational inefficiency on long sequences, but they have not performed as well as attention on important modalities such as language. We identify that a key weakness of such models is their inability to perform content-based reasoning, and make several improvements. First, simply letting the SSM parameters be functions of the input addresses their weakness with discrete modalities, allowing the model to selectively propagate or forget information along the sequence length dimension depending on the current token. Second, even though this change prevents the use of efficient convolutions, we design a hardware-aware parallel algorithm in recurrent mode. We integrate these selective SSMs into a simplified end-to-end neural network architecture without attention or even MLP blocks (Mamba). Mamba enjoys fast inference (5$\times$ higher throughput than Transformers) and linear scaling in sequence length, and its performance improves on real data up to million-length sequences. As a general sequence model backbone, Mamba achieves state-of-the-art performance across several modalities such as language, audio, and genomics. On language modeling, our Mamba-3B model outperforms Transformers of the same size and matches Transformers twice its size, both in pretraining and downstream evaluation.
Quote from the paper
Albert Gu, Tri Dao (2023). Mamba: Linear-Time Sequence Modeling with Selective State Spaces. arXiv:2312.00752v2. https://arxiv.org/abs/2312.00752v2
BibTeX
@misc{gu2023mamba,
title = {{Mamba: Linear-Time Sequence Modeling with Selective State Spaces}},
author = {Albert Gu and Tri Dao},
year = {2023},
eprint = {2312.00752},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2312.00752v2}
}