GAN training instability and mode collapse
Overview
Training GANs is notoriously difficult because we're trying to balance two networks playing a minimax game. The generator tries to fool the discriminator, while the discriminator tries to catch the generator's fakes. When this balance breaks, we get either training instability (wild oscillations, non-convergence) or mode collapse (generator produces limited variety).

The Minimax Game: Why Balance Matters
where:
- is the discriminator's probability that is real
- generates a fake sample from noise
- The discriminator tries to maximize (correctly classify real vs fake)
- The generator tries to minimize (fool the discriminator)
Deriving the Training Instability from First Principles
Step 1: What does the discriminator optimize?
For fixed , the discriminator maximizes:
where is the generator's distribution.
Taking the functional derivative with respect to and setting to zero:
Solving for the optimal discriminator:
Why this step? We're finding what discriminator outputs give maximum classification accuracy when both distributions are known. Notice that if everywhere (perfect generator), then everywhere—the discriminator is reduced to random guessing.
Step 2: What gradient does the generator receive?
The generator optimizes by gradient descent on:
Using the chain rule, the gradient w.r.t. generator parameters is:
Why this step? We need the gradient to update generator parameters . Notice there are two factors that depend on the discriminator: the scalar and the term (how the discriminator's output changes as we move the sample).
Step 3: The vanishing gradient problem (corrected)
When the discriminator is near-perfect, for fake samples. Let's examine both factors:
-
The scalar factor: — this is a constant, not small, so it does NOT cause the vanishing gradient by itself.
-
The real culprit is . A confident, well-trained discriminator has a saturated output: it outputs values very close to (fake) or (real) and is flat in between. A flat output means its input-gradient . So even though the scalar is , the whole product
vanishes. The generator receives almost no learning signal.
Why this step? This corrects a common misconception: the gradient does not vanish because shrinks (it approaches the constant ). It vanishes because a too-confident discriminator saturates, making its input-derivative . When wins too hard, stops improving.
Gradient becomes:
Now when , the scalar prefactor becomes large (). This large prefactor amplifies the (small) saturated , rescuing the learning signal that the original loss lost. This provides a stronger signal early in training.
Why this works: We inverted the problem—instead of minimizing "probability of being fake," we maximize "probability of being real." The two losses share the same fixed points but have very different gradient magnitudes when is confident.
Mode Collapse: The Copy-Paste Problem
Deriving Mode Collapse from Game Dynamics
Step 1: The generator's incentive structure
At iteration , suppose the generator has learned to produce sample that fools . The generator's loss for producing is:
If (discriminator thinks it's real), then (low loss, good!).
Step 2: What if the generator tries variety?
Now suppose the generator tries a different mode from the true distribution. But hasn't seen produce type samples before, so (discriminator is suspicious).
The loss is much higher! The generator is penalized for trying new modes.
Why this step? The generator's objective only cares about fooling right now, not about covering the full distribution.
Step 3: The discriminator can only punish current samples
The discriminator updates based on:
If never produces samples from mode , the discriminator never learns to check for that mode. The generator has no incentive to explore it.
Why this step? This is the core of mode collapse— exploits 's blindness to unseen modes.
Iteration 1-100: Generator learns to produce digit "1" (easiest to generate, nearly straight line). Discriminator learns "1" is suspicious.
Iteration 101-200: Generator switches to producing digit "7" (also simple). Discriminator now focused on detecting "7", forgets about "1".
Iteration 201-300: Generator switches back to "1". Discriminator has drifted, doesn't recognize "1" anymore.
Result: Generator oscillates between 2-3 digit types, never learns the full distribution of 0-9. This is mode collapse.
Why this happens: The generator found that switching between a few modes is easier than covering all modes, and the discriminator can't "remember" all modes simultaneously.
Solution: WGAN uses a critic that outputs a real number (no sigmoid), and optimizes the Wasserstein distance:
The critic is constrained to be 1-Lipschitz continuous (gradient clipping or gradient penalty).
Generator loss becomes:
Why this works:
- The critic provides non-vanishing gradients everywhere (no sigmoid saturation)
- The Wasserstein distance "pulls" the generator distribution toward the data distribution across all modes, not just currently visible ones
- Training is more stable because the objective correlates with sample quality
Detailed steps:
-
Critic update (multiple steps per generator update): Then clip: or apply gradient penalty
-
Generator update:
Why these steps: We're alternating between making the critic better at distinguishing (step 1) and making the generator better at fooling (step 2), but with continuous gradients throughout.
Common Training Instabilities
Why it feels right: "Both networks are equally important, so equal learning rates seem fair."
Why it's wrong: The discriminator's task (binary classification on already-generated samples) is easier than the generator's task (creating realistic samples from noise). With equal learning rates, typically learns much faster and becomes too strong.
The fix: Use a lower learning rate for than for , or train fewer times per update. Common ratio: train once per 1-3 updates (or use TTUR: Two Time-scale Update Rule with different learning rates for D and G in Adam).
Why it feels right: "When , surely some term in the gradient shrinks to zero and kills learning."
Why it's wrong: The scalar is a constant, not small. The real cause is that a too-confident discriminator saturates, so its input-gradient . The product vanishes because of the saturated derivative, not the scalar prefactor.
The fix: Use the non-saturating loss (whose prefactor blows up to counteract the small ), or switch to WGAN whose critic never saturates.
Why it feels right: "Batch norm stabilizes training in other deep networks, so it should help GANs."
Why it's wrong: Batch norm creates dependencies between samples in a batch. In the discriminator, this lets it detect fake batches (all fakes are correlated through BN statistics) vs real batches.
The fix:
- Use Virtual Batch Normalization (VBN): normalize each sample using statistics from a fixed reference batch
- Use Spectral Normalization instead: controls Lipschitz constant of layers without batch dependencies
- Use Layer Normalization or Instance Normalization in generator
Advanced Stabilization Techniques
For a weight matrix in layer , divide by its spectral norm (largest singular value):
where is the spectral norm.
Why this works: This constrains the Lipschitz constant of each layer to be at most 1:
The discriminator can't have extremely sharp transitions, which prevents mode collapse and stabilizes training.
How to compute efficiently: Use power iteration method:
- Initialize random vector
- Iterate: ,
- After convergence:
Why this step: Computing exact SVD is ; power iteration gives us in per iteration, and we only need 1-2 iterations per training step.
Instead of weight clipping, add a penalty term:
where with (points on lines between real and fake samples).
Why this works: The Wasserstein distance requires the critic to be 1-Lipschitz. This penalty enforces that the gradient norm is close to 1, which is the tightest form of the Lipschitz constraint.
Derivation:
- A 1-Lipschitz function satisfies
- For differentiable , this means everywhere
- The optimal critic has almost everywhere
- So we penalize deviation from norm = 1
Why interpolated points: The region between real and fake samples is where the critic must distinguish most sharply, so that's where we enforce the constraint.
Problem: Training high-resolution GANs (1024×1024) directly is unstable—too much detail for early training.
Solution: Start with low resolution (4×4), gradually add layers to increase resolution (8×8, 16×16, ..., 1024×1024). Each resolution trains until stable before growing.
Implementation:
- Start Generator outputs 4×4, Discriminator inputs 4×4
- Add layers: Smoothly fade in new layers using :
- Increase from 0 to 1 over several thousand iterations
- Stabilize at , then add next resolution layer
Why this works: Low-resolution images have less information, so the GAN learns the broad structure first (shape, layout) before details (texture, fine edges). This hierarchical learning is more stable than learning all scales simultaneously.
Monitoring and Diagnosing GAN Training
Q: What are signs that the discriminator is too strong? A: Generator loss stays high and constant, for all generated samples, generated samples don't improve visually
Q: What are signs of mode collapse? A: Low diversity in generated samples (e.g., all faces have same pose/expression), generator loss oscillates but samples don't improve in variety, Inception Score or FID suddenly drops
Q: How can you distinguish oscillation from convergence? A: Plot loss curves over time—convergence shows stabilizing losses, oscillation shows periodic swings. Check sample diversity over time—oscillation often means samples cycle between a few types.
Connections
- 4.5.01-Generative-Adversarial-Networks-fundamentals - Core GAN setup and original objective
- 4.5.07-Wasserstein-GAN-and-improved-training - WGAN solution to instability
- 4.5.09-StyleGAN-and-progressive-growing - Progressive training for high-res stability
- 4.5.10-Conditional-GANs-and-control - Mode collapse in conditional generation
- 3.4.05-Optimization-challenges-in-deep-learning - General optimization issues relevant to GANs
- 4.3.06-Batch-normalization-and-alternatives - Why batch norm causes GAN issues
Flashcards
#flashcards/ai-ml
What is the optimal discriminator D*(x) for a fixed generator?
What actually causes the vanishing gradient in original GAN training?
Why is it wrong to say the vanishing gradient comes from the -1/(1-D) factor?
What is the non-saturating GAN loss fix?
What is mode collapse in GANs?
Why does mode collapse occur from a game theory perspective?
What is the key innovation of Wasserstein GAN for stability?
What is spectral normalization and why does it stabilize GAN training?
Why is training D and G with the same learning rate often problematic?
What is the gradient penalty in WGAN-GP?
How does progressive GAN training improve stability?
What are three signs that a discriminator is too strong?
Why does batch normalization cause issues in GAN discriminators?
Recall Feynman: Explain to a 12-year-old
Imagine you have two friends playing a game. One friend (the Gener
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
Hinglish (regional understanding)
Intuition Hinglish mein samjho
GAN training samajhne ke liye ek simple picture socho: do students hain jo ek doosre ko compete karte hue improve kar rahe hain. Ek hai generator (jo fake images banata hai) aur doosra hai discriminator (jo pakadta hai ki image asli hai ya nakli). Dono ek "minimax game" khel rahe hain — generator chahta hai discriminator ko bewakoof banana, aur discriminator chahta hai har fake ko pakadna. Problem yeh hai ki inn dono ko ek same pace pe improve karna padta hai. Agar discriminator bahut jaldi bahut acha ban gaya, toh woh generator ko koi useful hint nahi deta ("tera sab kuch obviously fake hai"), aur generator seekhna band kar deta hai. Isko hi bolte hain training instability aur uska ek roop hai mode collapse jahan generator sirf limited variety produce karta hai.
Ab thodi si math intuition — jab discriminator bahut confident ho jata hai, toh woh fake samples ke liye output almost 0 dene lagta hai aur uska output curve "saturate" ho jata hai (matlab flat ho jata hai). Yahan ek common galatfehmi hai: log jaan-te hain ki gradient vanish ho jata hai, par wajah galat samajhte hain. Asli reason yeh hai ki jab discriminator ka output flat hota hai, toh uska input ke saath change () almost zero ho jata hai. Jab yeh zero ho jaye, toh generator ko poora learning signal hi nahi milta — chahe baaki factor constant () hi kyun na ho. Isliye jab discriminator "too hard" jeet jata hai, generator improve karna bilkul rok deta hai.
Yeh baat kyun important hai? Kyunki jab bhi tum real world mein GANs train karoge — chahe images generate karni ho, ya data augmentation karna ho — yeh instability tumhe zaroor face karni padegi. Is core intuition ko samajhne se tum debug kar paoge ki kyun tumhara model achanak fail ho raha hai, aur solutions jaise "non-saturating loss" ya learning rate balance karna kyun kaam karte hain. Basically, GANs ki asli challenge sirf architecture nahi, balki dono networks ko ek delicate balance mein rakhna hai — aur yeh samajhna hi ek accha ML engineer banne ka pehla step hai.