18 min read

Discrete diffusion


  • V\mathcal{V} vocabulary set; ∣V∣|\mathcal{V}| is the vocabulary size
  • S=VS\mathcal{S} = \mathcal{V}^S space of all possible sequences of length SS over the vocabulary
  • x=x1…xS\mathbf{x} = x^1 \dots x^S sequence of SS tokens, where each token xix^i takes values in V\mathcal{V}
  • ev\mathbf{e}_v one-hot vector in R∣V∣\mathbb{R}^{|\mathcal{V}|} for token v∈Vv \in \mathcal{V}
  • mm mask token
  • x≠i\mathbf{x}^{\neq i} sub-sequence of x\mathbf{x} at all positions except ii
  • Δk\Delta_k for k∈Nk \in \mathbb{N}, Δk={π∈R+k:∑ℓ=1kπℓ=1}\Delta_k=\{\pi\in\mathbb{R}_+^k:\sum_{\ell=1}^{k}\pi_\ell=1\} is the probability simplex
  • Cat\text{Cat} categorical distribution: x∼Cat(p)x \sim \text{Cat}(\mathbf{p}) means P(x=v)=pv\mathbb{P}(x = v) = \mathbf{p}_v, for a probability vector p∈Δ∣V∣\mathbf{p} \in \Delta_{|\mathcal{V}|}
  • Convention: t=0t=0: clean data; t=1t=1: noisy data.
  • p0p_0 clean data (target) distribution; the forward process corrupts it toward the mask distribution δm…m\delta_{m\ldots m} at the final time
  • ptp_t marginal distribution at time tt; the probability path between the clean data distribution p0p_0 and the mask distribution
  • βt\beta_t noise schedule: probability that a token is corrupted (masked) at step tt
  • αt=∏i=1t(1−βi)\alpha_t = \prod_{i=1}^t (1 - \beta_i) cumulative schedule, equal to the probability that a token is still clean (has survived) at step tt
  • Dθ,t(xt)∈Δ∣V∣D_{\theta,t}(\mathbf{x}_t) \in \Delta_{|\mathcal{V}|} learned denoiser: predicts the distribution over the clean token x0\mathbf{x}_0 given the noisy sequence xt\mathbf{x}_t
  • Q˙t\dot{Q}_t forward rate matrix (generator of the continuous-time forward process)
  • R˙θ,t\dot{R}_{\theta,t} learned reverse rate matrix (generator of the continuous-time reverse process)

In recent years, diffusion models have emerged as the state-of-the-art frameworks for continuous data generation, enabling the synthesis of high-quality data, such as images, audio and video [7, 8]. Their strong generation performance, training stability and flexibility motivated their extension to discrete data, including texts, graphs, or molecule sequences [2, 5, 6]. This blog post is a pedagogical introduction to the adaptation of diffusion models for discrete data.

As continuous-space diffusion models have been developed into two major branches, namely the variational [10, 11] and the score-based ones [9, 12], we present discrete diffusion through these two formalisms. We first introduce variational discrete diffusion; the reader already familiar with this technique can jump directly to the score-based perspective. Finally, in the last section, we first show how these two different viewpoints are in fact equivalent from both the training and sampling perspectives, then show the equivalence of discrete diffusion and discrete flow matching.

In this blog post, we deal with discrete data: the space on which the probability distributions are defined is S:=VS\mathcal{S} := \mathcal{V}^S, namely the space of sequences of length S∈NS \in \mathbb{N} over a given vocabulary V\mathcal{V}. A sequence x\mathbf{x} in S\mathcal{S} is denoted as x=x1…xS\mathbf{x} = x^1 \dots x^S, the xix^i‘s being called tokens. In the vocabulary, we add a special token: the mask token, denoted as mm. The reader interested to have a more complete introduction on discrete data modelling is referred to the blog post on discrete flow matching.

Variational discrete diffusion

Continuous-space diffusion models learn to generate data, e.g. images, by reversing a forward process that gradually corrupts data into pure noise through the addition of Gaussian noise. In discrete diffusion, an analogous approach generates sequences by reversing a masking process that progressively replaces tokens with a mask token.

DDPM Masked Diffusion denoising process

Figure 1: Analogy between continuous- and discrete-space diffusion. Left: the forward process corrupts a clean image by iteratively adding Gaussian noise, so the image gradually becomes pure noise. Given the current noisy image, the reverse model predicts the clean image that could have generated it, and uses this prediction to take one denoising step.
Right: the forward process masks tokens in a sentence, until the sequence is fully masked. Given a current partially masked sentence, the reverse model predicts a probability distribution over the clean sentences that could have generated it, and uses this prediction to unmask some tokens.

Forward process

We first consider the forward process: it starts from a clean sequence x0\mathbf{x}_0, and progressively replaces each token by the mask token, transforming the sequence into xT=mm...m\mathbf{x}_T = mm...m. Because each token is masked independently, the forward process factorizes over tokens, and we restrict to the case of a single token transitioning from x0ix_0^i to mm in the following.

In continuous Denoising Diffusion Probabilistic Models (DDPM), we start by defining a noising process over TT steps, where each step slightly corrupts the signal by adding Gaussian noise:

xt=1−βt xt−1+βt ε,ε∼N(0,I)\begin{equation} \htmlData{equation-label=eq:ddpm-step}{\htmlId{eq:ddpm-step}{}} x_t = \sqrt{1 - \beta_t}\, x_{t-1} + \sqrt{\beta_t}\,\varepsilon, \qquad \varepsilon \sim \mathcal{N}(0, I) \end{equation}

where βt∈[0,1]\beta_t \in [0,1] controls the amount of noise injected at step t∈{1,…,T}t \in \{1,\ldots,T\}. In discrete space diffusion, at each step, a token either survives unchanged with probability 1−βt1 - \beta_t, or is irreversibly replaced by the mask token mm with probability βt\beta_t:

xt={xt−1,with probability 1−βtm,with probability βt\begin{equation} \htmlData{equation-label=eq:mdm-step}{\htmlId{eq:mdm-step}{}} x_t = \begin{cases} x_{t-1}, & \text{with probability } 1 - \beta_t \\ m, & \text{with probability } \beta_t \end{cases} \end{equation}

From Eq. (?), we can infer the law of xtx_t given its starting value x0x_0, without simulating the full chain:

q(xt=x0∣x0)=∏i=1t(1−βi)=:αtq(x_t = x_0 | x_0) = \prod_{i=1}^{t} (1-\beta_i) =: \alpha_t

and we can interpret αt\alpha_t as the probability that a token has survived up to step tt, i.e. xtx_t is still x0x_0 and was not replaced by mm.

Proof
q(xt=x0∣x0)=q(xt=x0∣xt−1=x0,x0)⏟=q(xt=x0∣xt−1=x0) by the Markov property q(xt−1=x0∣x0)=(1−βt) q(xt−1=x0∣x0)=∏i=1t(1−βi)by recursion\begin{align} q(x_t = x_0 | x_0) &= \underbrace{q(x_t = x_0 | x_{t-1} = x_0, x_0)}_{ \substack{=\,q(x_t = x_0 | x_{t-1} = x_0)\text{ by the Markov property}}}\, q(x_{t-1} = x_0 | x_0) \\ &= (1-\beta_t)\, q(x_{t-1} = x_0 | x_0) \\ &= \prod_{i=1}^{t} (1-\beta_i) \qquad \text{by recursion} \end{align}

As expected, the schedule αt\alpha_t decreases in tt: as the step index tt increases, the probability of a token remaining unmasked decreases. You can observe this trend in Figure 1 when selecting “Show N trajectories”. It turns out that we can then compute the transition probabilities between any two steps s<ts < t as follows:

xt∣xs={xs,with probability αtαsm,with probability 1−αtαs\begin{equation} \htmlData{equation-label=eq:forward-transition}{\htmlId{eq:forward-transition}{}} x_t \mid x_s = \begin{cases} x_s, & \text{with probability } \frac{\alpha_t}{\alpha_s} \\ m, & \text{with probability } 1 - \frac{\alpha_t}{\alpha_s} \end{cases} \end{equation}
Proof

By the Markov property q(xt∣xs,x0)=q(xt∣xs)q(x_t | x_s, x_0) = q(x_t | x_s), the marginal q(xt∣x0)q(x_t | x_0) factorizes through any intermediate step ss:

q(xt∣x0)=∑xsq(xt∣xs) q(xs∣x0)\begin{equation} \htmlData{equation-label=eq:marginal-recursion}{\htmlId{eq:marginal-recursion}{}} q(x_t | x_0) = \sum_{x_s} q(x_t | x_s)\, q(x_s | x_0) \end{equation}

Using q(xs∣x0)=αs I(xs=x0)+(1−αs) I(xs=m)q(x_s | x_0) = \alpha_s\, \mathbb{I}(x_s = x_0) + (1 - \alpha_s)\, \mathbb{I}(x_s = m), the sum simplifies to:

q(xt∣x0)=αs q(xt∣xs=x0)+(1−αs) q(xt∣xs=m)\begin{equation} \htmlData{equation-label=eq:marginal-split}{\htmlId{eq:marginal-split}{}} q(x_t | x_0) = \alpha_s\, q(x_t | x_s = x_0) + (1 - \alpha_s)\, q(x_t | x_s = m) \end{equation}

Since masking is irreversible, q(xt∣xs=m)=I(xt=m)q(x_t | x_s = m) = \mathbb{I}(x_t = m). Writing q(xt∣xs=x0)=a I(xt=x0)+(1−a) I(xt=m)q(x_t | x_s = x_0) = a\, \mathbb{I}(x_t = x_0) + (1 - a)\, \mathbb{I}(x_t = m), for xt=x0x_t = x_0, Eq. (?) becomes: αt=αs⋅a\alpha_t = \alpha_s \cdot a, so a=αtαsa = \dfrac{\alpha_t}{\alpha_s}

Therefore, for an unmasked token xs≠mx_s \neq m (since the probabilities sum to 1):

q(xt∣xs)=αtαs I(xt=xs)+(1−αtαs)I(xt=m)\begin{equation} \htmlData{equation-label=eq:masked-transition}{\htmlId{eq:masked-transition}{}} q(x_t | x_s) = \frac{\alpha_t}{\alpha_s}\, \mathbb{I}(x_t = x_s) + \left(1 - \frac{\alpha_t}{\alpha_s}\right) \mathbb{I}(x_t = m) \end{equation}

Masked Diffusion: Forward Process

αt =
Startt = 0.00
T
seed
x₀mt=0t=11 − βₜ0.90
slowfast

Figure 2: Forward process with T steps as in Eq. (?). At step tt, an unmasked token gets masked with probability βt\beta_t; after masking, this probability is 1. The trajectories are stochastic: changing the seed changes the step at which x0x_0 transitions to mm.
The “Show NN trajectories” button switches to an aggregate view that samples NN independent trajectories with the same transition rule; at step tt, the plotted proportion of still-unmasked trajectories approaches the schedule αt\alpha_t as TT and NN grow.

In summary, the forward process masks each token independently and irreversibly: a token remains unmasked until time tt with probability αt\alpha_t, and once it reaches the mask state mm, it stays masked. The user-defined schedule αt\alpha_t therefore controls how quickly clean data is transformed into pure mask noise. We now turn to reversing this process, in order to generate data from noise.

Reverse process

Generating data requires a reverse process that progressively unmasks tokens to produce samples from the discrete data distribution, i.e. generating samples xsx_s from xtx_t for s<ts < t until s=0s=0. However, the transition kernel q(xs∣xt)q(x_s|x_t) is intractable. To overcome this difficulty, we express q(xs∣xt)q(x_s|x_t) by marginalizing the conditional reverse transition q(xs∣xt,x0)q(x_s | x_t, x_0) over all possible x0x_0.

Lemma 1 (Conditional reverse transitions q(xs∣xt,x0)q(x_s | x_t,x_0)).

For xt=mx_t = m and s<ts<t, we have:

q(xs∣xt,x0)=[αs−αt1−αtI(xs=x0)+1−αs1−αtI(xs=m)]\begin{equation} \htmlData{equation-label=eq:bridge-mask}{\htmlId{eq:bridge-mask}{}} q(x_s | x_t, x_0) = \left[ \frac{\alpha_s - \alpha_t}{1 - \alpha_t} \mathbb{I}(x_s = x_0) + \frac{1 - \alpha_s}{1 - \alpha_t} \mathbb{I}(x_s = m) \right] \end{equation}

Equivalently:

xs∣xt=m,x0={x0,with probability αs−αt1−αtm,with probability 1−αs1−αt\begin{equation} \htmlData{equation-label=eq:bridge-mask-sampling}{\htmlId{eq:bridge-mask-sampling}{}} x_s | x_t=m, x_0 = \begin{cases} x_0, & \text{with probability } \dfrac{\alpha_s - \alpha_t}{1 - \alpha_t} \\ m, & \text{with probability } \dfrac{1 - \alpha_s}{1 - \alpha_t} \end{cases} \end{equation}
Proof

We use Bayes’ theorem to compute the probability that a token which is masked at step tt reverts to the clean token x0x_0 by step s<ts < t:

P(xs=x0∣x0,xt=m)=P(xt=m∣xs=x0) P(xs=x0∣x0)P(xt=m∣x0)=(1−αtαs)αs1−αt=αs−αt1−αt\begin{align} \mathbb{P}(x_s = x_0 | x_0, x_t = m) &= \frac{\mathbb{P}(x_t = m | x_s = x_0)\, \mathbb{P}(x_s = x_0 | x_0)}{\mathbb{P}(x_t = m | x_0)} \htmlData{equation-label=eq:bridge-bayes-1}{\htmlId{eq:bridge-bayes-1}{}} \\ &= \frac{\left(1 - \tfrac{\alpha_t}{\alpha_s}\right) \alpha_s}{1 - \alpha_t} \htmlData{equation-label=eq:bridge-bayes-2}{\htmlId{eq:bridge-bayes-2}{}} \\ &= \frac{\alpha_s - \alpha_t}{1 - \alpha_t} \htmlData{equation-label=eq:bridge-bayes-3}{\htmlId{eq:bridge-bayes-3}{}} \end{align}

We conclude using that xsx_s is either at state x0x_0 or at state mm with probabilities that sum to 1.

The reverse process conditioned on x0x_0, namely sampling reccursively from q(xs∣xt,x0)q(x_s | x_t, x_0) as described in Eq. (?), can also be simulated in Figure 2 by clicking the reverse button.

Lemma 2 (Reverse transitions q(xs∣xt)q(x_s | x_t)).

For Masked Diffusion and steps s<ts<t:

q(xs=v∣xt=m)=αs−αt1−αt P(X0=v∣Xt=xt)(v∈V∖{m}),q(xs=m∣xt=m)=1−αs1−αt.\begin{align} q(x_s=v| x_t=m) &= \frac{\alpha_s-\alpha_t}{1-\alpha_t}\,\mathbb{P}(X_0=v | X_t=x_t)\quad (v\in\mathcal{V}\setminus\{m\}), \htmlData{equation-label=eq:bridge-denoiser-1}{\htmlId{eq:bridge-denoiser-1}{}} \\ q(x_s=m| x_t=m) &= \frac{1-\alpha_s}{1-\alpha_t}. \htmlData{equation-label=eq:bridge-denoiser-2}{\htmlId{eq:bridge-denoiser-2}{}} \end{align}
Proof

By the law of total probability:

q(xs=y∣xt=m)=∑v∈Vq(xs=y∣xt=m,x0=v) P(X0=v∣Xt=xt).\begin{align} q(x_s=y | x_t=m) &= \sum_{v\in\mathcal{V}} q(x_s=y | x_t=m, x_0=v)\,\mathbb{P}(X_0=v | X_t=x_t). \htmlData{equation-label=eq:denoiser-bridge-proof-1}{\htmlId{eq:denoiser-bridge-proof-1}{}} \end{align}

If y∈Vy\in\mathcal{V}, Eq. (?) gives:

q(xs=y∣xt=m)=∑v∈Vαs−αt1−αtI(y=v) P(X0=v∣Xt=xt)=αs−αt1−αt P(X0=y∣Xt=xt).\begin{align} q(x_s=y | x_t=m) &= \sum_{v\in\mathcal{V}} \frac{\alpha_s-\alpha_t}{1-\alpha_t}\mathbb{I}(y=v)\,\mathbb{P}(X_0=v | X_t=x_t) \htmlData{equation-label=eq:denoiser-bridge-proof-token-1}{\htmlId{eq:denoiser-bridge-proof-token-1}{}} \\ &= \frac{\alpha_s-\alpha_t}{1-\alpha_t}\,\mathbb{P}(X_0=y | X_t=x_t). \htmlData{equation-label=eq:denoiser-bridge-proof-token-2}{\htmlId{eq:denoiser-bridge-proof-token-2}{}} \end{align}

For the mask token, Eq. (?) gives a term independent of vv, hence:

q(xs=m∣xt=m)=∑v∈V1−αs1−αt P(X0=v∣Xt=xt)=1−αs1−αt,\begin{align} q(x_s=m | x_t=m) &= \sum_{v\in\mathcal{V}} \frac{1-\alpha_s}{1-\alpha_t}\,\mathbb{P}(X_0=v | X_t=x_t) \htmlData{equation-label=eq:denoiser-bridge-proof-mask-1}{\htmlId{eq:denoiser-bridge-proof-mask-1}{}} \\ &= \frac{1-\alpha_s}{1-\alpha_t}, \htmlData{equation-label=eq:denoiser-bridge-proof-mask-2}{\htmlId{eq:denoiser-bridge-proof-mask-2}{}} \end{align}

because P(X0=⋅∣Xt=xt)\mathbb{P}(X_0=\cdot | X_t=x_t) is a probability distribution over V\mathcal{V}.

This directly gives the sampling process from a fully masked sequence toward a clean sequence: for s<ts<t, we sample each still masked position ii as

xsi∼Cat(αs−αt1−αtP(X0i=⋅∣Xt=xt)+1−αs1−αtem).\begin{equation} \htmlData{equation-label=eq:masked-diffusion-denoiser-sampling}{\htmlId{eq:masked-diffusion-denoiser-sampling}{}} x_s^i \sim \mathrm{Cat}\left( \frac{\alpha_s-\alpha_t}{1-\alpha_t}\mathbb{P}(X_0^i=\cdot | \mathbf{X}_t=\mathbf{x}_t) + \frac{1-\alpha_s}{1-\alpha_t}\mathbf{e}_m \right). \end{equation}

When a token is already unmasked, the reverse process simply keeps it fixed.

Training

We learn the reverse process by training a neural network whose generated trajectories align with those of the forward process. In Variational Diffusion, this is done by minimizing the KL divergence between the distribution induced by the (known) forward process q(x0:T)q(x_{0:T}) and the one induced by the learned backward process pθ(x0:T)p_\theta(x_{0:T}):

min⁡θ  KL ⁣(q(x0:T), pθ(x0:T))\begin{equation} \htmlData{equation-label=eq:path-kl}{\htmlId{eq:path-kl}{}} \min_\theta\; \mathrm{KL}\!\Big(q(x_{0:T}),\, p_\theta(x_{0:T})\Big) \end{equation}

We can show that:

min⁡θ  KL ⁣(q(x0:T), pθ(x0:T))    ⟺    max⁡θ  Eq(x0) ⁣[ELBOθ(x0)]\begin{equation} \htmlData{equation-label=eq:path-kl-2}{\htmlId{eq:path-kl-2}{}} \min_\theta\; \mathrm{KL}\!\Big(q(x_{0:T}),\, p_\theta(x_{0:T})\Big) \;\iff\; \max_\theta\; \mathbb{E}_{q(x_0)}\!\left[\text{ELBO}_{\theta}(x_0)\right] \end{equation}

where the ELBO (evidence lower bound) is defined as:

ELBOθ(x0)=Ex1:T∼q(⋅∣x0)[log⁡pθ(x0:T)−log⁡q(x1:T∣x0)]\begin{equation} \htmlData{equation-label=eq:elbo}{\htmlId{eq:elbo}{}} \text{ELBO}_{\theta}(x_0) = \mathbb{E}_{x_{1:T} \sim q(\cdot | x_0)} \left[ \log p_\theta(x_{0:T}) - \log q(x_{1:T}|x_0) \right] \end{equation}
Equivalence of KL minimization and ELBO maximization

Expand the KL by factoring q(x0:T)=q(x0) q(x1:T∣x0)q(x_{0:T}) = q(x_0)\, q(x_{1:T}|x_0):

KL ⁣(q(x0:T), pθ(x0:T))=Eq(x0:T) ⁣[log⁡q(x0:T)pθ(x0:T)]=Eq(x0) ⁣[Eq(x1:T∣x0) ⁣[log⁡q(x0) q(x1:T∣x0)pθ(x0:T)]]=Eq(x0) ⁣[log⁡q(x0)]+Eq(x0) ⁣[Eq(x1:T∣x0) ⁣[log⁡q(x1:T∣x0)−log⁡pθ(x0:T)]]=−H(q)−Eq(x0) ⁣[ELBOθ(x0)]\begin{align} \mathrm{KL}\!\Big(q(x_{0:T}),\, p_\theta(x_{0:T})\Big) &= \mathbb{E}_{q(x_{0:T})}\!\left[\log \frac{q(x_{0:T})}{p_\theta(x_{0:T})}\right] \htmlData{equation-label=eq:kl-elbo-proof-2}{\htmlId{eq:kl-elbo-proof-2}{}} \\ &\hspace{-8em}{}= \mathbb{E}_{q(x_0)}\!\left[\mathbb{E}_{q(x_{1:T}|x_0)}\!\left[\log \frac{q(x_0)\,q(x_{1:T}|x_0)}{p_\theta(x_{0:T})}\right]\right] \htmlData{equation-label=eq:kl-elbo-proof-3}{\htmlId{eq:kl-elbo-proof-3}{}} \\ &\hspace{-8em}{}= \mathbb{E}_{q(x_0)}\!\left[\log q(x_0)\right] + \mathbb{E}_{q(x_0)}\!\left[\mathbb{E}_{q(x_{1:T}|x_0)}\!\left[\log q(x_{1:T}|x_0) - \log p_\theta(x_{0:T})\right]\right] \htmlData{equation-label=eq:kl-elbo-proof-4}{\htmlId{eq:kl-elbo-proof-4}{}} \\ &\hspace{-8em}{}= -H(q) - \mathbb{E}_{q(x_0)}\!\left[\text{ELBO}_{\theta}(x_0)\right] \htmlData{equation-label=eq:kl-elbo-proof-6}{\htmlId{eq:kl-elbo-proof-6}{}} \end{align}

Since H(q)=−Eq(x0)[log⁡q(x0)]H(q) = -\mathbb{E}_{q(x_0)}[\log q(x_0)] does not depend on θ\theta, minimizing the KL is exactly equivalent to maximizing Eq(x0)[ELBOθ(x0)]\mathbb{E}_{q(x_0)}[\text{ELBO}_{\theta}(x_0)].

As written, Eq. (?) couples all TT steps along a whole trajectory x1:Tx_{1:T}. The following theorem shows that we can simplify this global objective into a sum of local objectives, one for each step.

Theorem 3 (Discrete diffusion ELBO).

The ELBO for a discrete diffusion process is given by [1, 2, 10]:

ELBOθ(x0)=−KL(q(xT∣x0),pT)−∑t=1TExt∼q(⋅∣x0)[KL ⁣(q ⁣(xt−1∣xt,x0), pθ ⁣(xt−1∣xt))]\begin{align} \text{ELBO}_{\theta}(x_0) ={}& - \mathrm{KL}(q(x_T | x_0) , p_T) \htmlData{equation-label=eq:discrete-elbo-1}{\htmlId{eq:discrete-elbo-1}{}} \\ & - \sum_{t=1}^{T} \mathbb{E}_{x_t \sim q( \cdot | x_0)} \left[ \mathrm{KL}\!\left(q\!\left(x_{t-1} | x_t, x_0\right),\, p_\theta\!\left(x_{t-1} | x_t\right)\right) \right] \htmlData{equation-label=eq:discrete-elbo-2}{\htmlId{eq:discrete-elbo-2}{}} \notag \end{align}

where pTp_T is a the prior distribution, here pT=δm…mp_T = \delta_{m\ldots m}.

Proof

The forward process follows a Markovian structure:

q(x1:T∣x0)=∏t=1Tq(xt∣xt−1,xt−2,…,x0)=∏t=1Tq(xt∣xt−1,x0)\begin{align} q(x_{1:T}|x_0) &= \prod_{t=1}^{T} q(x_t | x_{t-1}, x_{t-2}, \dots, x_0) \htmlData{equation-label=eq:forward-markov-1}{\htmlId{eq:forward-markov-1}{}} \\ &= \prod_{t=1}^{T} q(x_t | x_{t-1}, x_0) \htmlData{equation-label=eq:forward-markov-2}{\htmlId{eq:forward-markov-2}{}} \end{align}

where the last equality holds because the forward process is memoryless given the previous states. Similarly, the reverse model decomposes as:

pθ(x0:T)=pθ(xT)∏t=1Tpθ(xt−1∣xt).\begin{equation} \htmlData{equation-label=eq:reverse-factorization}{\htmlId{eq:reverse-factorization}{}} p_\theta(x_{0:T}) = p_\theta(x_T) \prod_{t=1}^{T} p_\theta(x_{t-1} | x_t). \end{equation}

Substituting into the ELBO:

ELBOθ(x0)=Ex1:T∼q(⋅∣x0)[log⁡pθ(xT)]+∑t=1TEx1:T∼q(⋅∣x0)[log⁡pθ(xt−1∣xt)−log⁡q(xt∣xt−1,x0)]\begin{align} \text{ELBO}_{\theta}(x_0) &= \mathbb{E}_{\substack{x_{1:T} \sim q( \cdot | x_0)}} \left[ \log p_\theta(x_T) \right] \htmlData{equation-label=eq:elbo-expand-1}{\htmlId{eq:elbo-expand-1}{}} \\ &\quad + \sum_{t=1}^{T} \mathbb{E}_{\substack{x_{1:T} \sim q( \cdot | x_0)}} \left[ \log p_\theta(x_{t-1} | x_t) - \log q(x_t | x_{t-1}, x_0) \right] \htmlData{equation-label=eq:elbo-expand-2}{\htmlId{eq:elbo-expand-2}{}} \notag \end{align}

Using Bayes’ theorem, we can rewrite the forward process conditional:

log⁡q(xt∣xt−1,x0)=log⁡q(xt−1∣xt,x0)+log⁡q(xt∣x0)−log⁡q(xt−1∣x0)\begin{equation} \htmlData{equation-label=eq:elbo-sum}{\htmlId{eq:elbo-sum}{}} \begin{aligned} \log q(x_t | x_{t-1}, x_0) &= \log q(x_{t-1} | x_t, x_0) + \log q(x_t | x_0) \\ &\quad - \log q(x_{t-1} | x_0) \end{aligned} \end{equation}

Substituting into the ELBO and observing that consecutive terms telescope:

ELBOθ(x0)=Ex1:T∼q(⋅∣x0)[log⁡q(xT∣x0)−log⁡q(x0∣x0)]+Ex1:T∼q(⋅∣x0)[log⁡pθ(xT)]+∑t=1TEx1:T∼q(⋅∣x0)[log⁡pθ(xt−1∣xt)−log⁡q(xt−1∣xt,x0)]\begin{equation} \htmlData{equation-label=eq:elbo-mask}{\htmlId{eq:elbo-mask}{}} \begin{aligned} \text{ELBO}_{\theta}(x_0) &= \mathbb{E}_{\substack{x_{1:T} \sim q( \cdot | x_0)}} \left[ \log q(x_T | x_0) - \log q(x_0 | x_0) \right] \\ &\quad + \mathbb{E}_{\substack{x_{1:T} \sim q( \cdot | x_0)}} \left[ \log p_\theta(x_T) \right] \\ &\quad + \sum_{t=1}^{T} \mathbb{E}_{\substack{x_{1:T} \sim q( \cdot | x_0)}} \left[ \log p_\theta(x_{t-1} | x_t) - \log q(x_{t-1} | x_t, x_0) \right] \end{aligned} \end{equation}

Since log⁡q(x0∣x0)=log⁡(1)=0\log q(x_0 | x_0) = \log(1) = 0:

ELBOθ(x0)=−Ex1:T∼q(⋅∣x0)[log⁡q(xT∣x0)−log⁡pθ(xT)]−∑t=1TEx1:T∼q(⋅∣x0)[log⁡q(xt−1∣xt,x0)−log⁡pθ(xt−1∣xt)]\begin{align} \text{ELBO}_{\theta}(x_0) &= - \mathbb{E}_{\substack{x_{1:T} \sim q( \cdot | x_0)}} \left[ \log q(x_T | x_0) - \log p_\theta(x_T) \right] \notag \\ &\quad - \sum_{t=1}^{T} \mathbb{E}_{\substack{x_{1:T} \sim q( \cdot | x_0)}} \big[ \log q(x_{t-1} | x_t, x_0) - \log p_\theta(x_{t-1} | x_t) \big] \htmlData{equation-label=eq:elbo-rewrite}{\htmlId{eq:elbo-rewrite}{}} \end{align}

We simplify by marginalizing over all intermediate variables. For the first term:

Ex1:T∼q(⋅∣x0)[log⁡q(xT∣x0)−log⁡pθ(xT)]=ExT∼q(⋅∣x0)[log⁡q(xT∣x0)−log⁡pθ(xT)]\begin{align} &\mathbb{E}_{\substack{x_{1:T} \sim q( \cdot | x_0)}} \left[ \log q(x_T | x_0) - \log p_\theta(x_T) \right] \htmlData{equation-label=eq:elbo-continuous}{\htmlId{eq:elbo-continuous}{}} \\ &= \mathbb{E}_{\substack{x_T \sim q( \cdot | x_0)}} \left[ \log q(x_T | x_0) - \log p_\theta(x_T) \right] \notag \end{align}

For each term in the sum:

Ex1:T∼q(⋅∣x0)[log⁡q(xt−1∣xt,x0)−log⁡pθ(xt−1∣xt)]=Ext∼q(⋅∣x0)[Ext−1∼q(⋅∣xt,x0)[log⁡q(xt−1∣xt,x0)−log⁡pθ(xt−1∣xt)]]\begin{align} &\mathbb{E}_{\substack{x_{1:T} \sim q( \cdot | x_0)}} \left[ \log q(x_{t-1} | x_t, x_0) - \log p_\theta(x_{t-1} | x_t) \right] \htmlData{equation-label=eq:posterior-exp-1}{\htmlId{eq:posterior-exp-1}{}} \\ &= \mathbb{E}_{\substack{x_t \sim q( \cdot | x_0)}} \bigg[ \mathbb{E}_{\substack{x_{t-1} \sim q( \cdot | x_t, x_0)}} \htmlData{equation-label=eq:posterior-exp-2}{\htmlId{eq:posterior-exp-2}{}} \\ &\qquad \left[ \log q(x_{t-1} | x_t, x_0) - \log p_\theta(x_{t-1} | x_t) \right] \bigg] \notag \end{align}

Therefore:

ELBOθ(x0)=−KL(q(xT∣x0),pT)−∑t=1TExt∼q(⋅∣x0)[KL(q(xt−1∣xt,x0),pθ(xt−1∣xt))]\begin{align} \text{ELBO}_{\theta}(x_0) &= - \mathrm{KL}\left(q(x_T|x_0) , p_T\right) \htmlData{equation-label=eq:discrete-elbo-proof-1}{\htmlId{eq:discrete-elbo-proof-1}{}} \\ &\quad - \sum_{t=1}^{T} \mathbb{E}_{\substack{x_t \sim q( \cdot | x_0)}} \left[ \mathrm{KL}\left(q(x_{t-1} | x_t, x_0) , p_\theta(x_{t-1} | x_t)\right) \right] \htmlData{equation-label=eq:discrete-elbo-proof-2}{\htmlId{eq:discrete-elbo-proof-2}{}} \notag \end{align}

where the first KL term is a constant independent of θ\theta, since pθ(xT)=pTp_\theta(x_T) = p_T is a fixed base distribution.

The sum of KL terms corresponds to a forward trajectory where x0,x1,…,xTx_0, x_1, \ldots, x_T is sampled from the noising process, and at each step the learned reverse transition pθ(xt−1∣xt)p_\theta(x_{t-1} | x_t) is trained to match the reverse transition conditioned on the initial clean token x0x_0: q(xt−1∣xt,x0)q(x_{t-1} | x_t, x_0).

To sample from the data, we therefore need to learn the transitions pθ(xt−1∣xt)p_\theta(x_{t-1} | x_t). However, the discrete diffusion models of [1, 2] prefer to follow the key innovation of DDPM [11] instead: predict the clean signal x0x_0 and rebuild the reverse step using q(xt−1∣xt,x0)q(x_{t-1} | x_t, x_0). Here, we use Eq. (?), which combines this term with the denoiser P(X0=v∣Xt=xt)\mathbb{P}(X_0 = v | X_t=x_t) to weight each possible clean token. Since this denoiser is itself intractable, we approximate it by a learned denoiser Dθ,t(xt)∈Δ∣V∣D_{\theta,t}(x_t) \in \Delta_{|\mathcal{V}|}.. This definition naturally extends to each position ii if we consider sequences: [Dθ,ti(xt)]v≈P(X0i=v∣Xt=xt)[D_{\theta,t}^i(\mathbf{x}_t)]_v \approx \mathbb{P}(X_0^i = v | \mathbf{X}_t = \mathbf{x}_t).

The following proposition rewrites the ELBO term entirely in terms of this denoiser.

Proposition 4 (Masked diffusion training loss).

In the specific case of Masked Diffusion, we can express the loss in terms of the denoiser output Dθ,t(xt)=(Dθ,t1(xt),…,Dθ,tS(xt))∈Δ∣V∣SD_{\theta,t}(\mathbf{x}_t) = (D_{\theta,t}^1(\mathbf{x}_t), \ldots, D_{\theta,t}^S(\mathbf{x}_t)) \in \Delta_{|\mathcal{V}|}^S, where t∼Unif{1,…,T}t \sim \mathrm{Unif}\{1,\ldots,T\}:

LT(θ)=T Ex0∼p0t∼Unif{1,…,T}xt∼q(⋅∣x0)[∑i=1SI(xti=m)(−αt−1−αt1−αtx0i⊤log⁡Dθ,ti(xt))]\begin{equation} \htmlData{equation-label=eq:mdm-loss}{\htmlId{eq:mdm-loss}{}} L_T(\theta) = T\,\mathbb{E}_{\substack{\mathbf{x}_0 \sim p_0 \\ t \sim \mathrm{Unif}\{1,\ldots,T\} \\ \mathbf{x}_t \sim q( \cdot | \mathbf{x}_0)}} \left[ \sum_{i=1}^{S} \mathbb{I}(x_t^i = m) \left( -\frac{\alpha_{t-1} - \alpha_t}{1 - \alpha_t} \mathbf{x}_0^{i \top} \log D_{\theta,t}^i(\mathbf{x}_t) \right) \right] \end{equation}
Proof

We write the proof only for one token, starting from Eq. (?). Since xT=mx_T = m is fully masked, we have KL(q(xT∣x0),pθ(xT))=0\mathrm{KL}(q(x_T|x_0) , p_\theta(x_T)) = 0. Therefore:

ELBOθ(x0)=−∑t=1TExt∼q(⋅∣x0)[KL(q(xt−1∣xt,x0),pθ(xt−1∣xt))]\begin{align} &\text{ELBO}_{\theta}(x_0) = {} \htmlData{equation-label=eq:mdm-elbo-no-source}{\htmlId{eq:mdm-elbo-no-source}{}} \\ &- \sum_{t=1}^{T} \mathbb{E}_{\substack{x_t \sim q( \cdot | x_0)}} \left[ \mathrm{KL}\left(q(x_{t-1} | x_t, x_0) , p_\theta(x_{t-1} | x_t)\right) \right] \notag \end{align}

Let s=t−1s = t-1. The KL divergence can be expanded as a sum over all possible values of xs∈Vx_s \in \mathcal{V}:

KL(q(xs∣xt,x0),pθ(xs∣xt))=∑xs∈Vq(xs∣xt,x0)log⁡q(xs∣xt,x0)pθ(xs∣xt)\begin{align} & \mathrm{KL}\left(q(x_s | x_t, x_0) , p_\theta(x_s | x_t)\right) \htmlData{equation-label=eq:bridge-kl}{\htmlId{eq:bridge-kl}{}} \\ & \quad = \sum_{x_s \in \mathcal{V}} q(x_s | x_t, x_0) \log \frac{q(x_s | x_t, x_0)}{p_\theta(x_s | x_t)} \notag \end{align}

When xt≠mx_t\neq m, both q(xs∣xt,x0)q(x_s| x_t,x_0) and pθ(xs∣xt)p_\theta(x_s| x_t) put all their mass on xs=xt=x0x_s=x_t=x_0, so the KL term is zero.

Hence only the case xt=mx_t=m contributes. Therefore, using Eq. (?) together with the learned reverse transition Eq. (?) and @bridge-denoiser-2,

KL ⁣(q(xs∣xt,x0) ∥ pθ(xs∣xt))=I(xt=m)∑xs∈V∪{m}q(xs∣xt,x0) log⁡q(xs∣xt,x0)pθ(xs∣xt)=I(xt=m)∑xs∈V∪{m}[αs−αt1−αtI(xs=x0)+1−αs1−αtI(xs=m)]log⁡αs−αt1−αtI(xs=x0)+1−αs1−αtI(xs=m)αs−αt1−αt[Dθ,t(xt)]xsI(xs≠m)+1−αs1−αtI(xs=m)=I(xt=m)[αs−αt1−αtlog⁡αs−αt1−αtαs−αt1−αt[Dθ,t(xt)]x0+1−αs1−αtlog⁡1−αs1−αt1−αs1−αt⏟=0]=I(xt=m) αs−αt1−αt (−log⁡[Dθ,t(xt)]x0).\begin{align} &\mathrm{KL}\!\left(q(x_s| x_t,x_0)\,\|\,p_\theta(x_s| x_t)\right) \notag \\ &= \mathbb{I}(x_t=m) \sum_{x_s \in \mathcal{V}\cup\{m\}} q(x_s| x_t,x_0)\, \log\frac{q(x_s| x_t,x_0)}{p_\theta(x_s| x_t)} \htmlData{equation-label=eq:bridge-kl-proof-2}{\htmlId{eq:bridge-kl-proof-2}{}} \\ &= \mathbb{I}(x_t=m) \sum_{x_s \in \mathcal{V}\cup\{m\}} \left[ \frac{\alpha_s-\alpha_t}{1-\alpha_t}\mathbb{I}(x_s=x_0) + \frac{1-\alpha_s}{1-\alpha_t}\mathbb{I}(x_s=m) \right] \htmlData{equation-label=eq:bridge-kl-proof-3}{\htmlId{eq:bridge-kl-proof-3}{}} \\ &\quad \log \frac{ \frac{\alpha_s-\alpha_t}{1-\alpha_t}\mathbb{I}(x_s=x_0) + \frac{1-\alpha_s}{1-\alpha_t}\mathbb{I}(x_s=m) }{ \frac{\alpha_s-\alpha_t}{1-\alpha_t}[D_{\theta,t}(x_t)]_{x_s}\mathbb{I}(x_s\neq m) + \frac{1-\alpha_s}{1-\alpha_t}\mathbb{I}(x_s=m) } \notag \\ &= \mathbb{I}(x_t=m)\Bigg[ \frac{\alpha_s-\alpha_t}{1-\alpha_t} \log\frac{\frac{\alpha_s-\alpha_t}{1-\alpha_t}} {\frac{\alpha_s-\alpha_t}{1-\alpha_t}[D_{\theta,t}(x_t)]_{x_0}} +\frac{1-\alpha_s}{1-\alpha_t} \underbrace{\log\frac{\frac{1-\alpha_s}{1-\alpha_t}} {\frac{1-\alpha_s}{1-\alpha_t}}}_{=0} \Bigg] \htmlData{equation-label=eq:bridge-kl-proof-4}{\htmlId{eq:bridge-kl-proof-4}{}} \\ &= \mathbb{I}(x_t=m)\,\frac{\alpha_s-\alpha_t}{1-\alpha_t}\, \big(-\log [D_{\theta,t}(x_t)]_{x_0}\big). \htmlData{equation-label=eq:bridge-kl-proof-5}{\htmlId{eq:bridge-kl-proof-5}{}} \end{align}

Plugging this into the ELBO yields:

ELBOθ(x0)=∑t=1TExt∼q(⋅∣x0)[I(xt=m) αt−1−αt1−αt x0⊤log⁡Dθ,t(xt)].\begin{equation} \text{ELBO}_{\theta}(x_0) = \sum_{t=1}^T \mathbb{E}_{x_t \sim q(\cdot | x_0)} \left[\mathbb{I}(x_t=m)\,\frac{\alpha_{t-1}-\alpha_t}{1-\alpha_t}\,x_0^\top \log D_{\theta, t}(x_t)\right]. \htmlData{equation-label=eq:mdm-elbo-sum-1}{\htmlId{eq:mdm-elbo-sum-1}{}} \end{equation}

Equivalently, by sampling a step t∼Unif{1,…,T}t \sim \mathrm{Unif}\{1,\ldots,T\}, we use ∑t=1Tf(t)=T Et∼Unif{1,…,T}[f(t)]\sum_{t=1}^{T} f(t) = T\,\mathbb{E}_{t \sim \mathrm{Unif}\{1,\ldots,T\}}[f(t)]:

ELBOθ(x0)=T Et∼Unif{1,…,T}xt∼q(⋅∣x0)[I(xt=m) αt−1−αt1−αt x0⊤log⁡Dθ,t(xt)].\begin{align} \text{ELBO}_{\theta}(x_0) &= T\,\mathbb{E}_{\substack{t \sim \mathrm{Unif}\{1,\ldots,T\} \\ x_t \sim q( \cdot | x_0)}} \left[ \mathbb{I}(x_t=m)\,\frac{\alpha_{t-1}-\alpha_t}{1-\alpha_t} \,x_0^\top \log D_{\theta, t}(x_t)\right]. \htmlData{equation-label=eq:mdm-elbo-uniform-t}{\htmlId{eq:mdm-elbo-uniform-t}{}} \end{align}
To go further: continuous time limit

A drawback of the discrete-time construction presented in this section is that the loss Eq. (?) only evaluates the denoiser Dθ,tD_{\theta,t} at the TT grid times t∈{1,…,T}t\in\{1,\ldots,T\}, so it learns to undo the noise at the levels α1,…,αT\alpha_1,\ldots,\alpha_T and no others. Refining the schedule αt\alpha_t at sampling time places new levels between the trained ones, where the denoiser must be evaluated at a noise level it never saw. Avoiding this mismatch ties us to the fixed grid α1,…,αT\alpha_1,\ldots,\alpha_T. To remove this constraint, [3] introduced the continuous-time limit of these models (later simplified for masked diffusion by [13]): training over t∼U(0,1)t\sim\mathcal{U}(0,1) exposes the denoiser to every noise level, so the number of steps and the schedule become choices made after training rather than before.

In order to provide a continuous-time version of the loss Eq. (?), we first need define a continuous-time analogue of the survival schedule αt=∏i=1t(1−βi)\alpha_t = \displaystyle\prod_{i=1}^{t} (1 - \beta_i), and give an intuition for its form.

Introduce a continuous masking-rate function β:[0,1]→R+\beta : [0,1] \to \mathbb{R}_+. We normalize the discrete steps 0,1,…,T0,1,\ldots,T to the continuous grid 0,1/T,…,10,1/T,\ldots,1 and define the step size Δt=1/T\Delta t = 1/T. The corresponding masking probability at grid point i/Ti/T is

βi:=β(i/T)Δt=1Tβ(iT).\begin{equation} \htmlData{equation-label=eq:ct-beta-discretization}{\htmlId{eq:ct-beta-discretization}{}} \beta_i := \beta(i/T)\Delta t = \frac{1}{T}\beta\left(\frac{i}{T}\right). \end{equation}

For a continuous time t∈[0,1]t\in[0,1], write n=⌊Tt⌋n=\lfloor Tt\rfloor. The discrete survival probability becomes

q(xt=x0∣x0)≈∏i=1n(1−1Tβ(iT))=exp⁡(∑i=1nlog⁡(1−1Tβ(iT)))≈exp⁡(−∑i=1n1Tβ(iT))→T→∞exp⁡(−∫0tβ(s) ds),\begin{align} q(x_t = x_0 | x_0) &\approx \prod_{i=1}^{n} \left(1- \frac{1}{T}\beta\left(\frac{i}{T}\right)\right) \htmlData{equation-label=eq:survival-prob-ct-1}{\htmlId{eq:survival-prob-ct-1}{}} \\ &= \exp\left( \sum_{i=1}^{n} \log\left(1-\frac{1}{T}\beta\left(\frac{i}{T}\right)\right) \right) \htmlData{equation-label=eq:survival-prob-ct-2}{\htmlId{eq:survival-prob-ct-2}{}} \\ &\approx \exp\left( -\sum_{i=1}^{n} \frac{1}{T}\beta\left(\frac{i}{T}\right) \right) \htmlData{equation-label=eq:survival-prob-ct-3}{\htmlId{eq:survival-prob-ct-3}{}} \\ &\xrightarrow[T\to\infty]{} \exp\left(-\int_0^t \beta(s)\, ds\right), \htmlData{equation-label=eq:survival-prob-ct-4}{\htmlId{eq:survival-prob-ct-4}{}} \end{align}

where the last line recognizes a Riemann sum.

This motivates the continuous-time survival schedule

αt=exp⁡ ⁣(−∫0tβ(s) ds).\begin{equation} \htmlData{equation-label=eq:alpha-def}{\htmlId{eq:alpha-def}{}} \alpha_t = \exp\!\left(-\int_0^t \beta(s)\, ds\right). \end{equation}

We deduce the following properties on αt\alpha_t from the derivation above:

  • α0=1\alpha_0 = 1: at time t=0t=0, all tokens are unmasked.
  • α1=0\alpha_1 = 0: at time t=1t=1, all tokens are masked.
  • αt\alpha_t is decreasing in tt: as the step index increases, the probability of a token remaining unmasked decreases.

Now we want to express the continuous-time limit of denoiser loss Eq. (?). We normalize the timsteps in [0,1] and therefore define the grid τn=n/T\tau_n=n/T, Δt=1/T\Delta t=1/T, with αn=ατn\alpha_n=\alpha_{\tau_n} and τn−1=τn−Δt\tau_{n-1}=\tau_n-\Delta t.

LT(θ)=T Ex0∼p0  En∼Unif{1,…,T}⏟= 1T∑n=1T  Exτn∼q(⋅∣x0)[∑i=1SI(xτni=m)(−αn−1−αn1−αn x0i⊤log⁡Dθ,τni(xτn))]=Ex0∼p0  1T∑n=1T  Exτn∼q(⋅∣x0)[∑i=1SI(xτni=m)  T αn−1−αn1−αn⏟= −α˙τn1−ατn+o(1)(−x0i⊤log⁡Dθ,τni(xτn))]\begin{align} L_T(\theta) &= T\,\mathbb{E}_{\mathbf{x}_0\sim p_0}\; \underbrace{\mathbb{E}_{n\sim\mathrm{Unif}\{1,\ldots,T\}}}_{\textstyle =\,\frac{1}{T}\sum_{n=1}^{T}}\; \mathbb{E}_{\mathbf{x}_{\tau_n}\sim q(\cdot|\mathbf{x}_0)} \\ &\quad \left[\sum_{i=1}^{S}\mathbb{I}(x_{\tau_n}^i=m)\left(-\frac{\alpha_{n-1}-\alpha_n}{1-\alpha_n}\,\mathbf{x}_0^{i\top}\log D_{\theta,\tau_n}^i(\mathbf{x}_{\tau_n})\right)\right] \notag \\[1.4em] &= \mathbb{E}_{\mathbf{x}_0\sim p_0}\; \frac{1}{T}\sum_{n=1}^{T}\; \mathbb{E}_{\mathbf{x}_{\tau_n}\sim q(\cdot|\mathbf{x}_0)} \\ &\quad \left[\sum_{i=1}^{S}\mathbb{I}(x_{\tau_n}^i=m)\; \underbrace{T\,\frac{\alpha_{n-1}-\alpha_n}{1-\alpha_n}}_{\textstyle =\,\frac{-\dot{\alpha}_{\tau_n}}{1-\alpha_{\tau_n}}+o(1)} \left(-\mathbf{x}_0^{i\top}\log D_{\theta,\tau_n}^i(\mathbf{x}_{\tau_n})\right)\right] \notag \end{align}

As T→∞T\to\infty this average is a Riemann sum, 1T∑n=1Tg(τn)→∫01g(t) dt=Et∼U(0,1)[g(t)]\tfrac{1}{T}\sum_{n=1}^{T} g(\tau_n)\to\int_0^1 g(t)\,dt=\mathbb{E}_{t\sim\mathcal{U}(0,1)}[g(t)], and we obtain the continuous-time masked denoiser loss:

L(θ)=Ex0∼p0t∼U(0,1)xt∼q(⋅∣x0)[∑i=1SI(xti=m) −α˙t1−αt(−x0i⊤log⁡Dθ,ti(xt))].\begin{equation} \htmlData{equation-label=eq:mdm-loss-ct}{\htmlId{eq:mdm-loss-ct}{}} L(\theta) = \mathbb{E}_{\substack{ \mathbf{x}_0 \sim p_0 \\ t \sim \mathcal{U}(0,1) \\ \mathbf{x}_t \sim q(\cdot|\mathbf{x}_0) }} \left[ \sum_{i=1}^{S} \mathbb{I}(x_t^i=m)\, \frac{-\dot{\alpha}_t}{1-\alpha_t} \left(-\mathbf{x}_0^{i\top}\log D_{\theta,t}^i(\mathbf{x}_t)\right) \right]. \end{equation}

To wrap up, we end this section with a table summarizing the important steps in variational masked discrete diffusion, put in parallel with their equivalent for continuous space diffusion (DDPM).

Table 3: Continuous-space diffusion and masked discrete diffusion side by side.
Continuous-space diffusionMasked discrete diffusion
1. Final distribution after noising

xT∼N(0,I)x_T \sim \mathcal{N}(0, I)

xT∼δm…mx_T \sim \delta_{m\ldots m}

2. Local view of the forward process

Markov chain with TT steps, t∈{1,…,T}t \in \{1,\ldots,T\}, and variance/noise schedule βt\beta_t.

q(xt∣xt−1)=N ⁣(1−βt xt−1,  βtI)q(x_t | x_{t-1}) = \mathcal{N}\!\left(\sqrt{1-\beta_t}\,x_{t-1},\; \beta_t I\right)

q(xt∣xt−1)=Cat ⁣(xt; (1−βt)ext−1+βtem)q(x_t | x_{t-1}) = \mathrm{Cat}\!\left(x_t;\, (1-\beta_t)\mathbf{e}_{x_{t-1}} + \beta_t \mathbf{e}_m\right)

3. Big jump view of the forward process

Survival probability αt=∏i=1t(1−βi)\alpha_t = \displaystyle\prod_{i=1}^{t} (1 - \beta_i)

q(xt∣x0)=N ⁣(αt x0,  (1−αt)I)q(x_t | x_0) = \mathcal{N}\!\left(\sqrt{\alpha_t}\,x_0,\; (1-\alpha_t)I\right)

q(xt∣x0)=Cat ⁣(xt; αtex0+(1−αt)em)q(x_t | x_0) = \mathrm{Cat}\!\left(x_t;\, \alpha_t \mathbf{e}_{x_0} + (1-\alpha_t)\mathbf{e}_m\right)

4. Sandwich view

q(xt−1∣xt,x0)=N ⁣(μ~t(xt,x0),  β~tI)q(x_{t-1} | x_t, x_0) = \mathcal{N}\!\left(\tilde{\mu}_t(x_t,x_0),\; \tilde{\beta}_t I\right)

q(xt−1∣xt,x0)=Cat ⁣(xt−1;  αt−1−αt1−αt ex0+1−αt−11−αt em)q(x_{t-1} | x_t, x_0) = \mathrm{Cat}\!\left(x_{t-1};\; \tfrac{\alpha_{t-1} - \alpha_t}{1 - \alpha_t}\, \mathbf{e}_{x_0} + \tfrac{1 - \alpha_{t-1}}{1 - \alpha_t}\, \mathbf{e}_m\right)

5. Learnable backward process

xT∼N(0,I)x_T \sim \mathcal{N}(0, I)
pθ,t(xt−1∣xt)=N ⁣(μθ,t(xt),  σt2I)p_{\theta,t}(x_{t-1} | x_t) = \mathcal{N}\!\left(\mu_{\theta,t}(x_t),\; \sigma_t^2 I\right)

xT∼δm…mx_T \sim \delta_{m\ldots m}
pθ,t(xt−1∣xt)=Cat ⁣(xt−1;  αt−1−αt1−αt Dθ,t(xt)+1−αt−11−αt em)p_{\theta,t}(x_{t-1} | x_t) = \mathrm{Cat}\!\left(x_{t-1};\; \tfrac{\alpha_{t-1} - \alpha_t}{1 - \alpha_t}\, D_{\theta,t}(x_t) + \tfrac{1 - \alpha_{t-1}}{1 - \alpha_t}\, \mathbf{e}_m\right)

6. Training loss L=KL ⁣(q(x0:T), pθ(x0:T))\mathcal{L} = \mathrm{KL}\!\left(q(x_{0:T}),\, p_\theta(x_{0:T})\right)

Lt=βt2(1−αt) ∥ε−εθ,t(xt)∥2\mathcal{L}_t = \tfrac{\beta_t}{2(1-\alpha_t)}\,\left\| \varepsilon - \varepsilon_{\theta,t}(x_t) \right\|^2

Lt=−∑i=1S1(xti=m) αt−1−αt1−αt log⁡[Dθ,ti(xt)]x0i\mathcal{L}_t = -\sum_{i=1}^S \mathbf{1}(x_t^i = m)\,\tfrac{\alpha_{t-1}-\alpha_t}{1-\alpha_t}\,\log \big[D_{\theta,t}^i(x_t)\big]_{x_0^i}


Score-based discrete diffusion

In this section, we study the score-based perspective on discrete diffusion. The main idea is to learn a transport guided by the score function st(xt)s_t(x_t) to reverse the diffusion process. This quantity points toward more likely samples at noise level tt, guiding the generation process back toward the data distribution. In continuous-space diffusion models, the generation process, i.e. the backward process, is defined by the reverse SDE (see Figure 1, bottom); critically, the reverse SDE involves the score, namely ∇xlog⁡pt(xt)\nabla_x \log p_t(x_t), where ptp_t is the distribution of the variables xtx_t defined by the forward process.

We follow the same approach in discrete space. Since there is no SDE involved here, we work with the first-order expansion of q(xt+Δt∣xt)q(x_{t+\Delta t} | x_t) as Δt→0\Delta t \to 0, which plays the role of dxtdx_t in the forward SDE, i.e. describing the evolution of xtx_t during the corruption process. Then we reverse the process to obtain p(xt−Δt∣xt)p(x_{t-\Delta t} | x_t) and identify the concrete score st(xt)ys_t(x_t)_{y}, the discrete analogue of ∇xlog⁡pt(xt)\nabla_x \log p_t(x_t) (the score function of the continuous process). Finally, we learn a neural network to predict the concrete score and use it to generate new discrete data.

Score-based categorical SDE diagram

Figure 4: Analogy between continuous-space and discrete-space score-based diffusion. In continuous space, Euler sampling with five steps discretizes the continuous-time SDE: in the forward direction, the drift and Gaussian increments add noise to the sample; in the reverse direction, the learned score changes the drift so that noise is removed. In discrete space, the same idea becomes an Euler sampler built from the local continuous-time transition rates: the forward rates move probability mass toward noisier categorical states, while the learned reverse rates move probability mass back toward cleaner states.

Forward process

In continuous-space score-based diffusion, we model the forward process as the solution of the SDE dxt=ft(xt) dt+gt dWtdx_t = f_t(x_t)\,dt + g_t\,dW_t, where we fix the drift ftf_t and the diffusion coefficient gtg_t, and WtW_t is a Wiener process. We follow a similar approach in discrete space: we model the forward process as a continuous-time Markov chain (CTMC), which can be written as

q(xt+Δt=y∣xt)=I(y=xt)+[Q˙t(xt)]yΔt+o(Δt),\begin{equation} \htmlData{equation-label=eq:forward-rate}{\htmlId{eq:forward-rate}{}} q(x_{t+\Delta t} = y | x_t) = \mathbb{I}(y = x_t) + [\dot{Q}_t(x_t)]_y \Delta t + o(\Delta t), \end{equation}

where we choose the forward rate matrix Q˙t∈R∣V∣×∣V∣\dot{Q}_t \in \mathbb{R}^{|\mathcal{V}| \times |\mathcal{V}|}. In the above equation and in what follows, [Q˙t(xt)]y[\dot{Q}_t(x_t)]_y denotes the entry of Q˙t\dot{Q}_t at row xtx_t and column yy.

For continuous-space diffusion models, the forward SDE means that over an infinitesimal time dtdt, a particle at xtx_t moves by a deterministic drift ft(xt) dtf_t(x_t)\,dt plus an independent Gaussian increment of standard deviation gtdtg_t\sqrt{dt}. Here, [Q˙t(xt)]y[\dot{Q}_t(x_t)]_y is the instantaneous rate at which a particle at state xtx_t jumps to state yy: over a small interval Δt\Delta t, the probability of such a jump is [Q˙t(xt)]yΔt[\dot{Q}_t(x_t)]_y\Delta t to first order.

Then, we need to specify the forward rate matrix Q˙t\dot{Q}_t that governs the masking process. A simple choice is to set the rate of transition from any unmasked token to the mask state:

Q˙t=σ(t)(1em⊤−I)=σ(t)(−10…010−1…01⋮⋮⋱⋮⋮00…−1100…00),\begin{equation} \htmlData{equation-label=eq:q-dot-def}{\htmlId{eq:q-dot-def}{}} \dot{Q}_t = \sigma(t) (\mathbf{1}\mathbf{e}_m^\top - I) = \sigma(t) \begin{pmatrix} -1 & 0 & \dots & 0 & 1 \\ 0 & -1 & \dots & 0 & 1 \\ \vdots & \vdots & \ddots & \vdots & \vdots \\ 0 & 0 & \dots & -1 & 1 \\ 0 & 0 & \dots & 0 & 0 \end{pmatrix}, \end{equation}

where σ(t)>0\sigma(t) > 0 is the instantaneous masking rate, em\mathbf{e}_m is the one-hot vector for the mask token. The last column of Q˙t\dot{Q}_t indicates that the rates for jumping to mm are equal to σ(t)\sigma(t) for any token xt∈V∖{m}x_t\in\mathcal{V}\setminus\{m\}, and the last row indicates that the rate for jumping from mm to any other state is 0 (the mask is an absorbing state).

Continuous-space diffusion models benefits from simulation-free forward processes, which mean we can directly sample xtx_t given x0x_0 without having to simulate the process step by step, simply using the closed-form expression q(xt∣x0)=N ⁣(xt; αt x0, (1−αt)I)q(x_t | x_0) = \mathcal{N}\!\left(x_t;\ \sqrt{\alpha_t}\,x_0,\ (1-\alpha_t)I\right), where αt=exp⁡ ⁣(−∫0tβ(s) ds)\alpha_t = \exp\!\left(-\int_0^t \beta(s)\,ds\right) is the cumulative noise schedule. The same thing is possible in discrete space, we can define the transition matrix from time 00 to time tt, denoted Qˉt∣0\bar{Q}_{t|0}, such that q(xt∣x0)=Cat(xt; Qˉt∣0⊤x0)q(x_t | x_0)=\mathrm{Cat}(x_t;\ \bar{Q}_{t|0}^\top x_0). Denoting αt=exp⁡ ⁣(−∫0tσ(s) ds)\alpha_t = \exp\!\left(-\int_0^t \sigma(s)\,ds\right) the cumulative masking schedule, we have that Qˉt∣0\bar{Q}_{t|0} takes the following form:

Qˉt∣0=αtI+(1−αt)1em⊤=(αt0…01−αt0αt…01−αt⋮⋮⋱⋮⋮00…αt1−αt00…01),\begin{align} \bar{Q}_{t|0} &= \alpha_t I + (1-\alpha_t)\mathbf{1}\mathbf{e}_m^\top \\ &= \begin{pmatrix} \alpha_t & 0 & \dots & 0 & 1-\alpha_t \\ 0 & \alpha_t & \dots & 0 & 1-\alpha_t \\ \vdots & \vdots & \ddots & \vdots & \vdots \\ 0 & 0 & \dots & \alpha_t & 1-\alpha_t \\ 0 & 0 & \dots & 0 & 1 \end{pmatrix}, \htmlData{equation-label=eq:integrated-forward-transition}{\htmlId{eq:integrated-forward-transition}{}} \end{align}

Therefore, for a clean token x0x_0, the forward marginal is simply:

xt={x0,with probability αt,m,with probability 1−αt.\begin{equation} \htmlData{equation-label=eq:ctmc-forward-marginal}{\htmlId{eq:ctmc-forward-marginal}{}} x_t = \begin{cases} x_0, & \text{with probability } \alpha_t, \\ m, & \text{with probability } 1-\alpha_t. \end{cases} \end{equation}
Justification of Qˉt∣0\bar{Q}_{t|0}

Start by composing local transitions over a partition 0=t0<t1<⋯<tn=t0=t_0<t_1<\dots<t_n=t:

q(xt∣x0)=∑xt1,…,xtn−1∏i=0n−1q(xti+1∣xti)=[(Qˉt1∣t0Qˉt2∣t1⋯Qˉtn∣tn−1)⊤x0]xt.\begin{align} q(x_t | x_0) &= \sum_{x_{t_1},\dots,x_{t_{n-1}}} \prod_{i=0}^{n-1} q(x_{t_{i+1}} | x_{t_i}) \\ &= \left[\left(\bar{Q}_{t_1|t_0}\bar{Q}_{t_2|t_1}\cdots \bar{Q}_{t_n|t_{n-1}}\right)^\top x_0\right]_{x_t}. \end{align}

In the continuous-time limit, each local transition is Qˉt+Δt∣t=I+Q˙tΔt+o(Δt)\bar{Q}_{t+\Delta t|t}=I+\dot{Q}_t\Delta t+o(\Delta t), so this product becomes the exponential of the accumulated local rates. Let A=1em⊤−IA = \mathbf{1}\mathbf{e}_m^\top - I. Since Q˙t=σ(t)A\dot{Q}_t = \sigma(t)A has a fixed matrix direction for all tt, this integration reduces to an ordinary matrix exponential:

Qˉt∣0=exp⁡ ⁣(∫0tQ˙s ds)=exp⁡ ⁣((∫0tσ(s) ds)A)=exp⁡(−Λt)I+(1−exp⁡(−Λt))1em⊤,\begin{align} \bar{Q}_{t|0} &= \exp\!\left(\int_0^t \dot{Q}_s\,ds\right) \\ &= \exp\!\left(\left(\int_0^t \sigma(s)\,ds\right)A\right) \\ &= \exp(-\Lambda_t)I + \left(1-\exp(-\Lambda_t)\right)\mathbf{1}\mathbf{e}_m^\top, \end{align}

where Λt=∫0tσ(s) ds\Lambda_t = \int_0^t \sigma(s)\,ds, hence αt=exp⁡(−Λt)\alpha_t = \exp(-\Lambda_t).

Masked Diffusion: Forward Process

αt =
Startt = 0.00
T
seed
x₀mt=0t=11 − σ(t)Δt0.90
slowfast

Figure 5: Euler simulation of the forward process Eq. (?), with absorbing generator Eq. (?). At time tt, an unmasked token gets masked with probability σ(t)Δt=−α˙tαtΔt\sigma(t)\Delta t = -\dfrac{\dot{\alpha}_t}{\alpha_t}\Delta t, where Δt=1/T\Delta t=1/T; after masking, this probability is 1. The trajectories are stochastic: changing the seed changes the step at which x0x_0 transitions to mm.
The “Show NN trajectories” button switches to an aggregate view that samples NN independent trajectories with the same transition rule; as TT and NN grow, the plotted fraction still unmasked approaches the schedule αt\alpha_t.

Reverse process

In the previous section, we have described the forward process of score-based discrete diffusion models. To generate new data samples, we need to reverse the forward process.

Similarly to continuous-space diffusion, where the reverse process is obtained by reversing the forward SDE, in discrete space, the reverse process is obtained by reversing the forward Markov chain, and is also a continuous-time Markov chain.

Proposition 5 (Reverse process).

Interestingly, the reverse process is also a continuous-time Markov chain, and its transition probabilities can be expressed as:

p(xt−Δt=y∣xt)=I(y=xt)+Δt [R˙t(xt)]y+o(Δt)\begin{equation} \htmlData{equation-label=eq:reverse-rate}{\htmlId{eq:reverse-rate}{}} p(x_{t-\Delta t} = y | x_t) = \mathbb{I}(y = x_t) + \Delta t \, [\dot{R}_t(x_t)]_y + o(\Delta t) \end{equation}

where the generator matrix R˙t\dot{R}_t is:

[R˙t(xt)]y={[Q˙t(y)]xtq(Xt=y)q(Xt=xt)if y≠xt−∑y′≠xt[R˙t(xt)]y′if y=xt\begin{equation} \htmlData{equation-label=eq:reverse-rate-mask}{\htmlId{eq:reverse-rate-mask}{}} [\dot{R}_t(x_t)]_y = \begin{cases} [\dot{Q}_t(y)]_{x_t} \frac{q(X_t = y)}{q(X_t = x_t)} & \text{if } y \neq x_t \\ - \sum_{y' \neq x_t} [\dot{R}_t(x_t)]_{y'} & \text{if } y = x_t \end{cases} \end{equation}
Proof

Using Bayes’ theorem, for y≠xty \neq x_t:

p(xt−Δt=y∣xt)=q(xt∣xt−Δt=y)q(xt−Δt=y)q(xt)=([Q˙t(y)]xtΔt+o(Δt))(q(Xt=y)+O(Δt))q(Xt=xt)=([Q˙t(y)]xtq(Xt=y)q(Xt=xt))Δt+o(Δt)\begin{align} p(x_{t-\Delta t} = y | x_t) &= \frac{q(x_t | x_{t-\Delta t} = y) q(x_{t-\Delta t} = y)}{q(x_t)} \htmlData{equation-label=eq:reverse-rate-proof-1}{\htmlId{eq:reverse-rate-proof-1}{}} \\ &= \frac{\big([\dot{Q}_t(y)]_{x_t}\Delta t + o(\Delta t)\big) \big(q(X_t = y) + O(\Delta t)\big)}{q(X_t = x_t)} \htmlData{equation-label=eq:reverse-rate-proof-2}{\htmlId{eq:reverse-rate-proof-2}{}} \\ &= \left( [\dot{Q}_t(y)]_{x_t} \frac{q(X_t = y)}{q(X_t = x_t)} \right)\Delta t + o(\Delta t) \htmlData{equation-label=eq:reverse-rate-proof-3}{\htmlId{eq:reverse-rate-proof-3}{}} \end{align}

By identifying this result with the definition of the reverse local transition p(xt−Δt=y∣xt)=Δt[R˙t(xt)]y+o(Δt)p(x_{t-\Delta t} = y | x_t) = \Delta t [\dot{R}_t(x_t)]_y + o(\Delta t), we conclude for y≠xty \neq x_t. For y=xty = x_t, we use the fact that probabilities sum to one, so the rows of a valid transition rate matrix must sum to zero, leading to [R˙t(xt)]xt=−∑y′≠xt[R˙t(xt)]y′[\dot{R}_t(x_t)]_{x_t} = - \sum_{y' \neq x_t} [\dot{R}_t(x_t)]_{y'}.

In continuous-space diffusion, the score function ∇xlog⁡pt(xt)\nabla_x \log p_t(x_t) governs the reverse SDE, i.e. the generative process. In the discrete space, the analog to the score function is the concrete score st(xt)ys_t(x_t)_y, defined as the ratio of marginal probabilities between a candidate destination state and the current state:

st(xt)y  =  q(Xt=y)q(Xt=xt)(y≠xt).s_t(x_t)_y \;=\; \frac{q(X_t = y)}{q(X_t = x_t)} \quad (y \neq x_t).

Recalling Eq. (?), the concrete score is precisely the quantity that converts the (known) forward rate Q˙t\dot{Q}_t into the reverse rate R˙t\dot{R}_t:

st(xt)y  =  [R˙t(xt)]y[Q˙t(xt)]y.\begin{equation} \htmlData{equation-label=eq:concrete-score}{\htmlId{eq:concrete-score}{}} s_t(x_t)_y \;=\; \frac{[\dot{R}_t(x_t)]_y}{[\dot{Q}_t(x_t)]_y}. \end{equation}

Then the reverse process can be simulated using the concrete score as follows:

xt−h∼Cat(ext+h R˙t(xt)+o(h))=Cat(ext+h ([Q˙t(xt)]⋅⊙st(xt)⋅)+o(h)),\begin{align} \htmlData{equation-label=eq:score-sampling}{\htmlId{eq:score-sampling}{}} x_{t-h} &\sim \mathrm{Cat}\left( \mathbf{e}_{x_t} + h\,\dot{R}_t(x_t) + o(h) \right) \\ &= \mathrm{Cat}\left( \mathbf{e}_{x_t} + h\,\big([\dot{Q}_t(x_t)]_{\cdot}\odot s_t(x_t)_{\cdot}\big) + o(h) \right), \htmlData{equation-label=eq:score-sampling-cat}{\htmlId{eq:score-sampling-cat}{}} \end{align}

where ⊙\odot denotes the elementwise product. The forward rate Q˙t\dot{Q}_t is known because it is a design choice of the noising process. However, the concrete score st(xt)ys_t(x_t)_y (or equivalently the reverse rate R˙t\dot{R}_t) depends on the noisy-data marginals q(Xt=⋅)q(X_t=\cdot) which are unknown and untractable. This is why, in practice, we learn a neural approximation of it, denoted by sθ,t(xt)ys_{\theta, t}(x_t)_y.

See the reverse process conditioned on x0x_0, where the unknown st(xt)s_t(x_t) is replaced by the known st(xt∣x0)s_t(x_t | x_0) in Figure 5 by clicking the reverse button.

Training

In the forward and reverse process sections, we showed how these processes can be simulated with respectively the forward rate Q˙t\dot{Q}_t Eq. (?) and the reverse rate R˙t\dot{R}_t Eq. (?), and that the unknown quantity connecting them is the concrete score st(xt)ys_t(x_t)_y Eq. (?). However, this last is untractable and therefore we need to rewrite it before approximating it with a neural network sθ,ts_{\theta,t}. To do so, we apply the marginalisation trick, meaning we express the concrete score st(xt)ys_t(x_t)_y as a conditional expectation of the conditional concrete score st(xt∣x0)ys_t(x_t | x_0)_y over x0x_0:

st(xt)y  =  pt(y)pt(xt)  =  ∑x0pt(y∣x0) p(x0)pt(xt)  =  ∑x0pt(y∣x0)pt(xt∣x0)  pt(xt∣x0) p(x0)pt(xt)⏟q(x0∣xt) by Bayes  =  Ex0∼q(⋅∣xt) ⁣[ st(xt∣x0)y ]\begin{align} s_t(x_t)_y \;=\; \frac{p_t(y)}{p_t(x_t)} &\;=\; \frac{\sum_{x_0} p_t(y|x_0)\,p(x_0)}{p_t(x_t)} \htmlData{equation-label=eq:concrete-score-cond-exp-1}{\htmlId{eq:concrete-score-cond-exp-1}{}} \\ &\;=\; \sum_{x_0} \frac{p_t(y|x_0)}{p_t(x_t|x_0)}\; \underbrace{\frac{p_t(x_t|x_0)\,p(x_0)}{p_t(x_t)}}_{q(x_0 | x_t)\ \text{by Bayes}} \htmlData{equation-label=eq:concrete-score-cond-exp-2}{\htmlId{eq:concrete-score-cond-exp-2}{}} \\ &\;=\; \mathbb{E}_{x_0 \sim q(\cdot|x_t)}\!\left[\,s_t(x_t|x_0)_y\,\right] \htmlData{equation-label=eq:concrete-score-cond-exp-3}{\htmlId{eq:concrete-score-cond-exp-3}{}} \end{align}

This gives the characterization:

st  =  argmin⁡s Ex0∼p0xt∼q(⋅∣x0) ⁣[∑y≠xtKL ⁣(st(xt∣x0)y, s(xt)y)]\begin{equation} \htmlData{equation-label=eq:score-kl-argmin}{\htmlId{eq:score-kl-argmin}{}} s_t \;=\; \underset{s}{\operatorname{argmin}}\ \mathbb{E}_{\substack{x_0 \sim p_0 \\ x_t \sim q(\cdot|x_0)}}\!\Bigg[ \sum_{y \neq x_t} \mathrm{KL}\!\left(s_t(x_t | x_0)_y,\, s(x_t)_y\right) \Bigg] \end{equation}

By weighting each term by the forward rate [Q˙t(xt)]y[\dot{Q}_t(x_t)]_y (which leaves the minimizer unchanged), we can derived a new loss function to train the concrete score approximation sθ,ts_{\theta,t}:

Lt(θ)=Ex0∼p0xt∼q(⋅∣x0)[∑y≠xt[Q˙t(xt)]y KL ⁣(st(xt∣x0)y, sθ,t(xt)y)]\begin{equation} \htmlData{equation-label=eq:score-kl-loss}{\htmlId{eq:score-kl-loss}{}} L_t(\theta) = \mathbb{E}_{\substack{x_0 \sim p_0 \\ x_t \sim q(\cdot|x_0)}} \Bigg[ \sum_{y \neq x_t} [\dot{Q}_t(x_t)]_y\, \mathrm{KL}\!\left(s_t(x_t | x_0)_y,\, s_{\theta,t}(x_t)_y\right) \Bigg] \end{equation}

Finally, by expanding the KL divergence and dropping θ\theta-independent terms, we obtain an explicit form for the score-based discrete diffusion loss:

Proposition 6 (Concrete score matching sts_t).

The concrete score sts_t is the minimizer (over sθ,ts_{\theta,t}) of

Lt(θ)=Ex0∼p0xt∼q(⋅∣x0)[∑y≠xt[Q˙t(xt)]y(sθ,t(xt)y−pt(y∣x0)pt(xt∣x0)log⁡sθ,t(xt)y)]+C\begin{equation} \htmlData{equation-label=eq:score-loss-prop}{\htmlId{eq:score-loss-prop}{}} L_t(\theta) = \mathbb{E}_{\substack{x_0 \sim p_0 \\ x_t \sim q( \cdot |x_0)}} \Bigg[ \sum_{y \neq x_t} [\dot{Q}_t(x_t)]_y \bigg( s_{\theta,t}(x_t)_y - \frac{p_t(y|x_0)}{p_t(x_t|x_0)} \log s_{\theta,t}(x_t)_y \bigg) \Bigg] + C \end{equation}

where CC is a constant independent of θ\theta [4].

To wrap up, we end this section with a table summarizing the important steps in score-based diffusion, put in parallel with their equivalent for continuous-space diffusion.

Table 6: Continuous-space and masked discrete score-based diffusion side by side.
Continuous-space diffusionMasked discrete diffusion
1. Forward noising equation

dXt=ft(Xt) dt+gt dWtdX_t = f_t(X_t)\,dt + g_t\,dW_t

xt+Δt∼Cat ⁣(ext+Q˙t(xt)Δt+o(Δt))x_{t+\Delta t} \sim \mathrm{Cat}\!\left(\mathbf{e}_{x_t} + \dot{Q}_t(x_t)\Delta t + o(\Delta t)\right)

2. Simulation-free forward process

q(xt∣x0)=N ⁣(αt x0,  (1−αt)I)q(x_t | x_0) = \mathcal{N}\!\left(\sqrt{\alpha_t}\,x_0,\; (1-\alpha_t)I\right)

q(xt∣x0)=Cat ⁣(xt; αtex0+(1−αt)em)q(x_t | x_0) = \mathrm{Cat}\!\left(x_t;\, \alpha_t\mathbf{e}_{x_0} + (1-\alpha_t)\mathbf{e}_m\right)

3. Reverse sampling equation

dXt=(ft(Xt)−gt2∇log⁡pθ,t(Xt))dt+gt dWˉtdX_t = \left(f_t(X_t) - g_t^2 \nabla \log p_{\theta,t}(X_t)\right)dt + g_t\,d\bar{W}_t

xt−Δt∼Cat ⁣(xt−Δt; ext+Δt R˙θ,t(xt)+o(Δt))x_{t-\Delta t} \sim \mathrm{Cat}\!\left(x_{t-\Delta t};\, \mathbf{e}_{x_t} + \Delta t\, \dot{R}_{\theta,t}(x_t) + o(\Delta t)\right)

4. Concrete score

sθ,t(xt)=∇log⁡pθ,t(xt)=−εθ,t(xt)1−αts_{\theta,t}(x_t) = \nabla \log p_{\theta,t}(x_t) = -\dfrac{\varepsilon_{\theta,t}(x_t)}{\sqrt{1-\alpha_t}}

sθ,t(xt)y=pθ,t(y)pθ,t(xt)=[R˙θ,t(xt)]y[Q˙t(xt)]ys_{\theta,t}(x_t)_y = \dfrac{p_{\theta,t}(y)}{p_{\theta,t}(x_t)} = \dfrac{[\dot{R}_{\theta,t}(x_t)]_y}{[\dot{Q}_t(x_t)]_y}

5. Training loss (score matching)

L=gt22 ∥sθ,t(xt)−∇log⁡pt(xt∣x0)∥2\mathcal{L} = \dfrac{g_t^2}{2}\,\left\| s_{\theta,t}(x_t) - \nabla \log p_t(x_t | x_0) \right\|^2

L=Q˙t(xt) KL ⁣(st(xt∣x0), sθ,t(xt))\mathcal{L} = \dot{Q}_t(x_t)\, \mathrm{KL}\!\left(s_t(x_t | x_0),\, s_{\theta,t}(x_t)\right)

Equivalence between viewpoints

In the previous sections, we introduced two discrete diffusion perspectives for transporting an initial distribution to a target discrete distribution: the variational formulation and the score-based formulation. In all this section, we assume the fully corrupted distribution is δm…m\delta_{m\ldots m} We will show with this assumption that these two viewpoints are equivalent, and then we connect them to discrete flow matching.

Equivalence between the two discrete diffusion perspectives

In this section, we demonstrate that variational inference and score matching viewpoints for discrete diffusion are equivalent. We first show that their sampling schemes coincide, and then that their training objectives are equivalent.

Sampling: We first connect the two views of discrete diffusion at the sampling level. The key idea is that the reverse rate R˙t\dot{R}_t for score-based discrete diffusion can be written in terms of the denoiser Dti(x)v=P(X0i=v∣Xt=x)D_t^i(\mathbf{x})_v=\mathbb{P}(X_0^i=v | \mathbf{X}_t=\mathbf{x}):

R˙ti(x)v=I(xi=m) −α˙t1−αt(Dti(x)v−I(v=m)).\begin{equation} \htmlData{equation-label=eq:denoiser-reverse-rate}{\htmlId{eq:denoiser-reverse-rate}{}} \dot{R}_t^i(\mathbf{x})_v = \mathbb{I}(x^i=m)\, \frac{-\dot{\alpha}_t}{1-\alpha_t} \left( D_t^i(\mathbf{x})_v - \mathbb{I}(v=m) \right). \end{equation}
Proof

For s=t−hs=t-h and a masked token xi=mx^i=m, Eq. (?) gives:

P(Xt−hi=v∣Xt=x)=αt−h−αt1−αtDti(x)v+1−αt−h1−αtI(v=m).\begin{align} \mathbb{P}(X_{t-h}^i=v | \mathbf{X}_t=\mathbf{x}) &= \frac{\alpha_{t-h}-\alpha_t}{1-\alpha_t}D_t^i(\mathbf{x})_v + \frac{1-\alpha_{t-h}}{1-\alpha_t}\mathbb{I}(v=m). \htmlData{equation-label=eq:denoiser-reverse-rate-proof-1}{\htmlId{eq:denoiser-reverse-rate-proof-1}{}} \end{align}

Since αt−h−αt=−hα˙t+o(h)\alpha_{t-h}-\alpha_t=-h\dot{\alpha}_t+o(h), we also have 1−αt−h=1−αt+hα˙t+o(h)1-\alpha_{t-h}=1-\alpha_t+h\dot{\alpha}_t+o(h). Therefore:

P(Xt−hi=v∣Xt=x)=I(v=m)+h−α˙t1−αt(Dti(x)v−I(v=m))+o(h).\begin{align} \mathbb{P}(X_{t-h}^i=v | \mathbf{X}_t=\mathbf{x}) &= \mathbb{I}(v=m) + h\frac{-\dot{\alpha}_t}{1-\alpha_t} \left(D_t^i(\mathbf{x})_v-\mathbb{I}(v=m)\right) +o(h). \htmlData{equation-label=eq:denoiser-reverse-rate-proof-2}{\htmlId{eq:denoiser-reverse-rate-proof-2}{}} \end{align}

Comparing with the continuous-time reverse-rate definition:

P(Xt−hi=v∣Xt=x)=I(v=xi)+hR˙ti(x)v+o(h),\begin{equation} \mathbb{P}(X_{t-h}^i=v | \mathbf{X}_t=\mathbf{x}) = \mathbb{I}(v=x^i)+h\dot{R}_t^i(\mathbf{x})_v+o(h), \htmlData{equation-label=eq:denoiser-reverse-rate-proof-3}{\htmlId{eq:denoiser-reverse-rate-proof-3}{}} \end{equation}

and using xi=mx^i=m gives Eq. (?). If xi≠mx^i\neq m, the token is already unmasked and the reverse masked process leaves it fixed, so the rate is zero; this gives the prefactor I(xi=m)\mathbb{I}(x^i=m).

It remains to connect Eq. (?) and Eq. (?). Starting from Eq. (?), taking s=t−hs=t-h and letting h→0h \to 0, for a masked token xti=mx_t^i=m:

xt−hi∼Cat(αt−h−αt1−αtDti(xt)+1−αt−h1−αtem)=Cat(−hα˙t+o(h)1−αtDti(xt)+1−αt+hα˙t+o(h)1−αtem)=Cat(em+h −α˙t1−αt(Dti(xt)−em)⏟1−αt−α˙tR˙ti(xt)+o(h))=Cat(exti+h R˙ti(xt)+o(h)).\begin{align} x_{t-h}^i &\sim \mathrm{Cat}\left( \frac{\alpha_{t-h}-\alpha_t}{1-\alpha_t}D_t^i(\mathbf{x}_t) + \frac{1-\alpha_{t-h}}{1-\alpha_t}\mathbf{e}_m \right) \htmlData{equation-label=eq:masked-denoiser-euler-1}{\htmlId{eq:masked-denoiser-euler-1}{}} \\ &= \mathrm{Cat}\left( \frac{-h\dot{\alpha}_t + o(h)}{1-\alpha_t}D_t^i(\mathbf{x}_t) + \frac{1-\alpha_t + h\dot{\alpha}_t + o(h)}{1-\alpha_t}\mathbf{e}_m \right) \htmlData{equation-label=eq:masked-denoiser-euler-2}{\htmlId{eq:masked-denoiser-euler-2}{}} \\ &= \mathrm{Cat}\left( \mathbf{e}_m + h\,\frac{-\dot{\alpha}_t}{1-\alpha_t} \underbrace{\left(D_t^i(\mathbf{x}_t)-\mathbf{e}_m\right)}_{ \frac{1-\alpha_t}{-\dot{\alpha}_t}\dot{R}_t^i(\mathbf{x}_t) } + o(h) \right) \htmlData{equation-label=eq:masked-denoiser-euler-3}{\htmlId{eq:masked-denoiser-euler-3}{}} \\ &= \mathrm{Cat}\left( \mathbf{e}_{x_t^i} + h\,\dot{R}_t^i(\mathbf{x}_t) + o(h) \right). \htmlData{equation-label=eq:masked-denoiser-euler-4}{\htmlId{eq:masked-denoiser-euler-4}{}} \end{align}

using αt−h−αt=−hα˙t+o(h)\alpha_{t-h} - \alpha_t = -h\dot{\alpha}_t + o(h) in the second line and Eq. (?) in the third line. If xti≠mx_t^i\neq m, both sampling processes keep the token fixed, i.e., once denoised, a token cannot be masked again or change token value.

Training Objectives: Now we turn to the corresponding training objectives. The variational perspective gives the ELBO loss Eq. (?) (which can be rewritten as Eq. (?) for Masked Diffusion), while the score-based perspective gives the concrete score matching loss Eq. (?). We now show that these two objectives are in fact the same: taking the continuous-time limit of the ELBO produces, after a change of variable, exactly the concrete score matching loss Eq. (?).

Starting from the variational loss Eq. (?), in the continuous-time limit T→∞T \to \infty, each discrete transition q(xs∣xt)q(x_s | x_t) is replaced by an instantaneous rate R˙t(xt)\dot{R}_t(x_t). This motivates introducing the conditional reverse rate R˙t(xt∣x0)\dot{R}_t(x_t | x_0), defined by the first-order Taylor expansion:

q(y∣xt,x0)=I(y=xt)+Δt [R˙t(xt∣x0)]y+o(Δt),y∈V\begin{equation} \htmlData{equation-label=eq:reverse-kernel}{\htmlId{eq:reverse-kernel}{}} q(y | x_t, x_0) = \mathbb{I}(y = x_t) + \Delta t\, [\dot{R}_t(x_t | x_0)]_y + o(\Delta t), \quad y \in \mathcal{V} \end{equation}

For Masked Diffusion, this conditional reverse rate takes the explicit form (proof below in the spoiler):

R˙t(xt∣x0)=(00∣V∣⋮00… rt …0−rt)=rt em(ex0−em)⊤\begin{equation} \htmlData{equation-label=eq:reverse-kernel-mask}{\htmlId{eq:reverse-kernel-mask}{}} \dot{R}_t(x_t | x_0) = \begin{pmatrix} & & & 0 \\ & \mathbf{0}_{|\mathcal{V}|} & & \vdots \\ & & & 0 \\ 0 & \dots \, r_t \, \dots & 0 & -r_t \end{pmatrix} = r_t\, \mathbf{e}_m (\mathbf{e}_{x_0} - \mathbf{e}_m)^\top \end{equation}

where rt=−α˙t/(1−αt)r_t = -\dot{\alpha}_t / (1 - \alpha_t) is the instantaneous unmasking rate, and the entry rtr_t in the last row appears at the column index corresponding to x0x_0. Intuitively, this rate captures the instantaneous tendency of a masked token to revert to the clean token x0x_0.

Construction of R˙t(xt∣x0)\dot{R}_t(x_t | x_0)

To derive R˙t(xt∣x0)\dot{R}_t(x_t | x_0), we write the reverse transition probabilities q(xs∣xt,x0)q(x_s | x_t, x_0) for arbitrary s<ts < t using a matrix Rs∣tx0R_{s|t}^{x_0}, and then write the first-order Taylor expansion as Δt=t−s→0\Delta t = t - s \to 0 of this matrix.

Using Eq. (?), the reverse transition q(xs∣xt,x0)q(x_s | x_t, x_0) can be written as a categorical distribution governed by a reverse matrix Rs∣tx0R_{s|t}^{x_0}:

q(xs∣xt,x0)=Cat ⁣(xs; (Rs∣tx0)⊤xt)\begin{equation} \htmlData{equation-label=eq:bridge-cat}{\htmlId{eq:bridge-cat}{}} q(x_s | x_t, x_0) = \mathrm{Cat}\!\left(x_s;\ (R_{s|t}^{x_0})^\top x_t\right) \end{equation}

and:

Rs∣tx0=(0I∣V∣⋮00…αs−αt1−αt…01−αs1−αt)∈RK×K\begin{align} R_{s|t}^{x_0} = \left( \begin{array}{ccc|c} & & & 0 \\ & I_{|\mathcal{V}|} & & \vdots \\ & & & 0 \\ \hline 0 & \dots \quad \frac{\alpha_s - \alpha_t}{1 - \alpha_t} \quad \dots & 0 & \frac{1 - \alpha_s}{1 - \alpha_t} \end{array} \right) \in \mathbb{R}^{K \times K} \htmlData{equation-label=eq:bridge-matrix}{\htmlId{eq:bridge-matrix}{}} \end{align}

where the entry αs−αt1−αt\frac{\alpha_s - \alpha_t}{1 - \alpha_t} in the last row appears at the column corresponding to x0x_0, and can be compactly written as Rs∣tx0=I+αs−αt1−αtem(ex0−em)⊤R_{s|t}^{x_0} = I + \frac{\alpha_s - \alpha_t}{1 - \alpha_t} \mathbf{e}_m(\mathbf{e}_{x_0} - \mathbf{e}_m)^\top.

Taking the first-order Taylor expansion (noting that αt−Δt−αt≈−α˙tΔt\alpha_{t - \Delta t} - \alpha_t \approx -\dot{\alpha}_t \Delta t):

Rt−Δt∣tx0=I+−α˙tΔt1−αtem(ex0−em)⊤+o(Δt)=I+Δt R˙t(xt∣x0)+o(Δt)\begin{align} R_{t - \Delta t | t}^{x_0} &= I + \frac{-\dot{\alpha}_t \Delta t}{1 - \alpha_t} \mathbf{e}_m(\mathbf{e}_{x_0} - \mathbf{e}_m)^\top + o(\Delta t) \htmlData{equation-label=eq:bridge-rate-1}{\htmlId{eq:bridge-rate-1}{}} \\ &= I + \Delta t\, \dot{R}_t(x_t | x_0) + o(\Delta t) \htmlData{equation-label=eq:bridge-rate-2}{\htmlId{eq:bridge-rate-2}{}} \end{align}

which identifies the conditional reverse rate as R˙t(xt∣x0)=rt em(ex0−em)⊤\dot{R}_t(x_t | x_0) = r_t\, \mathbf{e}_m(\mathbf{e}_{x_0} - \mathbf{e}_m)^\top with rt=−α˙t/(1−αt)r_t = -\dot{\alpha}_t / (1 - \alpha_t).

Proposition 7 (Variational and score-based diffusion loss equivalence).

In the continuous-time limit, optimizing the variational ELBO Eq. (?) is equivalent to minimizing the loss:

Lt(θ)=Ex0∼p0xt∼q(⋅∣x0)[∑y≠xt([R˙θ,t(xt)]y−[R˙t(xt∣x0)]ylog⁡[R˙θ,t(xt)]y)].\begin{equation} \htmlData{equation-label=eq:ratio-loss}{\htmlId{eq:ratio-loss}{}} L_t(\theta) = \mathbb{E}_{\substack{x_0 \sim p_0 \\ x_t \sim q( \cdot |x_0)}} \Bigg[ \sum_{y \neq x_t} \bigg( [\dot{R}_{\theta,t}(x_t)]_y - [\dot{R}_t(x_t | x_0)]_y \log [\dot{R}_{\theta,t}(x_t)]_y \bigg) \Bigg]. \end{equation}
Continuous-time limit proof

We start from the full ELBO derived in Eq. (?):

The first term is independent of θ\theta, so we focus on the KL terms inside the sum. Let Δt=1/T\Delta t = 1/T, t=j/Tt = j/T, and s=(j−1)/Ts = (j-1)/T. Using Eq. (?) and the learned analogue of Eq. (?), the jj-th KL [KL ⁣(q ⁣(x(j−1)/T∣xj/T,x0), pθ ⁣(x(j−1)/T∣xj/T))]\left[ \mathrm{KL}\!\left(q\!\left(x_{(j-1)/T} | x_{j/T}, x_0\right),\, p_\theta\!\left(x_{(j-1)/T} | x_{j/T}\right)\right) \right] expands over the vocabulary as:

KL(q(⋅∣xt,x0),pθ(⋅∣xt))=∑y∈Vq(y∣xt,x0)⏟I(y=xt)+Δt[R˙t(xt∣x0)]y+o(Δt)log⁡q(y∣xt,x0)pθ(y∣xt)⏟I(y=xt)+Δt[R˙θ,t(xt)]y+o(Δt)\begin{align} \mathrm{KL}\left(q( \cdot | x_t, x_0) , p_\theta( \cdot | x_t)\right) &= \sum_{y \in \mathcal{V}} \underbrace{q(y | x_t, x_0)}_{\mathbb{I}(y=x_t)+\Delta t[\dot{R}_t(x_t|x_0)]_y+o(\Delta t)} \log \frac{ q(y | x_t, x_0) }{ \underbrace{p_\theta(y | x_t)}_{\mathclap{\mathbb{I}(y=x_t)+\Delta t[\dot{R}_{\theta,t}(x_t)]_y+o(\Delta t)}} } \htmlData{equation-label=eq:ratio-kl-1}{\htmlId{eq:ratio-kl-1}{}} \end{align}

Separating the sum into the case where the token changes (y≠xty \neq x_t) and stays the same (y=xty = x_t):

  1. For y≠xty \neq x_t:
(Δt [R˙t(xt∣x0)]y+o(Δt))log⁡Δt [R˙t(xt∣x0)]y+o(Δt)Δt [R˙θ,t(xt)]y+o(Δt)=Δt [R˙t(xt∣x0)]ylog⁡[R˙t(xt∣x0)]y[R˙θ,t(xt)]y+o(Δt)\begin{align} & (\Delta t\, [\dot{R}_t(x_t | x_0)]_y + o(\Delta t)) \log \frac{\Delta t\, [\dot{R}_t(x_t | x_0)]_y + o(\Delta t)}{\Delta t\, [\dot{R}_{\theta,t}(x_t)]_y + o(\Delta t)} \htmlData{equation-label=eq:ratio-kl-term-1}{\htmlId{eq:ratio-kl-term-1}{}} \\ & \quad = \Delta t\, [\dot{R}_t(x_t | x_0)]_y \log \frac{[\dot{R}_t(x_t | x_0)]_y}{[\dot{R}_{\theta,t}(x_t)]_y} + o(\Delta t) \notag \end{align}
  1. For y=xty = x_t, using the expansion log⁡1+a1+b=a−b+o(∣a∣+∣b∣)\log \frac{1+a}{1+b} = a - b + o(|a|+|b|):
(1+Δt [R˙t(xt∣x0)]xt+o(Δt))log⁡1+Δt [R˙t(xt∣x0)]xt+o(Δt)1+Δt [R˙θ,t(xt)]xt+o(Δt)=Δt [R˙t(xt∣x0)]xt−Δt [R˙θ,t(xt)]xt+o(Δt)=Δt(−∑y≠xt[R˙t(xt∣x0)]y+∑y≠xt[R˙θ,t(xt)]y)+o(Δt)\begin{align} & (1 + \Delta t\, [\dot{R}_t(x_t | x_0)]_{x_t} + o(\Delta t)) \log \frac{1 + \Delta t\, [\dot{R}_t(x_t | x_0)]_{x_t} + o(\Delta t)}{1 + \Delta t\, [\dot{R}_{\theta,t}(x_t)]_{x_t} + o(\Delta t)} \htmlData{equation-label=eq:ratio-kl-term-2-1}{\htmlId{eq:ratio-kl-term-2-1}{}} \notag \\ & \quad = \Delta t\, [\dot{R}_t(x_t | x_0)]_{x_t} - \Delta t\, [\dot{R}_{\theta,t}(x_t)]_{x_t} + o(\Delta t) \htmlData{equation-label=eq:ratio-kl-term-2-2}{\htmlId{eq:ratio-kl-term-2-2}{}} \\ & \quad = \Delta t \left( - \sum_{y \neq x_t} [\dot{R}_t(x_t | x_0)]_y + \sum_{y \neq x_t} [\dot{R}_{\theta,t}(x_t)]_y \right) + o(\Delta t) \htmlData{equation-label=eq:ratio-kl-term-2-3}{\htmlId{eq:ratio-kl-term-2-3}{}} \end{align}

Combining these terms, the jj-th KL term becomes:

KL=Δt∑y≠xt([R˙θ,t(xt)]y−[R˙t(xt∣x0)]ylog⁡[R˙θ,t(xt)]y+[R˙t(xt∣x0)]ylog⁡[R˙t(xt∣x0)]y−[R˙t(xt∣x0)]y⏟ independent of θ)+o(Δt).\begin{align} \mathrm{KL} &= \Delta t \sum_{y \neq x_t} \Bigg( [\dot{R}_{\theta,t}(x_t)]_y - [\dot{R}_t(x_t | x_0)]_y \log [\dot{R}_{\theta,t}(x_t)]_y \htmlData{equation-label=eq:ratio-kl-sum-1}{\htmlId{eq:ratio-kl-sum-1}{}} \\ &\quad + \underbrace{ [\dot{R}_t(x_t | x_0)]_y \log [\dot{R}_t(x_t | x_0)]_y - [\dot{R}_t(x_t | x_0)]_y }_{\text{ independent of }\theta} \Bigg) + o(\Delta t). \notag \end{align}

Writing tt=j/Tt_t=j/T and Δt=1/T\Delta t=1/T, the ELBO Eq. (?) is therefore (grouping the θ\theta-independent above and KL(q(x1∣x0),pT)\mathrm{KL}(q(x_1 | x_0) , p_T) into a constant CC):

∑j=1TExtt∼q(⋅∣x0)[KL(q(xtt−Δt∣xtt,x0),pθ(xtt−Δt∣xtt))]=∑j=1TΔt Extt∼q(⋅∣x0)[∑y≠xtt([R˙θ,tt(xtt)]y−[R˙tt(xtt∣x0)]ylog⁡[R˙θ,tt(xtt)]y)]+C+o(1),\begin{align} &\sum_{j=1}^{T} \mathbb{E}_{x_{t_t}\sim q(\cdot|x_0)} \left[ \mathrm{KL}\left(q(x_{t_t-\Delta t}|x_{t_t},x_0),p_\theta(x_{t_t-\Delta t}|x_{t_t})\right) \right] \htmlData{equation-label=eq:final-celbo}{\htmlId{eq:final-celbo}{}} \\ &= \sum_{j=1}^{T}\Delta t\, \mathbb{E}_{x_{t_t}\sim q(\cdot|x_0)} \Bigg[ \sum_{y\neq x_{t_t}} \bigg( [\dot{R}_{\theta,t_t}(x_{t_t})]_y -[\dot{R}_{t_t}(x_{t_t}|x_0)]_y \log [\dot{R}_{\theta,t_t}(x_{t_t})]_y \htmlData{equation-label=eq:ratio-riemann-1}{\htmlId{eq:ratio-riemann-1}{}} \bigg) \Bigg] + C + o(1), \notag \end{align}

where CC collects the terms independent of θ\theta. Taking T→∞T\to\infty turns the sum into a Riemann integral over tt, whose integrand is exactly the loss Eq. (?).

It remains to express Eq. (?) in terms of the concrete score. Writing the reverse rates as [R˙t(xt)]y=[Q˙t(xt)]y st(xt)y[\dot{R}_{t}(x_t)]_y = [\dot{Q}_t(x_t)]_y\,s_{t}(x_t)_y (see Eq. (?)), we recover, up to a θ\theta-independent constant, the concrete score matching loss Eq. (?) established in the score-based perspective. The two viewpoints therefore minimize the same objective.

Equivalence derivation

Applying Bayes’ theorem to xt→xsx_t \to x_s conditioned on x0x_0 gives:

R˙t(xt∣x0)y=[Q˙t(xt)]ypt(y∣x0)pt(xt∣x0)\begin{equation} \htmlData{equation-label=eq:reverse-bayes}{\htmlId{eq:reverse-bayes}{}} \dot{R}_t(x_t | x_0)_y = [\dot{Q}_t(x_t)]_y \frac{p_t(y|x_0)}{p_t(x_t|x_0)} \end{equation}

Substituting [R˙θ,t(xt)]y=[Q˙t(xt)]y sθ,t(xt)y[\dot{R}_{\theta,t}(x_t)]_y = [\dot{Q}_t(x_t)]_y\,s_{\theta,t}(x_t)_y and the expression above into Eq. (?):

Lt(θ)=Ex0∼p0xt∼q(⋅∣x0)[∑y≠xt([Q˙t(xt)]ysθ,t(xt)y−([Q˙t(xt)]ypt(y∣x0)pt(xt∣x0))log⁡([Q˙t(xt)]ysθ,t(xt)y))]\begin{equation} \htmlData{equation-label=eq:score-loss}{\htmlId{eq:score-loss}{}} \begin{aligned} L_t(\theta) &= \mathbb{E}_{\substack{x_0 \sim p_0 \\ x_t \sim q( \cdot |x_0)}} \Bigg[ \sum_{y \neq x_t} \Bigg( [\dot{Q}_t(x_t)]_y s_{\theta,t}(x_t)_y \\ &\quad - \left( [\dot{Q}_t(x_t)]_y \frac{p_t(y|x_0)}{p_t(x_t|x_0)} \right) \log \left( [\dot{Q}_t(x_t)]_y s_{\theta,t}(x_t)_y \right) \Bigg) \Bigg] \end{aligned} \end{equation}

Expanding the logarithm gives:

Lt(θ)=Ex0∼p0xt∼q(⋅∣x0)[∑y≠xt([Q˙t(xt)]ysθ,t(xt)y−[Q˙t(xt)]ypt(y∣x0)pt(xt∣x0)log⁡[Q˙t(xt)]y−[Q˙t(xt)]ypt(y∣x0)pt(xt∣x0)log⁡sθ,t(xt)y)].=Ex0∼p0xt∼q(⋅∣x0)[∑y≠xt[Q˙t(xt)]y(sθ,t(xt)y−pt(y∣x0)pt(xt∣x0)log⁡sθ,t(xt)y)]+Ex0∼p0xt∼q(⋅∣x0)[∑y≠xt−[Q˙t(xt)]ypt(y∣x0)pt(xt∣x0)log⁡[Q˙t(xt)]y]⏟C independent of θ.\begin{align} L_t(\theta) &= \mathbb{E}_{\substack{x_0 \sim p_0 \\ x_t \sim q( \cdot |x_0)}} \Bigg[ \sum_{y \neq x_t} \Bigg( [\dot{Q}_t(x_t)]_y s_{\theta,t}(x_t)_y \htmlData{equation-label=eq:score-loss-expand-1}{\htmlId{eq:score-loss-expand-1}{}} \\ &\qquad - [\dot{Q}_t(x_t)]_y \frac{p_t(y|x_0)}{p_t(x_t|x_0)} \log [\dot{Q}_t(x_t)]_y \notag \\ &\qquad - [\dot{Q}_t(x_t)]_y \frac{p_t(y|x_0)}{p_t(x_t|x_0)} \log s_{\theta,t}(x_t)_y \Bigg) \Bigg]. \notag \\ &= \mathbb{E}_{\substack{x_0 \sim p_0 \\ x_t \sim q( \cdot |x_0)}} \Bigg[ \sum_{y \neq x_t} [\dot{Q}_t(x_t)]_y \bigg( s_{\theta,t}(x_t)_y - \frac{p_t(y|x_0)}{p_t(x_t|x_0)} \log s_{\theta,t}(x_t)_y \bigg) \Bigg] \htmlData{equation-label=eq:score-loss-expand-group-1}{\htmlId{eq:score-loss-expand-group-1}{}} \\ &\quad + \underbrace{ \mathbb{E}_{\substack{x_0 \sim p_0 \\ x_t \sim q( \cdot |x_0)}} \Bigg[ \sum_{y \neq x_t} - [\dot{Q}_t(x_t)]_y \frac{p_t(y|x_0)}{p_t(x_t|x_0)} \log [\dot{Q}_t(x_t)]_y \Bigg] }_{C\ \text{independent of }\theta}. \notag \end{align}

This is exactly the loss Eq. (?) of the concrete score matching proposition.

Equivalence with discrete flow matching

We now connect discrete diffusion to discrete flow matching. In discrete flow matching, a velocity field utu_t defines the Euler sampling scheme:

xt+h∼Cat ⁣(ext+h ut(xt)).\begin{equation} \htmlData{equation-label=eq:dfm-euler-sampling}{\htmlId{eq:dfm-euler-sampling}{}} x_{t+h} \sim \mathrm{Cat}\!\left(\mathbf{e}_{x_t} + h\,u_t(x_t)\right). \end{equation}

We show that this sampling rule is equivalent to sampling in discrete diffusion (Eq. (?)).

Sampling: To align these two sampling equations directly, we must first account for the main discrepancy between the frameworks: their time conventions. In discrete diffusion, t=0t = 0 corresponds to clean data, and t=1t = 1 corresponds to the fully masked state. Discrete flow matching uses the exact opposite convention.

Suppose we know the discrete diffusion reverse rate R˙t\dot{R}_t. We define the flow matching velocity by the time reversal:

ut′FM=R˙1−t′\begin{equation} \htmlData{equation-label=eq:time-reversal}{\htmlId{eq:time-reversal}{}} u_{t'}^{\text{FM}} = \dot{R}_{1-t'} \end{equation}

Then, sampling from discrete diffusion using Eq. (?) is equivalent to sampling from the flow matching Euler scheme Eq. (?): for every t′∈[0,1]t'\in[0,1], the distribution pt′FMp^{\mathrm{FM}}_{t'} of samples obtained by simulating flow matching from 00 to t′t' is the same as the distribution p1−t′DDp^{\mathrm{DD}}_{1-t'} obtained by simulating the discrete diffusion reverse CTMC from 11 to 1−t′1-t', i.e. pt′FM=p1−t′DDp^{\mathrm{FM}}_{t'} = p^{\mathrm{DD}}_{1-t'}.

Proof

We start from the infinitesimal reverse-time transition of the discrete diffusion process Eq. (?).

We first perform the variable change t′=1−tt' = 1 - t in Eq. (?). We have t=1−t′t = 1 - t', so xt=x1−t′x_t = x_{1-t'} and xt−Δt=x1−t′−Δtx_{t - \Delta t} = x_{1 - t' - \Delta t}. The rate evaluates at R˙1−t′\dot{R}_{1-t'}, giving:

p(x1−t′−Δt=y∣x1−t′)=I(y=x1−t′)+Δt [R˙1−t′(x1−t′)]y+o(Δt)\begin{equation} \htmlData{equation-label=eq:time-change}{\htmlId{eq:time-change}{}} p(x_{1-t'-\Delta t} = y | x_{1-t'}) = \mathbb{I}(y = x_{1-t'}) + \Delta t \, [\dot{R}_{1-t'}(x_{1-t'})]_y + o(\Delta t) \end{equation}

Since tFM=1−tDDt_{\text{FM}} = 1 - t_{\text{DD}}, we identify xt′FM=x1−t′x^{\text{FM}}_{t'} = x_{1-t'}. We deduce xt′+ΔtFM=x1−t′−Δtx^{\text{FM}}_{t' + \Delta t} = x_{1 - t' - \Delta t}. Substituting these identities into Eq. (?):

p(xt′+ΔtFM=y∣xt′FM)=I(y=xt′FM)+Δt [R˙1−t′(xt′FM)]y+o(Δt)\begin{equation} \htmlData{equation-label=eq:fm-step}{\htmlId{eq:fm-step}{}} p(x^{\text{FM}}_{t' + \Delta t} = y | x^{\text{FM}}_{t'}) = \mathbb{I}(y = x^{\text{FM}}_{t'}) + \Delta t \, [\dot{R}_{1-t'}(x^{\text{FM}}_{t'})]_y + o(\Delta t) \end{equation}

Recall the definition of a probability velocity: a velocity field ut′u_{t'} generates a process xt′FMx^{\text{FM}}_{t'} if and only if p(xt′+ΔtFM=y∣xt′FM=x)=I(y=xt′FM)+Δt [ut′(xt′FM)]y+o(Δt)p(x^{\text{FM}}_{t' + \Delta t} = y | x^{\text{FM}}_{t'} = x) = \mathbb{I}(y = x^{\text{FM}}_{t'}) + \Delta t \, [u_{t'}(x^{\text{FM}}_{t'})]_y + o(\Delta t).

Identifying the first-order terms in Eq. (?) with the probability-velocity definition directly gives:

[ut′FM(x)]y=[R˙1−t′(x)]y\begin{equation} \htmlData{equation-label=eq:time-reversal-velocity}{\htmlId{eq:time-reversal-velocity}{}} [u_{t'}^{\text{FM}}(x)]_y = [\dot{R}_{1-t'}(x)]_y \end{equation}

and therefore ut′FM=R˙1−t′u_{t'}^{\text{FM}} = \dot{R}_{1-t'}.

Training Objectives: Now we show how their training objectives line up. The variational diffusion perspective gives the Masked Diffusion objective Eq. (?). In discrete flow matching, the velocity can be parameterized through a denoiser Pθ,t(X1i=x1i∣Xt=x)P_{\theta,t}(X_1^i = x_1^i | X_t=\mathbf{x}), trained with the cross-entropy objective:

LCDM(θ)=−Et∼U(0,1)x1∼p0x∼pt(⋅∣x1)[∑i=1Slog⁡Pθ,t(X1i=x1i∣Xt=x)].\begin{equation} \htmlData{equation-label=eq:cdm-loss}{\htmlId{eq:cdm-loss}{}} L_{\text{CDM}}(\theta) = -\mathbb{E}_{\substack{t \sim \mathcal{U}(0,1) \\ \mathbf{x}_1 \sim p_0 \\ \mathbf{x} \sim p_t( \cdot | \mathbf{x}_1)}} \left[ \sum_{i=1}^S \log P_{\theta,t}(X_1^i = x_1^i | X_t = \mathbf{x}) \right]. \end{equation}

To directly compare the two training losses, we first note that the denoiser used by discrete flow matching and the denoiser used by variational diffusion in Eq. (?) are exactly the same object. Applying the time reversal tFM=1−tDDt_{\text{FM}} = 1 - t_{\text{DD}} and identifying the clean data x1=x0x_1=x_0, we get:

Dθ,tDDi(x)x0i=Pθ,tDD(X0i=x0i∣XtDD=x)=Pθ,tFM(X1i=x1i∣XtFM=x).\begin{align} D_{\theta,t_{\text{DD}}}^i(\mathbf{x})_{x_0^i} &= P_{\theta,t_{\text{DD}}}(X_0^i=x_0^i | X_{t_{\text{DD}}}=\mathbf{x}) \htmlData{equation-label=eq:denoiser-time-identification-1}{\htmlId{eq:denoiser-time-identification-1}{}} \\ &= P_{\theta,t_{\text{FM}}}(X_1^i=x_1^i | X_{t_{\text{FM}}}=\mathbf{x}). \htmlData{equation-label=eq:denoiser-time-identification-2}{\htmlId{eq:denoiser-time-identification-2}{}} \end{align}
Proposition 8 (Masked diffusion/CDM loss equivalence).

Under the time reversal tFM=1−tDDt_{\text{FM}}=1-t_{\text{DD}}, the Masked Diffusion training loss LMDM(t)L_{\text{MDM}}(t) from Eq. (?) is directly comparable to the denoising loss LCDM(t)L_{\text{CDM}}(t) from Eq. (?). At fixed flow-matching time tt:

LMDM(t)≈11−t LCDM(t).\begin{equation} \htmlData{equation-label=eq:mdm-cdm-scale}{\htmlId{eq:mdm-cdm-scale}{}} L_{\text{MDM}}(t) \approx \frac{1}{1-t} \, L_{\text{CDM}}(t). \end{equation}
Derivation

Under the time reversal above, the weight in Eq. (?) satisfies −α˙tDD/(1−αtDD)=1/tDD=1/(1−tFM)-\dot{\alpha}_{t_{\text{DD}}}/(1-\alpha_{t_{\text{DD}}})=1/t_{\text{DD}}=1/(1-t_{\text{FM}}). Therefore the Masked Diffusion loss Eq. (?) becomes the weighted masked cross-entropy:

LMDM(t)=E ⁣[ ∑i=1SI(xti=m)⋅11−t⋅(−log⁡Pθ,t(X1i=x1i∣xt))].\begin{equation} \htmlData{equation-label=eq:mdm-mask-loss-fm-time}{\htmlId{eq:mdm-mask-loss-fm-time}{}} L_{\text{MDM}}(t) = \mathbb{E}\!\left[\,\sum_{i=1}^S \mathbb{I}(x_t^i = m) \cdot \frac{1}{1-t} \cdot \left(-\log P_{\theta,t}(X_1^i = x_1^i | \mathbf{x}_t)\right)\right]. \end{equation}

Since P(xti=m)=1−tP(x_t^i = m) = 1-t, applying the law of total expectation, E[Z]=P(xti=m)E[Z∣xti=m]+P(xti≠m)E[Z∣xti≠m]\mathbb{E}[Z]=P(x_t^i=m)\mathbb{E}[Z|x_t^i=m]+P(x_t^i\neq m)\mathbb{E}[Z|x_t^i\neq m]:

LMDM(t)=(1−t)⋅11−t⋅E ⁣[−log⁡Pθ,t(X1i=x1i∣xt)∣xti=m]+t⋅E ⁣[I(xti=m)11−t(−log⁡Pθ,t(X1i=x1i∣xt))∣xti≠m]⏟0 since xti≠m=E ⁣[−log⁡Pθ,t(X1i=x1i∣xt)∣xti=m].\begin{align} L_{\text{MDM}}(t) \htmlData{equation-label=eq:mdm-t-1}{\htmlId{eq:mdm-t-1}{}} &= (1-t) \cdot \frac{1}{1-t} \cdot \mathbb{E}\!\left[ \htmlData{equation-label=eq:mdm-t-2}{\htmlId{eq:mdm-t-2}{}} -\log P_{\theta,t}(X_1^i = x_1^i | \mathbf{x}_t) \htmlData{equation-label=eq:mdm-t-3}{\htmlId{eq:mdm-t-3}{}} | x_t^i = m \htmlData{equation-label=eq:mdm-t-4}{\htmlId{eq:mdm-t-4}{}} \right] \htmlData{equation-label=eq:mdm-t-5}{\htmlId{eq:mdm-t-5}{}} \\ &\quad + t \cdot \underbrace{\mathbb{E}\!\left[ \mathbb{I}(x_t^i=m)\frac{1}{1-t} \left(-\log P_{\theta,t}(X_1^i = x_1^i | \mathbf{x}_t)\right) | x_t^i \neq m \right]}_{0\ \text{since }x_t^i\neq m} \notag \\ &= \mathbb{E}\!\left[ \htmlData{equation-label=eq:mdm-t-6}{\htmlId{eq:mdm-t-6}{}} -\log P_{\theta,t}(X_1^i = x_1^i | \mathbf{x}_t) \htmlData{equation-label=eq:mdm-t-7}{\htmlId{eq:mdm-t-7}{}} | x_t^i = m \htmlData{equation-label=eq:mdm-t-8}{\htmlId{eq:mdm-t-8}{}} \right]. \htmlData{equation-label=eq:mdm-t-9}{\htmlId{eq:mdm-t-9}{}} \end{align}

We decompose LCDML_{\text{CDM}} using the same law of total expectation, splitting over masked and unmasked positions:

LCDM(t)=(1−t)⋅E ⁣[−log⁡Pθ,t(X1i=x1i∣xt)∣xti=m]+t⋅E ⁣[−log⁡Pθ,t(X1i=x1i∣xt)∣xti≠m].\begin{align} L_{\text{CDM}}(t) \htmlData{equation-label=eq:cm-t-1}{\htmlId{eq:cm-t-1}{}} &= (1-t) \cdot \mathbb{E}\!\left[ \htmlData{equation-label=eq:cm-t-2}{\htmlId{eq:cm-t-2}{}} -\log P_{\theta,t}(X_1^i = x_1^i | \mathbf{x}_t) \htmlData{equation-label=eq:cm-t-3}{\htmlId{eq:cm-t-3}{}} | x_t^i = m \htmlData{equation-label=eq:cm-t-4}{\htmlId{eq:cm-t-4}{}} \right] \htmlData{equation-label=eq:cm-t-5}{\htmlId{eq:cm-t-5}{}} \\ &\quad + t \cdot \mathbb{E}\!\left[ \htmlData{equation-label=eq:cm-t-6}{\htmlId{eq:cm-t-6}{}} -\log P_{\theta,t}(X_1^i = x_1^i | \mathbf{x}_t) \htmlData{equation-label=eq:cm-t-7}{\htmlId{eq:cm-t-7}{}} | x_t^i \neq m \htmlData{equation-label=eq:cm-t-8}{\htmlId{eq:cm-t-8}{}} \right]. \notag \end{align}

For unmasked positions ii, a well trained denoiser should just copy the current token xti=x1ix_t^i=x_1^i it sees, therefore Pθ,t(X1i=x1i∣xt)=1P_{\theta,t}(X_1^i=x_1^i|\mathbf{x}_t)=1, and the second term vanishes, giving:

LCDM(t)≈(1−t)⋅E ⁣[−log⁡Pθ,t(X1i=x1i∣xt)∣xti=m].\begin{equation} \htmlData{equation-label=eq:cm-mask-loss}{\htmlId{eq:cm-mask-loss}{}} L_{\text{CDM}}(t) \approx (1-t) \cdot \mathbb{E}\!\left[ -\log P_{\theta,t}(X_1^i = x_1^i | \mathbf{x}_t) | x_t^i = m \right]. \end{equation}

Both expressions share the same conditional expectation. Eliminating it yields Eq. (?).

Disclaimer In general, learning a velocity field uu (or equivalently a reverse rate R˙\dot{R}) with Eq. (?) is not equivalent to learning a denoiser with Eq. (?) for arbitrary source distributions or paths, for instance under uniform diffusion.

References

  1. Argmax Flows and Multinomial Diffusion: Learning Categorical Distributions [PDF]
    Emiel Hoogeboom, Didrik Nielsen, Priyank Jaini, Patrick Forre, Max Welling. NeurIPS 2021.
  1. Structured Denoising Diffusion Models in Discrete State-Spaces [PDF]
    Jacob Austin, Daniel D. Johnson, Jonathan Ho, Daniel Tarlow, Rianne van den Berg. NeurIPS 2021.
  1. A Continuous Time Framework for Discrete Denoising Models [PDF]
    Andrew Campbell, Joe Benton, Tom Rainforth, George Deligiannidis, Arnaud Doucet. NeurIPS 2022.
  1. Discrete Diffusion Modeling by Estimating the Ratios of the Data Distribution [PDF]
    Aaron Lou, Chenlin Meng, Stefano Ermon. ICML 2024.
  1. Generative Flows on Discrete State-Spaces: Enabling Multimodal Flows with Applications to Protein Co-Design [PDF]
    Andrew Campbell, Jason Yim, Regina Barzilay, Tom Rainforth, Tommi Jaakkola. ICML 2024.
  1. DiGress: Discrete Denoising diffusion for graph generation [PDF]
    Clement Vignac, Igor Krawczuk, Antoine Siraudin, Bohan Wang, Volkan Cevher, Pascal Frossard. ICLR 2023.
  1. Scaling Rectified Flow Transformers for High-Resolution Image Synthesis [PDF]
    Patrick Esser, Sumith Kulal, Andreas Blattmann, Rahim Entezari, Jonas Müller, Harry Saini, Yam Levi, Dominik Lorenz, Axel Sauer, Frederic Boesel, Dustin Podell, Tim Dockhorn, Zion English, Kyle Lacey, Alex Goodwin, Yannik Marek, Robin Rombach. ICML 2024.
  1. Stable Video Diffusion: Scaling Latent Video Diffusion Models to Large Datasets [PDF]
    Andreas Blattmann, Tim Dockhorn, Sumith Kulal, Daniel Mendelevitch, Maciej Kilian, Dominik Lorenz, Yam Levi, Zion English, Vikram Voleti, Adam Letts, Varun Jampani, Robin Rombach. Arxiv 2023.
  1. Generative Modeling by Estimating Gradients of the Data Distribution [PDF]
    Yang Song, Stefano Ermon, NeurIPS 2019.
  1. Deep Unsupervised Learning using Nonequilibrium Thermodynamics [PDF]
    Jascha Sohl-Dickstein, Eric Weiss, Niru Maheswaranathan, Surya Ganguli. PMLR 2015.
  1. Denoising Diffusion Probabilistic Models [PDF]
    Jonathan Ho, Ajay Jain, Pieter Abbeel. NeurIPS 2020.
  1. Score-Based Generative Modeling through Stochastic Differential Equations [PDF]
    Yang Song, Jascha Sohl-Dickstein, Diederik P. Kingma, Abhishek Kumar, Stefano Ermon, Ben Poole. ICLR 2021.
  1. Simplified and Generalized Masked Diffusion for Discrete Data [PDF]
    Jiaxin Shi, Kehang Han, Zhe Wang, Arnaud Doucet, Michalis K. Titsias. NeurIPS 2024.

Notes

For more details, see our blog post on discrete flow matching.

Here KL\mathrm{KL} denotes the generalized KL divergence between two positive vectors a,b∈R+da,b \in \mathbb{R}_+^d, KL(a,b)=∑j=1dajlog⁡(aj/bj)−aj+bj\mathrm{KL}(a,b) = \sum_{j=1}^d a_j \log(a_j/b_j) - a_j + b_j.

Up to a constant CC independent of θ\theta, Eq. (?) is KL(R˙t(xt∣x0), R˙θ,t(xt))\mathrm{KL}\left(\dot{R}_t(x_t | x_0),\, \dot{R}_{\theta,t}(x_t)\right).

We note q(xs∣xt,x0)q(x_s | x_t, x_0) the conditional law q(Xs=⋅∣Xt=xt,X0=x0)q(X_s = \cdot | X_t = x_t, X_0 = x_0).

For simplicity, we consider [Dθ,t(xt)]m=0[D_{\theta,t}(x_t)]_m = 0.

Passing from the single-token derivation to the full sequence uses two assumptions:

  1. The forward transition factorizes token-wise: q(Xt=xt∣Xs=xs)=∏i=1Sq(Xti=xti∣Xsi=xsi)q(\mathbf{X}_t=\mathbf{x}_t | \mathbf{X}_s=\mathbf{x}_s)=\prod_{i=1}^S q(X_t^i=x_t^i | X_s^i=x_s^i).
  2. The denoiser factorizes position per position: P(X0=x0∣Xt=xt)=∏i=1SP(X0i=x0i∣Xt=xt)\mathbb{P}(\mathbf{X}_0=\mathbf{x}_0 | \mathbf{X}_t=\mathbf{x}_t)=\prod_{i=1}^S \mathbb{P}(X_0^i=x_0^i | \mathbf{X}_t=\mathbf{x}_t). Each per-position prediction still use the whole current sequence xt\mathbf{x}_t as context.