Proof: MSE makes the Dirac-GAN locally convergent

Generative Adversarial Networks are notoriously unstable due to issues such as mode collapse and training divergence. However, in AI compression, the adversarial training is generally stable and reliable without the necessary tricks such as gradient penalty and adding noise to our input samples. I found this intriguing so I set out to explore why.

One obvious difference is that in compression GANs, we always have access to the ground truth image that we aim to generate. That allows us to use pixel-wise distortion losses in generator (encoder-decoder) training.

Convergence of GANs

Our starting point is the Mescheder et al., 2017 Numerics of GANs paper. We can think of GAN training as a two-player non-cooperative game. The first player is a generator Gθ(z) with parameters θ that wants to maximize its payoff g(θ,ψ), the second player is a discriminator Dψ(x), with parameters ψ that aims to maximize d(θ,ψ). The game is at a Nash equilibrium at (θ∗,ψ∗) when neither player can improve its payoff by changing its parameters slightly. When training approaches a Nash equilibrium and stays there, we can say that it has converged locally.

One method to train a GAN is to use a Simultaneous Gradient Descent, which can be thought of as a fixed point algorithm that applies an operator F(θ,ψ) to the parameters of the generator and discriminator (θ,ψ) respectively:

F(θ,ψ)=(θ,ψ)+hv(θ,ψ),

where h is a learning rate and v(θ,ψ) is the gradient vector field, the gradient of each player's payoff with respect to its own parameters:

v(θ,ψ)=[∇θg(θ,ψ)∇ψd(θ,ψ)]

Mescheder et al. demonstrate that the convergence near an equilibrium point (θ∗,ψ∗) can be assessed by looking at the spectrum of the Jacobian of our update operator Fh′(θ,ψ) at the point (θ∗,ψ∗):

For a detailed proof of why the eigenvalues need to lie in the unit circle, see [4], Proposition 4.4.1. This condition translates directly to the eigenvalues of the Jacobian of the gradient vector field v. Since Fh′(θ,ψ)=I+hv′(θ,ψ), the eigenvalues of Fh′ are λ=1+hμ, where μ are the eigenvalues of v′. For a small enough positive h, |λ|<1 exactly when μ has a negative real part, so we want all eigenvalues of v′ to have negative real parts.

Now let's look at a toy example to examine the conditions of convergence of GANs and discuss how the AI compression objective impacts convergence. We'll use the Dirac-GAN for simplicity with the non-saturating and vanilla loss for our analysis.

Dirac-GAN

The Dirac-GAN, introduced in [1], consists of a (univariate) generator distribution pg=δθ and a linear discriminator Dψ(x)=ψx. The true data distribution pD is given by a Dirac-distribution concentrated at 0.

Under this formulation, both the discriminator and the generator have exactly one parameter. This simplicity allows us to easily plot the vector field for the GAN in a 2D space to assess convergence behaviour. For a great explanation of vector fields and convergence of GANs, check out this inFERENCe blog post.

The non-saturating GAN generator maximises:

g(θ,ψ)=f(−ψθ)

where f(t)=−log⁡(1+e−t). The discriminator maximises:

d(θ,ψ)=f(ψθ)+f(0)

where f(0)=−log⁡2 is a constant. The gradient vector is then:

v(θ,ψ)=[−ψf′(−ψθ)θf′(ψθ)]

The system has a unique equilibrium point of the training objective, at point (θ,ψ)=(0,0). Indeed, g(θ,0)=f(0) and d(0,ψ)=2f(0) are constant for all θ,ψ∈R, so neither player can improve its payoff by moving away from 0. Therefore (θ∗,ψ∗)=(0,0) is a Nash-equilibrium. Now, assuming that f′(0)≠0 we have that v(θ,ψ)=0 only if θ=ψ=0.

Now we can analyse the convergence of the Dirac-GAN around the equilibrium point (θ∗,ψ∗)=(0,0) by calculating the Jacobian of the gradient vector field at the equilibrium point:

v′(θ,ψ)=[f″(−θψ)ψ2−f′(−θψ)+f″(−θψ)θψf′(θψ)+f″(θψ)θψf″(θψ)θ2]v′(0,0)=[0−f′(0)f′(0)0]

which has two eigenvalues, ±f′(0)i, which are both on the imaginary axis, so the equilibrium is a centre of the vector field [5] and we expect to see a circular vector field. The eigenvalues of Fh′ are then 1±hf′(0)i, with absolute value 1+h2f′(0)2>1, so simultaneous gradient descent does not converge to the equilibrium. Figure 1 shows that with the non-saturating loss, training spirals towards the equilibrium only very slowly, at a non-linear rate, and does not reach it.

Training behaviour of Dirac-GAN with the non-saturating loss

Figure 1: Training behaviour of Dirac-GAN with the non-saturating loss. Left: vector field and the training state of the system visualised for 500 steps (learning rate 0.1); the starting position is marked in red. Right: current value of the generator parameter θ. The green line indicates the value of the ground truth parameter θ∗=0, the blue line shows the estimated θ and the orange line shows the current angle of the gradient.

Adding MSE

Now, let us look at what happens by adding MSE to the loss for the generator parameters θ. The discriminator's payoff stays the same, but the generator's becomes:

g(θ,ψ)=f(−ψθ)−(0−θ)2

The gradient vector field now has an additional −2θ term in the θ partial derivative:

v(θ,ψ)=[−ψf′(−ψθ)−2θθf′(ψθ)]

The Jacobian of the vector field becomes:

v′(0,0)=[−2−f′(0)f′(0)0]

And eigenvalues of the Jacobian of the gradient vector field at the equilibrium point are −1±1−f′(0)2. Since f′(t)=1/(1+et), f′(0)=1/2 and the eigenvalues are −1±3/2 (about −0.13 and −1.87), both of which have negative real parts and 0 imaginary parts, which means that, for a small enough learning rate, the system should be locally convergent around (0,0), an attracting node [5]. The lack of imaginary parts means that there should not be any circular non-convergent behaviour in the gradient vector field, as Figure 2 shows. More generally, with a weight w on the MSE term, the eigenvalues are −w±w2−f′(0)2, which have negative real parts for any w>0.

Training behaviour of Dirac-GAN with the non-saturating loss and added MSE

Figure 2: Training behaviour of Dirac-GAN with the non-saturating loss and added MSE, shown as in Figure 1.

Vanilla GAN loss

We can repeat the analysis for the vanilla GAN loss function, where the generator instead minimises the discriminator's payoff, g(θ,ψ)=−d(θ,ψ). The gradient vector is then:

v(θ,ψ)=[−ψf′(ψθ)θf′(ψθ)]

As before, the system has a unique equilibrium point of the training objective at the point (θ∗,ψ∗)=(0,0), and since f′(−0)=f′(0), the Jacobian there is the same as for the non-saturating loss, with eigenvalues ±f′(0)i. The two losses only differ away from the equilibrium: Figure 3 demonstrates that Dirac-GAN with vanilla GAN loss is divergent around the equilibrium (0,0).

Training behaviour of Dirac-GAN with the vanilla loss

Figure 3: Training behaviour of Dirac-GAN with the vanilla loss, shown as in Figure 1.

However, for similar reasons as above, the behaviour completely changes once we add the MSE component to the generator loss. The gradient vector field now has an additional −2θ term in the θ partial derivative:

v(θ,ψ)=[−ψf′(ψθ)−2θθf′(ψθ)]

and, just like in the case of non-saturating loss, the Jacobian at the equilibrium point is the same as above, with eigenvalues −1±1−f′(0)2 (Figure 4).

Training behaviour of Dirac-GAN with the vanilla loss and added MSE

Figure 4: Training behaviour of Dirac-GAN with the vanilla loss and added MSE, shown as in Figure 1.

This analysis shows that adding MSE has the same impact as gradient regularisation and instance noise, which also remove the circular behaviours in the gradient field and force the negative real part in the eigenvalues. In the Dirac-GAN, an R1 gradient penalty [1] with weight γ=2 gives exactly the same eigenvalues as the MSE, although it acts on the discriminator rather than the generator. This analysis suggests how GANs in compression can sidestep the need for these regularisation methods by simply using the MSE.

Two caveats: this is a local analysis, so it tells us what happens close to the equilibrium, not from an arbitrary initialisation. And in the Dirac-GAN the MSE target is also the only data point, so MSE and the GAN agree on the equilibrium. In compression they generally don't, as the reconstruction with the lowest MSE is blurrier than a realistic one, so adding MSE also moves the point training converges to: the rate-distortion-perception trade-off [6].

Further reading: