Gradient penalty regularizes the discriminator in Wasserstein GAN training. It reduces vanishing-gradient opportunities and can make it easier for the generator to keep pace, helping address mode collapse. section 9.3.3
Implement the penalty inside the discriminator update:
- Sample ε values from [0, 1], shaped for broadcasting across each data example. section 9.3.3
- Interpolate between real and fake data with mixed = ε·real + (1−ε)·fake. section 9.3.3
- Do not detach fake before passing it to the discriminator, because the generator must remain connected to the penalty calculation. section 9.3.3
Training checks
The same training function is applied to a toy grid and 28×28 generated digits, followed by generated-sample plots and smoothed generator/discriminator loss curves.

