Diffusion Language Models › The Training Objective

Michael BrenndoerferNovember 17, 20264 min read
Language AI HandbookAll chapters
Part 19 of 67Alternative Sequence and Generative Architectures
Chapter 136Diffusion Language Models › The Training Objective
Reading section 5 of 13 · The Training Objective · 4 minSection 5 of 13 · 4 min

Section 5 of 13 · 4 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

The reveal probability also determines the weight on the denoising loss. To connect the two, start from the model’s likelihood over reverse paths.

The bound

A clean sequence x0x_0 can be reached by many reverse paths. The model probability pθ(x0)p_\theta(x_0) sums their probabilities. We can bound that probability by using the forward corruption chain as the distribution over latent paths. Write q(x1:T∣x0)q(x_{1:T}\mid x_0) for its path probability and pθ(x0:T)p_\theta(x_{0:T}) for the joint probability defined by the terminal prior and learned reverse transitions. Jensen's inequality gives

log⁡pθ(x0)≥Eq(x1:T∣x0)[log⁡pθ(x0:T)q(x1:T∣x0)]=ELBO⁡(x0).\log p_\theta(x_0) \ge \mathbb E_{q(x_{1:T}\mid x_0)} \left[\log\frac{p_\theta(x_{0:T})}{q(x_{1:T}\mid x_0)}\right] =\operatorname{ELBO}(x_0).

The likelihood can also include paths outside the forward chain's support. The inequality still holds because the ratio expectation sums only over paths in the forward support. Factorizing those paths in reverse order separates the negative bound into reconstruction, intermediate transitions and terminal prior mismatch:

−ELBO⁡(x0)=−Eqlog⁡pθ(x0∣x1)+∑k=2TEqKL⁡ ⁣(q(xk−1∣xk,x0) ∥ pθ(xk−1∣xk))+KL⁡ ⁣(q(xT∣x0) ∥ p(xT)).-\operatorname{ELBO}(x_0) = -\mathbb E_q\log p_\theta(x_0\mid x_1) +\sum_{k=2}^T \mathbb E_q\operatorname{KL}\!\left( q(x_{k-1}\mid x_k,x_0)\,\|\,p_\theta(x_{k-1}\mid x_k) \right) +\operatorname{KL}\!\left(q(x_T\mid x_0)\,\|\,p(x_T)\right).

Both distributions in the last term are point masses on the all-mask state when αˉT=0\bar\alpha_T=0 and we start the reverse model there. The term vanishes. If some visible tokens can survive forward corruption at TT, an all-mask prior gives those states zero probability and makes the terminal KL infinite. A different terminal prior requires carrying its KL term through the derivation.

A visible position contributes zero to the intermediate KL because both transitions copy it. For a masked position each distribution assigns the same mass 1−rk1-r_k to the mask. The true transition assigns the remaining mass rkr_k to the original token x0ix_0^i. The model assigns mass rkfθi(x0i∣xk)r_k f_\theta^i(x_0^i\mid x_k) to that token. The matching mask terms cancel, leaving

KL⁡i=rklog⁡rkrkfθi(x0i∣xk)=−rklog⁡fθi(x0i∣xk).\operatorname{KL}_i =r_k\log\frac{r_k}{r_k f_\theta^i(x_0^i\mid x_k)} =-r_k\log f_\theta^i(x_0^i\mid x_k).

At k=1k=1 the model reveals every remaining mask. The reconstruction term is the same sum of negative log probabilities with r1=1r_1=1. With independent corruption conditioned on x0x_0 and product reverse transitions, the result is the masked reconstruction loss

LNELBO(x0)=∑k=1Trk Eq(xk∣x0)[∑i: xki=m−log⁡fθi(x0i∣xk)].\mathcal L_{\mathrm{NELBO}}(x_0) = \sum_{k=1}^T r_k\, \mathbb E_{q(x_k\mid x_0)} \left[\sum_{i:\,x_k^i=m} -\log f_\theta^i(x_0^i\mid x_k)\right].

With the linear schedule, rk=1/kr_k=1/k. Training averages this bound over sequences drawn from the training distribution. Sahoo et al. (2024) use the carry-over and zero-mask-probability properties to simplify this objective for masked diffusion.

The continuous-time limit

Taking T→∞T \to \infty turns the sum into an integral with a 1/t1/t weight. Use Δ=1/T\Delta = 1/T, tk=k/Tt_k = k/T, and 1/tk=T/k1/t_k = T/k:

∑k=1T1kE[∑i∈Mkℓi]=∑k=1TΔ⋅1tkE[∑i∈Mkℓi]  ⟶  ∫011t E[∑i∈Mtℓi]dt,\sum_{k=1}^{T}\frac{1}{k}\mathbb{E}\left[\sum_{i\in M_k}\ell_i\right] = \sum_{k=1}^{T}\Delta\cdot\frac{1}{t_k}\mathbb{E}\left[\sum_{i\in M_k}\ell_i\right] \;\longrightarrow\; \int_0^1 \frac{1}{t}\,\mathbb{E}\left[\sum_{i\in M_t}\ell_i\right]dt,

where ℓi=−log⁡fθi(x0i∣xt)\ell_i = -\log f_\theta^i(x_0^i\mid x_t). In expectation form, with tt drawn uniformly:

  L∞=Et∼U[0,1]  Eq(xt∣x0)[1t∑i: xti=m(−log⁡fθi(x0i∣xt))]  \boxed{\;\mathcal{L}_\infty = \mathbb{E}_{t\sim U[0,1]}\;\mathbb{E}_{q(x_t\mid x_0)}\left[\frac{1}{t}\sum_{i:\,x_t^i = m}\left(-\log f_\theta^i(x_0^i\mid x_t)\right)\right]\;}

The evaluation points tk=k/Tt_k=k/T are right endpoints, and Δ/tk=1/k\Delta/t_k=1/k. A sufficient condition for convergence is that the mean loss given a position is masked extends continuously to the endpoints for every position. Drawing tt uniformly in (0,1)(0,1) and then sampling the mask gives an unbiased estimate of the integral when the expected weighted loss is integrable.

For t>0t>0, the expected sum of masked losses divided by tt equals ∑iE[ℓi∣xti=m]\sum_i\mathbb E[\ell_i\mid x_t^i=m]. Each mask indicator contributes a factor of tt in its expectation, which the denominator cancels. The conditional losses still depend on the visible context.

BERT selects prediction positions at random and applies its own corruption mixture to them. A masked-token training loss by itself gives no reverse transition rule or normalized sequence likelihood. Here the forward chain and the model's normalized reverse transitions supply both. In the population model, a content-independent mask schedule makes time redundant once a possible partially visible state is given. An implementation can still supply a time embedding as a modeling choice.

Estimating the bound

To estimate the continuous-time objective, sample tt uniformly from (0,1)(0,1) and draw the mask at that rate. Average the weighted masked loss over draws. At small tt, most samples have few masks, while a rare mask can receive a large weight. The estimator can have a finite mean and infinite variance. For one position whose masked loss is a constant c>0c>0, the contribution is c/tc/t with probability tt and zero otherwise. Its conditional mean is cc, while its conditional second moment is c2/tc^2/t. Integrating that second moment over uniform tt diverges. A stratum that includes the zero endpoint can still have this problem. Clipping tt to a positive threshold changes the sampling law and generally changes the estimand unless the procedure corrects for it.

For a finite TT, a direct Monte Carlo estimate samples kk uniformly from {1,…,T}\{1,\ldots,T\} and weights the masked cross-entropy by TrkT r_k. On short sequences one can instead enumerate all 2L2^L masks at each step. The code later in this chapter compares these two estimates at the same TT.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy