11.2 Training Dynamics
Minimax J. Non-saturating −log D(G(z)). A 99% D is often a dead G.
These notes match the lecture slides. Use (slides) on the course hub for the deck.
The two nets have opposite goals. You cannot treat a GAN as one ordinary loss. Each step is a small fight: first improve , then improve , and try not to let either win too hard. By the end you should be able to write , run the two-phase loop, and say why a 99% discriminator is a problem, not a trophy.
1. What GAN training is
GAN training is a min-max game, not a single supervised loss. wants to tell real from fake. wants to fool . Goodfellow et al. write that as . A Nash point you hope for is that matches the real distribution and is a coin flip. Training does not guarantee you land there.
Each iteration has two phases. First you improve on a batch of reals and fakes. Then you improve on fresh noise. The original saturating loss for is weak when is already sharp, so people use a non-saturating surrogate instead of minimizing .
You are not adding a KL term. That is RLHF, a different week. Here the only fight is , plus the surrogate actually climbs.
2. Why we use it
If you only train to 99%, gets no gradient: fakes are so obviously fake that sits near 0 and the slope with respect to vanishes. If you only train , is stale and becomes a noisy, lying teacher. The two parameter vectors have to stay in tension.
Watching is not evaluation. A falling generator loss can mean better fakes or a collapsing . You still have to look at samples and at coverage (note 11.3). Lab 11 is a 2-D version of this fight on purpose: you will see the tension in a scatter plot, not in a single scalar.
Learning rates, how many steps per step, and batch size all move that balance. The two nets can oscillate: losses look fine, then the samples jump.
3. Architecture
The architecture is the same two nets as note 11.1. What is new is the update rule: alternate (or simultaneous) SGD steps, with a freeze on the net you are not training.
- Train . A batch of reals (label 1) and fakes from the current (label 0). Binary cross-entropy. Update only . Detach the fakes so the step does not also move .
- Train . Fresh noise, fresh fakes. Labels are all 1: you want to be wrong. Freeze ; update only .

Lab 11’s loop is exactly this, with BCEWithLogitsLoss: one step, one step, 400 iterations. Print both losses. Do not rank checkpoints by the smaller number.
4. How it works, step by step
Read the two terms of out loud. First term: on reals, is large when . Second term: on fakes, is large when . only appears in the second term, and it wants that term small, i.e. near 1.
- Sample a real batch and a noise batch. Form fakes with the current generator.
- Phase D. Maximize on reals plus on fakes. Update only .
- Phase G. Draw fresh noise. In code you often maximize instead of minimizing . Early in training is too good and the second form saturates: if , then and the slope with respect to is tiny. still has slope.
- Repeat. If is too weak, gets a noisy teacher. If is too strong, ’s gradient vanishes.
Lab 11 feeds ones into the generator’s BCE: that is the non-saturating form. A 99% discriminator is the saturating regime, not a trophy.
5. Mathematical formulas
The two-player objective is
wants large (correct labels). wants small (fakes that look real). only appears in the second expectation.
The saturating generator loss is the second term of . The non-saturating surrogate that Lab 11 actually uses is
equivalently minimizing . minimizes a surrogate, not always this .
6. Positive points and negative points
Positive.
- When the two nets stay balanced, samples improve without writing a likelihood.
- The two-phase loop is ordinary SGD plus a freeze: Lab 11 can print both losses and a scatter plot.
- The non-saturating surrogate keeps a slope for after has already become sharp.
- You can diagnose the fight from the two losses and the samples, instead of from one scalar.
Negative.
- Oscillation is normal: losses can look fine while the samples jump.
- A too-strong starves of gradient; a too-weak lies.
- A falling generator loss can mean got worse, not that the pictures got better.
- Step sizes, how many steps per step, and batch size are all load-bearing knobs.
- The next note is collapse: even a healthy-looking does not measure coverage.
When not to. If you need a stable regression target instead of a moving adversary, that is diffusion (Week 12), not a different GAN learning rate.
7. Teaching this note
About 35 minutes at the board, then ~10 minutes of video.
- 0–12 min. Write and mark who maximizes which term. Circle that does not appear in the real term.
- 12–22 min. The two-phase loop. Non-saturating trick: .
- 22–33 min. Worked numbers: one real, one fake, both forms of the loss.
- Then play 54:00–64:00 of the assigned video (minimax objective and the training algorithm). Pause on the “train then ” loop.
8. Worked example
One real with , one fake with . Use natural log, , , .
Discriminator’s sample of :
wants this larger (less negative): push up, push down.
Saturating generator loss (the term minimizes):
If instead , that becomes : almost flat. The non-saturating surrogate is . At that is ; at it is . Still a slope. That is why Lab 11 feeds ones into the generator’s BCE: it is the non-saturating form.
The practical loop is the same minimax: update , then . A 99% discriminator is the saturating regime, not a trophy.
9. Where students get stuck
- Updating both nets in one
loss.backward()on a shared graph. Detach the fakes on the step; freeze on the step. - Reading a falling loss as “better pictures.” It can mean got worse.
- Using early, when is already sharp, and concluding “GANs cannot train.”
10. Video
Watch Generative models: training and , 54:00–64:00.
Pause on the minimax and on the practical loop (alternate and ). Same URL as note 11.1; do not replay 46:45–54:00 unless someone missed it.
11. Practice
-
In phase 2 the fake labels are 1. Who is being lied to, and why is that the generator’s loss?
-
Why might two discriminator steps per generator step help early training, and how could it hurt later?
-
The generator loss dropped and the pictures got worse. Give one explanation that is not “the learning rate is wrong.”
-
. Compute and (natural log; , ). Which number still has room to move ?
-
A batch has on every real and on every fake. Write the one-sample as a number (, ).