SandHouse
Pages and contents

Mamba SSM

0\. Metadata

Field
Value
⋮⋮
Authors
Gu, Dao
⋮⋮
Year
2024
⋮⋮
Link / arXiv
https://arxiv.org/pdf/2312.00752
⋮⋮
Code
https://github.com/state-spaces/mamba
⋮⋮
My relevance (1-5)
3
⋮⋮
Tags
#ssm #transformer

Main Idea

Mamba is an alternative to the transformer architecture. It scales linearly with the context window and does not implement an MLP layer.

1\. Problem

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. Mamba enjoys fast inference (5× higher throughput than Transformers) and linear scaling in sequence length, and its performance improves on real data up to million-length sequences.

2\. Background

Structured SSMs

Mamba is based on the theory of State Space Models which breaks up sequence modeling into vectors of state variables x(t), state inputs u(t), and state outputs y(t). It learns updates through the state matrix A, the control matrix B, the output matrix C and the command matrix D.

S4 SSMs are defined by four parameters, which models sequence-to-sequence transformations in two stages.

Structured SSMs impose a structure on the Amatrix to allow for efficient computation. Mamba imposes a diagonal structure on the A matrix. Before Mamba, SSMs used static time invariant matrices and treated all tokens exactly the same. Mamba takes a new approach by modeling B,C and the step size Δas functions of the input x(t). If a token is learned to be irrelevant to the input, then it is ignored, if it is critical, it is heavily weighted.

Sequence Modeling

The authors argue that a fundamental problem of sequence modeling is compressing context into a smaller state. “In fact, we can view the tradeoffs of popular sequence models from this point of view. For example, attention is both effective and inefficient because it explicitly does not compress context at all.”

In summary, the efficiency vs. effectiveness tradeoff of sequence models is characterized by how well they compress their state: efficient models must have a small state, while effective models must have a state that contains all necessary information from the context. In turn, we propose that a fundamental principle for building sequence models is selectivity: or the context-aware ability to focus on or filter out inputs into a sequential state. In particular, a selection mechanism controls how information propagates or interacts along the sequence dimension

Selection Mechanisms

A selection mechanism refers to the ability to efficiently select data in an input-dependent manner (i.e. focus on or ignore particular inputs). Mamba introduces a selection mechanism that parameterizes the SSM values based on the inputs.

3\. Architecture

We simplify prior deep sequence model architectures by combining the design of prior SSM architectures (Dao, Fu, Saab, et al. 2023) with the MLP block of Transformers into a single block, leading to a simple and homogenous architecture design (Mamba) incorporating selective state spaces.

[image: 2026-07-08_15-10-48.png]