- Key idea
- Markov chains, stationary distributions, Metropolis–Hastings, power distributions, and sequential Monte Carlo
- Real world
- A tourist wanders a city, at each corner picking a street at random. After a long afternoon, the fraction of time spent in each square no longer depends on where they started; busy hubs get visited most. Design the rules for picking streets, and you control those fractions.
- In an LLM
- Low-temperature decoding sharpens each token choice, but that isn't the same as favouring the most likely whole answers. A Markov chain that proposes rewrites of an answer and accepts or rejects them can sample from the sharpened distribution over whole answers, and recent work finds that this alone lifts a base model's reasoning scores close to those of RL-trained models.
Markov chains
A Markov chain is a random process where the next state depends only on the current state, not on how you got there. "Memoryless" is the key word.
- Weather modelled as: tomorrow depends only on today.
- A board game: your next square depends only on your current square and the dice.
- A language model is a Markov chain if the state is the whole text so far: the next token depends only on that. (With the state being only the last token, it isn't; that was the old n-gram model.)
Many chains settle into a stationary distribution: after enough steps, the chance of being in each state stops changing, whatever the starting point. That long-run distribution is what makes chains useful for sampling.
At each corner the tourist picks one of the connecting streets at random. Run the walk for hours: big squares with many streets get visited far more than dead ends, in fixed proportions. Google's original PageRank was exactly this: a random web surfer's long-run share of time on each page.
State: a complete answer to a maths question. Step: pick a random position, throw away everything after it, and let the model rewrite the rest. This defines a Markov chain over answers. On its own, its long-run distribution is just the model's own distribution. Add an accept/reject rule and you can make it favour whatever you want.
MCMC: designing the chain
Markov chain Monte Carlo (MCMC) builds a chain whose stationary distribution is a target you choose. You only need to be able to compute up to a constant. The classic recipe, Metropolis–Hastings:
- From the current state , propose a new state from some proposal .
- Accept the move with the probability below; otherwise stay at .
The ratio means you never need the normalising constant, which is often impossible to compute. The catch: successive samples are correlated, and you must run the chain long enough to forget its start ("burn-in" or "mixing").
Sharpening whole answers
Here's why this matters for LLMs. Say you want the model's answers, but sharpened towards its most confident ones. Two very different things go by that description:
- Low temperature: sharpen every token's distribution separately, which is easy and is what decoding does.
- The power distribution : sharpen the distribution over whole answers, which is hard to sample directly.
They disagree whenever an opening looks likely but leads into many weak continuations. Low temperature commits early to the likely-looking opening. The power distribution weighs where each opening leads. Metropolis–Hastings can target with the base model itself as the proposal.
Try it
A recruiter who sharpens every decision separately hires whoever interviews best at each stage, even if those candidates tend to fade later. One who scores whole careers prefers the candidate whose early stage was a little weaker but whose path almost always ends well.
Karan and Du (2025) ran Metropolis–Hastings on a base model's own answers, targeting with partial rewrites as proposals, with no training, reward model or verifier. On maths, coding and science benchmarks, single-sample accuracy nearly matched, and on some tasks beat, the same model after GRPO, without the loss of diversity across samples that RL causes. It's a strong hint that much of what RL does is sharpening the distribution the base model already has (Does RL teach new skills?).
Sequential Monte Carlo
Another family keeps a population of partial answers (particles), extends them a step at a time, scores them with a reward model or constraint, and resamples: duplicate promising particles, drop weak ones. It's importance sampling applied step by step, with resampling to stop the weights degenerating. It's used for constrained generation and for inference-time scaling, where it can beat best-of-n at the same compute.
Where this shows up
- Inference-time scaling with a base model: power sampling, particle filtering.
- Constrained generation (must contain a word, must parse as JSON) as probabilistic inference: SMC steering.
- Diffusion language models are a Markov chain from all-masked to complete text: diffusion LMs.
- Best-of-n and majority vote are simpler, non-chain answers to the same question: latent variables, tilting.
Markov chains
A chain with transition probabilities has stationary distribution if
Detailed balance, , is a sufficient condition and is what Metropolis–Hastings is built to satisfy.
Metropolis–Hastings acceptance
With an independence proposal and target , this simplifies to , which is what the widget runs.
Power distribution versus temperature
Each per-token normaliser depends on the prefix, so the product is not proportional to . Karan and Du show that upweights tokens whose futures are high-likelihood, while low temperature only looks at the current step.
Sequential Monte Carlo
With particles , extend each by sampling from the model, multiply its weight by an incremental factor (from a reward, constraint or learned "twist" function), and resample in proportion to the weights. The particle set approximates the target at the end, where encodes the constraint or reward.
Papers
- Reasoning with Sampling: Your Base Model is Smarter Than You Think (Karan & Du, 2025): MCMC for the power distribution
- Sequential Monte Carlo Steering of Large Language Models using Probabilistic Programs (Lew et al., 2023)
- Probabilistic Inference in Language Models via Twisted Sequential Monte Carlo (Zhao et al., 2024)
- Rollout Roulette: A Probabilistic Inference Approach to Inference-Time Scaling of LLMs using Particle-Based Monte Carlo Methods (Puri et al., 2025)