Why can reward fine-tuning of a diffusion model sampled with classifier-free guidance improve for a while and then give back its gains, even though every update is weighted toward higher-reward samples? We show that the exponentially weighted flow-matching objective hides two updates inside one gradient: a reward-driven change, and a second term that fits the model to its own guided rollouts. When guided sampling and the training reference disagree, this second term is not neutral: it pulls the conditional branch toward the guided field. Subtracting the state-conditional mean weight removes it. A reference-field straight-through estimator gives the same corrected objective at a different estimation and infrastructure cost, and the identical structure reappears as score centering for training–inference mismatch in LLMs.
The whole note in one line
∇GLW=fits the guided rolloutsm(z)(G−FQ(z))−reward-induced changem(z)(FQ⋆(z)−FQ(z))
Keep the green term and drop the orange one. The same colours are used throughout.
Abbreviations used in this note
RL
Reinforcement learning; here, fine-tuning a generative model toward a reward.
LLM
Large language model.
CFG
Classifier-free guidance. Sampling uses v∅+w(vc−v∅), mixing conditional and unconditional predictions with scale w; w=1 is plain conditional sampling.
FM
Flow matching: regressing a velocity field onto X−ϵ along noisy interpolations [4].
NFT
DiffusionNFT, an online diffusion RL method that trains with forward-process (flow-matching) losses on reward-weighted rollouts [6].
IGO
Information-geometric optimization: update a sampling distribution toward a reward-tilted one [2].
AWR
Advantage-weighted regression: supervised regression with weights eA/β[3].
KL
Kullback–Leibler divergence.
STE
Straight-through estimator: use one value in the forward pass and another's gradient in the backward pass, written with stop-gradient sg(⋅).
TIM
Training–inference mismatch: the sampler and the trainer assign different probabilities to the same tokens [1].
1. One structure, two sources of mismatch
Training–inference mismatch in LLM RL and CFG mismatch in diffusion RL look like unrelated engineering problems. They share one mathematical structure: the distribution that supplies the training samples is not the reference implicit in the training gradient. The causes differ; the resulting weighted gradients decompose in the same way.
For LLMs, a Megatron trainer and a vLLM sampler can produce different token probabilities because of numerical execution, sampling transforms, or checkpoint staleness [1]. For diffusion models, CFG changes the sampling procedure on purpose, while training may still use only the conditional branch [5].
LLM RL
Diffusion RL
Sampling
Tokens from the inference engine
Endpoints generated with CFG
Training
Weighted token log-likelihood
Weighted FM on re-noised endpoints
Mismatch
Trainer probabilities ≠ sampler probabilities
Trainable velocity ≠ rollouts' re-noised mean field
Conditioning
Prompt and token prefix
Prompt, noisy latent, noise level
Conditional baseline
Mean weight at a prefix
Mean weight at a noisy state
Forward correction
Sampler probabilities with the trainer's logit Jacobian
Rollout mean field with the student's output Jacobian
We derive the diffusion case first, then map it to LLMs. Throughout, the rollout distribution, reward weights, and estimated statistics are held fixed during differentiation.
2. From IGO to exponentially weighted flow matching
Take the distribution-first view of IGO. Let Q(X∣c) be the current CFG rollout distribution for input c and A(X,c) an advantage. A local improvement trades reward against staying close to Q:
Q⋆=argPmax{EP[A]−βDKL(P∥Q)},β>0.
Setting the functional derivative to zero, A−β(log(P/Q)+1)+λ=0, gives the familiar exponential tilt
Q⋆(X∣c)=Z(c)Q(X∣c)W(X,c),W(X,c)=eA(X,c)/β,
with Z(c)=EQ[W] assumed finite. This exponential weighting comes from this particular KL-regularized objective; it is the same tilt as in AWR [3], not a definition of all IGO algorithms [2].
To fit Q⋆ with flow matching, draw X∼Q and independent ϵ∼N(0,I), and set
xt=(1−t)X+tϵ,u=X−ϵ,z=(xt,t,c),
so t=1 is noise, t=0 is data, and u is the denoising velocity. The exponentially weighted objective is
LW(θ)=21EX∼Q,t,ϵ[W(X,c)∥Gθ(z)−u∥2].
For fixed c, weighting by W turns the endpoint measure Q into Q⋆ up to the constant Z(c), so the ideal regression target is the flow of Q⋆. (FM is a field regression, not literally a log-likelihood or forward KL; across inputs, Z(c) also sets their relative training weight [4].)
3. Two forces inside one gradient
Fix a noisy state z. Two conditional averages matter: the rollout mean field and the mean weight,
FQ(z)=EQ[u∣z],m(z)=EQ[W∣z].
Writing G=Gθ(z), the output gradient is EQ[W(G−u)∣z]=m(z)G−EQ[Wu∣z]. Splitting EQ[Wu∣z]=m(z)FQ(z)+CovQ(W,u∣z) gives
Gradient descent on the orange term moves G toward FQ. It survives when all weights equal one, so it expresses no preference between samples at all. At the pre-update field G0 it vanishes only where G0=FQ, which is exactly what CFG breaks.
With CFG rollouts and conditional-only training, this term transfers guided sampling behaviour into the conditional branch. Sampling with CFG afterwards may amplify that behaviour again.
Note that the relevant reference is FQ, not automatically the cached CFG velocity: re-noising endpoints and following the actual CFG trajectory define different joint distributions [5].
The green term is the reward-induced flow change
Under exponential reweighting, FQ⋆(z)=EQ[Wu∣z]/m(z). Therefore
CovQ(W,u∣z)=m(z)(FQ⋆(z)−FQ(z)).
The covariance isolates exactly the change from the rollout flow to the reward-tilted flow. If the goal is to distil Q⋆ completely, the orange term is appropriate. If the goal is to apply the reward-induced change to an existing policy G0, the orange term is an extra, unwanted update.
4. Two ways to remove the orange term
The fix has two parts: isolate the green covariance, then anchor the update to the frozen pre-update policy with a purple constraint. Centering plus this constraint and a fixed-reference STE give the same gradient when the conditional quantities are exact.
A. Center the weight, then anchor the update
Replace W by W−m(z), treating the baseline as a constant:
Lcenter(z)=21EQ[(W−m(z))∥G−u∥2∣z].
Because EQ[W−m(z)∣z]=0, the coefficient of G cancels and the orange term disappears:
∇GLcenter(z)=−CovQ(W,u∣z).
Centering alone has no finite optimum. With fixed rollout statistics, this gradient does not depend on G: the objective is affine in G and unbounded below. Repeated inner steps keep pushing the field even after the intended improvement has been reached. (Try the Centered only mode in the demo below.)
Let G0(z) be the policy output before the update window, held fixed throughout its inner steps. Add a constraint weighted by the same conditional mean m(z):
Since W=eA/β>0, m(z)>0 and the problem is strongly convex. The purple term is zero at G=G0 and restores the policy as it moves. It anchors to G0, not to the CFG field FQ, so it does not bring the orange term back. The pointwise optimum is
The corrected objective applies the reward-induced flow change to the pre-update policy, and nothing else. Two details matter in practice: G0 is the pre-update policy, not necessarily the pretrained model, and must stay fixed through the inner window; and the coefficient is the state-conditional m(z), not a batch average of W.
Estimating m(z) with a tempered posterior
For each input c, let X1,…,XK be the K rollout endpoints generated for that input. A uniform empirical prior and the Gaussian bridge xt∣X∼N((1−t)X,t2I) give, for 0<t<1,
ρj(T)(z)=softmaxj(−2Tt2∥xt−(1−t)Xj∥22),
mT(z)=j=1∑Kρj(T)(z)Wj.
Use the detached mT(z) both in the centered weight and as the constraint coefficient. At T=1 these are the exact posterior responsibilities of the empirical bank; T>1 inflates the assumed noise variance and smooths a concentrated posterior, at the cost of bias relative to the population conditional mean. Compute the full summed latent squared norm and use a stable log-softmax.
What an inexact baseline costs
Replacing m by a fixed estimate m in both places gives
A residue of the orange term survives in proportion to the baseline error. Positive regularization does not remove it; only an accurate conditional mean does. At low noise a concentrated posterior may correctly identify the source endpoint, so temperature smoothing is a regularizer, not a guarantee of a better estimate.
B. Correct the forward field with a fixed-reference STE
Instead of estimating the scalar m(z), estimate the vector field FQ directly by ordinary FM on the CFG endpoints, as GuidanceNFT does with online flow matching on guided samples [5]:
ϕmin21EQ[∥Fϕ(z)−u∥2],Fϕ(z)≈FQ(z).
With the same frozen G0, define the straight-through surrogate
Gθ=Gθ+sg(Fϕ−G0).
Its forward value is Gθ−G0+Fϕ, its Jacobian is that of Gθ. With an exact reference, ordinary weighted FM through this surrogate has gradient
identical to the centered-and-anchored objective above: the purple constraint is implicit in the fixed reference. Our contribution here is this equivalence; the learned-reference correction itself follows [5].
If G0 is replaced by the current Gθ inside the stop-gradient at every step, Gθ=Gθ+sg(FQ−Gθ), the purple term disappears and only the green covariance remains: the refreshed STE is centering without the constraint.
Which one to use
Conditional baseline
Learned-reference STE
Estimates
m(z)=E[W∣z]
FQ(z)=E[u∣z]
Implementation
Kernel posterior over stored endpoints
Auxiliary FM regression
Extra parameters
None
Reference model or adapter
Main error
Finite-bank and temperature bias
Reference-field approximation
A learned reference means maintaining an auxiliary model next to the policy; at trillion-parameter scale its weights, training, and communication are expensive, while the kernel estimator needs no extra parameters. Both still need a fixed G0: cached predictions suffice at fixed training queries, fresh queries need extra reference evaluations or an explicit approximation, and the reference and student must use the same branch or CFG composition. STE itself does not require an auxiliary model; the difference is how the reference field is obtained. Learning both FQ and FQ⋆ explicitly is a third way to build the difference target. None of these output-space identities guarantees that a shared network can realize the pointwise target exactly.
5. The same picture for LLMs
The decomposition, and both fixes, carry over to logit space. At a fixed prefix h, let q be the sampler's probabilities, pθ=softmax(ℓθ) the trainer's, ey the one-hot sampled token, and m(h)=Eq[W∣h]. The logit score is sθ(y)=ey−pθ with Eq[sθ∣h]=q−pθ, so negative weighted log-likelihood has gradient
∇ℓθL=m(h)(pθ−q)−Covq(W,ey∣h),
the categorical twin of m(z)(G−FQ)−CovQ(W,u∣z). The orange term pulls the trainer toward the sampler's distribution, whatever the reward says.
Baseline or score centering: two routes to the same expectation
Score centering [1] subtracts the conditional mean of the score, sθ−Eq[sθ∣h]=ey−q. Subtracting the conditional weight baseline instead gives the same expected update:
The diffusion baseline uses the first form; LLM score centering uses the second, with sampler probabilities. They agree in expectation with exact conditional means, not necessarily as finite-batch estimators.
Straight-through, in logits
The logit-level STE is
ℓθ=ℓθ+sg(logq−ℓθ).
For positive q its forward softmax is q and its logit Jacobian is the identity, so weighted cross-entropy yields the green term alone, like the refreshed diffusion STE. Freezing the correction at the pre-update logits ℓ0, ℓθ=ℓθ+sg(logq−ℓ0), additionally keeps a restoring term m(h)(pθ−q) with pθ=softmax(ℓθ), the analogue of the purple constraint. Correcting only the sampled token's scalar log-probability leaves its derivative unchanged and is not enough.
The practical difference: LLM score centering can read the sampler's conditional token probabilities directly, while diffusion needs a conditional expectation over latent endpoints, either the scalar mean weight or the vector mean field. Kernel estimation and auxiliary-model training are two approximations to these. In both domains, centering removes the identified mismatch term; it does not in general recover an exact on-policy gradient under the trainer's own distribution.
6. What we see at CFG = 5
We compare NFT [6] with the corrected objective at guidance scale 5, using K=8 rollouts per input. The corrected run keeps rising over its logged range; NFT improves at first and then gives back part of the gain.
Figure 1. Reward versus training step at CFG = 5, K=8 rollouts per input. Blue: corrected objective; brown: NFT [6]. Values are approximate readings of a single run per method, shown up to the last logged step (32 and 41) without smoothing or extrapolation. Hover over a point to see its value.
This is one run per method, so it motivates a controlled ablation rather than establishing the mismatch correction as the cause. Removing the orange term also does not by itself guarantee visual fidelity, prevent reward-induced oversaturation, or make reward improvement monotonic.
Citation
If you find this note useful, please cite it as:
@misc{yang2026tim,
title = {Training--Inference Mismatch in Generative {RL}},
author = {Yang, Zeshi and Wang, Yujie},
year = {2026},
month = oct,
howpublished = {\url{https://zeshiyang.github.io/blog/training-inference-mismatch.html}},
note = {Blog post}
}
References
The cross-domain correspondence and the equivalence identities are derived in this note; the learned-reference correction for diffusion follows [5]. The experiment is separate from the published results below.
Try it: three objectives at a single noisy state动手试试:同一个带噪状态下的三种目标
Toy picture of the output space at one noisy state z, with m(z)=1. The unconditional prediction sits at the origin, G0 is the pre-update conditional prediction, and the guided field is FQ=wG0; the reward tilt adds FQ⋆−FQ. For illustration we identify FQ with the CFG field, which the text cautions is only approximate. Arrows at the moving point show the forces: orange=−m(G−FQ), green=Cov, purple=−m(G−G0). At w=1 the original and corrected objectives coincide.某个带噪状态 z 处输出空间的示意(取 m(z)=1)。无条件预测位于原点,G0 是更新前的条件预测,guided 场为 FQ=wG0;reward 倾斜再加上 FQ⋆−FQ。为便于演示,这里把 FQ 等同于 CFG 场,正文已说明这只是近似。移动点上的箭头表示各项的力:橙色=−m(G−FQ),绿色=Cov,紫色=−m(G−G0)。当 w=1 时,原始目标与修正目标重合。