Mamba

The paper introduced selective state-space models as a sequence-modeling backbone with input-dependent dynamics and linear-time scaling.

Metadata

FieldValue
PaperMamba: Linear-Time Sequence Modeling with Selective State Spaces
AuthorsAlbert Gu, Tri Dao
Year2023 preprint; 2024 conference
VenueCOLM 2024
arXiv2312.00752
OpenReviewtEYskw1VY2
Statusverified

Question

Transformers mix tokens with attention, but dense attention scales quadratically in sequence length. Previous subquadratic sequence models often struggled on information-dense discrete modalities. The question was whether a state-space sequence model could add content-dependent selection while keeping linear-time scaling.

The deeper architecture question is whether sequence models need explicit pairwise token-token attention to be expressive. Mamba argues that a recurrent state-space model can become competitive if its dynamics are selective: the model should decide, from the current input, what to remember, what to ignore, and what to expose.

This puts Mamba between several older ideas:

FamilyStrengthWeakness Mamba Targets
RNNslinear recurrence over sequence lengthhard to scale and train as modern backbones
SSMslong-range linear dynamics and efficient convolution/scan formslimited content-dependent routing
Transformersflexible content-based token mixingquadratic attention cost

Main Claim

Selective state-space models make SSM parameters input-dependent, allowing sequence models to choose what to propagate or forget while retaining efficient long-sequence computation.

Narrowed claim:

where the transition and readout depend on the current input token.

The useful narrowed claim is:

This is not a claim that attention is obsolete. It is a claim that selective recurrence can be a serious backbone primitive.

Architecture Contract

ItemContract
Inputsequence of token or feature vectors
Outputsequence representations or next-token predictions
Main mixing primitiveselective state-space recurrence
Sequence scalinglinear in sequence length for the recurrent scan
Memory representationcompressed hidden state, not explicit all-pair attention
Selection mechanisminput-dependent SSM parameters and gates
Practical requirementhardware-aware parallel scan/kernel implementation

For a sequence:

Mamba maps:

through a recurrent state:

The difference from a vanilla RNN is that has structured state-space dynamics and is implemented with a scan that can be parallelized efficiently.

State-Space Starting Point

A continuous-time linear state-space model is:

After discretization, a sequence model can be written as:

Classical SSMs use fixed parameters across the sequence. That makes them efficient and stable, but can make content-based selection difficult.

Mamba changes this by making key parameters depend on the current input:

and, in the broader selective formulation, the update can vary by token.

Selectivity

Selectivity means the model can condition its memory update on the current token.

Conceptually:

This is why Mamba is closer to gated recurrence than to a fixed linear filter. The model does not only run the same dynamics over every token; it can choose what information should enter the state and what should be emitted.

MechanismRole
input-dependent controls discretization/time-step behavior
input-dependent controls how input enters state
input-dependent controls how state is read out
gatingcontrols the block output

This is the paper’s answer to the weakness of earlier SSMs on discrete, information-dense data.

Method

Mamba combines:

ComponentRole
selective SSMinput-dependent recurrence over sequence length
hardware-aware scanparallelizes recurrent computation efficiently
gated block designbuilds a simple sequence backbone around the selective SSM
linear sequence scalingavoids dense attention cost

The architecture changes the sequence mixing primitive from dense pairwise attention to recurrent state updates with selective dynamics.

Block Structure

A Mamba block can be read as a sequence mixing block with projection, local mixing, selective SSM, and gating.

StageRole
input projectionexpands or splits channels for SSM and gate paths
local convolutionadds short-range local context
selective SSMperforms recurrent long-range sequence mixing
gate pathmodulates output
output projectionreturns to model dimension

The exact implementation details matter because Mamba’s practical claim is not just mathematical recurrence. It depends on making the selective scan efficient on modern accelerators.

Scan View

Although the recurrence is sequential in definition:

the computation can be implemented with a parallel scan under the right associative structure.

At a high level:

This is the practical bridge between recurrence and high-throughput training.

Complexity and Memory

ModelToken MixingSequence CostMemory Pattern
dense Transformer attentionpairwise token-token attention attention interactionsstores attention-like pair interactions
RNNrecurrent hidden state sequential recurrencecompressed state
Mambaselective SSM scan sequence scalingcompressed state plus hardware-aware scan buffers

The tradeoff is clear:

This can be much better for long sequences, but it changes what information is represented and how it is retrieved.

Relation to Attention

Attention computes a content-dependent weighted sum over previous tokens:

Mamba instead updates a latent state:

and reads from it:

So the question is not only efficiency. It is also about memory layout:

AttentionMamba
keeps access to many token states through pairwise weightscompresses history into recurrent state
flexible retrieval from contextefficient state update
quadratic dense form unless approximatedlinear sequence scaling
easy to inspect attention weights, though not always faithfulharder to interpret hidden state memory

Relation to Mamba-2

Mamba-2 reframes the comparison between SSMs and attention through structured state space duality. The useful shift is from “attention vs recurrence” to “what structured sequence mixing matrix is being computed?”

Mamba can be expanded into a causal matrix mixer:

Mamba-2 studies this matrix view more directly and uses it to design a faster SSD/Mamba-style layer. For reading follow-up papers, separate:

AxisMambaMamba-2
core contributionselective SSM blockstructured state space duality and SSD layer
main questioncan input-dependent SSMs compete with attention?how are SSMs and attention-like mixers related?
implementation angleselective scanfaster block/chunk algorithms

Benchmark Reading

Mamba’s benchmark claims should be read in three separate layers.

LayerWhat to check
qualityloss, accuracy, downstream task performance
scalingsequence length, throughput, memory, wall-clock
implementationwhether custom kernels and hardware assumptions are used

The paper is strongest when quality and efficiency are both considered. A linear-time architecture that loses too much quality is not enough; a competitive model that only wins with specific kernels should be described with that caveat.

Evidence

ClaimEvidence in paperCaveat
Selective SSMs improve prior SSM weakness on discrete datalanguage modeling and synthetic/selective-copy style tasksresults depend on implementation and training setup
Mamba scales linearly with sequence lengthalgorithmic design and long-sequence experimentshardware kernels are part of the practical claim
Mamba is competitive across modalitieslanguage, audio, and genomics experimentsnot a proof that attention is obsolete

Ablation Reading

Important ablation axes:

AxisWhat it testsReading
selectivity vs fixed SSMwhether input-dependent parameters mattercentral to the paper’s contribution
scan/kernel implementationwhether theoretical scaling becomes practical speedhardware-aware part of claim
block designhow much gating, convolution, and projection matterMamba is a block, not only an equation
sequence lengthwhere linear scaling becomes visibleshort-context tasks may not show the advantage
modalitylanguage, audio, genomics, etc.tests whether sequence bias transfers

For this wiki, the main reusable idea is selectivity: make sequence memory update depend on the token.

Benchmark Card

FieldValue
Main tasksequence modeling
Input/output unitsequence tokens to sequence representations or predictions
Main comparisonTransformer and prior subquadratic sequence models
Main metric familylanguage-modeling loss, downstream accuracy, throughput, sequence-length scaling
Not directly testedall Transformer workloads, tool-use agents, structure-based molecular modeling

Implementation Notes

  • The mathematical recurrence is simple to write but not enough for performance; scan kernels are part of the system.
  • Long-sequence speedups depend on sequence length, batch size, hidden size, hardware, and kernel maturity.
  • Mamba is not a drop-in proof that attention can be removed from every architecture.
  • Hybrid attention-SSM designs may be better when exact retrieval from context matters.
  • For biological sequences, the appealing part is long-context scaling, but benchmark design must avoid leakage and family overlap.
  • For protein or genome modeling, the sequence length advantage does not remove the need for careful tokenization and evaluation splits.

Limitations

  • The paper’s strongest practical claims depend on custom kernels and hardware-aware implementation.
  • Linear-time scaling does not automatically imply better quality at every compute budget.
  • Input-dependent recurrence changes interpretability and memory behavior relative to attention.
  • Later Mamba variants may change the best block design, normalization, hybridization, and scaling behavior.
  • Compressed recurrent state may be weaker than attention for tasks requiring precise retrieval of arbitrary earlier tokens.
  • Linear sequence scaling does not automatically imply lower end-to-end latency in every setting.
  • Comparisons against Transformers must control for data, training budget, implementation quality, and inference setup.

Why It Matters

Mamba is a key anchor for modern state-space model architectures and alternatives to attention-based token mixing.

The reusable pattern is:

This matters for architecture reading because it creates a third major branch:

BranchAnchor
attention sequence modelsAttention Is All You Need
decoder-only LMsGPT-2
selective state-space modelsMamba

Mamba should be read as a serious alternative sequence primitive, especially when sequence length and throughput are first-order constraints.

Connections