GAN training instability and mode collapse
4.5.8· AI-ML › Generative Models
Overview
GAN training notoriously difficult hai kyunki hum do networks ko minimax game mein balance karne ki koshish kar rahe hain. Generator discriminator ko fool karne ki koshish karta hai, jabki discriminator generator ke fakes ko pakadne ki koshish karta hai. Jab yeh balance toot ta hai, toh hume ya toh training instability milti hai (wild oscillations, non-convergence) ya mode collapse (generator limited variety produce karta hai).

The Minimax Game: Balance Kyun Matters Karta Hai
jahan:
- discriminator ki probability hai ki real hai
- noise se ek fake sample generate karta hai
- Discriminator maximize karne ki koshish karta hai ko (real vs fake sahi classify kare)
- Generator minimize karne ki koshish karta hai ko (discriminator ko fool kare)
Training Instability ko First Principles se Derive Karna
Step 1: Discriminator kya optimize karta hai?
Fixed ke liye, discriminator maximize karta hai:
jahan generator ki distribution hai.
ke respect mein functional derivative lete hain aur zero set karte hain:
Optimal discriminator ke liye solve karte hain:
Yeh step kyun? Hum dhoondh rahe hain ki kaunse discriminator outputs maximum classification accuracy dete hain jab dono distributions known hain. Notice karo ki agar har jagah ho (perfect generator), toh har jagah hoga—discriminator random guessing tak reduce ho jaata hai.
Step 2: Generator ko kaunsa gradient milta hai?
Generator gradient descent se optimize karta hai:
Chain rule use karte hue, generator parameters ke w.r.t. gradient hai:
Yeh step kyun? Hume generator parameters update karne ke liye gradient chahiye. Notice karo ki do factors hain jo discriminator par depend karte hain: scalar aur term (discriminator ka output kitna change hota hai jab hum sample ko move karte hain).
Step 3: Vanishing gradient problem (corrected)
Jab discriminator near-perfect hota hai, fake samples ke liye. Dono factors examine karte hain:
-
Scalar factor: — yeh ek constant hai, small nahi, isliye yeh akele vanishing gradient cause nahi karta.
-
Asli culprit hai . Ek confident, well-trained discriminator ka output saturated hota hai: woh (fake) ya (real) ke bahut kareeb values output karta hai aur beech mein flat rehta hai. Flat output ka matlab hai uska input-gradient . Toh bhale hi scalar hai, poora product
vanish ho jaata hai. Generator ko almost koi learning signal nahi milta.
Yeh step kyun? Yeh ek common misconception correct karta hai: gradient isliye vanish nahi hota kyunki shrink hota hai (yeh constant ke paas jaata hai). Yeh isliye vanish hota hai kyunki ek bahut confident discriminator saturate kar jaata hai, jisse uska input-derivative ho jaata hai. Jab bahut zyada jeet jaata hai, improve karna band kar deta hai.
Gradient ban jaata hai:
Jab hota hai, scalar prefactor bada ho jaata hai (). Yeh bada prefactor (chhote) saturated ko amplify karta hai, us learning signal ko rescue karta hai jo original loss ne khoi thi. Yeh training ke early stages mein stronger signal provide karta hai.
Yeh kyun kaam karta hai: Humne problem ko invert kar diya—"probability of being fake" minimize karne ki jagah, hum "probability of being real" maximize karte hain. Dono losses ke same fixed points hain lekin jab confident hota hai toh gradient magnitudes bahut different hoti hain.
Mode Collapse: The Copy-Paste Problem
Mode Collapse ko Game Dynamics se Derive Karna
Step 1: Generator ka incentive structure
Iteration par, maan lo generator ne sample produce karna seekh liya hai jo ko fool karta hai. produce karne ke liye generator ka loss hai:
Agar ho (discriminator sochta hai yeh real hai), toh (low loss, accha!).
Step 2: Agar generator variety try kare toh kya hoga?
Ab maan lo generator true distribution se ek alag mode try karta hai. Lekin ne pehle ko type samples produce karte nahi dekha, isliye (discriminator suspicious hai).
Loss bahut zyada hai! Generator ko naye modes try karne par penalty milti hai.
Yeh step kyun? Generator ka objective sirf abhi ko fool karne ki parwah karta hai, full distribution cover karne ki nahi.
Step 3: Discriminator sirf current samples ko punish kar sakta hai
Discriminator update hota hai based on:
Agar kabhi mode se samples produce nahi karta, toh discriminator kabhi us mode ko check karna nahi seekhta. Generator ke paas use explore karne ka koi incentive nahi hai.
Yeh step kyun? Yahi mode collapse ka core hai— exploit karta hai ki unseen modes ke baare mein blindness ko.
Iteration 1-100: Generator digit "1" produce karna seekhta hai (generate karne mein sabse aasaan, almost straight line). Discriminator seekhta hai ki "1" suspicious hai.
Iteration 101-200: Generator digit "7" produce karne par switch karta hai (yeh bhi simple hai). Discriminator ab "7" detect karne par focused hai, "1" ke baare mein bhool jaata hai.
Iteration 201-300: Generator wapas "1" par switch karta hai. Discriminator drift kar chuka hai, "1" ko ab nahi pehchaanta.
Result: Generator 2-3 digit types ke beech oscillate karta hai, 0-9 ki full distribution kabhi nahi seekhta. Yeh mode collapse hai.
Yeh kyun hota hai: Generator ne paaya ki kuch modes ke beech switch karna sabhi modes cover karne se aasaan hai, aur discriminator saare modes ko simultaneously "remember" nahi kar sakta.
Solution: WGAN ek critic use karta hai jo real number output karta hai (no sigmoid), aur Wasserstein distance optimize karta hai:
Critic constrained hota hai 1-Lipschitz continuous rehne ke liye (gradient clipping ya gradient penalty).
Generator loss ban jaata hai:
Yeh kyun kaam karta hai:
- Critic har jagah non-vanishing gradients provide karta hai (no sigmoid saturation)
- Wasserstein distance generator distribution ko data distribution ki taraf saare modes mein "pull" karta hai, sirf currently visible modes mein nahi
- Training zyada stable hoti hai kyunki objective sample quality ke saath correlate karta hai
Detailed steps:
-
Critic update (generator update ke per multiple steps): Phir clip karo: ya gradient penalty apply karo
-
Generator update:
Yeh steps kyun: Hum alternating kar rahe hain critic ko distinguishing mein better banane (step 1) aur generator ko fooling mein better banane (step 2) ke beech, lekin poore time continuous gradients ke saath.
Common Training Instabilities
Kyun sahi lagta hai: "Dono networks equally important hain, toh equal learning rates fair lagte hain."
Kyun galat hai: Discriminator ka task (already-generated samples par binary classification) generator ke task (noise se realistic samples create karna) se aasaan hai. Equal learning rates se, typically bahut jaldi seekhta hai aur bahut strong ban jaata hai.
Fix: ke liye se lower learning rate use karo, ya update ke per ko kam baar train karo. Common ratio: ko 1-3 updates per once train karo (ya TTUR use karo: Two Time-scale Update Rule with D aur G ke liye Adam mein different learning rates).
Kyun sahi lagta hai: "Jab hota hai, toh surely gradient mein koi term zero tak shrink ho jaata hai aur learning ko kill kar deta hai."
Kyun galat hai: Scalar ek constant hai, small nahi. Asli cause yeh hai ki bahut confident discriminator saturate kar jaata hai, isliye uska input-gradient ho jaata hai. Product vanish hota hai saturated derivative ki wajah se, scalar prefactor ki wajah se nahi.
Fix: Non-saturating loss use karo (jiski prefactor blow up hoti hai chhote ko counteract karne ke liye), ya WGAN par switch karo jiska critic kabhi saturate nahi karta.
Kyun sahi lagta hai: "Batch norm doosre deep networks mein training stabilize karta hai, toh GANs mein bhi help karna chahiye."
Kyun galat hai: Batch norm batch mein samples ke beech dependencies create karta hai. Discriminator mein, yeh use fake batches (saare fakes BN statistics ke through correlated hain) vs real batches detect karne deta hai.
Fix:
- Virtual Batch Normalization (VBN) use karo: har sample ko ek fixed reference batch ki statistics use karke normalize karo
- Spectral Normalization use karo: batch dependencies ke bina layers ki Lipschitz constant control karta hai
- Generator mein Layer Normalization ya Instance Normalization use karo
Advanced Stabilization Techniques
Layer mein weight matrix ke liye, uski spectral norm (largest singular value) se divide karo:
jahan spectral norm hai.
Yeh kyun kaam karta hai: Yeh har layer ki Lipschitz constant ko at most 1 hone ke liye constrain karta hai:
Discriminator mein extremely sharp transitions nahi ho sakti, jo mode collapse prevent karta hai aur training stabilize karta hai.
Efficiently compute kaise karein: Power iteration method use karo:
- Random vector initialize karo
- Iterate karo: ,
- Convergence ke baad:
Yeh step kyun: Exact SVD compute karna hai; power iteration hume per iteration mein deta hai, aur hume per training step sirf 1-2 iterations chahiye.
Weight clipping ki jagah, ek penalty term add karo:
jahan with (real aur fake samples ke beech lines par points).
Yeh kyun kaam karta hai: Wasserstein distance require karta hai ki critic 1-Lipschitz ho. Yeh penalty enforce karta hai ki gradient norm 1 ke kareeb ho, jo Lipschitz constraint ka tightest form hai.
Derivation:
- Ek 1-Lipschitz function satisfy karta hai
- Differentiable ke liye, iska matlab hai har jagah
- Optimal critic mein almost everywhere hota hai
- Isliye hum norm = 1 se deviation ko penalize karte hain
Interpolated points kyun: Real aur fake samples ke beech ka region woh jagah hai jahan critic ko sabse sharply distinguish karna hota hai, isliye wahan hum constraint enforce karte hain.
Problem: High-resolution GANs (1024×1024) ko directly train karna unstable hota hai—early training ke liye bahut zyada detail hoti hai.
Solution: Low resolution (4×4) se start karo, gradually layers add karke resolution badhaao (8×8, 16×16, ..., 1024×1024). Har resolution stable hone tak train karta hai phir grow karta hai.
Implementation:
- Start Generator outputs 4×4, Discriminator inputs 4×4
- Layers add karo: use karke naye layers smoothly fade in karo:
- ko 0 se 1 tak kaafi hazaar iterations mein increase karo
- par stabilize karo, phir next resolution layer add karo
Yeh kyun kaam karta hai: Low-resolution images mein kam information hoti hai, isliye GAN pehle broad structure seekhta hai (shape, layout) phir details (texture, fine edges). Yeh hierarchical learning sabhi scales simultaneously seekhne se zyada stable hai.
Monitoring aur GAN Training Diagnose Karna
Q: Kya signs hain ki discriminator bahut strong hai? A: Generator loss high aur constant rehti hai, saare generated samples ke liye, generated samples visually improve nahi hote
Q: Mode collapse ke kya signs hain? A: Generated samples mein low diversity (e.g., saare faces ka same pose/expression hai), generator loss oscillate karta hai lekin samples variety mein improve nahi hote, Inception Score ya FID suddenly drop ho jaata hai
Q: Tum oscillation aur convergence mein distinguish kaise kar sakte ho? A: Time ke saath loss curves plot karo—convergence mein stabilizing losses dikhti hain, oscillation mein periodic swings dikhte hain. Time ke saath sample diversity check karo—oscillation often matlab hota hai samples kuch types ke beech cycle karte hain.
Connections
- 4.5.01-Generative-Adversarial-Networks-fundamentals - Core GAN setup aur original objective
- 4.5.07-Wasserstein-GAN-and-improved-training - Instability ke liye WGAN solution
- 4.5.09-StyleGAN-and-progressive-growing - High-res stability ke liye progressive training
- 4.5.10-Conditional-GANs-and-control - Conditional generation mein mode collapse
- 3.4.05-Optimization-challenges-in-deep-learning - General optimization issues jo GANs se relevant hain
- 4.3.06-Batch-normalization-and-alternatives - Kyun batch norm GAN issues cause karta hai
Flashcards
#flashcards/ai-ml
Fixed generator ke liye optimal discriminator D*(x) kya hota hai?
Original GAN training mein vanishing gradient actually kya cause karta hai?
Yeh kehna kyun galat hai ki vanishing gradient -1/(1-D) factor se aata hai?
Non-saturating GAN loss fix kya hai?
GANs mein mode collapse kya hota hai?
Game theory perspective se mode collapse kyun hota hai?
Wasserstein GAN ka stability ke liye key innovation kya hai?
Spectral normalization kya hai aur yeh GAN training kyun stabilize karta hai?
D aur G ko same learning rate se train karna aksar problematic kyun hota hai?
WGAN-GP mein gradient penalty kya hai?
Progressive GAN training stability kaise improve karta hai?
Kya teen signs hain ki discriminator bahut strong hai?
GAN discriminators mein batch normalization issues kyun cause karta hai?
Recall Feynman: 12-year-old ko Explain Karo
Socho tumhare do dost ek game khel rahe hain. Ek dost (the Gener