A T ALE OF T WO F LOWS : C OOPERATIVE L EARNING OF L ANGEVIN F LOW AND N ORMALIZING F LOW T OWARD E NERGY -B ASED M ODEL
This paper studies the cooperative learning of two generative flow models, in which the two models are iteratively updated based on the jointly synthesized examples.
The first flow model is a normalizing flow that transforms an initial simple density to a target density by applying a sequence of invertible transformations.
The second flow model is a Langevin flow that runs finite steps of gradientbased MCMC toward an energy-based model.
We start from proposing a generative framework that trains an energy-based model with a normalizing flow as an amortized sampler to initialize the MCMC chains of the energy-based model.
In each learning iteration, we generate synthesized examples by using a normalizing flow initialization followed by a short-run Langevin flow revision toward the current energy-based model.
Then we treat the synthesized examples as fair samples from the energy-based model and update the model parameters with the maximum likelihood learning gradient, while the normalizing flow directly learns from the synthesized examples by maximizing the tractable likelihood.
Under the short-run non-mixing MCMC scenario, the estimation of the energy-based model is shown to follow the perturbation of maximum likelihood, and the short-run Langevin flow and the normalizing flow form a two-flow generator that we call CoopFlow.
We provide an understating of the CoopFlow algorithm by information geometry and show that it is a valid generator as it converges to a moment matching estimator.
We demonstrate that the trained CoopFlow is capable of synthesizing realistic images, reconstructing images, and interpolating between images.
I NTRODUCTION AND M OTIVATION
Normalizing flows (Dinh et al., 2015; 2017; Kingma & Dhariwal, 2018) are a family of generative models that construct a complex distribution by transforming a simple probability density, such as
Gaussian distribution, through a sequence of invertible and differentiable mappings.
Due to the tractability of the exact log-likelihood and the efficiency of the inference and synthesis, normalizing flows have gained popularity in density estimation (Kingma & Dhariwal, 2018;
Ho et al., 2019;
Yang et al., 2019; Prenger et al., 2019; Kumar et al., 2020) and variational inference (Rezende &
Mohamed, 2015; Kingma et al., 2016).
However, for the sake of ensuring the favorable property of closed-form density evaluation, the normalizing flows typically require special designs of the sequence of transformations, which, in general, constrain the expressive power of the models.
Energy-based models (EBMs) (Zhu et al., 1998; LeCun et al., 2006; Hinton, 2012) define an unnormalized probability density function of data, which is the exponential of the negative energy function.
The energy function is directly defined on data domain, and assigns each input configuration with a scalar energy value, with lower energy values indicating more likely configurations.
Recently, with the energy function parameterized by a modern deep network such as a ConvNet, the
ConvNet-EBMs (Xie et al., 2016) have gained unprecedented success in modeling large-scale data sets (Gao et al., 2018;
Nijkamp et al., 2019; Du & Mordatch, 2019; Grathwohl et al., 2020; Gao et al., 2021;
Zhao et al., 2021; Zheng et al., 2021) and exhibited stunning performance in synthesizing different modalities of data, e.g., videos (Xie et al., 2017; 2021c), volumetric shapes (Xie et al.,
2018b; 2020b), point clouds (Xie et al., 2021a) and molecules (Du et al., 2020).
The parameters of the energy function can be trained by maximum likelihood estimation (MLE).
However, due to the intractable integral in computing the normalizing constant, the evaluation of the gradient of the loglikelihood typically requires Markov chain Monte Carlo (MCMC) sampling (Barbu & Zhu, 2020), e.g., Langevin dynamics (Neal, 2011), to generate samples from the current model.
However, the
Langevin sampling on a highly multi-modal energy function, due to the use of deep network parameterization, is generally not mixing.
When sampling from a density with a multi-modal landscape, the Langevin dynamics, which follows the gradient information, is apt to get trapped by local modes of the density and is unlikely to jump out and explore other isolated modes.
Relying on non-mixing
MCMC samples, the estimated gradient of the likelihood is biased, and the resulting learned EBM may become an invalid model, which is unable to approximate the data distribution as expected.
Recently, Nijkamp et al.
(2019) propose to train an EBM with a short-run non-convergent Langevin dynamics, and show that even though the energy function is invalid, the short-run MCMC can be treated as a valid flow-like model that generates realistic examples.
This not only provides an explanation of why an EBM with a non-convergent MCMC is still capable of synthesizing realistic examples, but also suggests a more practical computationally-affordable way to learn useful generative models under the existing energy-based frameworks.
Although EBMs have been widely applied to different domains, learning short-run MCMC in the context of EBM is still underexplored.
In this paper, we accept the fact that MCMC sampling is not mixing in practice, and decide to give up the goal of training a valid EBM of data.
Instead, we treat the short-run non-convergent Langevin dynamics, which shares parameters with the energy function, as a flow-like transformation that we call the Langevin flow because it can be considered a noise-injected residual network.
Even though implementing a short-run Langevin flow is surprisingly simple, which is nothing but a design of a bottom-up ConvNet for the energy function, it might still require a sufficiently large number of
Langevin steps (each Langevin step consists of one step of gradient descent and one step of diffusion) to construct an effective Langevin flow, so that it can be expressive enough to represent the data distribution.
Motivated by reducing the number of Langevin steps in the Langevin flow for computational efficiency, we propose the CoopFlow model that trains a Langevin flow jointly with a normalizing flow in a cooperative learning scheme (Xie et al., 2020a), in which the normalizing flow learns to serve as a rapid sampler to initialize the Langevin flow so that the Langevin flow can be shorter, while the Langevin flow teaches the normalizing flow by short-run MCMC transition toward the EBM so that the normalizing flow can accumulate the temporal difference in the transition to provide better initial samples.
Compared to the original cooperative learning framework (Xie et al., 2020a) that incorporates the MLE algorithm of an EBM and the MLE algorithm of a generator, the
CoopFlow benefits from using a normalizing flow instead of a generic generator because the MLE of a normalizing flow generator is much more tractable than the MLE of any other generic generator.
The latter might resort to either MCMC-based inference to evaluate the posterior distribution or another encoder network for variational inference.
Besides, in the CoopFlow, the Langevin flow can overcome the expressivity limitation of the normalizing flow caused by invertibility constraint, which also motivates us to study the CoopFlow model.
We further understand the dynamics of cooperative learning with short-run non-mixing MCMC by information geometry.
We provide a justification that the CoopFlow trained in the context of EBM with non-mixing MCMC is a valid generator because it converges to a moment matching estimator.
Experiments, including image generation, image reconstruction, and latent space interpolation, are conducted to support our justification.
C ONTRIBUTIONS AND R ELATED W ORK
Our paper studies amortized sampling for training a short-run non-mixing Langevin sampler toward an EBM.
We propose a novel framework, the CoopFlow, which cooperatively trains a short-run
Langevin flow as a valid generator and a normalizing flow as an amortized sampler for image representation.
We provide both theoretical and empirical justifications for the proposed CoopFlow algorithm, which has been implemented in the PaddlePaddle deep learning platform.
The following are some closely related work.
We will point out the differences between our work and the prior arts to further highlight the contributions and novelty of our paper.
Learning short-run MCMC as a generator.
Recently, Nijkamp et al.
(2019) propose to learn an EBM with short-run non-convergent MCMC that samples from the model, and they eventually keep the short-run MCMC as a valid generator and discard the biased EBM.
Nijkamp et al.
(2020b) use short-run MCMC to sample the latent space of a top-down generative model in a variational learning framework.
An et al.
(2021) propose to correct the bias of the short-run MCMC inference by optimal transport in training latent variable models.
Pang et al.
(2020) adopt short-run MCMC to sample from both the EBM prior and the posterior of the latent variables.
Our work studies learning a normalizing flow to amortize the sampling cost of a short-run non-mixing MCMC sampler (i.e.,
Langevin flow) in data space, which makes a further step forward in this underexplored theme.
Cooperative learning with MCMC teaching.
Our learning algorithm is inspired by the cooperative learning or the CoopNets (Xie et al., 2018a; 2020a), in which an ConvNet-EBM
(Xie et al., 2016) and a top-down generator (Han et al., 2017) are jointly trained by jump-starting their maximum learning algorithms.
Xie et al.
(2021b) replace the generator in the original CoopNets by a variational autoencoder (VAE) (Kingma & Welling, 2014) for efficient inference.
The proposed
CoopFlow algorithm is different from the above prior work in the following two aspects.
(i)
In the idealized long-run mixing MCMC scenario, our algorithm is a cooperative learning framework that trains an unbiased EBM and a normalizing flow via MCMC teaching, where updating a normalizing flow with a tractable density is more efficient and less biased than updating a generic generator via variational inference as in Xie et al.
(2021b)
or MCMC-based inference as in Xie et al.
(2020a).
(ii)
Our paper has a novel emphasis on studying cooperative learning with short-run non-mixing
MCMC, which is more practical and common in reality.
Our algorithm actually trains a short-run
Langevin flow and a normalizing flow together toward a biased EBM for image generation.
We use information geometry to understand the learning dynamics and show that the learned two-flow generator (i.e., CoopFlow) is a valid generative model, even though the learned EBM is biased.
Joint training of EBM and normalizing flow.
There are other two works studying an EBM and a normalizing flow together as well.
To avoid MCMC, Gao et al.
(2020) propose to train an EBM using noise contrastive estimation (Gutmann & Hyv ¨ arinen, 2010), where the noise distribution is a normalizing flow.
Nijkamp et al.
(2020a) propose to learn an EBM as an exponential tilting of a pretrained normalizing flow, so that neural transport MCMC sampling in the latent space of the normalizing flow can mix well.
Our paper proposes to train an EBM and a normalizing flow via short-run MCMC teaching.
More specifically, we focus on short-run non-mixing MCMC and treat it as a valid flow-like model (i.e., short-run Langevin flow) that is guided by the EBM.
Disregarding the biased EBM, the resulting valid generator is the combination of the short-run Langevin flow and the normalizing flow, where the latter serves as a rapid initializer of the former.
The form of this two-flow generator shares a similar fashion with the Stochastic Normalizing Flow (Wu et al., 2020), which consists of a sequence of deterministic invertible transformations and stochastic sampling blocks.
T WO F LOW M ODELS 3. L ANGEVIN F LOW
Energy-based model.
Let x ∈ R D be the observed signal such as an image.
An energy-based model defines an unnormalized probability distribution of x as follows:
[Equation]
where f θ : R D
→ R is the negative energy function and defined by a bottom-up neural network whose parameters are denoted by θ .
The normalizing constant or partition function Z ( θ ) =
(cid:82) exp
[ f θ ( x )]
dx is analytically intractable and difficult to compute due to high dimensionality of x .
Maximum likelihood learning.
Suppose we observe unlabeled training examples { x i , i = 1 , ..., n } from unknown data distribution p data ( x ) , the energy-based model in Eq.
(1) can be trained from { x i } by Markov chain Monte Carlo (MCMC)-based maximum likelihood estimation, in which MCMC samples are drawn from the model p θ ( x ) to approximate the gradient of the log-likelihood function for updating the model parameters θ .
Specifically, the log-likelihood is L ( θ ) =
1 n (cid:80) ni =1 log p θ ( x i ) .
For a large n , maximizing L ( θ ) is equivalent to minimizing the Kullback-Leibler (KL) divergence D
KL ( p data || p θ ) .
The learning gradient is given by
[Equation]
where the expectations are approximated by averaging over the observed examples { x i } and the synthesized examples {
˜ x i } generated from the current model p θ ( x ) , respectively.
Langevin dynamics as MCMC.
Generating synthesized examples from p θ ( x ) can be accomplished with a gradient-based MCMC such as Langevin dynamics, which is applied as follows
[Equation]
where t indexes the Langevin time step, δ denotes the Langevin step size, ϵ t is a Brownian motion that explores different modes, and p 0 ( x ) is a uniform distribution that initializes MCMC chains.
Langevin flow.
As T → ∞ and δ → 0 , x T becomes an exact sample from p θ ( x ) under some regularity conditions.
However, it is impractical to run infinite steps with infinitesimal step size to generate fair examples from the target distribution.
Additionally, convergence of MCMC chains in many cases is hopeless because p θ ( x ) can be very complex and highly multi-modal, then the gradient-based Langevin dynamics has no way to escape from local modes, so that different MCMC chains with different starting points are unable to mix.
Let ˜ p
θ ( x ) be the distribution of x T , which is the resulting distribution of x after T steps of Langevin update starting from x 0 ∼ p 0 ( x ) .
Due to the fixed p 0 ( x ) , T and δ , the distribution ˜
p
θ ( x ) is well defined, which can be implicitly expressed by
[Equation]
where K θ denotes the transition kernel of T steps of Langevin dynamics that samples p θ .
Generally, ˜ p θ ( x ) is not necessarily equal to p θ ( x ) .
˜
p
θ ( x ) is dependent on T and s , which are omitted in the notation for simplicity.
The KL-divergence D KL
[Equation]
[ f ( x )]
+ log Z .
The gradient ascent part of Langevin dynamics, x t = x t − 1 + δ 2 / 2 ∇ x f θ ( x t − 1 ) , increases the negative energy
f
θ ( x ) by moving x to the local modes of f θ ( x ) , and the diffusion part δϵ t increases the entropy of ˜ p
θ ( x ) by jumping out of the local modes.
According to the law of thermodynamics (Cover & Thomas, 2006), D KL (˜ p θ ( x ) || p θ ( x )) decreases to zero monotonically as T → ∞ .
3. N ORMALIZING F LOW
Let z ∈ R D be the latent vector of the same dimensionality as x .
A normalizing flow is of the form
[Equation]
where q 0 ( z ) is a known prior distribution such as Gaussian white noise distribution N (0 , I D ) , and g α : R D
→ R D is a mapping that consists of a sequence of L invertible transformations, i.e., g ( z ) =
g L ◦ · · · ◦ g 2 ◦ g 1 ( z ) , whose inversion z = g − 1 α ( x ) and log-determinants of the Jacobians can be computed in closed form.
α are the parameters of g α .
The mapping is used to transform a random vector z that follows a simple distribution q 0 into a flexible distribution.
Under the change-of-variables law, the resulting random vector x = g α ( z ) has a probability density q α ( x ) =
q 0 ( g − 1 α ( x )) | det( ∂g − 1 α ( x ) /∂x ) | .
Let h l = g l ( h l − 1 ) .
The successive transformations between x and z can be expressed as a flow z
g 1 ←→ h 1 g 2 ←→ h 2 · · · g L ←→ x , where we define z := h 0 and x := h L for succinctness.
Then the determinant becomes | det( ∂g − 1 α ( x ) /∂x )
| = (cid:81)
L l =1 | det( ∂h
[Equation]
/∂h
[Equation]
) | .
The log-likelihood of a datapoint x can be easily computed by
[Equation]
With some smart designs of the sequence of transformations g α = { g l , l = 1 , ..., L } , the logdeterminant in Eq.
(6) can be easily computed, then the normalizing flow q α ( x ) can be trained by maximizing the exact data log-likelihood L ( α ) = 1 n (cid:80) ni
=1 log q α ( x i ) via gradient ascent algorithm.
C OOP F LOW : C OOPERATIVE T RAINING OF T WO F LOWS 4. C OOP F LOW A LGORITHM
We have moved from trying to use a convergent Langevin dynamics to train a valid EBM.
Instead, we accept the fact that the short-run non-convergent MCMC is inevitable and more affordable in practice, and we treats a non-convergent short-run Langevin flow as a generator and propose to jointly train it with a normalizing flow as a rapid initializer for more efficient generation.
The resulting generator is called CoopFlow, which consists of both Langevin flow and normalizing flow.
Specifically, at each iteration, for i = 1 , ..., m , we first generate z i ∼ N (0 , I D ) , and then transform z i by a normalizing flow to obtain ˆ x i =
g α
( z i ) .
Next, starting from each ˆ x i , we run a Langevin flow (i.e., a finite number of Langevin steps toward an EBM p θ ( x ) ) to obtain ˜ x i .
˜
x
i are considered synthesized examples that are generated by the CoopFlow model.
We then update α of the normalizing flow by treating ˜ x i as training data, and update θ of the Langevin flow according to the learning gradient of the EBM, which is computed with the synthesized examples { ˜ x i } and the observed examples { x i } .
Algorithm 1 presents a description of the proposed CoopFlow algorithm.
The advantage of this training scheme is that we only need to minimally modify the existing codes for the MLE training of EBM p θ and normalizing flow q α .
The probability density of the CoopFlow π ( θ,α ) ( x ) is well defined, which can be implicitly expressed by
[Equation]
K θ is the transition kernel of the Langevin flow.
If we increase the length T of the Langevin flow, π ( θ,α ) will converge to the EBM p θ ( x ) .
The network f θ ( x ) in the Langevin flow is scalar valued and is of free form, whereas the network g α ( x ) in the normalizing flow has high-dimensional output and is of a severely constrained form.
Thus the Langevin flow can potentially provide a tighter fit to p data ( x ) than the normalizing flow.
The Langevin flow may also be potentially more data efficient as it tends to have a smaller network than the normalizing flow.
On the flip side, sampling from the
Langevin flow requires multiple iterations, whereas the normalizing flow can synthesize examples via a direct mapping.
It is thus desirable to train these two flows simultaneously, where the normalizing flow serves as an approximate sampler to amortize the iterative sampling of the Langevin flow.
Meanwhile, the normalizing flow is updated by a temporal difference MCMC teaching provided by the Langevin flow, to further amortize the short-run Langevin flow.
Given { ˜ x i } , update α by maximizing 1 m mi =1 log q α (˜ x i ) with Eq.
Given { x i } and { x i } , following the gradient
4. U NDERSTANDING THE L EARNED T WO F LOWS Convergence
equations.
In the traditional contrastive divergence (CD) (Hinton, 2002) algorithm, MCMC chains are initialized with observed data so that the CD learning seeks to minimize D
KL ( p data ( x ) || p
θ ( x ))
− D KL (( K θ p data )( x ) || p
θ ( x )) , where ( K θ p data )( x ) denotes the marginal distribution obtained by running the Markov transition K θ , which is specified by the Langevin flow, from the data distribution p data .
In the CoopFlow algorithm, the learning of the EBM (or the Langevin flow model) follows a modified contrastive divergence, where the initial distribution of the Langevin flow is modified to be a normalizing flow q α .
Thus, at iteration t , the update of θ follows the gradient of D KL ( p data || p θ ) − D KL ( K θ ( t )
q α ( t ) ||
p θ ) with respect to θ .
Compared to the traditional CD loss, the modified one replaces p data by q α in the second KL divergence term.
At iteration t , the update of the normalizing flow q α follows the gradient of D KL ( K θ ( t ) q α ( t )
||
q α ) with respect to α .
Let ( θ ∗ , α ∗ ) be a fixed point the learning algorithm converges to, then we have the following convergence equations
[Equation]
[Equation]
Ideal case analysis.
In the idealized scenario where the normalizing flow q α has infinite capacity and the Langevin sampling can mix and converge to the sampled EBM, Eq.
(9) means that q α ∗ attempts to be the stationary distribution of K θ ∗ , which is p θ ∗ because K θ ∗ is the Markov transition kernel of a convergent MCMC sampled from p θ ∗ .
That is, min α D KL ( K θ ∗ q α ∗
|| q α )
= 0 , thus q α ∗ =
p θ ∗ .
With the second term becoming 0 and vanishing, Eq.
(8) degrades to min θ D KL ( p data || p θ ) and thus θ ∗ is the maximum likelihood estimate.
On the other hand, the normalizing flow q α chases the
EBM p θ toward p data , thus α ∗ is also a maximum likelihood estimate.
Moment matching estimator.
In the practical scenario where the Langevin sampling is not mixing, the CoopFlow model π t = K θ ( t ) q α ( t ) is an interpolation between the learned q α ( t ) and p θ ( t ) , and it converges to π ∗ =
K θ ∗ q α ∗ , which is an interpolation between q α ∗ and p θ ∗ .
π ∗ is the short-run Langevin flow starting from q α ∗ towards EBM p θ ∗ .
π ∗ is a legitimate generator because E p data [ ∇ θ f θ ∗ ( x )] =
E π ∗ [ ∇ θ f θ ∗ ( x )] at convergence.
That is, π ∗ leads to moment matching in the feature statistics ∇ θ f θ ∗ ( x ) .
In other words, π ∗ satisfies the above estimating equation.
Understanding via information geometry .
Consider a simple EBM with f θ ( x ) = ⟨ θ, h ( x ) ⟩ , where h ( x ) is the feature statistics.
Since ∇ θ f θ ( x ) = h ( x ) , the MLE of the EBM p θ MLE is a moment matching estimator due to E p data [ h ( x )] =
E p θ MLE [ h ( x )] .
The CoopFlow π ∗ also converges to a moment matching estimator, i.e., E p data [ h ( x )]
=
E π ∗ [ h ( x )] .
Figure 1 is an illustration of model distributions that correspond to different parameters at convergence.
We first introduce three families of distributions: Ω = { p : E p [ h ( x )] =
E p data [ h ( x )] } , Θ = { p θ ( x ) = exp( ⟨ θ, h ( x ) ⟩ ) /Z
( θ ) , ∀ θ } , and A = { q α , ∀ α } , which are shown by the red, blue and green curves respectively in Figure 1.
Ω is the set of distributions that reproduce statistical property h ( x ) of the data distribution.
Obviously, p θ MLE , p data , and π ∗ =
K θ ∗ q α ∗ are included in Ω .
Θ is the set of EBMs with different values of θ , thus p θ MLE and p θ ∗ belong to Θ .
Because of the short-run Langevin flow, p θ ∗ is not a valid model that matches the data distribution in terms of h ( x ) , and thus p θ ∗ is not in Ω .
A is the set of normalizing flow models with different values of α , thus q α ∗ and q α MLE belong to A .
The yellow line shows the MCMC trajectory.
The solid segment of the yellow line, starting from q α ∗ to K θ ∗ q α ∗ , illustrates the short-run non-mixing MCMC that is initialized by the normalizing flow q α ∗ in A and arrives at π ∗ =
K θ ∗ q α ∗ in Ω .
The dotted segment of the yellow line, starting from π ∗ =
K θ ∗ q α ∗ in Ω to p θ ∗ in Θ , shows the potential long-run
MCMC trajectory, which is not really realized because we stop short in MCMC.
If we increase the number of steps of short-run Langevin flow, D KL ( π ∗ || p θ ∗ ) will be monotonically decreasing to 0.
Though π ∗ stops midway in the path toward p θ ∗ , π ∗ is still a valid generator because it is in Ω .
Perturbation of MLE .
p θ MLE is the intersection between Θ and Ω .
It is the projection of p data onto Θ because θ MLE = arg min θ D KL ( p data || p θ ) .
q α MLE is also a projection of p data onto A because α MLE = arg min α D KL ( p data || q α ) .
Generally, q α MLE is far from p data due to its restricted form network, whereas p θ MLE is very close to p data due to its scalar-valued free form network.
Because the short-run MCMC is not mixing, θ ∗ ̸ = θ MLE and α ∗ ̸ = α MLE .
θ ∗ and α ∗ are perturbations of θ MLE and α MLE , respectively.
p θ MLE shown by an empty dot is not attainable unfortunately.
We want to point out that, as T goes to infinity, p θ ∗ =
p θ MLE , and q α ∗ =
q α MLE .
Note that Ω , Θ and A are high-dimensional manifolds instead of 1D curves as depicted in Figure 1, and π ∗ may be farther away from p data than p θ MLE is.
During learning, q α ( t +1) is the projection of K θ ( t ) q α ( t ) on A .
At convergence, q α ∗ is the projection of π ∗ =
K θ ∗ q α ∗ on A .
There is an infinite looping between q α ∗ and π ∗ =
K θ ∗ q α ∗ at convergence of the CoopFlow algorithm, i.e., π ∗ lifts q α ∗ off the ground A , and the projection drops π ∗ back to q α ∗ .
Although p θ ∗ and q α ∗ are biased, they are not wrong.
Many useful models and algorithms, e.g., variational autoencoder and contrastive divergence are also biased to
MLE.
Their learning objectives also follow perturbation of MLE.
E XPERIMENTS
We showcase experiment results on various tasks.
We start from a toy example to illustrate the basic idea of the CoopFlow in Section 5.1.
We show image generation results in Section 5.2.
Section 5.3 demonstrates the learned CoopFlow is useful for image reconstruction and inpainting, while
Section 5.4 shows that the learned latent space is meaningful so that it can be used for interpolation.
5. T OY E XAMPLE S TUDY
We first demonstrate our idea using a two-dimensional toy example where data lie on a spiral.
We train 3 CoopFlow models with different lengths of Langevin flows.
As shown in Figure 2, the rightmost box shows the results obtained with 10,000 Langevin steps.
We can see that both the normalizing flow q α and the EBM p θ can fit the ground truth density, which is displayed in the red box, perfectly.
This validates that, with a sufficiently long Langevin flow, the CoopFlow algorithm can learn both a valid q α and a valid p θ .
The leftmost green box represents the model trained with
Langevin steps.
This is a typical non-convergent short-run MCMC setting.
In this case, neither q α nor p θ is valid, but their cooperation is.
The short-run Langevin dynamics toward the EBM actually works as an flow-like generator that modifies the initial proposal by the normalizing flow.
We can see that the samples from q α are not perfect, but after the modification, the samples from π ( θ,α ) fit the ground truth distribution very well.
The third box shows the results obtained with 500 Langevin steps.
This is still a short-run setting, even though it uses more Langevin steps.
p θ becomes better than that with 100 steps, but it is still invalid.
With an increased number of Langevin steps, samples from both q α and π ( θ,α ) are improved and comparable to those in the long-run setting with 10, steps.
The results verify that the CoopFlow might learn a biased BEM and a biased normalizing flow if the Langevin flow is non-convergent.
However, the non-convergent Langevin flow together with the biased normalizing flow can still form a valid generator that synthesizes valid examples.
5. I MAGE G ENERATION
We test our model on 3 image datasets for image synthesis.
(i) CIFAR-10 (Krizhevsky & Hinton, 2009) is a dataset containing 50k training images and 10k testing images in 10 classes; (ii) SVHN (Netzer et al., 2011) is a dataset containing over 70k training images and over 20k testing images of house numbers; (iii) CelebA
(Liu et al., 2015) is a celebrity facial dataset containing over 200k images.
We downsample all the images to the resolution of 32 × 32 .
For our model, we show results of three different settings.
CoopFlow(T=30) denotes the setting where we train a normalizing flow and a Langevin flow together from scratch and use 30 Langevin steps.
CoopFlow(T=200) denotes the setting that we increase the number of Langevin steps to 200.
In the CoopFlow(Pre) setting, we first pretrain a normalizing flow from observed data, and then train the CoopFlow with the parameters of the normalizing flow being initialized by the pretrained one.
We use a 30-step-long Langevin flow in this setting.
For all the three settings, we slightly increase the Langevin step size at the testing stage for better performance.
We show both qualitative results in Figure 3 and quantitative results in
Table 1.
To calculate FID Heusel et al.
(2017) scores, we generate 50,000 samples on each dataset.
Our models outperform most of the baseline algorithms.
We get lower FID scores comparing to the single normalizing flow models and the prior works that jointly train a normalizing flow with an
EBM, e.g., Gao et al.
; Nijkamp et al.
(2020a).
We also achieve comparable results with the state-of-the-art EBMs.
We can see using more Langevin steps or a pretrained normalizing flow can help improve the performance of the CoopFlow.
The former enhances the expressive power, while the latter stabilizes the training.
More experimental details and results can be found in Appendix.
[Figure] [Figure]
[Table]
5. I MAGE R ECONSTRUCTION AND I NPAINTING
We show that the learned CoopFlow model is able to reconstruct observed images.
We may consider the CoopFlow model π ( θ,α ) ( x ) a latent variable generative model:
z ∼ q 0 ( z ); ˆ x =
g α
( z ); x =
F θ (ˆ x, e ) , where z denotes the latent variables, e denotes all the injected noises in the Langevin flow, and F θ denotes the mapping realized by a T -step Langevin flow that is actually a T -layer noise-injected residual network.
Since the Langevin flow is not mixing, x is dependent on ˆ x in the
Langevin flow, thus also dependent on z .
The CoopFlow is a generator x = F θ ( g α ( z ) , e ) , so we can reconstruct any x by inferring the corresponding latent variables z using gradient descent on L ( z ) =
|| x − F θ ( g α
( z ) , e )
|| 2 , with z being initialized by q 0 .
However, g is an invertible transformation, so we can infer z by an efficient way, i.e., we first find ˆ x by gradient descent on L (ˆ x ) =
|| x −
F θ (ˆ x, e ) || 2 , with ˆ x being initialized by ˆ x 0 = g α ( z ) where z ∼ p 0 ( z ) and e being set to be 0, and then use z = g − 1 α (ˆ x ) to get the latent variables.
These two methods are equivalent, but the latter one is computationally efficient, since computing the gradient on the whole two-flow generator
F θ ( g α ( z ) , e ) is difficult and time-consuming.
Let ˆ x ∗ =
arg min ˆ x L (ˆ x ) .
The reconstruction is given by F θ (ˆ x ∗ ) .
The optimization is done using 200 steps of gradient descent over ˆ x .
The reconstruction results are shown in Figure 4.
We use the CIFAR-10 testing set.
The right column displays the original images x that need to be reconstructed.
The left and the middle columns display ˆ x ∗ and F θ (ˆ x ∗ ) , respectively.
Our model can successfully reconstruct the observed images, verifying that
the
CoopFlow with a non-mixing MCMC is indeed a valid latent variable model.
We further show that our model is also capable of doing image inpainting.
Similar to image reconstruction, given a masked observation x mask along with a binary matrix M indicating the positions of the unmasked pixels, we optimize ˆ x to minimize the reconstruction error between F θ (ˆ x ) and x mask in the unmasked area, i.e., L (ˆ x ) =
||
M ⊙ ( x mask − F θ (ˆ x ))
|| 2 , where ⊙ is the elementwise multiplication operator.
ˆ x is still initialized by the normalizing flow.
We do experiments on the CelebA training set.
In Figure 5, each row shows one example of inpainting with a different initialization of ˆ x provided by the normalizing flow and the first 17 columns display the inpainting results at different optimization iterations.
The last two columns show the masked images and the original images respectively.
We can see that our model can reconstruct the unmasked areas faithfully and simultaneously fill in the blank areas of the input images.
With different initializations, our model can inpaint diversified and meaningful patterns.
5. I NTERPOLATION IN THE L ATENT S PACE
The CoopFlow model is capable of doing interpolation in the latent space z .
Given an image x , we first find its corresponding ˆ x ∗ using the reconstruction method described in Section 5.3.
We then infer z by the inversion of the normalizing flow z ∗ =
g − 1 α (ˆ x ∗ ) .
Figure 6 shows two examples of interpolation between two latent vectors inferred from observed images.
For each row, the images at the two ends are observed.
Each image in the middle is obtained by first interpolating the latent vectors of the two end images, and then generating the image using the CoopFlow generator, This experiment shows that the CoopFlow can learn a smooth latent space that traces the data manifold.
C ONCLUSION
This paper studies an interesting problem of learning two types of deep flow models in the context of energy-based framework for image representation and generation.
One is the normalizing flow that generates synthesized examples by transforming Gaussian noise examples through a sequence of invertible transformations, while the other is the Langevin flow that generates synthesized examples by running a non-mixing, non-convergent short-run MCMC toward an EBM.
We propose the
CoopFlow algorithm to train the short-run Langevin flow model jointly with the normalizing flow serving as a rapid initializer in a cooperative manner.
The experiments show that the CoopFlow is a valid generative model that can be useful for image generation, reconstruction, and interpolation.
A CKNOWLEDGMENTS
The authors sincerely thank Dr. Ying Nian Wu for the helpful discussion on the information geometry part and thank Dr. Yifei Xu for his assistance with some extra experiments during the rebuttal.
The authors would also like to thank the anonymous reviewers of ICLR’22 program committee for providing constructive comments and suggestions to improve our work
A A PPENDIX A. N ETWORK A RCHITECTURE IN THE C OOP F LOW
We use the same network architecture for all the experiments.
For the normalizing flow g α ( z ) in our
CoopFlow framework, we use the Flow++ (Ho et al., 2019) network architecture that was originally designed for the CIFAR-10 ( 32 × 32 pixels) dataset in Ho et al.
As to the EBM in our
CoopFlow, we use the architecture shown in Table 2 to design the negative energy function f θ ( x ) .
3 × 3 Conv2d, str =1, pad =1, ch =128; Swish
Residual Block, ch =
Residual Block, ch =
Residual Block, ch =1, 3 × 3 Conv2d, str
=4, pad =0, ch =100; Swish
Sum over channel dimension (a) EBM architecture 3 × 3 Conv2d, str =1, pad =1; Swish 3 × 3 Conv2d, str =1, pad =1; Swish + 3 × 3 Conv2d, str =1, pad =1; Swish (input) 2 × 2 Average pooling
[Figure]
E XPERIMENTAL D ETAILS
We have three different settings for the CoopFlow model.
In the CoopFlow(T=30) setting and
CoopFlow(T=200) setting, we train both the normalizing flow and the Langevin flow from scratch.
The difference between them are only the number of the Langevin steps.
The CoopFlow(T=200) uses a longer Langevin flow than the CoopFlow(T=30) .
We follow Ho et al.
and use the datadependent parameter initialization method (Salimans & Kingma, 2016) for our normalizing flow in both settings CoopFlow(T=30) and CoopFlow(T=200) .
On the other hand, as to the CoopFlow(Pre) setting, we first pretrain a normalizing flow on training examples, and then train a 30-step Langevin flow, whose parameters are initialized randomly, together with the pretrained normalizing flow by following Algorithm 1.
The cooperation between the pretrained normalizing flow and the untrained
Langevin flow would be difficult and unstable because the Langevin flow is not knowledgeable at all to teach the normalizing flow.
To stabilize the cooperative training and make a smooth transition for the normalizing flow, we include a warm-up phase in the CoopFlow algorithm.
During this phase, instead of updating both the normalizing flow and the Langevin flow, we fix the parameters of the pretrained normalizing flow and only update the parameters of the Langevin flow.
After a certain number of learning epochs, the Langevin flow may get used to the normalizing flow initialization, and learn to cooperate with it.
Then we begin to update both two flows as described in Algorithm 1.
This strategy is effective in preventing the Langevin flow from generating bad synthesized examples at the beginning of the CoopFlow algorithm to ruin the pretrained normalizing flow.
We use the Adam optimizer (Kingma & Ba, 2015) for training.
We set learning rates η α = 0 .and
η θ = 0 .
for the normalizing flow and the Langevin flow, respectively.
We use β 1 = 0 .
9 and β 2 = 0 .
999 for the normalizing flow and β 1 = 0 .
5 and β 2 = 0 .
5 for the Langevin flow.
In the Adam optimizer, β 1 is the exponential decay rate for the first moment estimates, and β 2 is the exponential decay rate for the second-moment estimates.
We adopt random horizontal flip as data augmentation only for the CIFAR-10 dataset.
We remove the noise term in each Langevin update by following
Zhao et al.
The values of other hyperparameters can be found in Table 3.
A. A NALYSIS OF H YPERPARAMETERS OF L ANGEVIN F LOW
We investigate the influence of the Langevin step size δ and the number of Langevin steps T on the
CIFAR-10 dataset using the CoopFlow(Pre) setting.
We first fix the Langevin step size to be 0.
and vary the number of Langevin steps from 10 to 50.
The results are shown in Table 4.
On the other hand, we show the influence of the Langevin step size in Table 5, where we fix the number of Langevin steps to be 30 and vary the Langevin step size used in training.
When synthesizing examples from the learned models in testing, we slightly increase the Langevin step size by a ratio
[Table]
of 4 / 3 for better performance.
We can see that our choices of 30 as the number of Langevin steps and 0.03 as the Langevin step size are reasonable.
Increasing the number of Langevin steps can improve the performance in terms of FID
[Table]
but also be computationally expensive.
The choice of
T = 30 is a trade-off between the synthesis performance and the computation efficiency.
[Table] [Table]
A. A BLATION S TUDY
To show the effect of the cooperative training, we compare a CoopFlow model with an individual normalizing flow and an individual Langevin flow.
For fair comparison, the normalizing flow component in the CoopFlow has the same network architecture as that in the individual normalizing flow, while the Langevin flow component in the CoopFlow also uses the same network architecture as that in the individual Langevin flow.
We train the individual normalizing flow by following Ho et al.
and train the individual Langevin flow by following Nijkamp et al.
All three models are trained on the CIFAR-10 dataset.
We present a comparison of these three models in terms of FID in Table 6, and also show generated samples in Figure 7.
From Table 6, we can see that the CoopFlow model outperforms both the normalizing flow and the Langevin flow by a large margin, which verifies the effectiveness of the proposed CoopFlow algorithm.
[Table]
A. M ORE I MAGE G ENERATION R ESULTS
In Section 5.2, we have shown generated examples from the CoopFlow(Pre) model.
In this section, we show examples generated by the CoopFlow(T=30) model in Figure 8 and examples generated by the CoopFlow(T=200) in Figure 9.
We can see that all the generated examples are meaningful.
[Figure] On the other hand, we show the examples generated from the normalizing flow component of the CoopFlow model in Figure 10.
By comparing the synthesized images shown in Figure 8 and those in Figure 10, we can see that there is a gap between the normalizing flow and the CoopFlow.
The samples from the normalizing flow look blurred but become sharp and clear after the Langevin flow revision.
This supports our claim in Section 4.2.
[Figure]
[Figure]
A. M ORE I MAGE I NPAINTING R ESULTS
We show more image inpainting results in Figure 11.
Each panel corresponds to one inpainting task.
Each row in each panel represents one inpainting result with a different initialization.
In each panel, the last two columns show the masked and the ground truth images respectively, and images from the 1st column to the 20th column are the inpainted images at different optimization iterations.
[Figure]
A. FID C URVE OVER T RAINING E POCHS
Figure 12 shows the FID trends during the training of the CoopFlow models on the CIFARdataset.
Each curve represents the FID scores over training epochs.
We train the CoopFlow models using the settings of CoopFlow(T=30) and CoopFlow(pre) .
For each of them, we can observe that, as the cooperative learning proceeds, the FID keeps decreasing and converges to a low value.
This is an empirical evidence to show that the proposed CoopFlow algorithm is a convergent algorithm.
[Figure]
A. Q UANTITATIVE R ESULTS F OR I MAGE R ECONSTRUCTION
We provide additional quantitative results for the image reconstruction experiment in Section 5.3.
Following Nijkamp et al.
(2019), we calculate the per-pixel MSE on 1,000 examples in the testing set of the CIFAR-10 dataset.
We use a 200-step gradient descent to minimize the reconstruction loss.
We plot the reconstruction error curve showing the MSEs over iterations in Figure 13 and report the final per-pixel MSE in Table 7.
For a baseline, we train an EBM using a 100-step short-run MCMC and the resulting model is the short-run Langevin flow.
We then apply it to the reconstruction of the same 1,000 images by following Nijkamp et al.
The baseline EBM has the same network architecture as that of the EBM component in our CoopFlow model for fair comparison.
The experiment results show that the CoopFlow works better than the individual short-run Langevin flow in this image reconstruction task.
[Figure]
[Table]
[Figure]
A. M ODEL C OMPLEXITY
In Table
[Table]
we present a comparison of different models in terms of model size and FID score.
Here we mainly compare those models that have a normalizing flow component, e.g., EBM-FCE,
NT-EBM, GLOW, Flow++, as well as an EBM jointly trained with a VAE generator, e
[Table]
g., VAEBM.
We can see the CoopFlow model has a good balance between model complexity and performance.
It is noteworthy that both the CoopFlow and the EBM-FCE consist of an EBM and a normalizing flow
[Table]
and also have similar model sizes, but the CoopFlow achieves a much lower FID than the
EBM-FCE.
Note that the Flow++ baseline uses the same structure as the one in our CoopFlow.
By comparing the Flow++ and the CoopFlow, we can find that recruiting an extra Langevin Flow can help improve the performance of the normalizing flow in terms of FID.
On the other hand, although the VAEBM model achieves a better FID than ours, but it relies on a much larger pretrained NVAE model (Vahdat & Kautz, 2020) that significantly increases the model complexity.
[Table]
A. C OMPARISON WITH M ODELS U SING S HORT -R UN MCMC
Our method is relevant to the short-run MCMC.
In this section, we compare the CoopFlow model with other models that use a short-run MCMC as a flow-like generator.
The baselines include (1) the single EBM with short-run MCMC starting from the noise distribution (Nijkamp et al., 2019), and (ii) cooperative training of an EBM and a generic generator (Xie et al., 2020a).
In Table 9, we report the FID scores of different methods over different numbers of MCMC steps.
We can see that with the same number of Langevin steps, the CoopFlow can generate much more realistic image patterns than the other two baselines.
The results show that the CoopFlow can use less number of Langevin steps (i.e., a shorter Langevin flow) to achieve better performance.
[Table]
A. N OISE T ERM IN THE L ANGEVIN D YNAMICS
While for the experiments shown in the main text, we completely disable the noise term δϵ of the
Langevin equation presented in Eq.
(3) by following Zhao et al.
(2021) to achieve better results, here we try an alternative way where we gradually decay the effect of the noise term toward zero during the training process.
The decay ratio for the noise term can be computed by the following:
[Equation]
where K is a hyper-parameter controlling the decay speed of the noise term.
Such a noise decay strategy enables the model to do more exploration in the sampling space at the beginning of the training and then gradually focus on the basins of the reachable local modes for better synthesis quality when the model is about to converge.
Note that we only decay the noise term during the training stage and still remove the noise term during the testing stage, including image generation and FID calculation.
We carry out experiments on the CIFAR-10 and the SVHN datasets using the
CoopFlow(Pre) setting.
The results are shown in Table 10.
[Table]
A. C OMPARISON B ETWEEN C OOP F LOW AND S HORT -R UN EBM VIA I NFORMATION G EOMETRY
Figure 14 illustrates the convergences of both the CoopFlow and the EBM with a short-run MCMC starting from an initial noise distribution q 0 .
We define the short-run EBM in a more generic form (Xie et al., 2016) as follows
[Equation]
(11) which is an exponential tilting of a known reference distribution q 0 ( x ) .
In general, the reference distribution can be either the Gaussian distribution or the uniform distribution.
When the reference distribution is the uniform distribution, q 0 can be removed in Eq.
Since the initial distribution of the CoopFlow is the Gaussian distribution q 0 , which is actually the prior distribution of the normalizing flow.
For a convenient and fair comparison, we will use the Gaussian distribution as the reference distribution of the EBM in Eq.
And the CoopFlow and the baseline short-run
EBM will use the same EBM defined in Eq.
(11) in their frameworks.
We will use ¯ p ¯ θ to denote the baseline short-run EBM and keep using p θ to denote the EBM in the CoopFlow.
There are three families of distributions: Ω = { p : E p
[ h ( x )]
=
E p data [ h ( x )] } , Θ = { p θ ( x ) = exp( ⟨ θ, h ( x ) ⟩ ) q 0 ( x ) /Z
( θ ) , ∀ θ } , and
A = { q α , ∀ α } , which are shown by the red, blue and green curves respectively in Figure 14, which is an extension of Figure 1 by adding the following elements:
• q 0 , which is the initial distribution for both the CoopFlow and the short-run EBM.
It belongs to Θ because it corresponds to θ = 0 .
q 0 is just a noise distribution thus it is far under the green curve.
That is, it is very far from q α ∗ because q α ∗ has been already a good approximation of p θ ∗ .
• g α ∗ , which is the learned transformation of the normalizing flow q α , and is visualized as a mapping from q 0 to q α ∗ by a directed brown line segment.
• The MCMC trajectory of the baseline short-run EBM ¯ p ¯ θ , which is shown by the yellow line on the right hand side of the blue curve.
The solid part of the yellow line, starting from q 0 to ¯ π ∗ =
K ¯ θ ∗ q 0 , shows the short-run non-mixing MCMC starting from the initial Gaussian distribution q 0 in Θ and arriving at ¯ π ∗ in Ω .
The dotted part of the yellow line is the potential long-run MCMC trajectory that is unrealized.
By comparing the MCMC trajectories of the CoopFlow and the short-run EBM in Figure 14, we can find that the CoopFlow has a much shorter MCMC trajectory than that of the short-run EBM, since the normalizing flow g α ∗ in the CoopFlow amortizes the sampling workload for the Langevin flow in the CoopFlow model.
A. M ORE C ONVERGENCE A NALYSIS
The CoopFlow algorithm simply involves two MLE learning algorithms: (i) the MLE learning of the
EBM p θ and (ii) the MLE learning of the learning algorithms has been well studied and verified in the existing literature, e.g., Younes (1999);
Xie et al.
; Kingma & Dhariwal (2018).
That is, each of them has a fixed point.
The only interaction between these two MLE algorithms in the proposed CoopFlow algorithm is that, in each learning iteration, they feed each other with their synthesized examples and use the cooperatively synthesized examples in their parameter update formulas.
To be specific, the normalizing flow uses its synthesized examples to initialize the MCMC of the EBM, while the EBM feeds the normalizing flow with its synthesized examples as training examples.
The synthesized examples from the
Langevin flow are considered the cooperatively synthesized examples by the two models, and are used to compute their learning gradients.
Unlike other amortized sampling methods (e.g., Han et al.
(2019); Grathwohl et al.
(2021)) that uses variational learning, the EBM and normalizing flow in our framework do not back-propagate each other through the cooperatively synthesized examples.
They just feed each other with some input data for their own training algorithms.
That is, each learning algorithm will still converge to a fixed point.
Now let us analyze the convergence of the whole CoopFlow algorithm that alternates two maximum likelihood learning algorithms.
We first analyze the convergence of the objective function at each learning step, and then we conclude the convergence of the whole algorithm.
The convergence of CD learning of EBM.
The learning objective of the EBM is to minimize the
KL divergence between the EBM p θ and the data distribution p data .
Since the MCMC of the EBM in our model is initialized by the normalizing flow q α , it follows a modified contrastive divergence algorithm.
That is, at iteration t , it has the following objective,
[Equation]
No matter what kind of distribution is used to initialize the MCMC, it will has a fixed point when the learning gradient of θ equals to 0, i.e., L ′ ( θ ) =
[Equation]
n
[Equation]
The initialization of the MCMC only affects the location of the fixed point of the learning algorithm.
The convergence and the analysis of the fixed point of the contrastive divergence algorithm has been studied by Hinton (2002); Carreira-Perpi˜n´an & Hinton (2005).
The convergence of MLE learning of normalizing flow.
The objective of the normalizing flow is to learn to minimize the KL divergence between the normalizing flow and the Langevin flow (or the EBM) because, in each learning iteration, the normalizing flow uses the synthesized examples generated from the Langevin dynamics as training data.
At iteration t , it has the following objective
[Equation]
(13) which is a convergent algorithm at each t .
The convergence has been studied by Younes (1999).
The convergence
of
CoopFlow.
The CoopFlow alternates the above two learning algorithms.
The EBM learning seeks to reduce the KL divergence between the EBM and the data, i.e., p θ → p data ; while the MLE learning of normalizing flow seeks to reduce the KL divergence between the normalizing flow and the EBM, i.e., q α → p θ .
Therefore, the normalizing flow will chase the EBM toward the data distribution gradually.
Because the process p θ → p data will stop at a fixed point, therefore q α → p θ will also stop at a fixed point obviously.
Such a chasing game is a contraction algorithm, therefore the fixed point of the CoopFlow exists.
Empirical evidence also support our claim.
If we use ( θ ∗ , α ∗ ) to denote the fixed point of the CoopFlow, according to the definition of a fixed point, ( θ ∗ , α ∗ ) will satisfy
[Equation]
[Equation]
The convergence of the cooperative learning framework (CoopNets) that integrates the MLE algorithm of an EBM and the MLE algorithm of a generic generator has been verified and discussed in
Xie et al.
(2020a).
The CoopFlow that uses a normalizing flow instead of a generic generator has the same convergence property as that of the original CoopNets.
The major contribution in our paper is to start from the above fixed point equation to analyze where the fixed point will be in our learning algorithm, especially when the MCMC is non-mixing and non-convergent.
This goes beyond all the prior works about cooperative learning.