U NDERSTANDING DDPM L ATENT C ODES T HROUGH
O PTIMAL T RANSPORT
Anonymous authors
Paper under double-blind review
A BSTRACT
Diffusion models have recently outperformed alternative approaches to model the distribution of natural images.
Such diffusion models allow for deterministic sampling via the probability flow ODE, giving rise to a latent space and an encoder map.
While having important practical applications, such as the estimation of the likelihood, the theoretical properties of this map are not yet fully understood.
In the present work, we partially address this question for the popular case of the VP-SDE (DDPM) approach.
We show that, perhaps surprisingly, the DDPM encoder map coincides with the optimal transport map for common distributions; we support this hypothesis by extensive numerical experiments using advanced tensor train solver for multidimensional Fokker-Planck equation.
We provide additional theoretical evidence for the case of multivariate normal distributions.
I NTRODUCTION
Denoising diffusion probabilistic models (DDPMs) (Sohl-Dickstein et al., 2015; Ho et al., 2020) have recently outperformed alternative approaches to model the distribution of natural images both in the realism of individual samples and their diversity (Dhariwal & Nichol, 2021).
These advantages of diffusion models are successfully exploited in applications, such as colorization (Song et al., 2021b), inpainting (Song et al., 2021b), super-resolution (Saharia et al., 2021; Li et al., 2022), and semantic editing (Meng et al., 2021), where DDPM often achieve more impressive results compared to GANs.
One crucial feature of diffusion models is the existence of a deterministic invertible mapping from the data distribution to the limiting distribution of the diffusion process, commonly being a standard normal distribution.
This approach termed denoising diffusion implicit model (DDIM) (Song et al., 2021a), or the probability flow ODE in the continuous model (Song et al., 2021b), allows to invert real images easily, perform data manipulations, obtain a uniquely identifiable encoding, as well as to compute exact likelihoods.
Despite these appealing features, not much is known about the actual mathematical properties of the encoder map and corresponding latent codes, which is the question we address in this work.
Concretely, in this paper, we show that for the DDPM diffusion process, based on the Variance Preserving (VP) SDE (Song et al., 2021b), this encoder map with a large numerical accuracy coincides with the Monge optimal transport map between the data distribution and the standard normal distribution.
We provide extensive empirical evidence on controlled synthetic examples and real datasets and give a proof of equality for the case of multivariate normal distributions.
Our findings suggest a complete description of the encoder map and an intuitive approach to understanding the ‘structure’ of a latent code for DDPMs trained on visual data.
In this case, the pixel–based Euclidean distance corresponds to high–level texture and color–level similarity, directly observed on real DDPMs.
To summarize, the contributions of our paper are:
We theoretically verify that for the case of multivariate normal distributions the Monge optimal transport map coincides with the DDPM encoder map.
We study the DDPM encoder map by numerically solving the Fokker-Planck equation on a large class of synthetic distributions and show that the equality holds up to negligible errors.
We provide additional qualitative empirical evidence supporting our hypothesis on real image datasets.
R EMINDER ON DIFFUSION MODELS
We start by recalling various concepts from the theory of diffusion models and stochastic differential equations (SDEs).
2. D ENOISING DIFFUSION PROBABILISTIC MODELS
Denoising diffusion probabilistic models (DDPMs) is a class of generative models recently shown to obtain excellent performance on the task of image synthesis (Dhariwal & Nichol, 2021;
Ho et al., 2020; Song et al., 2021b).
We start with a forward (non-parametric) diffusion which gradually adds noise to data, transforming it into a Gaussian distribution.
Formally, we specify the transitions probabilities as
[Equation]
for some fixed variance schedule β 1 , . . .
, β t .
Importantly, a noisy sample x t can be obtained directly from the clean sample x 0 as x t =
√ ¯ α t x 0 + √ 1 − ¯ α t z , with z ∼ N (0 , I ) and α t := 1 − β t , ¯ α t :=
(cid:81) ts =1 α s .
The generative model then learns to reverse this process and thus gradually produce realistic samples from noise.
Specifically, DDPM learns parameterized Gaussian transitions:
[Equation]
In practice, rather than predicting the mean of the distribution in Equation (2), the noise predictor network ϵ θ ( x t , t ) predicts the noise component from the sample x t and the step t ; the mean is then a linear combination of this noise component and x t .
The covariances σ t can be either fixed or learned as well; the latter was shown to improve the quality of models (Nichol & Dhariwal, 2021).
Interestingly, the noise predictor ϵ θ ( x t , t ) is tightly related to the score function (Stein, 1972; Liu et al., 2016; Gorham, 2017) of the intermediate distributions; specifically by defining s θ ( x t , t ) as
[Equation]
we obtain that s θ ∗ ( x t , t )
≈ ∇ x log p t ( x t ) , with p t ( x t ) being the density of the target distribution after t steps of the diffusion process and θ ∗ are the parameters at convergence.
Stochastic and deterministic sampling.
Given the DDPM model, the generative process is expressed as
[Equation]
with the initial sample x T ∼ N (0 , I ) and z ∼ N (0 , I ) .
The sampling procedure is stochastic, and no single ‘latent space‘ exists.
The authors of Song et al.
(2021a) proposed a deterministic approach to produce samples from the target distribution, termed DDIM (denoising diffusion implicit model).
Importantly, this approach does not require retraining DDPM and only changes the sampling algorithm; the obtained marginal probability distributions p t are equal to those produced by the stochastic sampling.
It takes the following form:
[Equation] [Equation]
By utilizing DDIM, we obtain a concept of a latent space and encoder for diffusion models, since the only input to the generative model now is x T ∼ N (0 , I ) for sufficiently large T .
In the next section, we will see how it is defined in the continuous setup.
2. SDE VIEW ON D IFFUSION M ODELS
The authors of Meng et al.
(2021) proposed to view diffusion models as a discretization of certain stochastic differential equations.
SDEs generalize standard ordinary differential equations (ODEs) by injecting random noise into dynamics.
Specifically, the diffusion process specified by Equation (1) is a discretization of the following SDE:
[Equation]
where dx is an increment of x over the infinitesimal time step dt .
Here, w represents a Brownian motion process, so dw can be intuitively understood as an infinitesimal Gaussian noise.
Similar to
DDPMs, an initial distribution with density p 0 evolves into a standard normal distribution under this SDE.
Various DDPM algorithms can be seen as discretizations of SDE-based algorithms.
For instance, the continuous analogue of DDIM sampling (4) is constructed in the following way. The following (deterministic) ODE, termed probability flow ODE (Song et al., 2021b)
[Equation]
6) results in the same marginal distributions p t as given by the SDE (5). Here, the score function ∇ x log p t ( x ) is similarly approximated via a neural network during training.
If we reverse this ODE, we obtain a mapping from the limiting distribution to the data distribution. It turns out that the DDIM sampling is a discretization of this continuous approach (Song et al., 2021b).
The well-developed theory of SDEs provides us with a rigorous mathematical apparatus allowing us to study the properties of diffusion models at hand.
We will utilize the following well-known equation termed the forward Kolmogorov, or Fokker-Planck equation (Risken, 1996).
This equation determines how a density p 0 evolves under a (general) SDE.
For (5) it takes the following form:
[Equation]
Note, that β ( t ) can be removed from (7) by change of variables dt := β ( t ) 2 dt, resulting in the PDE of the form
[Equation]
Without loss of generality, we will work with this simplified equation since the specific form of β ( t ) does not affect the results.
In this case, the probability flow ODE takes the following form:
[Equation]
Encoder map.
As mentioned above, by considering the probability flow ODE (6), we can obtain latent codes for samples from the original distribution.
For a given distribution µ 0 and a timestep t , let us denote the flow generated by this vector field as E µ 0 ( t, · ) .
I.e., a point x ∼ µ 0 is mapped to
E µ 0 ( t, x ) when transported along the vector field for a time t .
The ‘final’ encoding map is obtained when t → ∞ , i.e,
[Equation]
Note that E µ 0 implicitly depends on all the intermediate densities µ t obtained from the diffusion process (or the Fokker-Planck equation).
DDPM E NCODER AND O PTIMAL T RANSPORT
By construction and properties of the phase flow, the map E µ transforms the original distribution µ 0 into the standard normal distribution π := µ ∞ ∼ N (0 , I ) .
Our further analysis investigates a perhaps surprising hypothesis that this map is very close to the optimal transport map.
How to arrive at this idea?
A priori, it seems nontrivial that the theory of optimal transportation is related to the
Fokker-Planck equation and diffusion processes.
Some intuition may be obtained from the Otto calculus (Otto, 1996; 2001; Villani, 2009).
It presents an alternative view of the solutions of the
Fokker-Planck-type PDEs and diffusion equations in the following manner
It can be shown that the trajectory { µ t } ∞ t =0 , obtained by solving the Fokker-Planck equation (or an equivalent diffusion SDE), is, in fact, the gradient flow of a certain functional in the Wasserstein space of probability measures.
Moreover, locally, optimal transport maps between two ‘consecutive’ densities (i.e., separated by an infinitesimal time interval) along this trajectory are given precisely by the flow of the ODE (6).
Thus, this trajectory is generally a sequence of infinitesimal optimal transports, which may not result in the ‘global’ optimal transport map.
However, our experiments suggested that in the case when the target density is N (0 , I ) as in DDPMs, the map is practically indistinguishable from the optimal transport map.
We start with a toy example and then proceed to more general cases.
t = 0 .t
= 1 .t
= 2 .t
=
3 .x ∼ µ E µ ( x ) ∼ N ( 0 , 1 )
3. T OY EXAMPLE
One of the few cases when both optimal transport and diffusion equations can be solved explicitly is the case of multivariate Gaussian distributions.
For simplicity, in this example, we consider µ 0 ∼ N ( a, I ) with a ∈ R n and I ∈ R n × n being the identity matrix.
Rather than utilizing
Equation (8) to obtain intermediate density values, we can do it directly from the transition formulas for SDE (5) found in Song et al.
(2021b); S¨arkk¨a & Solin (2019)
; the corresponding probabilities then take the form:
[Equation]
The probability flow ODE takes the form dxdt = − ae − t .
Solving this ODE amounts to simply integrating the function in the right-hand side, and in the limit t → ∞ we obtain E µ 0 ( x ) = x − a .
Note that this is exactly the optimal transport map between µ 0 and N (0 , I ) .
3. R EMINDER ON OPTIMAL TRANSPORT
We now briefly recall the main definitions of the optimal transport theory.
For a thorough review of optimal transport, we refer the reader to classical texts such as Thorpe (2018); Villani (2009);
Ambrosio et al.
Kantorovich and Monge formulation.
Suppose we have two random variables with densities µ and ν supported on spaces X and Y respectively (in our work, we only consider distributions in
Euclidean spaces).
We consider the optimal transport problem between µ and ν .
There are several possible formulations of this task, namely the Kantorovich formulation and Monge formulation.
Under quite general assumptions, these two formulations are equivalent.
We will start from the
Kantorovich formulation.
In this formulation, we consider densities γ ∈ P ( X × Y ) such that their marginal densities are µ and ν respectively.
Such set is denoted by Π( µ, ν ) and its elements are termed transport plans .
The Kantorovich formulation of the optimal transport problem is finding the optimal transport plan:
[Equation]
where c ( x, y ) is a cost function.
Under quite general assumptions on µ, ν , there exists a unique solution to the Kantorovich problem.
Rather than working with transport plans, it is more convenient to work with transport maps, which provide the means to actually move one distribution to another.
In this formulation (termed the Monge formulation), our goal is to find a transport map S :
X → Y such that
[Equation]
over all µ -measurable transport maps S such that ν = S # µ .
Here, S # µ is the push-forward measure, i.e., ( S # µ )( A ) =
µ ( S − 1 ( A )) for all measurable sets A .
Importantly, for non-atomic measures, these two definitions are equivalent (Villani, 2009).
Given an optimal transport map, it can be straightforwardly converted to the optimal transport plan.
Such a plan is deterministic, as we know precisely where to move each point.
In this work, we consider the quadratic cost function, i.e., c ( x, y ) =
∥ x − y ∥ 2 , as commonly done in the study of diffusion equations and gradient flows in Wasserstein spaces Villani (2009).
In this case, the distance between distributions is denoted as W 2 ( · , · ) and is given by the square root of the optimal transport cost (11).
In the appendix, we also discuss the Benamou-Brenier formulation of optimal transport.
3. M ULTIVARIATE NORMAL DISTRIBUTION CASE
We start by showing theoretically that for arbitrary multivariate normal distributions, the DDPM encoder map coincides with the optimal transport map.
This map is known analytically for normal distributions in the case of the quadratic cost function (Givens & Shortt, 1984).
Theorem 3.1.
Let µ 0 ∼ N ( a (0) , Σ(0)) be a multivariate normal distribution.
Then E µ 0 is the
Monge optimal transport map between µ 0 and N (0 , I ) , i.e.,
[Equation]
See the appendix for the proof.
Discussion.
We show that for multivariate normal distributions, the probability flow induced by the
DDPM diffusion reduces to the optimal transport map in the limit.
Despite the apparent simplicity of this case, the proof requires a non-trivial argument about the probability flow ODE.
Thus, it is hard to attribute this result to a mere coincidence.
We hypothesize that the statement of Theorem 3.1 is valid, perhaps, approximately, for arbitrary distributions (or at least a very large class of distributions), but defer more precise theoretical analysis of this statement to future work.
For now, we thoroughly evaluate this hypothesis on a large class of synthetic and real distributions and show that it holds with high numerical precision.
Very recently, in Lavenant & Santambrogio (2022) appeared a counterexample to the above statement with the two maps not being exactly equal (at a single point).
However, our further analysis suggests that when given a finite number of samples in higher dimensions, the difference is still extremely low.
N UMERICAL EXPERIMENTS ON SYNTHETIC DATA
In this section, we numerically evaluate the aforementioned optimal transport map hypothesis.
The main computational difficulty is the solution of the multidimensional Fokker-Planck equation (8).
To maintain accuracy in traditional discretization-based numerical methods, the number of degrees of freedom of the approximation, i.e., the number of unknowns, grows exponentially as the dimensionality of the underlying state-space increases.
In recent years, low-rank (low-parametric) tensor approximations have become especially popular for solving multidimensional problems in various fields of knowledge (Cichocki et al., 2016; 2017).
Recently proposed approach (Chertkov &
Oseledets, 2021) for the solution of the Fokker-Planck equation utilizing low-rank tensor train (TT) format (Oseledets, 2011), Chebyshev interpolation, splitting and spectral differentiation techniques, allowing us to consider sufficiently fine grids.
Method.
We start by numerically solving the Fokker-Planck equation for an initial density p 0 ( x ) ≡ p ( x, 0) .
According to approach (Chertkov & Oseledets, 2021), Equation (8) is discretized on a tensor-product Chebyshev grid with N nodes for each dimension, and the density p at each time step is represented as a d -dimensional tensor (array) P .
This tensor is approximated in the low-rank
TT-format
P
[Equation]
(13) where n k = 1 , 2 , . . .
, N ( k = 1 , 2 , . .
, d ) represent the multi-index, three-dimensional tensors
G k ∈ R R k − 1 × N × R k are named TT-cores, and integers R 0 , R 1 , . . .
, R d (with convention R 0 =
R d = 1 ) are named TT-ranks.
Storage of the TT-cores G 1 , G 2 , . .
. , G d requires less or equal than d × N × max 1 ≤ k ≤ d R 2 k memory cells instead of N d cells for the uncompressed tensor, and hence the TT-decomposition is free from the curse of dimensionality if the TT-ranks are bounded.
Thus, at each time step m = 1 , 2 , . . .
, t max h , we obtain discrete values of the density p ( x, mh ) , represented in the compact TT-format as in Equation (13).
In the appendix, we describe the algorithm in more details.
Next, we solve the probability flow ODE from Equation (9).
We sample a set of points, termed
X 0 , from the original density p 0 ( x ) (since the initial density is presented in the TT-format, we use a specialized method for sampling from (Dolgov & Scheichl, 2019)).
Then we numerically solve the probability flow ODE with the Runge-Kutta method (DeVries & Wolf, 1994) for each point (we calculate the density logarithm gradient using the spectral differentiation methods in the TT-format from (Chertkov & Oseledets, 2021)).
The resulting set is denoted as X 1 .
Given these two point clouds, X 0 and X 1 , we numerically compute the optimal transport cost with the Python Optimal Transport (POT) library (Flamary et al., 2021).
We then compute the transport cost for the map sending a point x i ∈
X 0 to its counterpart E p ( x i ) ∈
X 1 .
Our hypothesis suggests that these two costs will be equal to a reasonable precision.
Distributions.
We consider d -dimensional distributions specified by the following set of parameters: a 1 ∈ R d , a 2 ∈ R d , Q 1 ∈ R d × d , Q 2 ∈ R d × d , with Q 1 and Q 2 being symmetric positive definite.
Given these parameters, we set the density p ( x ) (with x ∈ R d ) by the following formula
[Equation]
where the square in q 2 is understood elementwise (so q 2 is a polynomial of degree 4 ) and Z is a normalizing constant obtained by numerical integration.
We then consider uniform mixtures of up to 5 of such randomly generated distributions, i.e., [Equation]
[Equation]
with p i being as above.
Some examples for the 2 -dimensional case (i.e., d = 2 ) are visualized at
Figure 2.
We see that the distributions are quite diverse and lack any symmetry.
We use the distribution from Equation (14) for the 2 and 3 -dimensional case.
If d > 3 , the number of parameters in the TT-representation of this distribution turns out to be too large, so we use a density of a simpler form
[Equation]
where Z is a normalizing constant obtained by numerical integration in the TT-format and q ( x ) is a random function in the TT-format with positive TT-cores (each element of the TT-cores was sampled from U (0 , 1) ) and of rank 2 . Since the Gaussian density has rank 1 with variables being completely separated, the above formula provides us with a low-rank fast decaying density suitable for experiments.
Experiment and results.
We consider three dimension numbers d = 2 , 3 , 7 .
For the case d =and d = 3 we use the density from Equation (14) and for the case d = 7 we use the density from
Equation (15).
As the spatial domain, we consider the square [ − 8 , 8] d , and densities were scaled beforehand to decay sufficiently fast towards the boundary.
For the time dimension, we consider the range [0 , 5] .
We construct 100 random densities for each d and compute two transport costs as described above.
Some examples of the obtained encoder maps for the 2 -dimensional case are given at Figure 3.
The trajectories of the probability flow ODE are highly nonlinear, despite providing the optimal transport map in the limit.
The obtained results are presented at Table 1.
Here, the error is defined as
[Equation]
and in the table we report the obtained maximum value of the error for 100 random densities.
For all three considered settings, we have a very high (up to machine precision) accuracy, and we conclude that this experiment fully supported our hypothesis.
Note that these calculations were carried out on a regular laptop and run for one random density took about 100 seconds on average for each model problem.
We have additionally run this experiment for the counterexample provided in Lavenant &
[Figure]
[Figure] [Table] [Figure] Santambrogio (2022), again obtaining a machine precision level difference, which is not surprising since the difference between two maps is shown to hold only at (0 , 0) .
This suggests that constructing a ‘numerical’ counterexample is a nontrivial task.
The code is available in the supplementary material.
We now attempt to verify it on a more qualitative level for high-dimensional distributions where solving the Fokker-Planck equation directly is infeasible.
Namely, we consider DDPMs trained on high-resolution image data.
3. E XPERIMENTS OF IMAGE DATASETS
Our experiments in this section are organized as follows.
Suppose that we are given two datasets and train a DDPM for each dataset.
Then, by the hypothesis, each DDPM encoder performs optimal transport from respective distributions to N (0 , I ) .
Since the optimal transport in our setting is performed in the L 2 sense, for images, this will be reflected by similarity in the pixel space, i e., highlevel texture similarity.
We can perform the following experiment to see if this indeed holds.
Take a latent code from N (0 , I ) and compute a corresponding image from each distribution respectively by reversing the encoder map.
We can now compare if these images share texture and a high level semantic structure.
Indeed, if each of those images is L 2 -close ‘on average’ to the same latent code, we expect them to also be similar on the pixel level.
Additionally, on datasets of relatively small sizes, we again can compare the directly computed OT map in the pixel space with the DDPM encoder map.
Datasets.
We consider the AFHQ animal dataset (Choi et al., 2020).
It consists of 15000 images split into 3 categories: cat, dog, and wild.
This is a common benchmark for image-to-image methods.
We also verify our theory on the FFHQ dataset of 70 .
000 human faces (Karras et al., 2019) and the
MetFaces dataset (Karras et al., 2020) consisting of 1000 human portraits.
Finally, we consider a conditional DDPM on the ImageNet dataset (Deng et al., 2009).
By changing the conditioning label, we can control what distribution is being produced, and the argument above still holds.
Models.
We consider guided-diffusion, state-of-the-art DDPMs (Dhariwal & Nichol, 2021).
We use the official implementation available at github 1 .
For each of the datasets we train a separate
DDPM model with the same config as utilized for the LSUN datasets in Dhariwal & Nichol (2021) (with dropout); we use default 1000 timesteps for sampling.
The AFHQ models were trained for 3 · 10 5 steps, the FFHQ model was trained for 10 6 steps; for the MetFaces model, we finetune the FFHQ checkpoint for 25 · 10 3 steps similar to Choi et al.
All models were trained on 256 × 256 resolution.
For the ImageNet experiment, we utilize the 256 resolution checkpoint for the conditional model available at the GitHub link above.
Algorithm.
We follow the aforementioned experimental setup: we sample a number of latent codes from N (0 , I ) in the pixel space ( R 256 × 256 × 3 ) and decode them by different DDPMs with the DDIM algorithm.
For the ImageNet, we have a single DDPM model but vary the conditioning label.
Qualitative results.
We fix a number of latent codes and produce images by all the AFHQ models.
The obtained samples are visualized on Figure 4 (top).
We observe that samples from different rows indeed share high-level features such as texture and pose.
Similarly, we visualize samples from FFHQ and MetFaces on Figure 4 (bottom).
We note that samples are aligned in this case as well; notably, in most cases, pose, gender, and various features such as hairstyle and mustache are transferred.
Interestingly, artifacts of models such as slight noisiness also seem to be shared.
Results obtained with the ImageNet model are provided at Figure 5.
We selected a number of diverse classes, namely, rooster , pizza , crab , corgi .
We sampled a number of latent codes and produced images by conditioning on the respective label.
We see that in this case, high-level textures are transferred as well, sometimes in quite amusing ways (e.g., rooster/pizza rows).
As a sanity check, we performed a similar experiment with the conditional BigGAN model (Brock et al., 2019) pretrained on ImageNet.
We did not observe similar behavior, suggesting that the texture alignment is an artifact specific to DDPM and not happening simply due to the conditioning mechanism.
We observe that samples share texture and pixel-based similarity.
Numerical results.
We now apply the evaluation scheme of Section 3.4 to the AFHQ dataset.
We take the validation subset of each part of the dataset ( Cat / Dog / Wild ) containing 500 images and invert them with DDIM.
We then compute the optimal transport matrix between the images and their respective codes (understood as vectors in R 256 × 256 × 3 ) with POT.
We then compared the obtained OT cost with the cost for the ODE induced map.
In all three cases, they matched up to a machine precision .
Given the high dimensionality of the pixel space and a low number of samples, the exact coincidence with the hypothesis is not surprising, since for the majority of synthetic experiments, there was an exact match.
Intuitively, this should become easier in high dimensions as we may trade some inaccuracies in the model with there being ‘more space’.
To conclude, experiments on real image datasets support our hypothesis and provide interesting examples of how latent codes can be utilized to transfer images from one distribution to another via a ‘proxy’ normal distribution.
R ELATED WORK
Optimal transport (OT) is a classical area of mathematics tightly related to diffusion processes and PDEs.
With hundreds of papers on this topic, we can not provide a thorough review of all the literature and refer the reader to great texts such as Villani (2009);
Ambrosio et al.
; Thorpe (2018).
Computational approaches to OT have been extensively studied by the machine learning communities (Cuturi, 2013; Altschuler et al., 2017; Lin et al., 2019).
We also note the work (Onken et al., 2021) in which the relationship between OT and normalizing flows was considered, as well as the work (Mokrov et al., 2021), where a method based on the Wasserstein gradient flows was proposed for solution of the Fokker-Planck equation.
A recently introduced class of score-based models termed diffusion Schr¨odinger bridges (Chen et al., 2016; De Bortoli et al., 2021; Gushchin et al., 2022) is tightly related to the entropy-regularized OT problem, providing a continuous analog of the Sinkhorn algorithm.
In our paper, we show a connection between DDIM and (non-regularized) OT formulations, not covered by the Schr¨odinger bridge theory.
As mentioned in Section 3.2, a similar question was studied in Lavenant & Santambrogio (2022) providing a theoretical counterexample, while our analysis is mostly numerical and is motivated by the practical goal of understanding the DDPM encoder.
C ONCLUSION
In this work, we provided theoretical and experimental evidence that due to the nature of DDPMs, the encoder map turns out to be the optimal transport map.
We believe that this result will be interesting to both optimal transport and diffusion models communities.
We hope that it will inspire other researchers to obtain general proof of this hypothesis.
One observation about the obtained results is that the quadratic cost in the pixel space seems suboptimal when working with visual data.
Perhaps, a more elaborate diffusion process leading to feature-based cost may be constructed.
We leave this analysis to future work.
A B ENAMOU -B RENIER FORMULATION OF OPTIMAL TRANSPORT
It will be instructive to consider another formulation of the optimal transport, originating in spirit from the fluid dynamics (Benamou & Brenier, 2000; Villani, 2003).
Assume that at t = 0 we are given a set of ‘particles’ from the density ρ 0 which move in such a way that at t = 1 their state is described by the density ρ 1 .
Moreover, these particles move in such that they perform the least amount of work.
Formally, they minimize the following action :
[Equation]
with x varying in the set of particles.
In the continuous limit, we obtain the following formulation (with v t being the velocity field):
[Equation]
where the infimum is taken over all time-dependent probability densities { ρ t } 1 t =0 which agree with ρ 0 and ρ 1 at respective times t = 0 and t = 1 , and overall time-dependent velocity fields { v t } 1 t = which convect ρ t , as expressed by the continuity equation in the right-hand side of Equation (16).
It can be shown that the infimum in Equation (16) is given by W 2 ( ρ 0 , ρ 1 ) 2 .
Moreover, given an optimal transport map the corresponding admissible trajectory for the Benamou-Brenier formulation can be easily constructed.
Importantly, trajectories generated by this vector field are straight lines , which does not hold for the probability flow ODE (see, e.g., Figure 1).
There is no contradiction here: we do not claim that the probability flow ODE is the solution of the Benamou-Brenier problem, but only that the flow map induced by this ODE (in the limit t → ∞ ) solves the Monge problem.
So, in general, the vector field solving (16) and the vector field of the probability flow ODE will be different.
B P ROOF OF T HEOREM 3.
The proof of Theorem 3.1 is based on the fact that in the case of µ 0 being normal distribution, all the intermediate densities µ t are normal as well, i.e, µ t ∼ N ( a ( t ) , Σ( t )) .
Moreover, we can easily obtain ODEs describing how their means and covariances transform (Song et al., 2021b; S¨arkk¨a & Solin, 2019).
These ODEs take the following form:
[Equation]
with the solutions
[Equation]
Let us start with the homogeneous case a (0)[-= 
-]
= 0 , so a ( t ) ≡ {+
+}
(we provide the proof of the general case below).
The probability flow ODE then takes the following form:
[Equation]
We start by noticing that all the matrices Σ( t ) commute with each other.
We then can write the solution of Equation (20) as:
[Equation]
with exp being the matrix exponential.
Let us consider the eigendecomposition of Σ(0) , i.e., assume that Σ(0) =
U T Λ U with Λ = diag ( λ 1 , . . .
, λ d ) being a diagonal matrix of positive eigenvalues and
U T U
=
I .
We obtain that
[Equation]
where f ( λ, t ) is a function defined as
[Equation]
where now all the functions operate on real numbers.
Direct integration shows that:
[Equation]
We see that lim t →∞ f ( λ, t ) =
λ − 1 / 2 .
Then, by definition of the matrix square root, E µ 0 ( x ) = Σ(0) − 1 / 2 x .
This is exactly the optimal transport map between µ 0 and N (0 , I ) .
For a general case, we obtain the following ODE.
[Equation]
This is an inhomogeneous ODE.
We can obtain its solution via the following standard approach.
Let
Z ( t ) be the fundamental solution of the homogeneous part (see Equation (18))
, i
[Equation]
e, [Equation]
with
[Equation]
We find that a particular solution (with 0 initial condition) of the inhomogeneous problem is given by:
[Equation]
Recall that
[Equation]
[Equation]
We obtain:
[Equation]
Again, it suffices to work on the level of the spectrum.
I.e,
[Equation]
with
[Equation]
Direct integration shows that:
[Equation]
Thus, we obtain that
[Equation]
By combining this piece with the limit of general solution obtained above, we find that
[Equation]
which is exactly the desired optimal transport map between µ 0 and N (0 , 1) (Dowson & Landau, 1982; Olkin & Pukelsheim, 1982).
This expression is also familiar from the commonly used Frech´et Inception Distance metric, where the OT distance is used to evaluate generative models (Heusel et al., 2017). C T ENSOR - TRAIN SOLVER FOR THE F OKKER -P LANCK EQUATION Let us briefly summarize the algorithm from (Chertkov & Oseledets, 2021) for solving the FokkerPlanck equation.
If we introduce diffusion and convection operators from Equation (8)
[Equation]
then on each time step m ( m = 1 , 2 , . .
, M ) the standard second order operator splitting technique (Glowinski et al., 2017) may be formulated
[Equation]
where h is the size of the temporal grid and p m ( x ) = p ( x, mh ) is a solution on the m -th time step. It is equivalent to the sequential solution of the following equations [Equation]
24) with the final approximation of the solution ρ m +1 (
· ) =
p (2) D ( · , t m + h 2 ) .
To solve the diffusion part (see Equations (22) and (24)), we discretize the Laplace operator using the second order Chebyshev differential matrices (Trefethen, 2000), and convolve the matrix exponential with the TT-cores of p m .
The convection part (see Equation (23)) is solved by efficient interpolation in the TT-format with the TT-cross method (Oseledets & Tyrtyshnikov, 2010).
Finally, at each time step m , we obtain discrete values of the density p ( x, mh ) , represented in the low rank TT-format as in Equation (13).
Then we can solve the probability flow ODE, using these tensors, as described in the main text.