S=VS space of all possible sequences of length S over the vocabulary
x=x1…xS sequence of S tokens, where each token xi takes values in V
ev one-hot vector in R∣V∣ for token v∈V
m mask token
x=i sub-sequence of x at all positions except i
Δk for k∈N, Δk={π∈R+k:∑ℓ=1kπℓ=1} is the probability simplex
Cat categorical distribution: x∼Cat(p) means P(x=v)=pv, for a probability vector p∈Δ∣V∣
punif uniform distribution: punif(v)=∣V∣1
Convention: t=0: noisy data; t=1: clean data.
p0 source distribution (mask or uniform)
p1 target (data) distribution
pt marginal distribution at time t; the probability path interpolating between the source p0 and the target p1 distributions
z conditioning variable, of law π(z)
pt(x∣z)=∏j=1Sqt(xj∣zj) factorized conditional probability path given the conditioning variable z
qt(x∣z) token-wise conditional distribution given z
ut(x)y velocity: the instantaneous rate at which the sequence transitions from x to y at time t
uti(x)v token-wise velocity at position i: the instantaneous rate at which the i-th token of x transitions to v at time t
ut(x∣z)y conditional velocity field given z
uθ,ti(x)v learned velocity field parameterized by θ
Pθ,t(X1i∣xt) learned denoiser: at coordinate j, probability that the i-th token at time 1 is ej, given current sequence xt
Flow matching and diffusion have emerged as the state-of-the-art techniques for generation of continuous data modalities, in particular images, audio and video [6, 7].
Their strong generation performance, training stability and flexibility motivated their extension to discrete data, including texts, graphs, or molecule sequences [1, 2, 5].
This blog post is an introduction to flow matching for discrete data.
A second part TODO link is dedicated to discrete diffusion.
The first section is an introduction to discrete data generation, and discrete flow matching is introduced in Section 2.
Generating discrete data
Discrete data
Autoregressive generative models have being especially successful for generation of sequences of discrete elements.
For instance, language models generate sequences of tokens (words or subwords) from a predefined discrete set (the vocabulary).
More precisely, in this blog post, we present flow matching/diffusion for sequences of discrete data:
sequences x=x1…xS of length S∈N,
where each element xi belongs to a predefined discrete/finite set called the vocabularyV: xi∈V.
Sequence x = x1x2x3x4of length 4
x1A
x2A
x3B
x4B
Vocabulary of 3 elements𝒱 = {A, B, m}
A
B
m
Figure 1: A toy vocabulary V of 3 elements: V={A,B,m} and an example sequence of length 4: each element xi of the sequence belongs to V: x1,x2,x3,x4∈V.
Elements of the vocabulary are called tokens. For example, for text data, tokens could be the letters: V={a,b,c,…,z}, while DNA sequences would correspond to V={A,T,C,G}.
In the vocabulary, a special token can be added, the mask token m.
Discrete data generation process
Discrete generative modelling on Sudoku.
The goal is to generate valid Sudoku grids, which are 9×9 grids filled with numbers from 1 to 9, such that each number appears exactly once in each row, column.
The vocabulary is the set of numbers from 1 to 9: V={1,2,…,9,m}, and the sequence length is number of squares to fill S=9×9=81.
Discrete diffusion/flow matching on Sudoku.
Discrete flow matching starts from a fully masked grid: each square is initially filled with the mask token m.
The model then iteratively fills this grid with non-mask tokens {1,2,…,9}. For example, one can iteratively unmask the grid one square after one square, and finally reach a filled Sudoku grid.
QBE: todo do a sort of gif?
Generating a Sudoku grid
t = 0.00
Diffusion
random order
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
81Masked
0Generated
Autoregressive
left to right
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
m
81Masked
0Generated
Masked [M]
Generated
Figure 2: Visualization of the sampling process for discrete flow matching: a fully masked Sudoku 9×9 grid is transformed into a valid 9×9 Sudoku grid.
Section 2 provides the details on to generate discrete data with discrete flow matching.
Discrete flow matching
Transporting distributions
Discrete flow matching iteratively transforms fully masked samples/images into samples/images from the target distribution.
At the distribution level, discrete flow matching can be seen as a transport of a simple source probability distribution p0 (e.g., x0∼p0 fully masked) to a target distribution p1, the data distribution we want to generate.
QBE: introduce later?
x0 ∼ p0
mmmm
mmmm
mmmm
mmmm
xt ∼ pt
mAmm
Ammm
mBmm
mAAB
x1 ∼ p1
AAAB
ABBB
BBBB
AAAB
Figure 3: The transport from the source p0 to the target p1, shown both as distributions over the whole sequence space S=VS and as samples xt∼pt drawn below each distribution. Each bar is one sequence x∈S, ordered by number of mask tokens, so that the fully masked sequence mmmm is right-most. At t=0 all the mass sits on the Dirac δm…m; as t grows that mass decreases and spreads over partially unmasked sequences, until it vanishes at t=1 and only p1 remains. p1 is the distribution where token B is not allowed to be placed before a A in the sequence. Bar heights use a square-root scale, so that the source Dirac and the much flatter intermediate distributions stay legible on the same axis.
The source distribution is typically chosen to be the mask distribution (p0=δm…m): all tokens in the starting sequence are equal to the mask token m; δ is the Dirac delta distribution.
QBE: schema transport distributions?
QBE: todo footnote uniform - The uniform distribution (p0=punif): All tokens in the starting sequence are sampled uniformly across the vocabulary V.
QBE: decide what to do with this figure. Not sure it is cristal clear.
Flow matching: from continuous-space discrete-space data
Reminder on flow matching for continuous data
See the former blog post for a comprehensive explanation.
In continuous-space flow matching, generated samples are obtained by solving the following Ordinary Differential Equation (ODE)
{x(0)=x0∂tx(t)=ut(x(t)),∀t∈[0,1]
which is driven by the so-called velocity fieldu:Rd×[0,1]→Rd.
From continuous-space to discrete-space
QBE: comparison Algorithm Euler continuous vs discrete? + pixel vs sequence
QBE: discussion “shape” of u
QBE todo rephrase. As solving an ODE on a discrete space is not possible (since at each time t, the current state is xt should be a discrete sequence), the generation process in discrete flow matching is different.
It is defined as
xt+h∼Cat(ext+hut(xt))+o(h),
where u:S×[0,1]→RS is the velocity field, ex∈R∣S∣ is the one-hot vector corresponding to state x∈S, and Cat denotes the categorical distribution.
The velocity ut(x) can be seen as the instantaneous rate at which the random variable Xt transitions from state x to state y at time t.
Below is a direct side by side analogy between the continuous and discrete flow matching generation processes.
Algorithm 1 — Continuous Flow Matching
Input: Initial image x0∈Rd, velocity ut, step size h.
Fork=0,…,N−1, set t=kh and update xk+1←xk+hut(xk).
Return the generated image xN.
Algorithm 2 — Discrete Flow Matching
Input: Initial sequence x0∈S=VS, velocity ut, step size h.
Fork=0,…,N−1, set t=kh and sample xk+1∼Cat(exk+hut(xk)).
Return the generated sequence xN.
Formal definition of the velocity ut.
Definition 1 (velocity ut).
Let u:S×[0,1]→RS, let (Xt)t∈[0,1] be random variables taking values in the space of sequences S, and having laws (pt)t∈[0,1].
Denote ut:=u(⋅,t).
In the discrete case, we say that ugenerates the probability path (pt)t∈[0,1] if for every sequences x,y∈S,
P(Xt+h=y∣Xt=x)=I(x=y)+hut(x)y+o(h)
If we index the state space as S={y1,…,y∣S∣} and choose k such that yk=x (the current state), then the full transition-probability vector reads
These two equations mean that as t increases to t+h, the variable Xt stays in its current state x with probability 1+hut(x)x, or moves to any other state y=x with probability hut(x)y.
A fundamental point is that unlike continuous FM, where sampling is deterministic once x0 has been sampled from p0, sampling in discrete flow matching is inherently stochastic at each step.
This explains why we are allowed to take p0 equal to a Dirac δm…m and still produce different final outputs, which would not be possible with a deterministic sampling.
Proposition 2 (Constraints on u).
The velocity u must preserve probability mass: for Eq. (?) to define a valid probability, for every t∈[0,1]ut must satisfy:
Positivity: ut(x)y≥0 for all y=x.
Normalization: ∑y∈Sut(x)y=0 for all x∈S (and so ut(x)x≤0).
Fundamental equation linking pt and ut: Kolmogorov equation
In continuous flow matching, we have the guarantee that a velocity field ut generates a probability path (pt)t∈[0,1] if the pair (pt,ut) satisfies the continuity equation ∂tpt+∇⋅(utpt)=0.
The equivalent result for discrete data relies on the so-called Kolmogorov Equation:
Proposition 3 (Kolmogorov equation).
The velocity ut generates (pt) in the sense of Eq. (?) if and only if the pair (ut,pt) satisfies the Kolmogorov equation:
∀y∈S,dtdpt(y)=x∈S∑ut(x)ypt(x).
Proof
We can derive this directly by expanding the marginal probability at t+h using the law of total probability and our velocity definition:
Rearranging the terms and taking the limit as h→0 gives the desired result.
For the reverse implication (if the equation holds, then u generates pt), let p~t denote the probability path that the velocity field ut generates, starting from the initial distribution p~0=p0. By the forward implication proven above, p~t satisfies the Kolmogorov equation.
By hypothesis, the given probability path pt also satisfies this exact same linear ordinary differential equation (ODE).
Because both pt and p~t are solutions to the same first-order linear ODEs and share the identical initial condition (p0=p~0), the Picard-Lindelöf uniqueness theorem guarantees that pt(y)=p~t(y) for all times t and all states y∈S. Therefore, the vector field ut generates the probability path pt.
Learning probability velocities taking values in the full sequence space S=VS is cumbersome, as the cardinality of the latter is ∣V∣S, e.g. 1081 for the sudoku example!
To make computations tractable, discrete flow matching makes a factorization assumption: each transition is applied to every token of the sequence independently, according to a token-wise velocity uti:S×[0,1]→R∣V∣.
The quantity uti(xt)v then predicts the rate of probability change from the current token xti toward the token v, that still depends on the whole noisy sequence xt.
The proposition in the toogle formalizes this assumption and its consequences.
Proposition
Proposition 4 (Factorized velocity).
Let (Xt) be random variables of laws pt, and assume that the transition probabilities factorize over tokens, namely for x,y∈S:
where I(y=i=x=i) equals 1 if y and x differ at most at position i, and we used ∏i=1SI(yi=xi)=I(y=x).
By comparing this result with the definition of the velocity (Eq. (?)), we directly identify:
ut(x)y=i=1∑SI(y=i=x=i)uti(x)yi
Example 5.
To understand Eq. (?), take the vocabulary V={A,B}, sequence length S=3, and current sequence x=ABA.
We represent the vector ut(x) in R8. From Eq. (?), the sequence can only transition to 4 possible values (its current state, or state differing by a single token), and the velocity writes as:
ABA
State y
Velocity ut(x)y
AAA
ut2(x)A
AAB
0
ABA
ut1(x)A+ut2(x)B+ut3(x)A
ABB
ut3(x)B
BAA
0
BAB
0
BBA
ut1(x)B
BBB
0
While ut outputs a vector in R8, ut1,ut2 and ut3 output vectors in R2 (as ∣V∣=2).
This modeling assumption has several important consequences:
for infinitesimally small time steps, a sequence x can only transition to states y differing by at most one token (even if we draw all tokens simultaneously, the probability of two or more tokens changing is o(h))
learning-wise, it implies a substantial computational gain: instead of learning one transition object u on the full sequence space S=VS (exponential in S), we can learn S local transition objects ui, each on the vocabulary space V (linear in S)
at each sampling step, we draw each token independently following:
xt+hi∼Cat(exti+huti(xt))
The following algorithms and figure illustrates the analogy between one Euler step in continuous and discrete flow matching, and makes explicit what this token-wise velocity represents and how to use it to sample sequences.
Algorithm 3 — Continuous Euler: pixel by pixel
Input: Initial image x0∈Rd, velocity ut, step size h.
Fork=0,…,N−1, set t=kh.
For each pixelj=1,…,d in parallel, set xk+1j←xkj+h[ut(xk)]j.
Return the generated image xN.
Algorithm 4 — Discrete Euler: token by token
Input: Initial sequence x0∈VS, token-wise velocities uti, step size h.
Fork=0,…,N−1, set t=kh.
For each tokeni=1,…,S in parallel, sample xk+1i∼Cat(exki+huti(xk)).
Return the generated sequence xN.
Continuous — an image x(t) ∈ Rd
x(t)
x(t+h) = x(t) + hut(x(t))deterministic
x(t+h)
Discrete — a sequence xt ∈ S (here V = {A, B, m}, S = 4)
AmBm
xt
x3t+h ∼ Cat(ex3t + hu3t(xt))stochastic
AmBB
xt+h
Figure 4: One Euler step of size h in continuous and discrete flow matching, on the samples and on the states (toggleable): the deterministic update x(t)+hut(x(t)) becomes a sampling step xt+hi∼Cat(exti+huti(xt)) applied to each token in parallel for discrete data.
Now that we are equipped with adequate definitions of probability paths and velocities for the discrete case, together with a way to check that one is associated to the other, we can state the approach of discrete flow matching, which is in fact the same as for continuous flow matching:
Build an explicit probability path (pt) going from p0 to p1 (Eq. (?)) using a conditioning variable, conditional probability paths and conditional velocities.
Provide an explicit loss to learn ut with a neural network (Eq. (?))
Building the probability path
Similarly to continuous flow matching, there are infinitely many possible choices for a probability path (pt) going from source p0 to target p1.
To build a specific one, we borrow the core idea from continuous flow matching: we first choose a choose a conditioning variable z=x1 and a conditional probability path pt(⋅∣x1) for which the exact conditional velocity ut(⋅∣x1) that generates this path is known and easy to compute.
Then, we show that the resulting global velocity (obtained by marginalizing the conditional velocities) is guaranteed to generate a probability path that transports p0 to p1.
All that’s left is to learn the global velocity as a simple conditional expectation from data, which neural networks know how to do!
In order to have factorized velocities (simpler to learn), we chose a conditional path pt(⋅∣x1) to be factorized:
This choice is similar to the linear interpolation path used in continuous flow matching pt(x∣x0,x1)=tx0+(1−t)x1, unless we cannot interpolate between two discrete tokens.
Instead, we use linear interpolation in probability space: at time t, the i-th token xti equals the target token x1i with probability t, or the mask token m with probability 1−t.
Therefore, p0(⋅∣x1) is a Dirac at the all-masked sequence, while p1(⋅∣x1) is a Dirac at x1.
The interest of this conditional probability path is that we can derive the associated velocity in closed-form.
Proposition 6 (Closed-form for conditional velocity).
Define the following token-wise conditional velocity:
ut(xi∣x1i)v:=⎩⎨⎧1−t1−1−t10if v=x1i and xi=m,if v=xi=m,otherwise.
Then, the velocity field
ut(x∣x1)y:=i=1∑SI(y=i=x=i)ut(xi∣x1i)yi
generates the conditional path pt(x∣x1) in Eq. (?)
Note: compared to Eq. (?), one may be surprised that ui in Eq. (?) depends only on xi and not on x. As the proof will show, this is a byproduct of the conditional probability paths factorizing over each token of the conditioning sequence x1.
Example 7 (Example of conditional velocity).
The velocity ut(xi∣x1i) progressively removes mass from m and transfers it to the target token x1i.
If xti is already x1i, then the conditional velocity is 0: the token remains at its value until the end.
As an example, for V={A,B,C,m}, and x1i=B, then the conditional velocity field is given by:
For the masked source, we show that the token-wise velocity ut(xi∣x1i) in Eq. (?) generates the token-wise conditional path qt(xi∣x1i) appearing in Eq. (?), in the sense that it satisfies the token-wise Kolmogorov equation
since qt(m∣x1i)=1−t. This matches Eq. (?), so (ut(⋅∣x1i),qt(⋅∣x1i)) satisfies the token-wise Kolmogorov equation.
We now show that, using Eq. (?), the pair (pt(⋅∣x1),ut(⋅∣x1)) satisfies the Kolmogorov equation Eq. (?). Since the conditional path is factorized, we have:
For a fixed coordinate i, the indicator I(y=i=x=i) forces xj=yj for every j=i. Therefore, the sum over x reduces to a sum over the single free token xi=v:
Plugging this back into Eq. (?) gives exactly Eq. (?). Hence:
dtdpt(y∣x1)=x∈S∑ut(x∣x1)ypt(x∣x1).
The pair (pt(⋅∣x1),ut(⋅∣x1)) satisfies the Kolmogorov equation.
Values of conditional velocities for and uniform source and interpolation between an arbitrary p0 and p1
Source-Target Conditioning:
Here, we condition on both the start and end points, so zi=(x0i,x1i). We choose qt as:
qt(xi∣x0i,x1i)=tI(xi=x1i)+(1−t)I(xi=x0i)
It means at time t, the i-th token xti equals the target token x1i with probability t, or the source token x0i with probability 1−t. Therefore, p0(⋅∣x0,x1) is a Dirac at x0, while p1(⋅∣x0,x1) is a Dirac at x1.
The conditional velocity field driving this transition is:
ut(xi∣x0i,x1i)v=⎩⎨⎧1−t1−1−t10if v=x1i and xi=x0i,if v=xi=x0i,otherwise.
Here, mass moves directly from the source token x0i toward the target token x1i. All rows except the source row are identically zero: once a token is already at state x1i, no transition occurs.
Concretely, if V={A,B,C}, x0i=A, and x1i=B:
It means that at time t, the i-th token xti equals the target token x1i with probability t+(1−t)∣V∣1, while each non-target token in the vocabulary V has probability (1−t)∣V∣1. Therefore, p0(⋅∣x1) is the uniform distribution over sequences, while p1(⋅∣x1) is a Dirac at x1.
The conditional velocity field driving this transition is:
ut(xi∣x1i)v=⎩⎨⎧1−t1−1−t10if v=x1i and xi=x1iif v=xi=x1iotherwise
Unlike the mask source, every non-target token can transition toward x1i, since the uniform source places initial mass everywhere. Concretely, if V={A,B,C} and x1i=B:
Figure 5: Top: evolution of the conditional path pt(⋅∣x1) defined in Eq. (?), where the vocabulary is restricted to the characters in x1∪{m}. In each cell, white indicates probability zero for sampling that token, while a fully colored cell indicates probability one. Bottom: for a given time t, five samples xt∣x1 drawn from the conditional probability path.
Building the target velocity
Now that we have defined our conditional probability paths and velocities, we can use them to build global, unconditional ones.
The overall distribution pt is obtained by marginalizing the conditional paths over target samples x1 drawn from p1:
pt(x):=x1∑pt(x∣x1)p1(x1)
As the proof below shows, the path defined by marginalization indeed goes from p0 to p1.
Proof that path (pt) does go from p0 to p1
We verify the two boundary conditions separately:
At t=0:
Recall the conditional path the mask source:
q0(xi∣x1i)=I(xi=m).
The value of x1i plays no role, so p0(x∣x1) does not depend on x1:
So ut satisfies the Kolmogorov equation for pt and therefore generates pt.
This theorem follows the exact same logic as in continuous FM, and has the same practical consequence: since the target field is identified as a conditional expectation, it can be learned through a regression problem.
In continuous spaces, this is typically introduced via the L2 projection view, as the conditional expectation solves
In discrete spaces, since we compare nonnegative rate vectors that behave like local probabilities, a Kullback-Leibler style objective is more natural.
More generally, this conditional expectation is the minimizer
for any Bregman divergence, and KL is the Bregman choice adapted to our setting:
ut(x)=uargminE[KL(u(Xt∣X1),u(Xt))]
The exact conditional expectation of Eq. (?) is approximated by a neural network uθ,t, trained by minimizing over θ:
With straight interpolation paths xt:=(1−t)x0+tx1, learning the ideal velocity E[X1−X0∣Xt=x] is mathematically equivalent to learning the ideal denoiser E[X1∣Xt=x], since the two are linked via E[X1−X0∣Xt=x]=1−t1(E[X1∣Xt=x]−x).
The denoiser can be understood as predicting the most plausible clean image x1 given a noisy image xt at time t.
It turns out the same type of denoiser-velocity equivalence holds in the discrete case:
uti(x)v=1−t1(P(X1i=v∣Xt=x)−I(v=xi)).
In this equation, the function x↦P(X1i=v∣Xt=x) can be interpreted as a denoiser: it gives the probability of the i-th token in the clean sequence x1 being v, given the full noisy sequence xt.
Proof of velocity-denoiser equivalence
We write the proof for the masked source and start from Eq. (?).
In a compact form, it can be rewritten as:
uti(xi∣x1i)v=1−t1I(xi=m)(I(v=x1i)−I(v=m)).
Case 1: xi=m (token already unmasked).
The indicator I(xi=m)=0, so uti(xi∣x1i)v=0 for all x1i,v
and hence uti(x)v=0.
It remains to check that Eq. (?) also gives zero. By Bayes’ rule,
where the last equality uses xi=m. Both cases match the claimed formula.
Because the term I(v=xi) is a known constant given the current state, learning the velocity field u is mathematically exactly equivalent to learning the denoiser probability P(X1i=v∣Xt=x).
Consequently, we can train a denoiser Pθ,t directly. Using the KL divergence between the true clean token distribution and the learned one, the loss simplifies to the standard cross-entropy [2, 3]:
Given x1, the true conditional posterior is a one-hot: Pt(X1i∣Xt=x,x1)=ex1i. The KL between a one-hot and any distribution reduces to a single log term:
Figure 6: Generation process of a sequence of length S=4 with a learned velocity uθ,t or denoiser Pθ,t(X1i∣Xt).
Key facts: 1) At each step, all tokens are updated independently 2) Different samples can be generated from the same initial sequence (change the seed!), because sampling is stochastic at each step.
Key empirical observations: 3) The probability of drawing the mask token m decreases at each step, while the probability of drawing other tokens increases. 4) Once a token is unmasked, it stays at its current value until the end.
To wrap up, we end this section with a table summarizing the important steps in discrete flow matching, put in parallel with their equivalent for continuous flow matching.
Table 7: Continuous and discrete flow matching side by side.
Continuous flow matching
Discrete flow matching
1. Define a conditioning variable z with known distribution π(z)
z=(x0,x1) with π(z)=p0×p1
z=x1 with π(z)=p1 (our choice for simplicity; z=(x0,x1) is also possible)
2. Define a simple conditional distribution pt(x∣z)
pt(x∣z)=δ(1−t)x0+tx1(x)
pt(x∣z)=∏j=1Sqt(xj∣x1j) where qt=Cat((1−t)em+tex1j)
3. Compute an associated conditional velocity field ut(x∣z)
ut(x∣z)=x1−x0
ut(x∣z)y=∑i=1SI(y=i=x=i)ut(xi∣x1i)yi with ut(xi∣x1i)=1−t1I(xi=m)(ex1i−em)
4. Training objective
Use L2: minθEt∼U[0,1]z∼πxt∼pt(⋅∣z)[∥uθ,t(xt)−(x1−x0)∥2]
Use KL: minθEt∼U[0,1]x1∼p1xt∼pt(⋅∣x1)[−∑i=1SlogPθ,t(X1i=x1i∣xt)]
5. Sampling Sample x0∼p0, integration scheme for k=0,…,N−1
Numerical Integration (Euler ODE): xk+1=xk+N1uθ,k/N(xk) If learned denoiser, use: uθ,t(x)=1−t1(Eθ[X1∣Xt=x]−x)
Continuous Time Markov Chain: xk+1i∼Cat(exki+N1uθ,k/Ni(xk)) If learned denoiser, use: uθ,ti(x)=1−t1(Pθ,t(X1i∣x)−exi)
To go further: planners in masked flow-matching sampling
Notes before reading this section:
We note the denoiser Dθ,t(xt):=Pθ,t(X1∣Xt=xt).
Because the noise level t in masked flow-matching can be easily inferred from the number of masked tokens in xt, the denoiser does not need to know the current time in its predictions.
Therefore, for any time t and any given sequence x, we write Dθ,t(x)=Dθ(x).
Sampling with a planner
With step size h, vanilla masked flow-matching sampling Eq. (?) uses 1/h time steps. Across a sequence of length S, this corresponds to S/h draws from probability vectors over the vocabulary ∣V∣. For h=0.01 and S=200, generating one sample therefore involves 20,000 such draws, which is computationally expensive. Moreover, some steps t→t+h can keep the current sequence xt unchanged, implying computational waste (it can be easily observed in figure 6).
To make generation more efficient, the standard approach used for large masked flow-matching models is planner-guided sampling. Instead of relying on infinitesimal time steps, we fix the total generation steps N and directly use the denoiser to reveal a fixed number of tokens at each step. For S=200 and N=50, we have NS=50×200=10,000 draws to do, which is half the cost of the previous example.
Definition 9 (Planner Gϕ).
A planner Gϕ maps a partially masked sequence xk and a denoised candidate z∼Dθ(xk) to a distribution over positions to reveal. At step k, with Mk={i:xki=m} the set of masked positions in xk, we write:
Gϕ(z,xk)∈ΔS,Gϕ(z,xk)i=0 for i∈/Mk.
In other words, the planner indicates, for each position i in the noisy sequence xk, the probability of denoising xki into zi. If xki=m, this probability is zero. For example, if xk=(m,A,m) and z=(B,A,A), then a possible value of Gϕ(z,xk) is (0.7,0,0.3), which means revealing position 1 into z1=B with probability 70% and position 3 into z3=A with probability 30%.
Algorithm 5 — Planner-Guided Sampling
Input: Planner Gϕ, trained denoiser Dθ, total number of sampling steps N, schedule f mapping step index to number of tokens to reveal at that step, e.g., f(k)=S/N for all k when N divides S.
Initialize:x0←(m,…,m) (a sequence of S mask tokens).
Fork=0,1,…,N−1:
Plan: Sample candidate tokens z∼Dθ(xk).
Select:
Initialize I←∅.
Forℓ=1,…,f(k):
Sample one position iℓ from Gϕ(z,xk), restricted to positions not already in I.
Add it to the set: I←I∪{iℓ}.
Denoise: Create xk+1 by setting xk+1i=zi for all i∈I, and leaving all other positions unchanged.
Return fully generated sequence xN.
Proposition 10 (Sampling-scheme equivalence).
If we choose the uniform random planner that selects positions uniformly at random among the masked tokens, i.e. G(z,xk)i=∣Mk∣1 for each i∈Mk, then planner-guided sampling with N=S steps and f(k)=1 token per step is exactly equivalent to the Euler sampling procedure given in Eq. (?) as h→0.
However, we rarely decide to unmask tokens by picking a random position at each step. Instead, we can use heuristic or learned planners that rank positions according to how reliable or informative they seem to reveal.
A simple and widely used strategy in this direction is the soft greedy planner. Instead of unmasking tokens at random, it selects the positions where the denoiser is most confident in its predictions. We then relax this strict selection into a soft probability distribution using a softmax function with a temperature parameter τ:
Gτ(z,xk)t∝exp(τ1logDθj(xk)zj)
As τ→∞, this reduces to uniform random sampling. As τ→0, it converges to a strict, hard selection of only the most confident token in the sampled sequence z.
Other planning strategies
Entropy planner. Another heuristic is to score each position by the negative entropy of the denoiser distribution. Low entropy means the denoiser is concentrated on a few tokens, so the position is treated as more reliable:
si(xk)=v∈V∑Dθi(xk)vlogDθi(xk)v.
The planner then applies a softmax over the still-masked positions:
Gτent(z,xk)i∝exp(τsi(xk))
Unlike soft greedy, this planner does not use the sampled token zi directly; it only uses the shape of the denoiser distribution at position i.
Learned planner. With a pretrained denoiser, one can also train a separate planner offline. This can be done with a cross-entropy objective of the form:
The learned planner can then be interpreted as a consistency scorer: positions whose sampled token looks reliable under the current partially denoised context receive more planner mass.
Example: one sampling step with a soft greedy planner
To illustrate one sampling step, take the vocabulary V={A,B,m} and sequences of length S=3.
Suppose that after one planner step (k=1), the current sequence is
x1=(A,m,m),
so positions 2 and 3 are still masked.
The denoiser proposes a full candidate sequence by sampling token-wise:
z∼Dθ(x1),for example z=(A,A,B).
For this sampled candidate, the planner only looks at the denoiser confidence assigned to the proposed token at each still-masked position, and assigns zero mass to positions that are already unmasked.
This means that the planner is more likely to reveal position 3, because the sampled token z3=B received higher denoiser confidence than z2=A.
If we take the limit cases for the temperature, we get:
G0(z,x1)=001,G∞(z,x1)=02121.
If the planner samples position 3, then the next sequence is obtained by copying only that proposed token:
x2=(A,m,B).
The figure below illustrates the sampling with a planner.
Figure 8: Flow-matching sampling with the soft greedy planner with Algorithm 5. Try changing the temperature τ to make the selection more diffuse or more sharply confidence-based.
Exposure bias
Introducing a planner-aware sampling process creates a mismatch between training and inference.
During training, the standard objective masks tokens uniformly at random across all positions and orderings.
During inference, the planner reveals tokens along a specific, confidence-guided trajectory.
This difference matters because uniform masking can put training weight on mask patterns that the planner would almost never visit in practice.
For example, in a structured sequence where the last token is only predictable after the first two have been revealed, uniform masking may still train the model to predict that last token from (m,m,m) or from (m,m,B), while a confidence-based planner would first reveal easier positions and avoid asking for that token with so little context.
These hard denoising tasks can inject extra error into the learned denoiser, and those errors can then be amplified during sampling when early wrong predictions are irreversible.
A fix is to reweight the denoising loss Eq. (?) toward the positions the planner would select. This gives the Planner-Aware Path Learning (PAPL) objective [4]:
Here, wi=Gϕ(z,xt)i is the normalized planner weight for position i, and α controls the strength of this guidance. The stop-gradient sg[⋅] detaches these weights: for example, soft greedy weights depend on θ through softmaxi(τ1logPθ,t(X1i=zi∣Xt=xt)), but gradients are not propagated through this dependence.
References
Structured Denoising Diffusion Models in Discrete State-Spaces[PDF]
Jacob Austin, Daniel D. Johnson, Jonathan Ho, Daniel Tarlow, Rianne van den Berg. NeurIPS 2021.
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.
Discrete Flow Matching[PDF]
Itai Gat, Tal Remez, Neta Shaul, Felix Kreuk, Ricky T. Q. Chen, Gabriel Synnaeve, Yossi Adi, Yaron Lipman. NeurIPS 2024.
Planner Aware Path Learning in Diffusion Language Models Training[PDF]
Fred Zhangzhi Peng, Zachary Bezemek, Jarrid Rector-Brooks, Shuibai Zhang, Anru R. Zhang, Michael Bronstein, Avishek Joey Bose, Alexander Tong. ICLR 2026.
DiGress: Discrete Denoising diffusion for graph generation[PDF]
Clement Vignac, Igor Krawczuk, Antoine Siraudin, Bohan Wang, Volkan Cevher, Pascal Frossard. ICLR 2023.
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.
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.
Notes
Here KL denotes the generalized KL divergence between two positive vectors a,b∈R+d, KL(a,b)=∑j=1dajlog(aj/bj)−aj+bj.
When applying it to probability velocities, we only compare the off-diagonal entries of ut(x), i.e. the rates ut(x)y for y=x.
These vectors are indeed positive, and we can skip the diagonal entry since its value is determined by all the other ones due to the zero-sum constraint (Proposition 2).
This exact equivalence relies on the masked source, but does not hold for an arbitrary source distribution p0.
However, learning a denoiser is still sufficient to recover the velocity field using Eq. (?), and therefore to generate data samples.