← All models

MODEL EXPLORER / GENERATIVE MODELS

Train a generator against a discriminator

Which network is being updated, and what is it trying to change?

Curated by TensorVizGenerative adversarial networks · 4-step tour
Static architecture
Which network is being updated, and what is it trying to change?
Opening the interactive graph…
Architecture snapshot · No Python requiredDownload graph ↓

RECORDED NUMERICAL EXAMPLE

Update one network at a time.

Recorded two-dimensional GAN updates on four toy points. Choose the discriminator and generator stages to inspect which parameters and generated samples change. One alternating update does not establish a learned distribution or stable GAN training.

Start from the same random initialization and fixed noise samples. The discriminator assigns probabilities to real and generated points. Two separate optimizers will update one network at a time.

1.38-1.381.38-1.380Feature xFeature yReal training points: (0.8, 0.9)Real training points: (1.1, 1)Real training points: (0.9, 1.2)Real training points: (1.2, 0.8)Generated points · fixed noise: (-0.2281, -0.3277)Generated points · fixed noise: (-0.2688, -0.1584)Generated points · fixed noise: (-0.1617, -0.1855)Generated points · fixed noise: (-0.02167, -0.008925)
  • Real training points
  • Generated points · fixed noise

Both axes use the same scale.

Recorded point coordinates
SeriesFeature xFeature y
Real training points0.80.9
Real training points1.11
Real training points0.91.2
Real training points1.20.8
Generated points · fixed noise-0.2281-0.3277
Generated points · fixed noise-0.2688-0.1584
Generated points · fixed noise-0.1617-0.1855
Generated points · fixed noise-0.02167-0.008925
D(real) probabilities
0.4504
0.4381
0.4473
0.4333
D(G(z)) probabilities
0.4594
0.466
0.4643
0.4636

Bars share one scale within this example. Values are rounded to four significant digits.

Generator parameter change · norm since initialization
0
Discriminator parameter change · norm since initialization
0
Discriminator loss
1.438
Non-saturating generator loss
0.7693
Verified by the local recipe
  • A discriminator update changes only D; detached samples give the generator no gradient
  • A generator update changes only G while retaining a gradient path through frozen D
  • Stable logit losses match minimax and non-saturating analytic gradients
  • The non-saturating loss gives a stronger gradient in the confident-fake example

Download the source and run.py to reproduce these checks. Choosing an example here replays recorded values.

ABOUT THIS EXAMPLE

Follow real and generated points through one discriminator, then replay separate optimizer steps and compare generator-loss gradients.

Training method · 2014

Generative adversarial networks

MLP generator 4 → 8 → 2 and shared discriminator 2 → 8 → 1. Stable logit losses reproduce the binary objectives; recorded training uses one D step and one non-saturating G step on four synthetic points.

Source, capture & limitations +

A toy two-dimensional training process, not a trained image model. One optimizer step does not demonstrate distribution matching, stable convergence or protection against mode collapse. The forward graph shares D across both inputs; separate update functions in the downloaded source implement detach/freeze behavior.

Original TensorViz teaching example. PyTorch provides the underlying operators.

No separate redistribution license has been declared for these project examples.

Content revision
c8dd1ae1b30e8df7
Source SHA-256
83dea846127a7455d89d2d0faaec5105d412b5b4eb434b34dce826aca371956d
Captured
2026-09-17 · Python 3.13.13 / Torch 2.7.1

Two-dimensional GAN forward, separate SGD updates, frozen/detached parameter checks and minimax/non-saturating gradient comparisons. No image dataset or trained generator.

Read the model manifest ↗