An unconditional generative model learns to sample from a distribution . But in practice, we almost never want a random sample from the full data distribution — we want an image of a specific subject, a molecule with specific properties, a protein that binds a specific target. The question of how to steer a trained generative model toward a desired subset or property of the data distribution is the subject of this chapter. The answer turns out to involve a single mathematical operation — tilting the distribution by a likelihood or reward function — realized through different mechanisms depending on whether the guidance signal is available at training time, inference time, or both.
The central tension is between fidelity (how well the guided sample satisfies the condition) and diversity (how much variation remains among guided samples). Perfect fidelity means every sample exactly matches the condition — but if the condition is “a photo of a cat,” there should still be many different cats. The guidance strength parameter , which appears in every method in this chapter, controls this tradeoff: low gives diverse but weakly conditioned samples; high gives precise but repetitive samples. Understanding this tradeoff — and its mathematical origin as a temperature parameter on a tilted distribution — is the unifying theme.
15.1 The Conditional Generation Problem
The formal setting: given a condition (a class label, a text prompt, a partial observation, an energy function), generate samples from the conditional distribution . By Bayes’ rule:
where is the unconditional data distribution (the prior), is the likelihood of the condition given the data, and is the evidence (a normalizing constant). The conditional distribution is the unconditional distribution tilted by the likelihood.
In the language of generative flows: the unconditional model provides access to through its score function or velocity field . The guidance signal provides access to or its gradient. The conditional score is:
where is the likelihood at noise level — the probability of the condition given a noisy version of the data. The conditional velocity field is derived from this conditional score via the probability flow ODE relationship.
The challenge is computing — the gradient of the likelihood with respect to the noisy data at intermediate noise levels. Different methods handle this differently, and the differences define the landscape of guided generation.
15.2 Classifier Guidance
The most direct approach: train a separate classifier on noisy data at all noise levels, and use its gradient to steer the generative process.
[!definition] 15.1 — Classifier Guidance Given an unconditional diffusion model with score and a noise-conditional classifier , the classifier-guided score is:
where is the guidance scale. At , sampling is unconditional. At , sampling targets exactly (in the limit of perfect models). At , sampling targets a sharpened conditional that concentrates on the most likely samples given .
The guided SDE or ODE replaces the unconditional score with the guided score — everything else (the noise schedule, the solver, the architecture) remains unchanged. The classifier gradient acts as an additional force that pushes samples toward regions where the condition is satisfied.
[!remark] 15.1 The guidance scale has no Bayesian justification — it corresponds to sampling from a tempered posterior that is more concentrated than the true conditional. In practice, produces the best samples by human evaluation, despite being statistically “wrong.” The explanation is that the unconditional model already assigns some mass to low-quality samples (blurry images, implausible molecules), and the extra guidance removes this mass. The price is reduced diversity — high produces near-identical samples for a given condition.
15.3 Classifier-Free Guidance
Classifier guidance requires training a separate classifier on noisy data — an additional model with its own training pipeline. Classifier-free guidance (CFG) eliminates this requirement by using the generative model itself as an implicit classifier.
The key identity: the classifier gradient can be written as the difference between conditional and unconditional scores:
Substituting into the guided score:
[!definition] 15.2 — Classifier-Free Guidance A classifier-free guided model is trained as a conditional model that can also run unconditionally by replacing the condition with a null token : . During training, the condition is dropped (replaced by ) with probability (typically 10–20%). At inference, the guided prediction is:
which requires two forward passes per step: one conditional, one unconditional.
CFG has become the dominant guidance method for large-scale generative models (Stable Diffusion, DALL-E, Imagen) for several reasons: (1) no separate classifier is needed; (2) the unconditional model is obtained for free by label dropout during training; (3) the method applies to any type of condition (text, class, image) without modification.
[!proposition] 15.1 — CFG as Tempered Bayes Classifier-free guidance with scale samples from the tilted distribution:
This is Bayes’ rule with the likelihood raised to the power : the guidance sharpens the influence of the condition relative to the prior. At , this is the true posterior; at large , the posterior concentrates on the maximum-likelihood estimate .
15.4 Conditional Flow Matching
For flow-based models, conditional generation can be built directly into the flow matching framework without the detour through scores and guidance.
[!definition] 15.3 — Conditional Flow Matching Given paired data where is the data and is the condition, conditional flow matching trains a velocity field using the conditional flow matching objective:
where is the linear interpolant. At inference, the ODE is solved with the desired condition .
Conditional flow matching is simply flow matching with the condition as an additional input to the network. No guidance scale is needed at inference — the model directly generates from rather than requiring post-hoc steering. CFG can still be applied on top of conditional flow matching for additional sharpening, using the same formula (15.3) with replacing .
The advantage of direct conditional training is efficiency: one forward pass per step (vs. two for CFG). The disadvantage is that the condition must be available at training time — you cannot guide toward conditions that were not seen during training.
15.5 Reward-Based and Energy-Based Steering
A more general setting: instead of a discrete condition , the guidance signal is a reward function or energy function that assigns a scalar score to each generated sample. The goal is to generate samples that maximize the reward (or minimize the energy) while maintaining diversity.
The tilted distribution is:
where is the inverse temperature. At , sampling is unconditional. As , sampling concentrates on the mode within the support of .
For a flow-based or diffusion-based model, the score of the tilted distribution at noise level is:
where is the expected reward conditioned on the current noisy state. This is analogous to classifier guidance, with the reward gradient replacing the classifier gradient.
[!remark] 15.2 Computing — the expected reward at the endpoint given a noisy intermediate — is the central challenge of reward-based guidance. Two approaches: (1) one-step denoising: approximate where is the one-step denoising estimate (Tweedie formula); (2) learned value function: train a neural network by regressing against the reward of denoised samples. Approach (1) is cheap but noisy at high noise levels; approach (2) is accurate but requires an additional training phase.
This framework connects to the reinforcement learning literature: the reward function plays the role of a terminal reward, the diffusion process is the dynamics, and the guidance is the optimal policy. The value function is the state-value function, and the guidance gradient is the policy gradient. Fine-tuning generative models with reinforcement learning (DDPO, DRaFT, ReFL) makes this connection explicit.
15.6 Posterior Sampling and Inverse Problems
A particularly important class of conditional generation problems is inverse problems: given a measurement (where is a known forward operator and is noise), recover from . This arises in medical imaging (MRI reconstruction from undersampled k-space), computational photography (super-resolution, inpainting, deblurring), and scientific measurement (cryo-EM structure determination).
The posterior is , where for Gaussian noise. The posterior score is:
For linear inverse problems ( is a matrix), the likelihood gradient is known analytically: . The guided score at noise level uses the one-step denoising estimate to approximate the likelihood:
which requires backpropagating through the denoiser — one additional backward pass per solver step.
where is the Tweedie denoiser and is a noise scale that accounts for the uncertainty in the denoising estimate. The guided score is:
DPS and its variants (PSLD, GDM, RED-diff) have achieved state-of-the-art results on inverse problems across imaging modalities, often outperforming task-specific methods that were trained end-to-end for each inverse problem.
15.7 Compositional Generation
A powerful consequence of the score-based formulation is compositionality: multiple conditions can be combined by adding their score contributions.
Given conditions with independent likelihoods , the joint conditional score decomposes as:
Each condition contributes an additive guidance term, and the terms can be combined freely at inference time without retraining. This enables:
- Multi-attribute generation: “a red car on a rainy street” = color guidance + object guidance + scene guidance
- Negation: “a landscape without people” = landscape guidance person guidance
- Logical operations: conjunction (add scores), disjunction (logsumexp of scores), negation (subtract scores)
[!remark] 15.3 Compositionality is exact when the conditions are truly independent given — meaning . In practice, conditions are rarely independent (the color and shape of an object are correlated), so the composed guidance is approximate. The approximation is usually good enough for practical use, but it can produce artifacts when conditions conflict (e.g., “a round square”). The severity of the approximation depends on the degree of conditional dependence and on the guidance scale — high amplifies both the guidance and its artifacts.
15.8 The Guidance-Diversity Tradeoff
All guidance methods in this chapter share a common parameter — the guidance strength (or inverse temperature ) — that controls the tradeoff between fidelity to the condition and diversity of the generated samples. This tradeoff has a precise information-theoretic characterization.
The guided distribution has entropy:
which decreases linearly with for small . Each unit of guidance strength costs approximately nats of diversity — the mutual information between and .
In practice, the optimal depends on the application:
- Image generation: (high guidance, favoring quality over diversity)
- Scientific sampling: (exact posterior, diversity is essential)
- Creative applications: (moderate guidance, balancing novelty and relevance)
- Inverse problems: is determined by the measurement noise level (higher SNR in the measurement allows stronger guidance)
The guidance-diversity tradeoff is the generative analog of the exploration-exploitation tradeoff in reinforcement learning: guidance exploits the condition, while unconditional sampling explores the data distribution.
15.9 Historical Notes
Classifier guidance was introduced by Dhariwal and Nichol (2021) (“Diffusion Models Beat GANs on Image Synthesis”), who trained noise-conditional classifiers and demonstrated that guided diffusion models produce higher-quality images than GANs on ImageNet. The guidance scale and its effect on the FID-IS tradeoff were characterized in this paper.
Classifier-free guidance was introduced by Ho and Salimans (2022) (“Classifier-Free Diffusion Guidance”), who showed that label dropout during training provides a free unconditional model and that the two-evaluation guidance formula (15.3) matches or exceeds classifier guidance without a separate classifier. CFG has since become the standard guidance method for large-scale text-to-image models: Ramesh et al. (2022) (DALL-E 2), Saharia et al. (2022) (Imagen), and Rombach et al. (2022) (Stable Diffusion) all use CFG.
The tilted-distribution interpretation of guidance was formalized by Karras et al. (2022) and Bradley (2024) (“Classifier-Free Guidance is a Predictor-Corrector”). The connection to reward maximization was developed by Black et al. (2024) (DDPO), Clark et al. (2024) (DRaFT), and Xu et al. (2024) (Imagereward), who fine-tuned diffusion models with reinforcement learning objectives.
Diffusion Posterior Sampling (DPS) was introduced by Chung, Kim, Mccann, Klasky, and Ye (2023) (“Diffusion Posterior Sampling for General Noisy Inverse Problems”). Related approaches include Song, Shen, Xing, and Ermon (2022) for linear inverse problems, Kawar, Elad, Ermon, and Song (2022) (DDRM) for spectral methods, and Chung et al. (2023) (GDM). The application to cryo-EM reconstruction was demonstrated by Levy, Poitevin, Marber, et al. (2024) (CryoFM).
Compositional generation was explored by Liu, Karalias, Rempel, and Fidler (2022) (“Compositional Visual Generation with Composable Diffusion Models”) and Du, Li, and Mordatch (2023). The information-theoretic analysis of the guidance-diversity tradeoff appears in Ho and Salimans (2022) and was further developed by Kynkäänniemi, Karras, Laine, Lehtinen, and Aila (2024).
Conditional flow matching was developed as a natural extension of the flow matching framework by Lipman et al. (2023) and Tong et al. (2024). The application to molecular design — conditioning on molecular properties, binding targets, or experimental constraints — is an active area developed by Jing et al. (2024) (AlphaFold 3’s diffusion module), Yim et al. (2023) (FrameFlow), and Song et al. (2024) (EquiFM).