Mamba: Linear-Time Sequence Modeling with Selective State Spaces

Gu & Dao, 2024, Mamba (First Conference on Language Modeling (COLM 2024))

Subscriber deck — free during early access

16 cards

1 Introduction

  1. What two drawbacks of attention motivate Mamba?
    Attention can’t model anything outside its finite window, and its cost scales quadratically with window length; efficient variants usually sacrifice the dense information routing that makes attention effective.
    • Gu & Dao, 2024, Mamba (First Conference on Language Modeling (COLM 2024)), §1
  2. What weakness of earlier subquadratic models (linear attention, gated convolutions, structured SSMs) does Mamba identify?
    They can’t perform content-based reasoning: their dynamics don’t depend on the input, so they can’t decide, token by token, what to remember and what to ignore. This made them weak on discrete, information-dense data like language.
    • Gu & Dao, 2024, Mamba (First Conference on Language Modeling (COLM 2024)), §1
  3. What are Mamba’s three main ingredients?
    A selection mechanism (SSM parameters become functions of the input), a hardware-aware parallel scan that computes the resulting time-varying recurrence efficiently, and a simple homogeneous architecture without attention or even separate MLP blocks.
    • Gu & Dao, 2024, Mamba (First Conference on Language Modeling (COLM 2024)), §1

2 State Space Models

  1. How does a structured state space model (S4) map an input sequence to an output?
    A continuous system \(h'(t) = A h(t) + B x(t)\), \(y(t) = C h(t)\) is discretized with a step size \(\Delta\) (e.g. zero-order hold, \(\bar A = \exp(\Delta A)\)), giving the recurrence \(h_t = \bar A h_{t-1} + \bar B x_t\), \(y_t = C h_t\), applied independently to each channel with an \(N\)-dimensional hidden state.
    • Gu & Dao, 2024, Mamba (First Conference on Language Modeling (COLM 2024)), §2
  2. Why could earlier SSMs be trained efficiently, and what did that require?
    Their parameters \((\Delta, A, B, C)\) were constant over time (linear time invariance), so the recurrence unrolls into a global convolution computable in parallel without materializing the large hidden state; recurrent mode was used for fast autoregressive inference.
    • Gu & Dao, 2024, Mamba (First Conference on Language Modeling (COLM 2024)), §2

3.1 Motivation: Selection as a Means of Compression

  1. How does Mamba frame the efficiency–effectiveness trade-off of sequence models?
    As how well a model compresses context into its state. Attention doesn’t compress at all (it stores the whole context as a KV cache): effective but slow. Recurrent models have a fixed-size state: fast, but only as good as what that state keeps. Selectivity—choosing what enters the state—is the key.
    • Gu & Dao, 2024, Mamba (First Conference on Language Modeling (COLM 2024)), §3.1
  2. Why can’t time-invariant models solve Selective Copying and Induction Heads?
    Plain Copying, with fixed spacing, can be solved by tracking time alone (a convolution kernel of the right length). In Selective Copying the tokens to remember are scattered among noise at random positions, and Induction Heads requires recalling what followed a token earlier; both need content-aware decisions that constant dynamics can’t make.
    • Gu & Dao, 2024, Mamba (First Conference on Language Modeling (COLM 2024)), §3.1

3.2 Improving SSMs with Selection

  1. What exactly does Mamba’s selection mechanism change?
    It makes \(\Delta\), \(B\) and \(C\) functions of the current input (linear projections of \(x_t\), with softplus for \(\Delta\)), so the model is time-varying: at each step it decides how much of the input to let into the state and how much state to keep.
    ht−1htytxtĀ(Δₜ)B̄(Δₜ, Bₜ)CₜΔₜ, Bₜ, Cₜ computed from xₜ(fixed for all t in earlier SSMs)
    Selection: the input decides how much enters and stays in the state
    • Gu & Dao, 2024, Mamba (First Conference on Language Modeling (COLM 2024)), §3.2

3.3 Efficient Implementation of Selective SSMs

  1. How does Mamba compute a time-varying recurrence efficiently on GPUs?
    With kernel fusion (load parameters from slow HBM into fast SRAM, discretize and run the recurrence there, write only outputs back), a work-efficient parallel scan instead of a sequential loop, and recomputation of intermediate states in the backward pass instead of storing them; memory use matches FlashAttention Transformers.
    • Gu & Dao, 2024, Mamba (First Conference on Language Modeling (COLM 2024)), §3.3

3.4 A Simplified SSM Architecture

  1. What does a Mamba block look like?
    It merges the H3-style SSM block with a gated MLP into one block repeated homogeneously: expand the model dimension (by \(E = 2\)), apply a short convolution, SiLU and the selective SSM on one branch, multiply by a SiLU gate branch, and project back; two blocks match a Transformer layer’s parameters.
    • Gu & Dao, 2024, Mamba (First Conference on Language Modeling (COLM 2024)), §3.4

3.5 Properties of Selection Mechanisms

  1. How is Mamba’s selection related to RNN gating?
    With \(N = 1\), \(A = -1\), \(B = 1\) and \(\Delta = \mathrm{softplus}(\mathrm{Linear}(x_t))\), the selective SSM reduces to the gated recurrence \(h_t = (1 - g_t) h_{t-1} + g_t x_t\) with \(g_t = \sigma(\mathrm{Linear}(x_t))\): discretization is the principled basis of gating.
    • Gu & Dao, 2024, Mamba (First Conference on Language Modeling (COLM 2024)), §3.5
  2. What does the step size \(\Delta\) control in a selective SSM?
    How much to focus on the current input versus keep the state: large \(\Delta\) resets the state and attends to \(x_t\); small \(\Delta\) preserves the state and ignores \(x_t\). This lets the model skip filler tokens, discard irrelevant history and reset at document boundaries.
    • Gu & Dao, 2024, Mamba (First Conference on Language Modeling (COLM 2024)), §3.5

4.1 Synthetic Tasks

  1. How did Mamba do on Induction Heads?
    A 2-layer Mamba trained on sequences of length 256 solved the task perfectly and generalized to length 1,048,576, 4,000× longer than training, while attention models with various position encodings failed beyond about 2× and other SSMs did poorly.
    • Gu & Dao, 2024, Mamba (First Conference on Language Modeling (COLM 2024)), §4.1

4.2 Language Modeling

  1. How did Mamba compare with Transformers on language modeling?
    It was the first attention-free model to match a strong modern Transformer recipe (Transformer++) in scaling laws from 125M to 1.3B parameters; Mamba-3B beat Pythia-3B by about 4 points on common-sense benchmarks and matched models twice its size.
    • Gu & Dao, 2024, Mamba (First Conference on Language Modeling (COLM 2024)), §4.2

4.3 DNA Modeling

  1. What did DNA experiments show about context length?
    Mamba’s pretraining perplexity kept improving as context grew to a million base pairs, while HyenaDNA (a time-invariant model) got worse; selection lets the model ignore noisy history that a long convolution would mix in.
    • Gu & Dao, 2024, Mamba (First Conference on Language Modeling (COLM 2024)), §4.3

4.5 Speed and Memory Benchmarks

  1. Why is Mamba faster at inference than a Transformer?
    As a recurrent model it needs no KV cache, only a fixed-size state, so each generated token costs constant time and much larger batches fit: about 4–5× the inference throughput of a similar-size Transformer. Its scan was also faster than FlashAttention-2 beyond length 2K.
    • Gu & Dao, 2024, Mamba (First Conference on Language Modeling (COLM 2024)), §4.5

Source

  • Albert Gu and Tri Dao. 2024. Mamba: Linear-Time Sequence Modeling with Selective State Spaces. In First Conference on Language Modeling (COLM 2024). https://arxiv.org/abs/2312.00752