↑↓ move Enter open ⌘K find from any page 256 of 256 tabs
Layer 1 of 24 1,536 channels · 16 state entries each · showing the 8 that draw most on earlier tokens
Loading the recorded scan…

What Mamba is

Attention keeps every past key and value and compares each new token with all of them. A state-space model instead carries a fixed-size state forward and updates it once per token, so each step costs the same however long the sequence grows. Earlier state-space layers updated the state the same way whatever the token, and they fell behind attention on language, where what to keep depends on what was just read. Mamba (Gu and Dao, 2023) makes the update depend on the token: a selective state space. The paper reports a Mamba-3B that outperforms Transformers of the same size and matches Transformers twice its size in language modelling.

The page records Mamba 130M, all 24 layers, on three short prompts. Each layer's mixer has 1,536 channels that scan the sequence independently; for every layer the page shows the 8 channels whose output draws most on earlier tokens.

A state space, discretised

Each channel holds a state of 16 numbers, one per diagonal entry of a decay matrix . In continuous time the state follows and is read out by . With a step size , Mamba turns this into a recurrence over tokens:

is negative, so lies between 0 and 1: the share of state entry that survives step . is a skip connection from input to output. The A box on the card lists the channel's 16 rates and their survival at the selected token.

Selection

In S4 and its successors , and were learned constants, so the whole layer was a fixed convolution over the sequence. Mamba computes them from each token through a projection called x_proj:

says what token writes into the state and how it reads the state; both are 16-dimensional and shared by all 1,536 channels of the layer. goes through a rank-48 bottleneck , is different for every channel and acts as a gate: a large writes the token strongly and decays what was there, a small one lets the state pass the token by. The B, C and Δ boxes list them for every token.

Input-dependent parameters rule out the convolution trick, so Mamba computes the recurrence with a hardware-aware parallel scan that keeps the expanded state in fast on-chip memory. The recording runs the plain sequential loop, which gives the same numbers.

The scan as an attention-like matrix

Unrolling the recurrence, each output is a weighted sum of the channel's past inputs, so the scan is a causal matrix applied to , with in the query's place, in the key's and the channel's as the value:

Ali et al. (2024) used this view to read the hidden attention of Mamba models. The Scan M view draws the recorded channel's matrix; Δ·C·B, no decay leaves the decay out. The decay sits inside the sum over the 16 state entries, each with its own rate, so is not the second matrix times one decay per distance. There is no softmax: weights are signed and need not sum to one. The page computes from the captured , , and , and it agrees with the recurrence to .

The Mamba block

Mamba has no attention and no separate MLP; one block, preceded by an RMSNorm, repeats 24 times:

  • in_proj maps the 768-dimensional input to two 1,536-wide streams, and .
  • passes a causal depthwise convolution of 4 taps and a SiLU; x_proj then selects , and from it, and the scan runs.
  • The scan output is multiplied by , a gate that went around the scan, and out_proj maps 1,536 channels back to 768.

There are no position embeddings: order enters through the short convolution and through the scan, which only carries information forward. The Output column is the block's mixer output before the residual add.

Where it came from

S4 (Gu et al., 2021) made long state-space layers trainable with a structured and a fixed convolution kernel; H3 (2022) and Hyena (2023, the Hyena tab) added data-dependent gates around long convolutions. Mamba made the state update itself selective. Mamba-2 (2024) restricted to one scalar per head, which turns the matrix above into a masked form of linear attention and allows a faster algorithm: see the Mamba-2 tab, and the Linear and RetNet tabs for the attention side of the same family.

Papers

  1. Mamba: Linear-Time Sequence Modeling with Selective State Spaces Albert Gu, Tri Dao · COLM 2024 The selective state space: Δ, B and C computed from the input, a hardware-aware scan, and the Mamba block.
  2. Efficiently Modeling Long Sequences with Structured State Spaces Albert Gu, Karan Goel, Christopher Ré · ICLR 2022 S4, the time-invariant state-space layer Mamba makes selective.
  3. The Hidden Attention of Mamba Models Ameen Ali, Itamar Zimerman, Lior Wolf · arXiv 2024 Writes Mamba's scan as a data-dependent attention matrix, the view the head card draws.
  4. Hungry Hungry Hippos: Towards Language Modeling with State Space Models Daniel Y. Fu et al. · ICLR 2023 H3: gated state-space layers for language, between S4 and Mamba.
  5. Transformers are SSMs: Generalized Models and Efficient Algorithms Through Structured State Space Duality Tri Dao, Albert Gu · ICML 2024 Mamba-2: one decay per head, which makes the scan a masked linear attention (the Mamba-2 tab).

See also