↑↓ move Enter open ⌘K find from any page 256 of 256 tabs
Layer 1 of 24 every third layer recorded 24 heads × 64 channels · 128-D state shared by all heads · run in chunks of 256 tokens
Loading the recorded scan…

What Mamba-2 is

Mamba-2 (Dao and Gu, 2024) simplifies Mamba's state update until its scan becomes exactly a masked, attention-like matrix product. The paper calls the correspondence state space duality (SSD): the same layer can run as a recurrence, carrying a state token by token, or as a quadratic matrix product over the tokens like attention, and its algorithm mixes the two. The abstract reports the new layer 2–8 times faster than Mamba's selective scan while staying competitive with Transformers in language modelling.

The page records Mamba-2 130M, every third of its 24 layers, on the Mamba tab's three prompts. Each layer has 24 heads of 64 channels. The recorded model continues the repeated phrase with “ fox” and the two-names prompt with “ Mary”.

One decay per head

Mamba gives each channel 16 decay rates. Mamba-2 gives each head one scalar , shared by its 64 channels and all 128 entries of its state. A head's state is then a 64 × 128 matrix, decayed as a whole and updated by an outer product:

is the head's 64 channels, and are 128-dimensional, and is one step size per token and head. The A box lists every head's rate, and the Δ box this head's step sizes with the share of the state that survives each step: a large writes token strongly and forgets more of what came before.

The matrix form

Unrolled over the sequence, the update is one matrix per head:

This is causal linear attention with as queries, as keys and as values, multiplied elementwise by a decay mask . Because the decay is a scalar, it factors out of the sum over state entries, which Mamba's per-entry decay does not. The card's three views show the factors: C·Bᵀ is the same for every head, since all heads share one and ; Decay L is the head's mask, between 0 and 1 and falling with distance at a pace set by each ; and M = L ∘ C·Bᵀ·Δ is their product, the weight that multiplies each 64-dimensional .

With this is the linear attention of Katharopoulos et al. (2020); with a fixed it is RetNet's retention (the RetNet tab). Mamba-2's mask depends on the input through : a learned forget gate.

Heads that share B and C

In this model all 24 heads read one and one (a single group) and differ in their , and . In attention terms the keys and queries are shared and the values have heads; the Mamba-2 paper calls this pattern multi-value attention, by analogy with multi-query attention (the MQA tab), where keys and values are shared and the queries have heads.

The block also differs from Mamba's in where things are computed. One in_proj produces , , , and in parallel; the causal convolution runs over , and together; and an RMSNorm over all 1,536 channels follows the gate before out_proj maps back to 768.

Chunks

The SSD algorithm splits the sequence into chunks, 256 tokens in this model. Inside a chunk it computes as dense matrix products, the operation GPUs run fastest; between chunks it passes only each head's 64 × 128 state, as the recurrence does. The cost stays linear in length, with most of the work in matrix multiplications.

These prompts fit in one chunk, so the recorder also ran the scan with chunks of 4 tokens to exercise the passing of states. The matrix drawn on the card agrees with the normal run to and with the 4-token chunks to .

Where it came from

Mamba (2023, the Mamba tab) introduced the selective scan; Mamba-2 traded per-entry decay for a scalar to gain the matrix form and a larger state, 128 entries here against Mamba's 16. Linear-attention work reached the same family from the other side: gated linear attention (Yang et al., 2023) learns a data-dependent decay on a linear-attention state, and Gated DeltaNet (Yang et al., 2024) combines a Mamba-2-style gate with a delta-rule update. Qwen3-Next uses Gated DeltaNet in three of every four layers (the Gated tab), and the Linear tab shows RWKV-7.

Papers

  1. Transformers are SSMs: Generalized Models and Efficient Algorithms Through Structured State Space Duality Tri Dao, Albert Gu · ICML 2024 Mamba-2 and state space duality: scalar decay per head, the matrix form M = L ∘ CBᵀ, and the chunked algorithm.
  2. Mamba: Linear-Time Sequence Modeling with Selective State Spaces Albert Gu, Tri Dao · COLM 2024 The selective scan Mamba-2 simplifies (the Mamba tab).
  3. Transformers are RNNs: Fast Autoregressive Transformers with Linear Attention Angelos Katharopoulos et al. · ICML 2020 Linear attention and its recurrent form, the L = 1 case of the SSD matrix.
  4. Retentive Network: A Successor to Transformer for Large Language Models Yutao Sun et al. · arXiv 2023 Retention, linear attention with a fixed decay per head: SSD with a constant mask rate (the RetNet tab).
  5. Gated Linear Attention Transformers with Hardware-Efficient Training Songlin Yang et al. · ICML 2024 Data-dependent decay on a linear-attention state, a parallel route to the same family.
  6. Gated Delta Networks: Improving Mamba2 with Delta Rule Songlin Yang, Jan Kautz, Ali Hatamizadeh · ICLR 2025 Mamba-2's gate combined with a delta-rule update, the linear layer of Qwen3-Next (the Gated tab).

See also