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 with parameters that wants to maximize its payoff , the second player is a discriminator , with parameters that aims to maximize . 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 to the parameters of the generator and discriminator respectively:
where is a learning rate and is the gradient vector field, the gradient of each player's payoff with respect to its own parameters:
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 at the point :
If all eigenvalues have absolute value less than 1, the system converges to with a linear rate (our desired case).
If there are any eigenvalues with absolute values greater than 1, the system diverges.
If all eigenvalues have an absolute value equal to 1 (lie on the unit circle), it can be convergent, divergent or neither, but if it is convergent, it will generally converge with a sublinear rate.
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 . Since , the eigenvalues of are , where are the eigenvalues of . For a small enough positive , exactly when has a negative real part, so we want all eigenvalues of 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 and a linear discriminator . The true data distribution 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:
where . The discriminator maximises:
where is a constant. The gradient vector is then:
The system has a unique equilibrium point of the training objective, at point . Indeed, and are constant for all , so neither player can improve its payoff by moving away from 0. Therefore is a Nash-equilibrium. Now, assuming that we have that only if .
Now we can analyse the convergence of the Dirac-GAN around the equilibrium point by calculating the Jacobian of the gradient vector field at the equilibrium point:
which has two eigenvalues, , 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 are then , with absolute value , 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.
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 , 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:
The gradient vector field now has an additional term in the partial derivative:
The Jacobian of the vector field becomes:
And eigenvalues of the Jacobian of the gradient vector field at the equilibrium point are . Since , and the eigenvalues are (about and ), 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 , 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 on the MSE term, the eigenvalues are , which have negative real parts for any .
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, . The gradient vector is then:
As before, the system has a unique equilibrium point of the training objective at the point , and since , the Jacobian there is the same as for the non-saturating loss, with eigenvalues . The two losses only differ away from the equilibrium: Figure 3 demonstrates that Dirac-GAN with vanilla GAN loss is divergent around the equilibrium .
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 term in the partial derivative:
and, just like in the case of non-saturating loss, the Jacobian at the equilibrium point is the same as above, with eigenvalues (Figure 4).
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 gradient penalty [1] with weight 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:
[1] Mescheder, Lars, Andreas Geiger, and Sebastian Nowozin. "Which training methods for GANs do actually converge?." International conference on machine learning. PMLR, 2018. https://arxiv.org/pdf/1801.04406.pdf
[2] Mescheder, Lars, Sebastian Nowozin, and Andreas Geiger. "The numerics of gans." Advances in Neural Information Processing Systems (2017). https://arxiv.org/pdf/1705.10461.pdf
[6] Blau, Yochai, and Tomer Michaeli. "Rethinking lossy compression: The rate-distortion-perception tradeoff." International Conference on Machine Learning. PMLR, 2019. https://arxiv.org/abs/1901.07821