State space model (SSM)

A state space model is a sequence model that compresses everything it has seen into a fixed-size hidden state and updates it step by step, so its cost grows linearly with sequence length rather than quadratically as in transformers.

The idea comes from control engineering and signal processing. A system is described by state variables, the smallest set of numbers that captures its condition at any moment. Each new state is computed from the current state and the latest input, and the output is read off the state. In the linear textbook form, two matrix equations do the work: one updates the state, the other produces the output. The same models are used in economics and statistics to track hidden trends in time series. Deep learning state space models learn these matrices from data and stack many such layers.

Their attraction is cost. A transformer's attention work grows with the square of the input length, and the memory it keeps of earlier tokens grows with every token. A state space model carries a fixed-size state, so each new token costs the same however long the sequence. That makes it resemble a recurrent neural network, but structured state space models can also be computed in parallel during training. S4, published by Albert Gu, Karan Goel and Christopher Ré in October 2021, set the state of the art on every task in the Long Range Arena benchmark and solved Path-X, a 16,000-step task on which all prior models had failed.

The breakthrough for language was Mamba, published in December 2023 by Albert Gu of Carnegie Mellon University and Tri Dao of Princeton University. Earlier fast sequence models lagged transformers on language, which the authors traced to an inability to reason based on content. Mamba made the model's parameters depend on each input, so it can choose what to keep and what to discard token by token, and added an algorithm designed around how GPUs move memory. The paper reported five times the inference throughput of transformers, and a 3 billion parameter Mamba matching transformers twice its size.

Many recent designs mix the two approaches. Jamba, described in March 2024, interleaves transformer and Mamba layers with mixture-of-experts, reported strong results with contexts up to 256,000 tokens and fit on a single 80GB GPU. The logic is that attention is good at looking back precisely at any earlier token, while state space layers handle the bulk of a long sequence cheaply.

The trade-off is built in. A fixed-size state is a compression, so a pure state space model cannot look back at every earlier token the way attention can; selectivity is the fix Mamba's authors proposed for this. For readers of AI news, a model described as an SSM or hybrid is usually aiming at long inputs and cheaper inference, and the claims to check are quality on long-context tasks and speed on real hardware.

Common questions

What is a state space model in AI?

It is a type of sequence model that keeps a fixed-size hidden state and updates it as each new input arrives, an approach borrowed from control engineering. Modern versions such as S4 and Mamba learn how to update that state from data. They are used for language, audio, genomics and other long sequences.

How is a state space model different from a transformer?

A transformer uses attention to compare every token with every other, so its cost grows with the square of the input length. A state space model compresses the past into a fixed-size state, so its cost grows only linearly. Transformers can recall any earlier token precisely; state space models trade some of that for speed and memory savings on long inputs.

What is Mamba?

Mamba is a state space model architecture published in December 2023 by Albert Gu and Tri Dao. It makes the model's state updates depend on the input, so it can decide what to remember, and uses a hardware-aware algorithm to run fast on GPUs. Its authors reported five times higher inference throughput than transformers.

Are state space models better than transformers?

Not across the board. They are faster and use less memory on long sequences, and Mamba matched transformers twice its size in its authors' tests, but attention remains better at precise recall of earlier content. That is why hybrid models combining both kinds of layer have become common.

Finding more

Search for "structured state space model", "S4", "Mamba architecture" or "hybrid transformer Mamba" to follow this line of research. The original papers on arXiv are the best primary sources, and conference talks by their authors often explain the ideas more simply. Treat speed comparisons with care, since results depend heavily on sequence length, hardware and implementation.

Working out what this means for your business?

Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.