Manuscript Offprint
arXiv:2610.40383Composing and Steering Diffusion Models with Generalized Feynman-Kac Correctors
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
ABSTRACT
Diffusion models have become the leading paradigm in generative modeling, yet many applications require sampling from distributions that are not those of any single pretrained model, but are instead defined through combinations of several models, possibly tilted toward high values of a downstream reward. Naively combining the scores of the models yields incorrect samples, while existing corrections are restricted to specific families of targets. In this work, we introduce the generalized Feynman–Kac correctors (GFKC), a principled framework for sampling from an arbitrary target function of several pretrained diffusion models. We show that the geometric interpolation between an arbitrary initial function and the target function of the models satisfies a Feynman–Kac partial differential equation, and derive its potential in closed form. To evaluate this potential during generation, we further generalize the log-probability ODE to track the density of each model along trajectories driven by a different velocity field. The resulting algorithm operates entirely in the log domain, incorporates reward-based steering at no additional conceptual cost, and corrects the generation on the fly, without retraining or fine-tuning the models. We validate the method on analytic Gaussian models, where it closely matches the ground-truth targets, and on diffusion models trained on MNIST, where it samples from non-trivial combinations of the models and enables effective steering.
1 Introduction
Diffusion models [1, 2, 3] have become the leading paradigm in generative modeling. By learning to reverse a gradual noising process, they produce samples of remarkable quality and diversity, and they are now the method of choice across a wide range of domains, including image synthesis [4, 5, 6, 7], audio [8] and video generation [9], inverse problems [10], and the design of molecules and proteins [11, 12, 13]. Beyond their empirical success, diffusion models rest on a solid mathematical foundation: in the continuous-time formulation of [3], generation amounts to simulating a stochastic or ordinary differential equation driven by a learned score, whose marginals evolve according to an explicit partial differential equation. This structure makes it possible to reason about, and to modify, the generative process in a principled way.
In many applications, however, the distribution of interest is not that of a single pretrained model. One may wish to combine several models, each trained on different data or capturing a different concept, and to sample from a distribution that is defined in terms of all of them: their product, which retains only what all models agree on; their mixture; or more elaborate combinations, such as distributions favoring the regions where one model assigns high probability and another does not. Training a new model for every such target is costly and often impractical, and a natural alternative is to reuse the pretrained models at inference time [14]. Yet, naive approaches that simply combine the scores of the models do not reproduce the correct intermediate distributions, and therefore yield biased samples [15]. Recently, [16] showed that this bias can be corrected exactly by means of the Feynman–Kac formula [17]: the generated particles are assigned weights that evolve along the generation, and are periodically resampled within a sequential Monte Carlo scheme [18]. These Feynman–Kac correctors, however, are derived separately for specific families of targets, namely annealed distributions, products of experts, and the geometric averages underlying classifier-free guidance [19].
School of Mathematical Sciences, Tel Aviv University, Israel.
Emails: waelmattar.95@gmail.com; d.e.freedman@gmail.com
A complementary need arises when the generated samples are required not only to be realistic, but also to optimize a downstream objective, such as the stability or binding affinity of a molecule, or the similarity of an image to a prescribed reference. This is the task of steering, or reward-guided generation [20]. A principled formulation consists in maximizing the expected reward, regularized by the Kullback–Leibler divergence to the pretrained distribution, whose solution is the pretrained distribution exponentially tilted by the reward. One approach is to fine-tune the pretrained model toward this tilted distribution [21, 22], which, however, requires additional training for every reward. Inference-time methods, such as classifier guidance [4] and SMC-based guidance [23, 24], instead approximate the tilted distribution during generation, without modifying the model, but are typically formulated for a single pretrained model.
In this paper, we unify and generalize these two lines of work. We introduce the generalized Feynman–Kac correctors (GFKC), which enable sampling from an arbitrary target function of several pretrained diffusion models, with an optional reward-based tilt. Our main result, Theorem 1, shows that the geometric interpolation between an arbitrary initial function and an arbitrary terminal function of the models satisfies a Feynman–Kac PDE, and provides its potential in closed form. To evaluate this potential along the generation, we derive a generalization of the log-probability ODE [25, 26], which tracks the density of every model along trajectories generated by a different velocity field. The resulting algorithm operates entirely in the log domain, performs the correction on the fly during the generation process, and requires neither retraining nor fine-tuning of the models. The framework of [16] is recovered as a special case.
The remainder of the paper is organized as follows. Section 2 reviews continuous-time diffusion models, the Feynman–Kac correctors, and reward-guided tilting. Section 3 presents our main result, the generalized log-probability ODE, the incorporation of steering, and the resulting GFKC algorithm. Section 4 illustrates the method in two settings of different nature: an analytic setting of overlapping Gaussian distributions, where the generated samples are compared with exact ground-truth densities, and a high-dimensional setting of diffusion models trained on the MNIST dataset [27], where we demonstrate both the sampling from non-trivial combinations of the models and the effect of steering. All numerical experiments are fully reproducible, and the code, together with the pretrained models, is publicly available at https://github.com/WaelMattar/GFKC.
2.1 Continuous-time diffusion models
Diffusion models [1, 2, 3] generate data by learning to reverse a gradual noising process. In the continuous-time formulation of [3], the noising process is described by a forward stochastic differential equation (SDE)
where is a drift, a scalar diffusion coefficient and a standard Brownian motion in . The coefficients are chosen so that the marginal distribution of approaches a tractable prior as . A widely used choice, which we adopt in Section 4, is the variance-preserving (VP) SDE, with and for a positive noise schedule .
Generation proceeds backward in . To be consistent with the convention used throughout this paper, we reparametrize time as and denote by the corresponding marginals, so that corresponds to noise and to data. By the classical time-reversal result of [28], the marginals are reproduced by the family of generative dynamics
where is the score. The case recovers the reverse-time SDE, whereas yields the deterministic probability flow ODE [3]
Intermediate values of interpolate between the two regimes; see also [5]. Regardless of , the marginals satisfy the continuity equation
In practice, the score is unknown and is approximated by a neural network trained via denoising score matching [29, 30]. A common parametrization, which we also adopt, is the noise-prediction objective of [2]: a network is trained to minimize , where with , and the score is recovered as . Finally, the probability flow ODE (3) also enables likelihood evaluation: along its trajectories, the instantaneous change-of-variables formula [25, 26] gives
where, in high dimension, the divergence is typically estimated with the Hutchinson trace estimator [31]. As discussed in Section 3, equation (5) only holds when the particle is transported by the velocity field of the model whose density is evaluated, and must be generalized in our multi-agent setting. This equation will become essential in deriving our main algorithm.
2.2 Feynman–Kac correctors
Many distributions of practical interest are not the marginals of a single trained diffusion model, even when they are explicitly defined in terms of such models. Typical examples include the annealed distribution , the product of two models, and the geometric average , which underlies classifier-free guidance [19]. A natural heuristic is to simulate (2) with the correspondingly combined scores, e.g., or . However, the resulting dynamics do not reproduce the desired intermediate distributions, and the generated samples are therefore biased [15].
To address this issue, [16] proposed the Feynman–Kac correctors (FKC). Their key observation is that, for each of the aforementioned targets, the time derivative of the desired path of distributions can be written as a continuity equation of the form (4), augmented with a term of the form , where is commonly referred to as the potential function, see [17]. In other words, it satisfies a Feynman–Kac partial differential equation (PDE), with a velocity field and a potential that are explicitly computable from the pretrained scores. By the Feynman–Kac formula [17], such a PDE can be simulated by a population of weighted particles: the particles are transported by the velocity field, while their log-weights accumulate the potential along the trajectories. The weights are then used within a sequential Monte Carlo (SMC) scheme [17, 18], in which particles are periodically resampled in proportion to their weights, which prevents weight degeneracy and focuses the computational effort on the relevant regions of space. This principle is formalized in the following lemma, which will become essential to proving our main result.
Lemma 1. Let be a function with for every . Assume that adheres to the following Feynman–Kac PDE
for some vector field in , and a real-valued potential function . Then, samples from the normalized density can be drawn by simulating the weighted SDE
where
We provide the proof of Lemma 1 in Appendix A for completeness. In practice, the weights in (7) relate the simulated particles to the normalized density as follows [16]. Denoting by the log-weight accumulated along a trajectory, one has, for any bounded test function ,
where the expectations on the right-hand side are taken over the trajectories of (7). Given simulated particles , replacing both expectations by empirical averages yields the self-normalized importance sampling estimator
which converges to the exact expectation as . Accordingly, approximate samples from are obtained by drawing particles from the categorical distribution with probabilities proportional to , which is precisely the resampling step of Algorithm 1.
Lemma 1 is a direct consequence of the Feynman–Kac formula [17], and underlies the constructions of [16]. Note that when , the PDE (6) reduces to the continuity equation (4), the weights remain constant, and the lemma recovers standard sampling with the velocity field v. Moreover, the centering term in (8) is common to all particles at a given time, and therefore cancels upon normalization of the weights. Consequently, in practice one may accumulate the uncentered potential g and normalize the weights only when they are used, as is done in Algorithm 1. Finally, we emphasize that, in [16], the potential g is derived separately for each specific family of targets. Theorem 1 below removes this restriction by providing the potential for an arbitrary combination of the agents.
2.3 Reward-guided tilting
A complementary line of work concerns the adaptation of a pretrained diffusion model to maximize a downstream reward at inference time, without fine-tuning [20]. Maximizing the reward alone would collapse the generation onto its maximizers and discard the information encoded in the pretrained model. The standard remedy is to regularize the objective by the Kullback–Leibler divergence to the pretrained distribution ,
This problem admits the closed-form solution
which follows from the identity
valid for any with . Indeed, the right-hand side is maximized if and only if . The parameter balances the two objectives: as , the tilted distribution reduces to , whereas as , it concentrates on the maximizers of within the support of .
As reviewed in [20], existing inference-time methods, such as classifier guidance [4], SMC-based guidance [23] and value-based sampling, can be viewed as approximations of the optimal denoising process that samples from (10). A central ingredient of these methods is a look-ahead function, the soft value function, which predicts, from an intermediate state , the reward attained at the end of the generation. Since the soft value function is generally intractable, it is commonly approximated by evaluating the reward at an estimate of the terminal state, obtained for instance from the posterior mean via Tweedie's formula [10] or by simulating the generative dynamics up to the terminal time. We adopt the latter approach in Section 4.
In this work, we apply the same principle to targets composed of several diffusion models. Given a terminal function of the agents, we denote by its normalization, and consider the tilted target (16), which, by (10), is the solution of (9) with .
Our contribution. The FKC framework [16] provides exact weighted sampling for specific families of targets built from pretrained models, while reward-guided methods [20] tilt the distribution of a single pretrained model toward high values of a reward. In this paper, we unify and generalize both approaches. We derive the Feynman–Kac potential for an arbitrary target function of N diffusion models, interpolated geometrically from an arbitrary initial function , with an optional reward-based tilt. The resulting GFKC algorithm performs the correction on the fly, during the generation process, and requires neither retraining nor fine-tuning of the agents.
3 Derivation of the generalized Feynman-Kac correctors algorithm
In this section, we present our main result, which generalizes the Feynman–Kac correctors of [16] from specific families of targets to arbitrary target functions of several pretrained diffusion models, and incorporates the reward-based tilting of Section 2.3 into the same framework.
We consider pretrained diffusion models, henceforth referred to as agents, with marginals , scores and velocity fields , . As in Section 2.1, each agent is assumed to satisfy the continuity equation (4) with its own velocity field, namely . Moreover, we assume that all agents share a common, tractable initial distribution at , as is the case for diffusion models with the same forward process, .
Our goal is to sample from a target distribution that is defined pointwise in terms of the agents. Specifically, given a positive and differentiable terminal function , we wish to sample from the normalized density proportional to
where the agents are evaluated at the terminal time , i.e., at their data distributions. This formulation encompasses, for instance, products of experts, geometric averages underlying classifier-free guidance [19], and annealed distributions, which are the targets considered in [16]. It also includes targets that are not of product form, such as the mixtures and ratios studied in Section 4. We refer to a terminal function as admissible whenever the resulting density is both differentiable and integrable, so that its normalization is well defined.
Since the target is generally not the terminal marginal of any single agent, we construct a path of distributions connecting a tractable initial distribution to the target. To this end, we introduce an initial function , chosen so that is easy to sample from. For instance, when the agents share a common prior , any with , such as the geometric mean, is a valid choice. A natural and flexible family of initial functions is given by
where is continuous and strictly monotone. This family includes the arithmetic mean for , the geometric mean for , and, more generally, the power means for with , among which the harmonic mean corresponds to . Every member of the family satisfies , and is therefore a valid initial function whenever the agents share a common prior . The choice of thus offers considerable freedom in designing the initial distribution of the path (13), without affecting the target at . In our experiments in Section 4, we use the geometric mean.
The two functions are then interpolated geometrically by means of differentiable schedules satisfying and . Throughout, we write for the derivative of with respect to , which is the natural quantity in the log domain.
The following theorem shows that the resulting path satisfies a Feynman–Kac PDE of the form (6), with an explicit potential, so that Lemma 1 applies.
Theorem 1. Let be a set of diffusion models with corresponding vector fields . Let be an initial annealing function, and denote by the target distribution function. Then, simulating (7) with an arbitrary unifying vector field and
(12)
amounts to sampling from the trajectory
which geometrically interpolates between at and at .
Proof. As in Equation (12), we omit the variables x and t throughout the proof for compactness. In the logarithmic domain, the trajectory distribution p of (13) becomes
Consequently, differentiating with respect to t and multiplying the result with p we get :
We now simplify the term in C using the agents' continuity equations (4) and get
Here we used the fact that for all . Before proceeding to the final step of the proof, we note that for an arbitrary unifying vector field , the term can be rewritten as
while the term D can be simplified by directly computing :
which overall gives
Finally, combining (14) with (15) we get
which coincides precisely with the Feynman-Kac equation (6) with the potential function g as in (12).
Theorem 1 establishes an interpolation between an initial function and a desired terminal function along the path given in (13). The sampling process consists of simulating the SDE (7) with a suitable choice of the function , which is constructed so that, at the terminal time , the reweighted samples are distributed according to . The choice of is discussed before the derivation of our main algorithm.
To evaluate the density of a sample under a flow model, one typically relies on the instantaneous change-of-variables formula, commonly known as the log-probability ODE. In our setting, however, this ODE cannot be applied directly, for reasons we now explain, and must instead be suitably modified.
Although the particles evolve under a velocity field , we must compute, for every particle, the densities associated with each model . In other words, even though a particle is transported by a velocity field , its density must still be evaluated under every model . This is achieved by a generalization of the log-probability ODE (5) as follows.
Here, the second line follows by expanding the total time derivative into the partial time derivative and the contribution from the time derivative of the trajectory ; the third line uses the continuity equation for ; the fourth line uses , since the trajectory is generated by the velocity field ; and the fifth line uses the identity . Note that when , the second term vanishes and we recover the standard log-probability ODE as one would expect.
We now examine how the inclusion of steering affects the framework. Suppose now that we wish to steer the generative process toward the tilted target
which is the equivalent of (10), solving the optimization problem in (9), where is the steering parameter, and is a reward function to be maximized. The only modification required in the algorithm is the addition of the term to the function in (12). This additional term alters the evolution of the distribution and tilts the path toward the maxima of the reward function .
The steering parameter controls the strength of the bias toward maximizing throughout the generation process. In the limit , the additional term becomes negligible, and the original path of distributions is recovered. In contrast, as , the steering term becomes increasingly dominant and ultimately governs the generative process, as illustrated in Figure 4.
Building on Theorem 1 and the mathematical evaluations presented in this section, we derive a practical algorithm, henceforth referred to as the GFKC algorithm, for sampling from any admissible target function , with optional reward-based steering. For clarity of presentation, the algorithm refers to the update equations (A)–(G), which are stated below.
Although Theorem 1 allows for an arbitrary unifying vector field , Algorithm 1 relies on a particular choice of . The particles are divided into equally sized sub-populations, and for the -th sub-population we take to be the projection onto its -th argument, for , so that each particle is transported by the velocity field of its own agent. Theorem 1 is thus applied with , which yields the potential in (E). In this way, each sub-population is driven by a genuine generative field and explores the high-density regions of its agent, while the terms in (C) correct for the discrepancy with the other agents. Since the path (13) and its normalizing constant do not depend on the choice of , all sub-populations target the same normalized density, and their particles can be pooled into a single weighted population for estimation and resampling. After resampling, each particle retains the label of its agent.
The quantities appearing in Algorithm 1 are defined as follows.
(A)
(B)
(C)
(D)
(E)
(F)
(G)
We emphasize that Equations (A)–(G) are expressed entirely in terms of the log-densities and of derivatives with respect to , rather than the densities themselves. Accordingly, all computations in the GFKC algorithm are carried out in the log domain. This is essential in practice, since in high-dimensional spaces the densities may take extremely large or extremely small values, which cannot be represented in floating-point arithmetic. Moreover, in some practical scenarios, the log-densities may additionally be clipped to prevent numerical overflow, as we illustrate in Section 4.
Algorithm 1: The generalized Feynman-Kac correctors (GFKC) algorithm
Input: Number of agents ; velocity fields and scores ; initial and target functions ; schedules ; reward function and steering parameter ; total number of particles ; space dimension ; time step ; set of resampling times
Output: Weighted particles approximating the target
Initialization: Assign an equal number of particles to each agent
foreach particle do Sample for to do end
Evolution: while do for to do foreach particle belonging to agent do Compute according to (A) if steering is True then Estimate clean samples from the intermediate states end for to do Compute according to (B) Compute according to (C) Eq. (D) end Compute according to (E) Eq. (F) Eq. (G) end end
if then Resample the particles from the multinomial distribution with weights proportional to end
end
4 Numerical illustrations
We illustrate the performance of Algorithm 1 in two settings of inherently different nature: the first involves analytic generative models for two overlapping bivariate Gaussian distributions, while the second consists of diffusion models trained on the MNIST dataset [27].
4.1 Overlapping bivariate normal distributions
We consider a two-dimensional synthetic setting in which all quantities of interest are available in closed form, which allows the output of the GFKC algorithm 1 to be compared against exact ground-truth densities. The setting consists of agents, each given by a diffusion model whose data distribution is an isotropic bivariate Gaussian with unit variance.
covariance,
with means and . Since is smaller than the unit standard deviation of each component, the two distributions overlap substantially, and their high-density regions are difficult to separate by sampling from either model alone.
Recall that we adopt the convention that corresponds to noise and to data. Each agent defines a path of marginals , , which interpolates between the standard Gaussian at and the data distribution at . In particular, all agents share the same initial distribution , and the scores are known exactly. Consequently, no learned approximation enters the experiment, and any discrepancy between the generated and target distributions can be attributed to the sampling procedure itself rather than to model error.
The interpolation between the initial and terminal functions follows the path (13) with linear schedules and . As the initial function we take the geometric mean of the two models
which at t = 0 coincides with the common standard Gaussian prior. This choice ensures that the interpolation starts from the distribution from which the particles are initialized.
For the terminal function we consider two cases; the first one is designed to emphasize the region in which one model disagrees with the other, while the second one is its symmetrized counterpart. In particular, the first is the asymmetric ratio
for some C > 0, which favors regions of high density under and low density under . The second one is
which favors regions where exactly one of the two models assigns high density. In both cases we set C = 100, so that the denominators strongly penalize regions in which the competing model is non-negligible. This choice of C produces a clear yet moderate shift of mass. Nevertheless, the results do not depend on this particular choice. Owing to the substantial overlap between and , the resulting targets are concentrated on relatively small regions of the plane, which makes them challenging to sample from directly.
We consider 100,000 particles per agent so that the generated samples cover the whole support of the target density, which allows an accurate comparison with the ground truth across the entire domain. We emphasize that this large population is needed only for visualizing and evaluating the full density: drawing individual samples from the target requires far fewer particles, as in the MNIST experiments of Section 4.2.
Since the setting is low-dimensional and the models are available in closed form, we compare the generated samples directly with the ground-truth target distributions. We first present the results for the two choices of , then report the convergence behavior of the algorithm, and finally illustrate the effect of steering.
Figure 2 reports the convergence of the GFKC algorithm for the two experiments of Figure 1 as the number of particles per agent increases. The error is measured in two ways: the Kullback–Leibler divergence between the ground-truth target and its empirical approximation produced by the algorithm, and the distance between the two.
Finally, for the steered variant of the algorithm, we use the reward function , so that the steered target of (16) tilts the terminal distribution toward points closer to the origin, with the strength of this tilt controlled by the steering parameter .
To examine the steering effect, we consider the symmetric terminal function defined in (19), together with the prescribed reward function and steering parameter . This choice creates a competition between two objectives: sampling from the symmetric target, which is bimodal as shown in Figure 1, and favoring samples that lie close to the origin.
Since the mode associated with the first agent, centered around , is closer to the origin, the steered target naturally assigns more mass to this mode at the expense of the other. Figure 3 illustrates the effect of steering for and compares the result with the unsteered target . Figure 4 then shows the steered distributions for several values of , confirming that the steering effect strengthens as decreases, in agreement with the theory.



Figure 1: Sampling with the GFKC algorithm in the bivariate Gaussian setting. Each row corresponds to one choice of the terminal function : the asymmetric ratio of (18) on top and its symmetrized counterpart (19) on bottom. Left column: the ground-truth target densities, obtained by applying directly to the analytic densities (17). Middle column: the empirical densities generated by the GFKC algorithm, using 100,000 particles per agent and simulating up to time . Right column: the relative pointwise error between the ground-truth and the generated densities. Note the close agreement between the left and middle columns.

Figure 2: Convergence of the GFKC algorithm as a function of the number of particles per agent, measured by and the distance, for both choices of .

Figure 3: Effect of steering on the symmetric target of (19), with reward and . Left: the analytic unsteered target density . Middle: the empirical density generated by the GFKC algorithm with steering, using 100,000 particles per agent and simulating up to time . Right: the pointwise difference between the steered empirical density and the unsteered target. Note the shift of mass toward the mode closer to the origin.
During the steered GFKC algorithm, the reward must be evaluated at the terminal state of each particle, which is not available at intermediate times. We therefore estimate the terminal sample from the current state as follows: starting from , we continue the denoising process up to time using the diffusion model of the agent to which the particle belongs, and take the resulting endpoint as . This projection is performed independently of the algorithm, in the sense that the particle itself, its log-densities and its weight are left unchanged. The reward is then incorporated into (A) at the equispaced steering times k for , which form a dense grid of the time interval and are evenly distributed across the generation process.





Figure 4: Effect of the steering parameter on the symmetric target of (19), with reward . Each panel shows the density generated by the GFKC algorithm for a different value of . As decreases, the steering effect becomes increasingly pronounced, and mass is progressively transferred toward the mode closer to the origin. Conversely, for very large , here , the steering term is negligible and the generated density coincides with the unsteered target , as expected.
4.2 Experimenting with the MNIST dataset
We now move from the analytic Gaussian setting to a high-dimensional setting in which the agents are learned diffusion models. Whereas in the Gaussian experiments all quantities were available in closed form, here each agent is a diffusion model trained on a subset of the MNIST dataset [27], the data space has dimension , and neither the scores nor the densities for are known analytically. The two agents are trained on two sets of digit classes that share exactly one class. The shared class thus plays the role of the region where the agents agree, while the two remaining classes, each seen by only one agent, correspond to the regions in which they disagree.
To make the distinction between the shared and the agent-specific classes as clear as possible, we select the classes so that the three digits involved are pairwise far apart. To this end, we view each image as a probability measure on the uniform grid in , obtained by normalizing its pixel intensities, and compare images through the Wasserstein-1 distance with Euclidean ground cost, computed exactly by solving the corresponding optimal transport problem. Distances between classes are measured in two complementary ways: as the distance between the class-mean images, and as the average distance over 1,000 randomly drawn pairs of images from the two classes. Among all triples of digits , we then select the one maximizing the smallest of the three pairwise distances, and assign to the shared class b the digit whose distances to the other two are largest. This procedure leads to the choice
so that the digit 1 is shared by both agents, while the digits 6 and 7 are seen exclusively by the first and second agent, respectively.
Each agent is trained on the images of its two classes from the MNIST training and test sets, with pixel intensities rescaled to and images flattened into vectors in . Since the classes of MNIST are not equally represented, each training batch is drawn with equal probability from the two classes of the agent, so that the resulting model assigns comparable mass to both digits. As in the Gaussian setting, we adopt the convention that corresponds to noise and to data. The forward noising process is the variance-preserving diffusion with a linear noise schedule, with and , where denotes the forward time. The corresponding marginals are , with , and . Each network is trained with the standard noise-prediction objective, from which the score is recovered as .
Both agents share the same architecture, a fully connected network acting directly on the flattened images. The diffusion time is encoded through a 64-dimensional sinusoidal embedding, followed by a linear layer and a SiLU activation. The embedding is concatenated with the input image and passed through three hidden layers of width 2,048 with SiLU activations, followed by a linear output layer of dimension 784. Each agent is trained for 300,000 iterations using the Adam optimizer with learning rate and batch size 512, with the diffusion time sampled uniformly from .
Unlike in the Gaussian setting, the target cannot be evaluated in closed form. The results in this section are therefore assessed qualitatively, through the generated samples and their weights, rather than by comparison with a ground-truth density. Several adjustments to the GFKC algorithm are required in this setting:
- Divergence estimation. In the Gaussian experiments, the divergences appearing in (C) and (E) were computed exactly. In dimension , this is prohibitively expensive, as it requires backward passes per agent and per time step. We therefore replace it with the Hutchinson trace estimator [31]
where is the Jacobian matrix of with respect to , and Gaussian probe vectors .
-
Stochastic sampler. The particles are evolved with a stochastic sampler, namely an Euler–Maruyama discretization with 100 time steps and stochasticity parameter .
-
Double precision. To mitigate the accumulation of round-off errors, all computations during sampling are carried out in double precision.
-
Clipping of the log-densities. The accumulated log-densities are clipped from above at every time step, which prevents overflow in the evaluation of , and their derivatives.
-
Recentering of the log-weights. The log-weights are recentered by their mean at every time step, which prevents them from attaining extreme values. This recentering is valid since the normalized weights are obtained by applying a softmax to the log-weights, and the softmax is invariant under the addition of a constant to all of its elements.
Before applying the GFKC algorithm, we first examine the two agents in isolation. Figure 5 shows images generated independently by each agent using its own diffusion sampler, without any reweighting or resampling. As expected, the first agent produces images of the digits 1 and 6, while the second produces images of the digits 1 and 7. These samples serve as a reference for the results of the GFKC algorithm presented below.
To demonstrate the GFKC algorithm in this setting, we consider the ratio target function with (18), with , which favors regions of high density under the first agent and low density under the second, and hence the digit , which only the first agent has seen. In a parallel experiment, we use the same function with its arguments swapped, , which by symmetry favors the digit , exclusive to the second agent. Figure 6 shows the results of these two experiments, while Figure 7 shows the histograms of the resulting log-weights.
We next consider a target function of a different nature, namely . Since the digit 1 is assigned high density by both agents, , this target places the largest mass on the shared digit, in contrast to the ratio target, which suppressed it. To further emphasize this effect, we sharpen the target by raising it to a power,


Figure 5: Samples generated independently by each agent, without the GFKC algorithm. Left: 100 images generated by the first agent, trained on the digits . Right: 100 images generated by the second agent, trained on the digits .


Figure 6: Results of the GFKC algorithm with the ratio target (18). Left: . Right: . Each panel displays the 100 generated particles, 50 per agent, sorted by their final log-weights in decreasing order, from the top-left to the bottom-right corner. Particles from the first agent (digits 1 and 6) are shown in cyan, and particles from the second agent (digits 1 and 7) in magenta. In the left panel, the highest weights are assigned to the digit 6, exclusive to the first agent, followed by the shared digit 1, while the digit 7 receives the lowest weights. The right panel exhibits the symmetric behavior, with the digit 7 ranked highest and the digit 6 lowest.


Figure 7: Histograms of the final log-weights of the particles generated by the GFKC algorithm, with the ratio target (left) and the swapped target (right). Colors correspond to the agents as in Figure 6: cyan for the first agent (digits 1 and 6) and magenta for the second agent (digits 1 and 7). Solid curves show kernel density estimates of each histogram. In both cases, the log-weights of the two agents are clearly separated, with the agent holding the favored exclusive digit receiving the higher weights. Since the histograms are over log-weights, differences of several thousands translate into ratios of order or more between the weights themselves, so that, after normalization, essentially all the mass is carried by the particles of the favored agent.
and examine how the distribution of the log-weights evolves as increases.
Figure 8 shows the results of the GFKC algorithm for , while Figure 9 illustrates how the histogram of the log-weights evolves for increasing values of . As grows, the log-weights spread over an increasingly wide range, and the peak associated with the shared digit 1 shifts toward larger values. This behavior follows directly from the structure of the target: since , the contribution of to the weight increments in (A), (B) and (E) is scaled by . Consequently, differences in log-weight between particles are amplified roughly in proportion to , and after normalization the weights concentrate increasingly on the particles of highest density under .
We now demonstrate the effect of steering in the MNIST setting. To this end, we use the reward function
where denotes the rotation of an image by radians, and is the mean image of the digit 9 over the MNIST training set, with pixel intensities rescaled to as for the training data. As in the Gaussian setting, the terminal sample entering the steered term in (A) is estimated by projecting each particle to time with the diffusion model of its agent, at the same steering times k for . As the terminal function, we take the sum target , i.e., , which, as shown above, favors the shared digit 1.
Since a 6 rotated by radians closely resembles a 9, the reward function of (21) favors images of the digit 6, in competition with the target , which favors the digit 1. We therefore expect that, for a sufficiently small steering parameter , the highest-weighted particles will no longer depict the digit 1, but rather the digit 6.
We begin by illustrating the steering effect for a small value of , corresponding to strong steering. As shown in Figure 10, although the target favors the digit 1, the steering term dominates, and the highest-weighted particles depict the digit 6. As the weights decrease, the generated 6's become increasingly deformed and their rotations bear less resemblance to . Figure 11 compares the highest-weighted sample, rotated by radians, with .
To further examine the relation between the reward and the weights, Figure 12 displays the reward values of the 100 particles of Figure 10 against their final log-weights. The cluster in the top-right corner, combining the highest rewards with the highest log-weights, corresponds to the images of the digit 6 generated by the first agent.
We conclude this experiment by illustrating the steering effect for different values of . Analogously to Figure 4 in the Gaussian setting, Figure 13 shows the effect of steering as varies. However, since the density cannot be visualized in high dimension, we display, for each value of , the image with the highest log-weight. The values of were chosen deliberately to capture the transition between the two competing effects, namely sampling the digit 1, favored by the target , and steering toward the digit 6, favored by the reward. We observe that this transition occurs around the critical value .

Figure 8: Results of the GFKC algorithm with the annealed sum target (i.e., ). The 100 generated particles, 50 per agent, are sorted by their final log-weights in decreasing order, from the top-left to the bottom-right corner, and colored by agent as in Figure 6: cyan for the first agent (digits 1 and 6) and magenta for the second agent (digits 1 and 7). The highest weights are assigned to the shared digit 1, generated by both agents, while the exclusive digits 6 and 7 are interleaved among the lower weights.

Figure 9: Histograms of the final log-weights for the sharpened sum target , with , colored by agent as in Figure 6. As increases, the range of the log-weights widens and the peak associated with the shared digit 1 shifts toward larger values, so that the separation between the highest-weighted particles and the rest becomes increasingly pronounced. In contrast to the ratio target, the log-weights of the two agents overlap throughout, and the highest-weighted particles originate sometimes from the first agent and sometimes from the second, reflecting that both agents contribute to the shared digit.

Figure 10: Results of the steered GFKC algorithm with the sum target of (20) with , the reward of (21) and a small steering parameter . The 100 generated particles are sorted by their final log-weights in decreasing order, from the top-left to the bottom-right corner, and colored by agent as in Figure 6. Although favors the shared digit 1, the steering term dominates, and the highest weights are assigned to images of the digit 6, all generated by the first agent. As the weights decrease, the generated 6's become increasingly deformed, and their radians rotations bear progressively less resemblance to the mean image . They are followed by the digit 1, while the particles of the second agent, which cannot generate the digit 6, receive the lowest weights.

Figure 11: Left: the highest-weighted particle of the steered GFKC algorithm, a digit 6 generated by the first agent, rotated by radians. Right: the mean image of the digit 9 over the MNIST training set, which defines the reward r of (21). The rotated sample closely resembles the mean image, illustrating how the steering guides the generation toward high values of the reward.

Figure 12: The reward values against the final log-weights for the 100 particles of Figure 10, colored by agent. The two quantities are strongly positively correlated, reflecting the dominance of the steering term for the small . The cluster of roughly 30 points in the top-right corner, combining the highest rewards with the highest log-weights, corresponds to the images of the digit 6, all generated by the first agent. The particles of the second agent, which cannot generate the digit 6, are concentrated in the lower-left region.

Figure 13: Highest-weighted image of the steered GFKC algorithm for decreasing values of . For large , the top image depicts the digit 1, favored by , while for small the steering dominates and the digit 6 emerges. The critical shift occurs between the third and fourth panels, at around .
5 Conclusion
In this work, we introduced the generalized Feynman–Kac correctors, a principled framework for sampling from arbitrary target functions of several pretrained diffusion models, with optional reward-based steering. Our main result in Theorem 1 provides, in closed form, the Feynman–Kac potential of the geometric interpolation between an arbitrary initial and terminal function of the agents, and, combined with a generalized log-probability ODE, leads to Algorithm 1, which is a practical algorithm that operates entirely in the log domain and corrects the generation on the fly, without retraining or fine-tuning. The numerical experiments confirm that the method accurately recovers non-trivial targets in an analytic setting, and that it scales to learned diffusion models in high dimension, where it isolates, combines and steers the concepts captured by the individual agents. Several directions remain open, including the reduction of weight degeneracy in high dimension, for instance through adaptive resampling or lower-variance divergence estimators, cheaper look-ahead estimates for steering, and the application of the framework to large-scale models and scientific domains such as molecular design.
References
[1] Jascha Sohl-Dickstein, Eric Weiss, Niru Maheswaranathan, and Surya Ganguli. Deep unsupervised learning using nonequilibrium thermodynamics. In International Conference on Machine Learning, pages 2256–2265, 2015.
[2] Jonathan Ho, Ajay Jain, and Pieter Abbeel. Denoising diffusion probabilistic models. In Advances in Neural Information Processing Systems, volume 33, pages 6840–6851, 2020.
[3] Yang Song, Jascha Sohl-Dickstein, Diederik P. Kingma, Abhishek Kumar, Stefano Ermon, and Ben Poole. Score-based generative modeling through stochastic differential equations. In International Conference on Learning Representations, 2021.
[4] Prafulla Dhariwal and Alexander Nichol. Diffusion models beat GANs on image synthesis. In Advances in Neural Information Processing Systems, volume 34, pages 8780–8794, 2021.
[5] Tero Karras, Miika Aittala, Timo Aila, and Samuli Laine. Elucidating the design space of diffusion-based generative models. In Advances in Neural Information Processing Systems, volume 35, pages 26565–26577, 2022.
[6] Robin Rombach, Andreas Blattmann, Dominik Lorenz, Patrick Esser, and Björn Ommer. High-resolution image synthesis with latent diffusion models. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pages 10684–10695, 2022.
[7] Chitwan Saharia, William Chan, Saurabh Saxena, Lala Li, Jay Whang, Emily Denton, Seyed Kamyar Seyed Ghasemipour, Raphael Gontijo Lopes, Burcu Karagol Ayan, Tim Salimans, Jonathan Ho, David J. Fleet, and Mohammad Norouzi. Photorealistic text-to-image diffusion models with deep language understanding. In Advances in Neural Information Processing Systems, volume 35, pages 36479–36494, 2022.
[8] Zhifeng Kong, Wei Ping, Jiaji Huang, Kexin Zhao, and Bryan Catanzaro. DiffWave: A versatile diffusion model for audio synthesis. In International Conference on Learning Representations, 2021.
[9] Jonathan Ho, Tim Salimans, Alexey Gritsenko, William Chan, Mohammad Norouzi, and David J. Fleet. Video diffusion models. In Advances in Neural Information Processing Systems, volume 35, pages 8633–8646, 2022.
[10] Hyungjin Chung, Jeongsol Kim, Michael T. Mccann, Marc L. Klasky, and Jong Chul Ye. Diffusion posterior sampling for general noisy inverse problems. In International Conference on Learning Representations, 2023.
[11] Emiel Hoogeboom, Victor Garcia Satorras, Clément Vignac, and Max Welling. Equivariant diffusion for molecule generation in 3D. In International Conference on Machine Learning, pages 8867–8887, 2022.
[12] Joseph L. Watson, David Juergens, Nathaniel R. Bennett, Brian L. Trippe, Jason Yim, Helen E. Eisenach, Woody Ahern, Andrew J. Borst, Robert J. Ragotte, Lukas F. Milles, et al. De novo design of protein structure and function with RFdiffusion. Nature, 620(7976):1089–1100, 2023.
[13] Josh Abramson, Jonas Adler, Jack Dunger, Richard Evans, Tim Green, Alexander Pritzel, Olaf Ronneberger, Lindsay Willmore, Andrew J. Ballard, Joshua Bambrick, et al. Accurate structure prediction of biomolecular interactions with AlphaFold 3. Nature, 630(8016):493–500, 2024.
[14] Nan Liu, Shuang Li, Yilun Du, Antonio Torralba, and Joshua B. Tenenbaum. Compositional visual generation with composable diffusion models. In European Conference on Computer Vision, pages 423–439, 2022.
[15] Yilun Du, Conor Durkan, Robin Strudel, Joshua B. Tenenbaum, Sander Dieleman, Rob Fergus, Jascha Sohl-Dickstein, Arnaud Doucet, and Will Grathwohl. Reduce, reuse, recycle: Compositional generation with energy-based diffusion models and MCMC. In International Conference on Machine Learning, 2023.
[16] Marta Skreta, Tara Akhound-Sadegh, Viktor Ohanesian, Roberto Bondesan, Alán Aspuru-Guzik, Arnaud Doucet, Rob Brekelmans, Alexander Tong, and Kirill Neklyudov. Feynman-kac correctors in diffusion: Annealing, guidance, and product of experts. In International Conference on Machine Learning, 2025.
[17] Pierre Del Moral. Feynman-Kac Formulae: Genealogical and Interacting Particle Systems with Applications. New York. NY: Springer, 2004.
[18] Arnaud Doucet, Nando de Freitas, and Neil Gordon, editors. Sequential Monte Carlo Methods in Practice. Springer, 2001.
[19] Jonathan Ho and Tim Salimans. Classifier-free diffusion guidance. In NeurIPS 2021 Workshop on Deep Generative Models and Downstream Applications, 2021.
[20] Masatoshi Uehara, Yulai Zhao, Chenyu Wang, Xiner Li, Aviv Regev, Sergey Levine, and Tommaso Biancalani. Inference-time alignment in diffusion models with reward-guided generation: Tutorial and review. arXiv preprint arXiv:2501.09685, 2025.
[21] Kevin Black, Michael Janner, Yilun Du, Ilya Kostrikov, and Sergey Levine. Training diffusion models with reinforcement learning. In International Conference on Learning Representations, 2024.
[22] Carles Domingo-Enrich, Michal Drozdzal, Brian Karrer, and Ricky T. Q. Chen. Adjoint matching: Fine-tuning flow and diffusion generative models with memoryless stochastic optimal control. In International Conference on Learning Representations, 2025.
[23] Luhuan Wu, Brian L. Trippe, Christian A. Naesseth, David M. Blei, and John P. Cunningham. Practical and asymptotically exact conditional sampling in diffusion models. In Advances in Neural Information Processing Systems, volume 36, pages 31372–31403, 2023.
[24] Raghav Singhal, Zachary Horvitz, Ryan Teehan, Mengye Ren, Zhou Yu, Kathleen McKeown, and Rajesh Ranganath. A general framework for inference-time scaling and steering of diffusion models. In International Conference on Machine Learning, 2025.
[25] Ricky T. Q. Chen, Yulia Rubanova, Jesse Bettencourt, and David Duvenaud. Neural ordinary differential equations. In Advances in Neural Information Processing Systems, volume 31, 2018.
[26] Will Grathwohl, Ricky T. Q. Chen, Jesse Bettencourt, Ilya Sutskever, and David Duvenaud. FFJORD: Free-form continuous dynamics for scalable reversible generative models. In International Conference on Learning Representations, 2019.
[27] Li Deng. The MNIST database of handwritten digit images for machine learning research. IEEE Signal Processing Magazine, 29(6):141–142, 2012.
[28] Brian D. O. Anderson. Reverse-time diffusion equation models. Stochastic Processes and their Applications, 12(3): 313–326, 1982.
[29] Aapo Hyvärinen. Estimation of non-normalized statistical models by score matching. Journal of Machine Learning Research, 6:695–709, 2005.
[30] Pascal Vincent. A connection between score matching and denoising autoencoders. Neural Computation, 23(7): 1661–1674, 2011.
[31] Michael F. Hutchinson. A stochastic estimator of the trace of the influence matrix for Laplacian smoothing splines. Communications in Statistics – Simulation and Computation, 18(3):1059–1076, 1989.
Appendix A
Here we provide the proof of Lemma 1. We rewrite Equation (6) for the unnormalized without all of the explicit x and t dependencies:
Now, call the corresponding partition function (i.e. normalization factor) of the unnormalized distribution , and call the normalized version of the distribution . In this case,
Plugging this into our equation gives , and therefore
Now, using the fact that , we have that
Note that due to the Divergence Theorem and the fact that as , the first term is 0. Thus, we have that
which overall gives
Plugging this into the equation for gives
However, we know that such an equation for the normalized distribution may be sampled from via the weighted SDE (7). This result is derived in Section 2 of [16].