The short answer

A Transformer attends to every token pair, so cost grows quadratically with window length. It also cannot model anything past that window. Mamba instead runs a selective state space model. Its SSM parameters become functions of the input token. That selection, then, lets it remember or forget information along the sequence. Still, the paper is exact here. Mamba-3B “outperforms Transformers of the same size” and “matches Transformers twice its size.” That is not the looser “outperforms twice its size” claim you may have seen. So decoding cost is the real centerpiece here. Meanwhile, a Transformer’s KV cache grows with every generated token. Mamba carries a fixed-size recurrent state instead. So each decoding step costs the same constant time.

Two designs answer one question differently: what happens to cost as a sequence grows longer? Generally, a Transformer leans on dense attention across the whole window. Mamba instead runs a linear-time recurrent state.

This guide leans on one paper: Gu and Dao’s “Mamba: Linear-Time Sequence Modeling with Selective State Spaces.” Indeed, every number below traces back to that paper directly. So every fact and quote comes from its text, not from outside claims.

Mamba vs Transformer cost curves plotted against sequence length, showing attention rising quadratically with the window while Mamba rises linearly
Attention’s cost climbs with the square of the window; Mamba’s climbs linearly.

The Cost Attention Pays for Long Sequences

Self-attention, covered in our self-attention vs cross-attention guide, actually has one real strength. Certainly, in the paper’s words, it can “route information densely within a context window.” That strength comes with a cost, though. The paper names two drawbacks together, not one.

Firstly, a hard limit exists: attention cannot model anything outside a finite window. Secondly, quadratic scaling follows: cost grows with the square of window length. Most articles, though, mention only the second point. Few mention the finite-window limit instead.

What a State Space Model Does Instead

Mamba is, in fact, a selective state space model. That is not the same thing as a plain recurrent network, the kind our CNN vs RNN guide covers. A structured SSM maps each input channel to an output through a latent state h.

Prior SSMs could be computed efficiently as either a recurrence or a convolution. That efficiency, though, had one condition: linear time invariance, or LTI. Under LTI, the Δ, A, B, and C parameters stay constant across time. So that constancy is what made the efficient convolutional path possible.

The Selection Mechanism That Made Mamba Work

Prior models shared one limitation, the paper argues. In fact, they could not “efficiently select data in an input-dependent manner.” In other words, they could not focus on or ignore particular inputs.

Mamba’s fix is a selection mechanism. So it works by “parameterizing the SSM parameters based on the input.” That lets the model filter out noise and remember relevant information indefinitely. So the state is not empty; it holds what matters, on purpose.

The abstract frames the same idea differently. There, the paper lets the SSM parameters “be functions of the input.” So the model can “selectively propagate or forget information along the sequence length dimension.” So it does that “depending on the current token.”

Selectivity is not free. Input-dependent parameters break time invariance. The paper says so plainly: the change “prevents the use of efficient convolutions.” So Mamba trades convolution for a different computation path, covered next.

Mamba vs Transformer: Comparison Table

Comparison table of Transformer and Mamba covering core mechanism, scaling, cost per decoding step, what each carries between tokens, context limit and architecture contents
Six differences between a Transformer and Mamba.

The table below lines up a Transformer against Mamba, field by field. Every value traces back to the paper directly.

AspectTransformerMamba
Core mechanismSelf-attention across every token pairSelective state space model with a recurrent state
Scaling in sequence lengthQuadratic with window lengthLinear in sequence length
Cost per decoding stepGrows as the KV cache growsConstant time per step
Cache of past tokensRequired; keys and values for every past tokenNot required
State carried forwardNo fixed state; recomputes over the windowA fixed-size recurrent latent state h
Context-window limitCannot model anything outside the windowNone reported; selection remembers indefinitely
Time invarianceNot applicableDeliberately broken; parameters vary with the input
How parameters relate to inputAttention weights computed per token pairSSM parameters (Δ, A, B, C) are functions of the input
Efficient computation pathParallel attention matrix multiplicationHardware-aware parallel associative scan
Training parallelismFully parallel across the sequenceComputation and memory scale linearly in sequence length
What the architecture containsAttention and MLP blocksNeither attention nor MLP blocks
Longest sequence reportedNot stated in the paperPerformance gains reported up to 1M tokens
Reported throughput figureReference point in the paper’s comparison5x higher inference throughput than Transformers
Reported quality claim (3B scale)Baseline for the comparisonMatches Transformers twice its size; beats same-size Transformers
Best suited toDense, in-window routingLong context, constant-time decoding

One row deserves a second look: the cost per decoding step. A Transformer’s per-step cost climbs as its cache grows. Mamba’s stays flat instead, the subject of the next section.

Why Mamba Needs No Cache of Past Tokens

Four decoding steps showing a Transformer KV cache growing by one entry per token while Mamba carries a single fixed-size recurrent state that never changes size
A Transformer’s KV cache grows with every token; Mamba’s recurrent state stays the same size.

Property two in the paper’s introduction is, indeed, the centerpiece of this whole comparison. Training “scales linearly in sequence length,” the paper states. Inference is the more surprising claim.

Unrolling the model autoregressively “requires only constant time per step.” Why: it “does not require a cache of previous elements.”

A Transformer decoder, the autoregressive style our BERT vs GPT guide covers, works differently. It generates one token, then attends back over every prior token to generate the next. So it must keep a cache of past keys and values. That cache, then, grows with every new token the model produces.

Mamba carries a fixed-size recurrent state instead of a cache. Accordingly, the state’s size never changes as the sequence grows longer. So each decoding step costs the same constant time, no matter how long the sequence already is. A Transformer’s per-step cost keeps climbing; Mamba’s still does not.

The Hardware-Aware Scan

Selectivity closed off the convolutional path, so the authors needed a new algorithm. Their answer computes the model “recurrently with a scan instead of convolution.” It also avoids materializing the expanded state in memory.

The stated goal is “to avoid IO access between different levels of the GPU memory hierarchy.” Our GPU vs TPU vs NPU guide covers that memory hierarchy in more depth.

The mechanism itself is, essentially, a parallel associative scan. Scans cost O(B L D N) FLOPs, which is linear in sequence length L. So that linear cost is the whole point of the redesign.

The paper reports two separate speed numbers, and, notably, they measure different things. One is theoretical: scaling linearly in sequence length, “compared to pseudo-linear for all convolution-based SSMs.” The other is measured instead: “up to 3x faster on A100 GPUs.”

That 3x figure compares the scan against earlier SSM implementations, not against Transformers. A separate 5x figure, covered next, compares Mamba’s inference throughput against Transformers instead.

What the Paper Actually Claims

The introduction claims three things for Mamba. Firstly, high quality: selectivity “brings strong performance on dense modalities such as language and genomics.” Secondly, fast training and constant-time inference, detailed above. Thirdly, long context: real gains reported “up to sequence length 1M.”

Architecturally, Mamba integrates selective SSMs into one simplified network. Notably, that network runs “without attention or even MLP blocks.” So no feed-forward sub-block survives either, the piece our mixture of experts vs dense models guide examines closely.

Now the numbers that get misquoted the most often. Mamba reports “5x higher throughput than Transformers” during inference. At 3B parameters, though, the claim is exact and easy to overstate.

Mamba-3B “outperforms Transformers of the same size” — that part is simple. It also “matches Transformers twice its size,” not outperforms them. The widely repeated version, “outperforms Transformers twice its size,” accordingly overstates the paper’s own claim.

On copying and induction-head tasks, Mamba “not only solves them easily” but extrapolates further. So it extends solutions “indefinitely long (>1M tokens).”

The paper also reports state-of-the-art results “across several modalities such as language, audio, and genomics.” Even so, that is not a claim that attention is obsolete. Instead, Mamba reads as an alternative backbone, not a final replacement verdict.

What Mamba Gives Up

Mamba’s selectivity, though, is not without cost inside the model itself. Once parameters depend on the input, time invariance breaks. That, accordingly, “prevents the use of efficient convolutions,” the paper states plainly. So Mamba needs the custom scan kernel covered above, not a standard convolution.

The architecture also gives up two familiar blocks. There is no attention layer anywhere in the network. Likewise, there is no separate MLP block either. Both are simply absent from the design, per the paper’s own description.

Where Each One Fits

Neither design wins outright; the fit depends on the sequence. Attention still routes information densely within a window, when that window is enough. Mamba fits better once the sequence outgrows that window, or once decoding cost is the deciding factor.

The paper reports state-of-the-art results in language, audio, and genomics. Long-context gains, likewise, hold up to the reported 1M-token mark. None of that makes attention obsolete, though. Instead, Mamba reads as an alternative backbone for those workloads, not a verdict against attention.

Interview Questions

A finite context window and quadratic scaling with window length. Most summaries mention only the second one.

No. It is a selective state space model instead. Its parameters depend on the input, which earlier SSMs could not do.

No, that overstates it. The paper says Mamba-3B matches Transformers twice its size, and outperforms Transformers of the same size.

It carries a fixed-size recurrent state instead of a growing cache. So each decoding step costs constant time.

No. 5x is inference throughput against Transformers. 3x is the scan implementation against earlier SSM methods, measured on A100 GPUs.

Frequently Asked Questions

That phrasing overstates the paper. It says Mamba-3B outperforms Transformers of the same size, and matches Transformers twice its size.

A finite context window, since attention cannot model past it, and quadratic scaling with window length. Both appear together in the paper.

It is a selective state space model instead. Its SSM parameters are functions of the input, which breaks the time invariance earlier SSMs relied on.

No. The selection mechanism lets it remember relevant information indefinitely, even though it carries no cache of past tokens.

No. Input-dependent parameters break time invariance, which prevents the use of efficient convolutions and forces a hardware-aware scan instead.

5x is inference throughput against Transformers. 3x is the scan implementation against earlier SSM methods on A100 GPUs. They are not the same measurement.

The paper reports results across language, audio, and genomics, not a verdict that attention is obsolete. Mamba reads as an alternative backbone.

No. The architecture drops attention and the MLP block, combining both into one simplified network.

Wrapping Up

A Transformer’s cost climbs with the window; Mamba’s still does not. That gap comes from one design choice: no cache, just a fixed-size state. Each Mamba decoding step costs the same constant time, however long the sequence already is.

Remember the paper’s exact headline claim, then. Mamba-3B outperforms Transformers of the same size, and matches Transformers twice its size. The looser, widely repeated version overstates that. Get this one right, and the rest of the comparison follows.

Related reading on DiffStudy:

Whatsapp-color Created with Sketch.

By Arun Kumar

Full Stack Developer with a BE in Computer Science, working with React, Next.js, Node.js, MongoDB, and AI/ML tools. Founder of DiffStudy — built to help CS students ace GATE and university exams, and keep developers up to date across AI, cloud, system design, web development, and every field of computer science. Every article is written from real hands-on experience, not just theory.

Leave a Reply

Your email address will not be published. Required fields are marked *


You cannot copy content of this page