Beyond Left-to-Right: Multi-Token & Diffusion LMs
Multi-token prediction, the limits of teacher forcing, and masked diffusion language models.
The chain rule guarantees that predicting one token at a time, left to right, can represent any distribution over text. It guarantees nothing about whether training finds that representation, or whether left to right is the best order to write in. This lesson follows three answers to those doubts: a simple task on which teacher-forced training stalls, models that predict several future tokens at once, and masked diffusion models, which turn BERT's objective into a likelihood bound and generate text in any order.
What you’ll learn
- Explain how teacher forcing can fail to learn a lookahead task on its training distribution, using the path-star task, and distinguish this from exposure bias.
- Describe multi-token prediction with output heads on a shared trunk, the conditions under which it helped, and how its heads speed up decoding.
- Derive the continuous-time bound of an absorbing (masked) diffusion model as a weighted masked-language-modeling loss, show that it does not depend on the noise schedule, and prove that it equals the expected loss of a random-order autoregressive model.
- Explain parallel unmasking and its independence error, adaptive decoding orders, and the remaining likelihood and caching gaps between diffusion and autoregressive models.
- Describe fill-in-the-middle training and the open question of which objective best supports reasoning and planning.
Where teacher forcing fails
Next-token prediction draws two different criticisms, and Bachmann and Nagarajan (2024) insist on keeping them apart. The familiar one concerns inference: a model that generates from its own outputs can drift into prefixes unlike its training data, so errors may compound. This is exposure bias, analyzed in Training Recurrent Networks. The second concerns training: teacher forcing can fail to learn an accurate next-token predictor in the first place, even on the training distribution. Their example is a path-finding task designed to be easy.
Under teacher forcing the model sees the true prefix of the path when it predicts each node. After the first node, the next one is simply the successor of the previous node in the edge list, which a lookup in the style of an induction head finds without any planning; the authors call this the Clever Hans cheat. Fitting those easy targets drains most of the training signal, and the one decision that requires lookahead, the first node after the start, is left to be learned from a single token that the cheat cannot explain, the indecipherable token. Transformers trained from scratch, a fine-tuned GPT-2 and Mamba models all fit their training data yet chose that first node essentially at random.
On path-star graphs whose center has degree , about what accuracy do teacher-forced models reach on the first node after the start, in percent?
Show the answer
20 %
About : the model picks one of the five arms at random, and the edge lookup then completes that arm perfectly, so the whole path is right about one time in five. This is not a compounding of errors at inference: given the first node, the cheat would finish every path correctly.
Two changes helped in their experiments. Teacherless training replaces the revealed answer tokens in the input by uninformative dummy tokens and asks the model to predict all of them, so every node must be predicted from the graph alone, an idea proposed earlier for faster inference. It succeeded on some of the easier graphs; on most, the models could not even fit the training data. Reversing the target, from goal to start, removes the need for lookahead altogether, and models trained that way solved the task even from scratch. The lesson is narrow but sharp: the chain rule says next-token prediction can represent any distribution; it does not say teacher-forced training finds a representation that requires planning.
Predicting several tokens at once
One response is to make every position predict further ahead. In multi-token prediction (Gloeckle et al., 2024), a shared trunk computes a state for each position and output heads, each a transformer layer, predict the next tokens through a shared output layer:
import torch.nn.functional as F
def multi_token_loss(trunk, heads, unembed, x):
"""x: (B, T) token ids. heads[i] predicts the token i+1 positions ahead; heads[0] is next-token."""
h = trunk(x) # (B, T, d), causal
T, loss = x.size(1), 0.0
for i, head in enumerate(heads):
logits = unembed(head(h[:, : T - i - 1])) # positions that have a target i+1 tokens ahead
loss = loss + F.cross_entropy(logits.flatten(0, 1), x[:, i + 1 :].flatten())
return loss # sum of the n cross-entropiesThis simple version keeps all heads' logits alive for one backward pass. With large vocabularies the logits dominate memory, which is why the paper backpropagates through each head before computing the next.
What it bought. On code, with models from 0.3 to 13 billion parameters trained on at least 91 billion tokens, multi-token prediction was worse than next-token prediction for small models and better at scale: the 13-billion-parameter multi-token model solved 12% more HumanEval problems and 17% more MBPP problems than a comparable next-token model. The effect was largest with byte-level tokens, where predicting eight bytes ahead solved 67% more MBPP and 20% more HumanEval problems than predicting one; on natural-language benchmarks the gains were smaller and mixed. The authors suggest that predicting further ahead reduces the mismatch between teacher-forced training and generation; that explanation, like the gains, is empirical.
Faster decoding. The extra heads can draft the following tokens, which the next-token head then checks in a single forward pass, a form of self-speculative decoding descended from blockwise parallel decoding (Stern, Shazeer & Uszkoreit, 2018); four-token models decoded up to three times faster, even at large batch sizes. DeepSeek-V3 (DeepSeek-AI, 2024) adopted a sequential variant, in which each extra module predicts one more token while keeping the full causal chain, to densify the training signal; used for drafting, its second token was accepted 85% to 90% of the time, for about 1.8 times as many tokens per second. Speculative Decoding shows how such drafts can be verified without changing the output distribution.
Masked diffusion: a likelihood from masked prediction
A masked LM predicts hidden tokens but, as Pretraining Objectives Compared showed, does not define a generative model. Discrete diffusion makes it one. Austin et al. (2021) built diffusion models for discrete data (D3PM) from Markov transition matrices, and observed that BERT's objective is a single step of one of them. The variant that later language models built on is the absorbing process, in which tokens turn into [MASK] and stay masked. Its continuous-time version takes a strikingly simple form (Sahoo et al., 2024; Shi et al., 2024). In this step is the sequence length and is diffusion time, not a token position.
Posterior of the forward process. Take . A token masked at time was still visible at time if it survived to , with probability , and was masked between and , with probability . Divide by its total probability of being masked by time , which is :
One reverse step. The model's reverse step has the same form with the clean token replaced by the prediction . The two distributions agree on the probability of staying masked, so at a masked position the KL divergence keeps only the term for the true token, and at a visible position it is zero:
Continuous time. Sum these terms over a grid of times and refine the grid, so that . Refining tightens the bound as long as a masked token gets no easier to predict when more of the sequence is masked, which holds on average for the exact conditionals (a model that is worse with fewer masks can make it looser). The ELBO's other two terms vanish at the ends, since nothing is masked at and everything is masked at , as the model assumes:
The schedule drops out. Substitute the masking rate , so that : the bound depends only on how much is masked, not on when. With the linear schedule the weight is simply .
In words: draw a masking rate uniformly, mask each token with that probability, train a bidirectional transformer to predict the masked tokens, and weight the loss by the inverse rate. That is BERT with a random masking rate and a reweighting, and it bounds the negative log-likelihood; LLaDA trains with exactly this loss. A sanity check: a model that ignores context and gives each token a fixed probability pays, at rate , for about masked tokens, times the weight , so each token is paid for exactly once, as in any honest code. Both Sahoo et al. and Shi et al. found that this simple parameterization and objective made masked diffusion much stronger than earlier discrete diffusion results had suggested.
import torch
import torch.nn.functional as F
def masked_diffusion_loss(model, x, mask_id):
"""x: (B, L) clean token ids. Linear schedule: masking rate t ~ U(0, 1), weight 1/t."""
B, L = x.shape
t = torch.rand(B, 1).clamp_min(1e-3) # one masking rate per sequence
masked = torch.rand(B, L) < t # each token masked with probability t
z = torch.where(masked, torch.full_like(x, mask_id), x)
logits = model(z) # bidirectional, no causal mask: (B, L, |V|)
nll = F.cross_entropy(logits.transpose(1, 2), x, reduction='none') # (B, L)
return ((nll * masked) / t).sum(1).mean() / L # bound on the NLL, nats per tokenFor a model whose logits are all equal over 100 tokens, this loss averages nats per token, the one-payment-per-token check above. Clamping away from keeps the weight finite; at small few tokens are masked, so such terms are rare and noisy, one reason training variance mattered in these papers.
Condition on the number of masked positions: with binomial probability, and given its size, is a uniformly random -subset.
Integrate against , using the Beta integral :
In a uniformly random order, when tokens are still missing, the missing set is a uniform -subset and the next token is uniform within it, so that step costs in expectation. Summing over gives the left side:
With the true conditionals, every order is an exact chain-rule factorization, so every order costs and the bound is tight. A learned model must be good at all orders at once, a harder job than one fixed order: one explanation for why masked diffusion trails left-to-right models in likelihood at equal training.
Lou, Meng and Ermon (2024) reached a similar destination from score matching. Their score entropy loss learns the ratios between sequences that differ in one position, the discrete counterpart of the score, and is minimized exactly at the true ratios; at comparable size it beat earlier diffusion language models by a wide margin and was competitive with GPT-2. For the absorbing process those ratios are clean-data conditionals times a scalar that depends only on time (Ou et al., 2025), which is why a denoiser with no time input suffices and why the different formulations lead to essentially the same masked-prediction objective.
Generating in any order
To generate, start from masks and run the process backward. In the exact reverse process each masked token is revealed between times and with probability ; practical samplers instead reveal a set number of tokens per step, chosen at random or by the model's confidence. With steps of one token each, chosen uniformly among the masked positions, sampling is exactly the random-order autoregressive model of the proposition. With fewer steps, several tokens are revealed at once, each drawn from its own conditional given the tokens already visible, so the tokens revealed together ignore each other: the product-of-marginals problem of masked language models returns at generation time.
import torch
@torch.no_grad()
def sample_masked(model, L, mask_id, steps):
"""Start fully masked; at each step reveal the most confident masked positions."""
z = torch.full((1, L), mask_id)
for s in range(steps):
masked = z == mask_id
n = int(masked.sum()) - (L * (steps - s - 1)) // steps # how many to reveal now
probs = model(z).softmax(-1) # (1, L, |V|)
conf, tok = probs.max(-1) # best token at each position
conf = conf.masked_fill(~masked, -1.0) # only masked positions compete
idx = conf.topk(n, dim=-1).indices[0]
z[0, idx] = tok[0, idx]
return zRevealing the most confident positions first, with their most likely tokens, is greedy in both the order and the tokens; sampling tokens instead of taking the maximum adds diversity. LLaDA's low-confidence remasking is the same idea seen from the other side: predict every masked token, then mask the least confident predictions again.
In the training data two adjacent blanks hold "ice cream" half the time, "fried rice" 30% of the time and "iced tea" 20% of the time, and the model has learned the exact conditional for each blank given the rest. If both blanks are revealed in the same step, what fraction of samples is incoherent, in percent?
Show the answer
62 %
Each blank is drawn from its own marginal: ice, fried or iced with probabilities , , , and cream, rice or tea likewise. A sample is coherent only when the draws match: , so 62% are incoherent. Revealing the blanks in two steps is always coherent, because the second is then predicted given the first.
Which tokens first? Kim et al. (2025) showed, in theory and in experiments, that masked diffusion models train on infilling subproblems some of which are computationally intractable, so their errors are uneven: small on easy subproblems, large on hard ones. A random unmasking order walks into the hard ones; an adaptive order can steer around them. On Sudoku, revealing at each step the position whose two most likely values differ most in probability, the top probability margin, raised the share of solved puzzles from 6.88% with random order to 89.49%, against 18.51% when revealing the position whose most likely value has the highest probability; the adaptive model beat autoregressive models with seven times as many parameters that had been trained with the correct solving order.
At scale. LLaDA (Nie et al., 2025) trained an 8-billion-parameter masked diffusion model from scratch on 2.3 trillion tokens, then fine-tuned it on 4.5 million instruction pairs. In scaling runs up to about FLOPs it performed comparably to autoregressive baselines that the authors trained on the same data, was competitive with LLaMA 3 8B at in-context learning, and outperformed GPT-4o on a reversal poem-completion task, a test of the "reversal curse" that afflicts left-to-right models. Bidirectional attention has a price: when any token may still change, nothing can be cached, so each denoising step reprocesses the whole sequence, and LLaDA's authors note that it is incompatible with KV caching. Block diffusion (Arriola et al., 2025) interpolates between the two worlds: it generates blocks from left to right and runs diffusion inside each block, which restores caching across blocks and allows outputs of any length.
| Property | Left-to-right autoregressive | Masked diffusion |
|---|---|---|
| Training targets per sequence | all tokens, in one fixed order | about masked tokens at a random rate , averaged over all orders |
| Likelihood | exact | an upper bound on |
| Generation | sequential steps, each cheap with a KV cache | any number of steps up to , each a full bidirectional pass |
| Infilling and editing | needs a reformatted input, such as fill-in-the-middle | native: mask any positions |
| OpenWebText, 262 billion training tokens | perplexity 17.54 | bounds of 23.21 (MDLM) and 24.10 (SEDD) |
Filling in the middle, and the open question
Left-to-right models can learn infilling without any change of architecture. Fill-in-the-middle training (Bavarian et al., 2022) cuts a document at two random character positions into a prefix, a middle and a suffix, and with some probability moves the middle to the end behind sentinel tokens, so that ordinary next-token prediction learns to write the middle given both sides; the loss stays on all three parts. With half of the documents transformed, models of every size they tested kept their left-to-right loss curves unchanged, on natural language and on code, a property the authors called FIM-for-free, and they recommended training with FIM by default.
document: prefix | middle | suffix split at two random character positions
training: <PRE> prefix <SUF> suffix <MID> middle <EOT>
inference: <PRE> prefix <SUF> suffix <MID> → the model continues with the middleThe prefix–suffix–middle order; the paper also trains a suffix–prefix–middle variant. Splitting at characters rather than tokens matters: it teaches the model to complete a middle that begins or ends inside a token, as real editing requests often do.
Key takeaways
- Teacher-forced next-token training can fail to learn a lookahead task on its own training distribution: on path-star graphs the revealed prefix lets a Clever Hans shortcut fit every later node and leaves the first choice at about accuracy; teacherless and reversed training succeeded in some settings.
- Multi-token prediction adds heads that predict from a shared trunk at the same parameter count; it hurt small code models, helped large ones (13B: 12% more HumanEval and 17% more MBPP problems solved), and its heads draft tokens for self-speculative decoding.
- Absorbing diffusion masks each token independently. Its continuous-time bound is a masked-LM loss weighted by , which is for a linear schedule; it depends only on how much is masked, not on the schedule, and equals the expected loss of an autoregressive model over uniformly random orders.
- Sampling reveals masked tokens in any order and in parallel. Tokens revealed together are drawn independently, so fewer steps trade quality for speed, and adaptive orders that reveal the most certain positions first sidestep hard subproblems (Sudoku: from under 7% to about 90% solved).
- At 8 billion parameters LLaDA was competitive with autoregressive baselines trained on the same data, but diffusion models still trail in likelihood at equal training and lose KV caching unless generation proceeds in blocks; fill-in-the-middle gives left-to-right models infilling at no left-to-right cost, and which objective best supports planning is open.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Why do teacher-forced models fail on the path-star task, although they fit their training data?
- Errors in the first nodes compound along the path at generation time
- The revealed prefix makes every later node easy to predict by following an edge, so the training signal no longer teaches the one decision that needs lookahead, the first node
- The graphs are too large for the context window
- Transformers cannot represent the path-finding algorithm
Show the answer
B. The revealed prefix makes every later node easy to predict by following an edge, so the training signal no longer teaches the one decision that needs lookahead, the first node
With the true previous node in the input, the next node is a lookup in the edge list: a shortcut that fits all later targets. The first node is the only target that requires planning, and its supervision alone does not teach the model to plan, so it is chosen at random, with accuracy about .
With the linear schedule , a training sequence whose tokens were masked at rate contributes its masked-token cross-entropy to the masked diffusion bound with which weight?
Show the answer
D.
The weight is . A lightly masked sequence has few masked tokens, each predicted with much context; the weight gives every masking rate about weighted terms on average, and the resulting integral bounds .
For a denoiser that does not depend on time, what does the masked diffusion bound on equal?
- The expected negative log-likelihood of an autoregressive model that writes the tokens in a uniformly random order
- The negative log-likelihood of a left-to-right autoregressive model
- BERT's loss at 15% masking
- The entropy of the data distribution
Show the answer
A. The expected negative log-likelihood of an autoregressive model that writes the tokens in a uniformly random order
Grouping masks by size , the weight integrates against the binomial probabilities to , which is exactly the chance that a uniformly random order predicts a given one of the missing tokens next. With the true conditionals every order gives , so the bound is then tight.
A masked diffusion model generates 256 tokens in 16 steps instead of 256. What is given up?
- Nothing: every step samples from the exact model distribution
- Speed, since fewer steps are slower
- The 16 tokens revealed in each step are drawn independently given the visible ones, so dependencies among them are ignored
- The ability to condition on a prompt
Show the answer
C. The 16 tokens revealed in each step are drawn independently given the visible ones, so dependencies among them are ignored
Each newly revealed token is sampled from its own conditional given the tokens already visible, as if the other new tokens did not exist: the same product-of-marginals error as filling several BERT masks at once. One token per step is an exact any-order autoregressive sampler; fewer steps trade that exactness for parallelism.
Further reading
- G. Bachmann & V. Nagarajan, "The pitfalls of next-token prediction," ICML (2024).
- F. Gloeckle, B. Youbi Idrissi, B. Rozière, D. Lopez-Paz & G. Synnaeve, "Better & faster large language models via multi-token prediction," ICML (2024).
- J. Austin, D. D. Johnson, J. Ho, D. Tarlow & R. van den Berg, "Structured denoising diffusion models in discrete state-spaces," NeurIPS (2021).
- S. S. Sahoo, M. Arriola, Y. Schiff, A. Gokaslan, E. Marroquin, J. T. Chiu, A. Rush & V. Kuleshov, "Simple and effective masked diffusion language models," NeurIPS (2024).
- S. Nie, F. Zhu, Z. You, X. Zhang, J. Ou, J. Hu, J. Zhou, Y. Lin, J.-R. Wen & C. Li, "Large language diffusion models," NeurIPS (2025).