Skip to content
← Generative AI
Q22

GAN architecture: forward/backward passes and the role of z

GANArchitectureLatent Space
Explain the architecture of a GAN and how the Generator and Discriminator interact during training. Illustrate the forward and backward passes and discuss the significance of the latent-space input to the Generator.

What's actually being asked

GAN architecture and G-D interaction, traced through a forward pass and a backward pass, plus why the latent-space input to G matters.

Answer

Architecture

  • Generator G (params θ_g): input is latent noise z, dimension typically much smaller than the output data (e.g., 100-D z for a 64×64 image). Built from fully-connected or transposed-convolutional layers with upsampling, batch norm, and ReLU/LeakyReLU activations, ending in a tanh or sigmoid output matching the data's value range.
  • Discriminator D (params θ_d): input is a data-shaped sample (real or fake); built from convolutional layers with LeakyReLU and downsampling, ending in a single sigmoid unit giving D(·)∈(0,1).

Forward pass

  1. Sample z ~ p_z (e.g., N(0,I)).
  2. x_fake = G(z) — forward through G.
  3. Sample a real batch x ~ p_data.
  4. Both x_fake and x are forwarded through D, producing D(G(z)) and D(x).
  5. These feed the value function: V(D,G) = 𝔼_{x∼p_data}[log D(x)] + 𝔼_{z∼p_z}[log(1−D(G(z)))].

(See the diagram — the forward-pass edges trace exactly this path: z → G → fake sample → D ← real sample → loss.)

Backward pass

Two separate backward passes happen, not one joint one:

  • D's backward pass: gradient of V(D,G) taken w.r.t. θ_d only (G's weights treated as constant for this step), and θ_d is updated by gradient ascent (D wants to maximize V) — θ_d ← θ_d + η∇_{θ_d} V.
  • G's backward pass: gradient taken w.r.t. θ_g only, through D's (now fixed) weights back into G — this is why D must be differentiable end-to-end, since the gradient signal for G has to pass through D. G is updated by gradient descent on 𝔼[log(1−D(G(z)))] (or ascent on the non-saturating 𝔼[log D(G(z))]) — θ_g ← θ_g − η∇_{θ_g}[log(1−D(G(z)))].

This alternation (the diagram's two backward edges, both flowing out of the loss node) is what makes it a minimax game rather than a single end-to-end supervised model — the loss is shared, but the update direction is opposite for each player on their own parameters.

Significance of the latent-space input

z is the only source of randomness/diversity in the entire system — without it, G would be a deterministic function producing one fixed output. Key properties this input gives the architecture:

  • Diversity of generation: different draws of z should map to different, diverse samples covering the breadth of p_data, not collapsing to a handful of outputs (mode collapse is exactly this property breaking down).
  • Structured, continuous space: because G is a smooth (differentiable) function, nearby points in z-space tend to decode to visually similar outputs, so the latent space supports meaningful interpolation (walking from z_1 to z_2 produces a smooth morph) and, in practice, sometimes exposes semantically meaningful directions (e.g., correlating with pose or style) even though nothing explicitly supervised that structure.
  • Decoupling from data at inference: once trained, generation needs no real data at all — just fresh z ~ p_z through G — which is what makes GANs usable as standalone generators, unlike models that need an encoder/input at inference time.
  • Dimensionality as a design choice: too low a dimension limits how much variation G can express; too high can make training harder to stabilize and the space harder to fill meaningfully — choosing z's dimensionality is an explicit architecture decision, not incidental.

Exam tip

If asked about "forward and backward passes" specifically, explicitly say that G's backward pass gradient has to flow through D's frozen weights — that single detail (gradient relay through a frozen network) is what examiners most often probe to check real understanding versus a memorized diagram.

ARCHITECTUREhow the pieces talk
6 components. Latent z ~ p_z to Generator G (forward); Generator G to Fake G(z) (forward); Fake G(z) to Discriminator D (forward); Real x to Discriminator D (forward); Discriminator D to Value V(D,G) (forward); Value V(D,G) to Discriminator D (backward: update D); Value V(D,G) to Generator G (backward: update G).Latent z ~ p_zGenerator GFake G(z)Real xDiscriminator DValue V(D,G)forwardforwardforwardforwardforwardbackward: update Dbackward: update G