Notes

Mamba (SSM)

Attention reads every earlier token again for every new token, and that bill grows with the square of the sequence. Mamba takes the opposite bet: keep a running state, update it as each token arrives, and never look back at the raw history.

A state instead of a lookup

Mamba is a state space model. Each layer carries a fixed-size hidden state advanced token by token by a linear recurrence, so cost per token is constant and total cost is linear in length. What made this competitive with transformers is selectivity: the recurrence parameters are themselves functions of the current token, so the layer decides what to absorb and what to forget — something earlier state space models, with their fixed dynamics, could not do. Training still parallelises, through a hardware-aware parallel scan rather than a sequential loop.

Why the efficiency matters
  • No KV cache: generation memory does not grow with the conversation, which is where transformer serving cost concentrates.
  • Throughput at long sequence lengths is several times that of a comparable transformer.
  • Very long inputs — genomes, raw audio, whole codebases — become tractable.
The trade-off

A fixed-size state is lossy by construction, and it shows on tasks needing exact recall of something seen far earlier, such as copying a string verbatim out of the context. That is why most shipped designs are hybrids, interleaving a few attention layers among many Mamba layers — Jamba and Codestral Mamba are the production examples, and Mamba-2 narrowed the gap further.

Mamba is a selective state space model used as an alternative to the transformer block: instead of attending over all previous tokens, each layer carries a fixed-size state advanced by a recurrence whose parameters depend on the current token. Cost is linear in sequence length and there is no KV cache, so long-sequence throughput and memory improve sharply. Exact recall from distant context is weaker, which is why production models interleave Mamba and attention layers.

Picture two people following a long meeting. One re-reads the entire transcript before every sentence they say; the other keeps a running set of notes and updates it as the meeting goes. The first never misses a detail but gets slower and slower. The second stays just as fast no matter how long the meeting runs. Today's chat models mostly work the first way; Mamba works the second. It is cheaper and faster on very long material, with one catch — a running summary can blur a detail it has already squeezed down, so real systems tend to mix both styles.