Diffusion Language Models Can Revise Text Instead of Writing Left to Right

The Stanford lecture explains masked diffusion, its parallel decoding opportunity and the training and latency tradeoffs.

AAAfshine AmidiVortrag · Stanford UniversitySAShervine AmidiVortrag · Stanford University
Kanal
Stanford Online
Veröffentlicht
1. Dez. 2026
Video
1:48:06
Lesezeit
10 Min.
Folien
3
Original
Englisch
Auf YouTube öffnen
Beim Scrollen schrumpft das Video in die rechte untere Ecke und läuft weiter. Untertitel folgen Ihrer Lesesprache.
LesespracheIn 2 Sprachen verfügbar
Diesen Artikel gibt es noch nicht auf Deutsch, daher wird das Original (Englisch) angezeigt.
ZUSAMMENFASSUNG

In 30 Sekunden

Diffusion language models generate text by repeatedly revealing or revising masked positions, rather than committing to one new token from left to right. Stanford lecturers Afshine and Shervine Amidi explain how a known masking process supplies training examples and a learned reverse process generates a response. Parallel generation can exploit context on both sides, but simultaneous predictions can conflict and repeated passes are not always faster for short answers. The lecture also notes a training-compute disadvantage and explores caching, distillation and speculative decoding as possible remedies.

  1. 1Left-to-right generation commits each token before seeing the restThe lecturers identify sequential latency, limited right-side context and difficulty revising earlier output as motivations for exploring diffusion.
  2. 2Continuous text diffusion must bridge vectors back to tokensNoisy embeddings need not correspond to any vocabulary item. Nearest-neighbor mapping is possible, but embedding-space loss and Gaussian noise do not necessarily match the discrete task.
  3. 3Masking gives text a discrete corruption processEach token can become a mask, and an already masked token stays masked in the forward process. The model learns a reverse process that reveals plausible tokens.
  4. 4A computable lower bound replaces an intractable trajectory sumThe known forward process can sample corruption paths. An evidence lower bound supplies a practical training surrogate for clean-sequence likelihood.
  5. 5Simultaneous predictions can contradict each otherTwo individually plausible token choices can form an inconsistent sentence when sampled together. Remasking can correct some mistakes but can also disturb correct choices.
  6. 6A long prompt and short answer can favor autoregressive decodingAn autoregressive model can cache prompt representations and generate a small response incrementally. Diffusion may repeatedly process a larger context, so fewer iterations do not guarantee lower latency.
  7. 7Parallel generation comes with a training-signal tradeoffThe lecture contrasts full next-token supervision under teacher forcing with masked-position supervision. It cites a roughly tenfold training-compute difference in one comparison and discusses hybrid drafting and verification.

Das Wichtigste

  1. Masked diffusion corrupts clean text with mask tokens, then trains a model to recover them at different noise levels.
  2. Parallel predictions may be inconsistent; remasking and reassessing tokens can permit revisions, with their own costs.
  3. Compare complete inference workloads, including prompt processing and caching, rather than counting generation steps alone.
  4. Continuous diffusion over token embeddings must map noisy vectors back into a discrete vocabulary.
  5. Training efficiency can favor autoregressive models; the lecture cites a roughly tenfold compute gap in one comparison, not a universal constant.
  6. Blockwise decoding, distillation and diffusion drafting with autoregressive verification are ways to explore different tradeoffs.
VOLLTEXT

Den bearbeiteten Text nach Kapiteln lesen

Nur das Transkript
01

Why reconsider left-to-right text generation

Sequential generation can be slow for long outputs and cannot naturally revise committed tokens. Diffusion offers a way to refine multiple positions over several passes.

Afshine Amidi begins with the familiar language-model recipe: a Transformer represents the input, and an autoregressive model generates its response one token at a time, conditioned on earlier tokens. The next-token objective gives the model a cross-entropy training loss.

At inference, a start token enters the model, the first generated token is appended, and the process repeats until a stop token appears. A long response needs many sequential iterations. That becomes especially noticeable when a reasoning model generates a long chain before its answer.

The left-to-right approach also limits each generated token to the context available so far. Some tasks, such as filling code between existing sections, naturally have context on both sides. Once a token is generated, ordinary autoregressive decoding cannot revise it in place; it can only continue with later tokens.

Diffusion offers another way to think about generation. In image generation, a model can start with noise and repeatedly transform the whole input into a cleaner image rather than predicting pixels one by one. Afshine compares the process to carving a sculpture from a rough block by removing material.

The text analogy is drafting a speech from coarse structure toward details, rather than necessarily writing from the first word to the last. The analogy provides intuition, not a claim that a model literally plans a speech as a person does. A diffusion model would iteratively turn a noisy representation into a clean sequence.

A student suggests an encoder-style Transformer. Afshine agrees that bidirectional attention is a natural fit for examining a partially corrupted sequence as a whole. BERT used an encoder and masked tokens too, but its original objective was representation learning rather than the iterative text generation discussed here.

The proposed generation process feeds a noisy sequence to a model, obtains a less noisy version, then repeats. The number of iterations is tied to the chosen diffusion steps rather than directly to the number of output tokens. That creates an opportunity for parallel generation, although the actual speed depends on the cost of each pass.

02

The difficulty of diffusing continuous text embeddings

Image-style corruption can operate on token vectors, but noisy vectors need not correspond to vocabulary items. The lecturer describes several ways researchers address that mismatch.

There is not one settled formulation. The lecture first considers continuous diffusion, as commonly used for images, then a discrete method that operates directly on text tokens. Image values can be represented continuously; language tokens come from a discrete vocabulary.

Afshine notes that diffusion, score matching and flow matching give different mathematical perspectives on generative modeling. The lecture focuses on the diffusion formulation: begin with clean training images, define a forward process that progressively adds noise, and learn a reverse process that removes it.

In the continuous example, the forward process adds Gaussian noise in stages. The reverse model learns to predict the noise added to a corrupted input, using a loss based on the difference between predicted and actual noise. Once trained, the reverse process can move from noise toward an image.

To apply that idea to text, one can represent each discrete token by a continuous embedding and combine the embeddings into a matrix for the sequence. A forward process can then add noise to that matrix, and a model can learn to reverse it.

Continuous diffusion over text embeddings
FOLIE 1 / 3Continuous diffusion over text embeddingsThe diagram represents a text sequence as continuous vectors and learns a reverse path from a noisy representation.

The difficulty is returning to actual tokens. A vector encountered during denoising need not match any vocabulary embedding. One possible final mapping selects the nearest token embedding, but much of a high-dimensional embedding space has no natural token interpretation.

Other difficulties follow. An L2 loss in embedding space does not directly optimize discrete token accuracy, and Gaussian noise may not corrupt text representations in a semantically meaningful way. Researchers have explored clamping representations back toward token embeddings and representing a whole sequence rather than each token independently.

03

Mask tokens as a discrete corruption process

A forward process progressively masks tokens and keeps masked tokens in an absorbing state. The model’s job is to learn to reverse that process.

The second formulation avoids that mapping issue by corrupting tokens directly. A discrete transition process specifies the probability that a token changes into another token at each step. The model is trained to reverse that process and recover clean text.

For the rest of the derivation, the lecture uses a special mask token as the corruption. At each step an ordinary token has a probability of becoming masked and a probability of staying unchanged. Once a token is masked in the forward process, it stays masked: the mask is an absorbing state.

The cumulative probability that an original token is still unmasked at step t can be written as the product of the per-step probabilities of remaining unmasked. The complementary probability gives the chance it has already been masked. This compact quantity lets the lecturers describe many corruption steps without listing every path.

An absorbing-state masking transition
FOLIE 2 / 3An absorbing-state masking transitionThe transition matrix illustrates ordinary tokens remaining unchanged or becoming masks, while an existing mask stays masked.

Consider a short sentence about a teddy bear reading. At each forward step some additional words become masks, while words already masked stay that way. After enough steps the entire sequence is masked. The forward process is deliberately specified; the goal is to learn a reverse process that recovers a plausible clean sequence.

04

Deriving a tractable training objective

The clean-data likelihood involves too many possible noising trajectories to sum directly. A lower bound and the known forward process yield a computable surrogate.

The training objective starts from maximum likelihood: choose model parameters that assign high probability to the observed clean training data. In an autoregressive model the chain rule decomposes that probability across tokens. A diffusion model instead needs a formulation involving successive noise levels.

The reverse process can be expressed over a trajectory of increasingly noisy versions of the sequence. A Markov assumption lets the model predict the preceding, less noisy state from the current state. But summing over every possible intermediate trajectory makes the clean-sequence likelihood intractable to compute directly.

The proposed strategy is to optimize a computable lower bound on the log likelihood. Because the forward corruption process is known, it can be used to sample trajectories. Jensen's inequality provides the evidence lower bound, or ELBO; maximizing that bound is a practical surrogate for the likelihood the model actually cares about.

The forward process provides a probability distribution over the noisy paths between a clean sequence and a fully corrupted one. Rather than enumerate those paths, the derivation multiplies and divides by the same known forward-process probability and expresses the sum as an expectation over samples from it.

Taking the logarithm and applying Jensen’s inequality moves the log inside that expectation to produce a lower bound. The lecturer stresses that the objective is to find a quantity that can actually be estimated; establishing the bound is only the first step, and the remaining terms still have to be shown computable.

The derivation rewrites the bound using KL divergences, which compare probability distributions. The terms compare what the known forward process implies about an earlier state with what the learned reverse model predicts. The course skips some algebra and focuses on whether those component distributions can be computed.

If a token is unmasked at the later forward step, it must have been unmasked at the earlier step: an absorbing mask cannot turn back into an ordinary token during corruption. If it is masked later, however, it could already have been masked or could have become masked during the most recent step.

The probability of those alternatives follows from the cumulative masking schedule. Afshine derives the probability that the earlier token was already masked as the earlier cumulative masking probability divided by the later one. The complementary probability corresponds to the original clean token being revealed at that earlier step.

The learned reverse model does not know the clean token at inference. It estimates a distribution over clean tokens from the noisy sequence, then uses that estimate in the reverse transition. Under the stated assumptions, the likelihood bound becomes a weighted objective involving the probability of predicting the clean token.

A linear noise schedule simplifies the expression: after rescaling time between zero and one, the masking probability can be set to the time value. Different papers use different conventions, so the meaning of the schedule and the model's prediction matters more than memorizing a particular notation.

05

Training and iterative generation

Training samples noise levels and predicts masked tokens. At inference the model starts with masked response positions and progressively reveals them.

In practice, training samples a noise level, masks each token with the corresponding probability and asks the model to predict the original tokens. The resulting predictions enter the derived loss; backpropagation updates the model. Repeating this across examples and noise levels teaches it to handle different degrees of corruption.

For inference, start with masked response positions, predict candidate clean tokens and reveal only some of them according to the reverse process. Feed the partially revealed sequence back into the model and repeat until the final step. A supplied user prompt stays available as context rather than being masked as part of the response.

06

What happens when parallel choices disagree

The diffusion objective differs from BERT’s representation-learning pretext. Remasking can repair inconsistent parallel predictions, though it can also alter correct tokens.

Shervine Amidi returns to the comparison with BERT. BERT masked a fixed fraction of tokens as a pretext for learning representations; generation was not its primary goal. The diffusion setup samples different noise levels and uses multiple reverse steps to produce the response.

Parallel predictions can disagree with one another. If two masked positions are sampled at the same time, each prediction may be plausible given the earlier context while their combination is ungrammatical. The example contrasts a singular noun with a plural verb: neither position knows the other's simultaneous choice.

One possible correction is remasking: hide previously committed tokens and predict them again in the context of other revealed words. Random remasking can also disturb a correct token, however, and a token's original confidence may not expose an inconsistency that arose when another position was filled at the same time.

A more informed approach can reassess a token against the current context, rather than relying only on the probability assigned when it was first generated. The lecturer notes that some work trains a classifier for this purpose. Such methods add choices and computational cost to the decoding process.

07

When parallel generation is actually faster

Caching makes autoregressive decoding competitive for long prompts and short responses. Prompt caching, blocks and distillation offer potential diffusion optimizations.

Parallel tokens do not automatically make diffusion faster in every workload. Consider a long prompt and a short answer: an autoregressive system can prefill the prompt, cache key and value representations, and then generate each short-answer token with relatively inexpensive incremental steps.

A bidirectional diffusion model may repeatedly process a prompt together with the evolving response. Even a fixed number of denoising passes can cost more when the answer is short. Architectural details and attention patterns affect the comparison, so number of iterations alone is not a complete latency measurement.

One proposed optimization caches prompt representations and refreshes them less often. Although bidirectional attention means prompt representations can change as response tokens are revealed, the cited work finds limited changes in its experiments. The lecturer notes an anecdotal case where not refreshing even improved accuracy, without treating that as a general law.

Another approach divides generation into blocks. Attention can remain bidirectional within the active block, while completed blocks are used as fixed past context and cached. This introduces a more autoregressive structure between blocks to recover some caching benefits.

To reduce the number of denoising passes, a teacher model can distill multiple steps into a student that takes fewer. In the illustration, a student learns to approximate two teacher steps in one, including probability distributions informed by intermediate token choices. The process can be repeated while monitoring quality.

08

Training compute and hybrid decoding

The lecture compares training signals and reports a compute disadvantage in one setting. Diffusion drafting with autoregressive verification offers one possible hybrid.

The lecture then turns to training efficiency. Autoregressive teacher forcing provides a ground-truth next-token target at each position during a parallel training pass. In masked diffusion, a pass may supervise only a subset of positions, and those positions can depend on representations that have not yet been resolved.

Autoregressive teacher forcing supplies token targets
FOLIE 3 / 3Autoregressive teacher forcing supplies token targetsThe slide shows parallel training inputs paired with their next-token targets.

The lecturer says that reaching a comparable loss can therefore require substantially more training compute in the discussed comparison, citing an order of magnitude of roughly ten times the floating-point operations. That figure is presented as a particular estimate, not a universal constant for every architecture or experiment.

A hybrid can combine diffusion's fast parallel proposals with autoregressive verification through speculative decoding. A diffusion model drafts tokens, and an autoregressive model checks them, potentially accepting several at once. The lecture says practical speedups have been observed, while the details of the system matter.

The tradeoff also includes throughput across batches, not just speed perceived by one user. Bidirectional generation is appealing for fill-in-the-middle coding tasks, where context exists on both sides and fast feedback matters. The remaining challenge is closing the training-compute gap while preserving generation quality and useful inference speed.

Mehr aus diesem Kanal

7 Folien1:17:10EN
Stanford Online· 1. Dez. 2026AI Agent Safety Starts With What the Agent Can Actually DoDiyi Yang · Stanford UniversityDiyi Yang explains how agents fail, how untrusted content redirects them, and why safety controls must be built into the system.AI SafetyPrompt injectionAgent Engineering+2
3 Folien1:22:20EN
Stanford Online· 30. Nov. 2026How SWE-bench Turned Real GitHub Issues Into an AI TestJohn Yang, Carlos Jimenez, Alexander Wettig · Stanford UniversityIts creators explain why the benchmark was easy to conceive, hard to run, and dependent on human judgment to keep scores meaningful.Coding-AgentenEvalsBenchmarks+2
1:11:12EN
Stanford Online· 30. Nov. 2026Why Neural Network Training Can Stay at the Edge of StabilitySuhas Kotha · Stanford UniversitySuhas Kotha explains self-stabilization, adaptive optimizers and why flatter solutions do not always generalize better.Deep LearningModelle & TrainingMathematics+2
1:14:45EN
Stanford Online· 29. Nov. 2026Why Averaging Neural Networks Works Only in Some PlacesSuhas Kotha · Stanford UniversitySuhas Kotha uses model averaging, river valleys and saddle points to explain what training can—and cannot—tell us about a loss landscape.Deep LearningModelle & TrainingMathematics+2
20:46EN
Stanford Online· 28. Nov. 2026Why momentum matters more at large batch sizesTatsunori Hashimoto · Stanford UniversityA Stanford optimization quiz shows why batch size changes momentum’s value and how learning rate and weight decay interact.Modelle & TrainingNeural NetworksAI research
7 Folien1:20:02EN
Stanford Online· 28. Nov. 2026John Yang: How to tell whether an AI judge is reliableJohn Yang · Stanford UniversityModel judges can grade open-ended work, but their own biases and consistency need testing against people.EvalsAI agentsAI research