ICLR 2026  ·  Oral

From Markov
to Laplace

How Mamba in-context learns Markov chains

Presented by

Shengbo Gong

Authors

Bondaschi, Rajaraman, Wei, Ramchandran, Pascanu, Gulcehre, Gastpar, Makkuva

arXiv:2502.10178  /  EPFL · UC Berkeley · Google DeepMind · Télécom Paris

01

The question underneath

What counts as
intelligence?

One workable answer: infer a rule from a handful of examples and apply it immediately — no retraining, no gradient step.

Five capabilities

Ilya Sutskever  ·  scope of this talk

01

In-context learning

this talk

02

Early stopping before failure

open

03

Lifelong learning

open

04

Zero-shot transfer

open

05

Deploy-time learning

open

In-context learning

Definition

Inferring an unseen task from examples in the prompt, and applying it in the same forward pass — with the weights frozen.

Example · mathematical

A rule drawn at random

prompt 0 1 1 0 1 1 0 1 ? The transition rule is fresh for this prompt. Only counting the prompt can answer.

Example · natural language

A label map drawn at random

prompt "loved it" B "broke twice" A "arrived at 2" C "adored it" ? must say B

Two accounts

Literature

Account A

Implicit gradient descent

the claim, in its original form W k+1 = W k − η ∇L ← one attention layer layer 1 layer 2 = k descent steps

von Oswald+ 2022 · Dai+ 2023

Account B

Implicit Bayesian inference

the claim, in its original form p(next | prompt) = ∫ p(next | θ) p(θ | prompt) dθ prompt evidence posterior on θ prediction no weight update anywhere in the picture

Xie+ 2021

One lens

Interpretive bridge / HMM hypothesis

Sequential modeling / literal HMM

States move; observations follow.

Hidden regime Observed sequence z1 z2 zt zt+1 ? x1 x2 xt xt+1 ? θ = transition T + emission E

Infer a transition law from one trajectory, then predict the next observation. In the paper, the emission is identity: zt = xt.

LLM demonstrations / HMM-style hypothesis

Meaning is hidden; text and answers reveal it.

Latent semantic state Observed text + code POS NEU NEG state ? dashed = Markov dynamics only if assumed "loved it" code B "arrived at 2" code C "broke twice" code A new query code ? θ = semantics + language emission + code map π

Infer the shared task mechanism from demonstrations, then complete the missing answer. Tokens are treated as emissions from a latent task state.

Shared inference template

p(next | context) = p(next | θ, context) p(θ | context) dθ

02

Two architectures, one estimator

Background

What Mamba is, what Laplacian smoothing is, and why a Markov chain is where they meet.

Complexity

Background  ·  Gu & Dao 2312.00752  /  Dao & Gu 2405.21060

Transformer Mamba Training compute O(T2 ) every token pair O(T) one pass Inference memory O(T) KV cache grows with T O(1) fixed state, any T

Mamba LM

Background / paper Fig. 2  ·  Bondaschi et al. 2502.10178

Autoregressive interface

Prefix in.
Next-token distribution out.

01

Embed every observed token xt.

02

Pass embeddings through Mamba; its recurrent state moves left to right.

03

MLP + linear + softmax produce P(xt+1 | x≤t).

Paper Figure 2. Input tokens are embedded, passed through recurrent Mamba cells and an MLP, projected to logits, and converted to a next-token distribution at every position.

Horizontal arrows between Mamba cells carry the recurrent state. Vertical arrows carry the token representation toward the language-model head.

Mamba block

Background  ·  Mamba-2 / S6, Gu & Dao 2312.00752 · Dao & Gu 2405.21060

Mamba-2 1 layer · 1 head — the exact model analysed in this talk
input xt input-dependent step size Δt = softplus(〈wΔ, xt〉 + δ) 1 · local binding three causal convolutions · window w t = ReLU(convX(WXxt−w+1:t)) · Δt bt = ReLU(convB(WBxt−w+1:t)) ct = ReLU(convC(WCxt−w+1:t)) where neighbours first meet t, bt input-dependent retention at = exp(−a · Δt) a > 0 learned · at: 1 keep · 0 forget scales x̃t 2 · selective state Ht−1 → Ht Ht = atHt−1 + x̃tbt retain the past + write the current local pattern running statistic Ht 3 · gated readout yt = Htct gt = ReLU(Wzxt) ot = Wo(yt ⊙ gt) output embedding ct selects what Ht reads out direct branch from xt creates gt ot out

The data

Background / data

Dirichlet prior Dir(β · 1) transition matrix P 0 → 0.71 / 0.29 1 → 0.18 / 0.82 one row per context one sampled sequence 0 1 1 0 1 1 0 0 1 throw P away repeat for every sequence Why this is the right testbed No two sequences share a law, so memorizing training transitions is worthless. The only way to predict is to count the sequence in front of you, at inference.

The estimator

Background / target

Counts for one fixed context

n — times that context occurred.
nj — times token j followed that context.

Naive: raw frequency

njn

Assigns probability zero to anything unseen — and a single zero sends cross-entropy to infinity.

FIX: ADD-𝛽 BEFORE DIVIDING  ·  LAPLACE, 1814

Pβ(xt+1=j|ctx) = nj + βn + 2β

Why this exact estimator

The Bayes-optimal closed form

For the unknown binary transition row θ ∼ Dirichlet(𝛽, 𝛽), the posterior predictive is exactly

E[θj | n0, n1] = nj + βn + 2β

That closed form is add-𝛽. It is the exact Bayes-optimal predictor for next-token cross-entropy, not a heuristic correction.

So the loss has a known floor — ask not "does it learn?" but "does it reach the optimum?"

Worked example

BACKGROUND / TARGET  ·  𝛽 = 1, ORDER 1

count the transitions out of context "0" 0 0 1 0 0 0→0 0→1 0→0 tally n0 = 2 n1 = 1 n = 3 raw frequency P(1) = 1 / 3 = 0.33 Unseen context→token pair: naive assigns P = 0; next-token cross-entropy pays −log 0 = +∞. ADD-𝛽, 𝛽 = 1 P(1) = (1+1) / (3+2) = 2 / 5 = 0.40 nothing is ever exactly zero

03

How this field actually works

Toy examples

You cannot prove anything about a frontier model. So you build the smallest synthetic task that still contains the phenomenon.

Lineage

Lineage

01

Linear & sparse regression

Fresh weight vector per sequence — compare against least squares.  Garg+ 2022

02

Trees & two-layer nets

Labels from a random tree or random network — tests non-linear classes.  Garg+ 2022

03

Random Markov chains

Fresh transition matrix per sequence — the only setting used from here on.  Edelman+ 2024

From here on: random binary Markov chains and their known add-𝛽 optimum.

Setup

Method

Architecture

Mamba-2, 1 layer, 1 head

Baselines

GPT-2 1–2L, linear attn 1–2L

Optimizer

AdamW, lr 1e-3, cosine

Iterations

10 000

Embedding dim d

grid { 2, 4, 8, 16, 32 }

SSM state dim N

N = d

Expansion factor e

e = 1 ⇒ inner width ed = d

State matrix Ht

Ht ∈ ℝ(ed)×N = ℝd×d

Conv window w

2 … 6

Compute

1× A100, 10–60 min per run

Objective

L(θ) = Σt E [ log fθ(xt+1 | x1t) ]

averaged over positions t

Plain next-token cross-entropy — nothing bespoke. Its minimizer is provably add-β, so the loss floor is known in advance.

Batch lab

Live / toy data lab

Markov order k

Batch of 5  one fresh P per row

Five sequences, five different transition matrices. At order k, the recurrent state Ht must keep one transition-count row for each of the 2k contexts.

Convergence

Live / convergence

Markov order k

Sequence  t = 0 / 96

Recurrent state — transition counts

Charted context  

add-β

true kernel

| error |

raw freq.

Estimated P(next = 1) for one fixed context

add-β estimate true kernel (hidden) raw frequency

The solid line is computed from counts alone; the dashed line is the kernel the estimator was never told. They converge — that convergence is the in-context learning.

04

The finding

One layer is
enough.

A single-layer Mamba tracks the Bayes-optimal estimator. A single-layer transformer cannot get off the ground.

On the optimum

Result / paper Fig. 1

Predicted P(next) along one sequence 1 .5 0 Mamba (1L) = optimum Transformer (2L) Transformer (1L) stuck at 0.5 position t L1 gap from optimal ≈0 Mamba 1L small TF 2L large TF 1L

The 1-layer Mamba curve sits on the optimum. The 1-layer transformer never leaves the marginal; two layers only track it loosely.

The measurement

Result / paper Fig. 1  ·  measured, not schematic

Paper Figure 1. Left: predicted next-token probability across a fixed test sequence — 1-layer Mamba overlays the optimal estimator, 2-layer Transformer tracks it loosely, 1-layer Transformer stays flat near 0.5. Right: L1 distance from optimal across Markov orders 1 to 4.

Left: the predicted probability along one test sequence. Right: the L1 gap from optimal across Markov orders 1–4. Mamba's line and the optimum are indistinguishable.

Two layers

Mechanism / transformer

the estimator needs two jobs ① bind context to what followed  ·  ② count matches input representations xs−1 xs xs+1 (xs−1, xs) not an object yet copy neighbour layer 1 · bind (xs−1, xs) the transition pair now exists job ① complete match pairs layer 2 · count (0,1)   (1,0)   (0,1)   … match (0,1) count = 2 job ② complete the pair exists after layer 1; counting starts at layer 2

One block

Mechanism / Mamba

the same two jobs ① bind context to what followed  ·  ② count matches inside one Mamba block 1 · causal convolution (xt−k:t−1, xt) forms context + next as one feature 2 · recurrent state Ht = atHt−1 + update adds that transition to the running count ot out both jobs finish before the block exits

The depth gap comes from where binding happens — not from attention.

05

Ablations

Which part is
load-bearing?

Take the architecture apart one component at a time. The answer is not the part anyone expected.

Ablation

Ablation / procedure

full Mamba remove… gating still solves it ReLU still solves it convolution FAILS width does not save it — gap ≈ 0.11–0.16 at d = 10, 100, 1000 alike the converse experiment 1-layer transformer fails + conv on Q, K, V now succeeds with one layer Symmetrically: strip Mamba's convolution and it needs two layers. Convolution > gating > non-linearity.

Convolution

Ablation / paper Fig. 11

1-layer transformer · no conv stays flat add conv on Q, K, V + convolution · same 1 layer climbs onto it

Bolt a convolution onto a transformer's Q, K, V and one layer suddenly suffices — the curve climbs onto the optimum. The depth requirement was about binding, not attention.

The measurement

Ablation / paper Fig. 11  ·  measured, not schematic

Paper Figure 11. Predicted probability and test loss comparing 1-layer Mamba, 1-layer Transformer, and 1-layer Transformer with convolution added to K, Q, V. Adding convolution lets the single-layer transformer match Mamba and the optimal predictor.

The convolution-augmented single-layer transformer lands on Mamba and the optimum; the plain single-layer transformer stays flat, well above the loss floor.

Gate open

Ablation / paper Fig. 4

The state transition factor a_t across 500 positions at convergence is nearly constant at one; an inset zoom shows values around 0.996.

The learned gate stays at at ≈ 0.996 everywhere.

The optimal estimator needs every historical count, so the model learns almost no forgetting. Selectivity is available, but this stationary task does not use it.

Order sets the window

Limits / local binding

An order-k transition contains two objects: a context of k tokens and the one token observed after it.

one transition xt−k ··· xt−1 context · k positions + xt successor · 1 w ≥ k + 1 A window of k sees the context, but cannot bind what followed.

This is the local requirement. It says what feature must enter the recurrence before any counting can be correct.

Paper Fig. 3b · learned, not constructed

Paper Figure 3b. Test loss by Mamba convolution window for Markov orders one through four, collapsing sharply once the window reaches k plus one.

The threshold moves one step for every increase in k.

Below w = k+1 the gap is large; at and above it, the gap collapses to zero. The staircase is the signature of a representational threshold.

Order sets the state

Limits / global memory

The same k creates the global requirement

An order-k binary chain has 2k contexts. The recurrent state H must preserve a separate predictive count for every one of them.

Ht := all recurrent states, flattened ∈d

For fixed accuracy and precision:
dim(H) = Ω(2k).

This is an information bound on the total recurrent state, not a quirk of one Mamba parameterization.

Test loss by Markov order for hidden dimensions 2, 4, 8, 16, 32. Each dimension solves orders up to log2(d) and degrades beyond it, confirming d = 2^k is sufficient.

Measured, not just argued: d = 4 handles k = 2 and fails at k = 3. Each curve gives out one order after the last.

So order controls both resources: locally, w ≥ k+1; globally, the state capacity grows exponentially in k.

What depth changes

Depth / two roles

Test loss gap from optimal by Markov order for one to four layers. Mamba is uniformly low and flat in depth because one layer already has enough capacity at these orders; transformers improve sharply from one to two layers.

Mamba is flat in depth here because one layer already saturates the task.

Transformer / local binding

Layer 1 binds.
Layer 2 retrieves and counts.

Depth supplies the missing local step — which is why a transformer needs two layers.

SSM / Mamba / global memory

Depth and capacity are interchangeable.

Stacking recurrent layers adds capacity linearly through L · C, where C = dim(H) is the recurrent-state capacity per layer.

The capacity law

Limits / L · C ≳ 2ᵏ  ·  training-free sweep

Gap to add-β collapses to zero exactly when L · C ≥ 2k.

One layer · grow state capacity C

k \ C

2

4

8

16

1

.000

.000

.000

.000

2

.234

.000

.000

.000

3

.319

.243

.000

.000

4

.374

.326

.209

.000

Zero exactly on and past C = 2k. Capacity alone must grow exponentially in k.

Fixed C = 4 per layer · grow depth L

k \ L

1

2

4

8

1

.000

.000

.000

.000

2

.000

.000

.000

.000

3

.243

.000

.000

.000

4

.326

.209

.000

.000

Same staircase — depth and capacity enter symmetrically, as the product L · C. Depth does add capacity, but only linearly, while the demand grows as 2k — so the layers needed still double each order.

Trade-offs

Summary  ·  sequence length T / Markov order k

Transformer Mamba Training compute O(T2 ) every token pair O(T) one pass Inference memory O(T) KV cache grows with T O(1) fixed state, any T Task order k O(k) width scales with k w ≥ k + 1 L × C ≳ 2k

06

Consequences

At LLM scale

Does any of this survive on real text — and what did the frontier labs ship once they had to choose?

Real text

At scale / WikiText-103

Same ablation, real language. Mamba-2 at 14.5 M parameters on WikiText-103 — remove one component at a time and read the perplexity.

Model

PPL

Δ

Mamba-2, full

27.55

without non-linearities

28.98

5%

without convolution

30.68

11%

without gating factor

32.16

17%

The two components the Markov analysis singled out are the two that hurt most on real text.

An honest caveat

At 12 layers the
advantage nearly
vanishes.

Mamba-2, 110 M

21.38

without convolution

21.46

Likely because other layers learn to approximate the convolution themselves. The mechanism is still needed — it just stops needing its own module.

Kimi K3

LLM practice / mixed memory

93-layer text backbone · 69 KDA + 24 Gated MLA KDA recurrent KDA recurrent KDA recurrent Gated MLA global attention repeat three cheap recurrent layers one global retrieval layer KDA · fixed recurrent memory St = f(St−1, xt) state size is fixed as sequence length T grows memory O(1) fast sequential statistics still subject to the recurrent-state bound Gated MLA · sequence memory KV1:t cache grows with T and can retrieve earlier positions memory O(T) periodic global access breaks the pure-recurrence assumption

Take away

Close

01

A 1-layer Mamba implements the exact Bayes-optimal add-β estimator.

02

The convolution binds context to successor; recurrent state H accumulates the counts.

03

Order k sets both costs: w ≥ k+1 locally and L × C ≳ 2k globally.

04

Markov prediction is not language, and in-context learning is only one capability of an LLM.

Thank you

Questions?

Paper

From Markov to Laplace: How Mamba In-Context Learns Markov Chains. ICLR 2026, Oral. arXiv:2502.10178

Architecture

Gu & Dao, Mamba: Linear-Time Sequence Modeling with Selective State Spaces. arXiv:2312.00752  ·  Dao & Gu, Transformers are SSMs (Mamba-2 / SSD). arXiv:2405.21060

Code

github.com/Bond1995/Markov-Mamba — and the training-free reproduction shown here, in toy_reproduce.py

Presenter

Shengbo Gong