Generative Models
Level 4 (Application: novel problems, no hints) Time limit: 60 minutes Total marks: 60
Answer all questions. Show all derivations. Use / notation for mathematics.
Question 1 — VAE ELBO and the Reparameterization Trick (14 marks)
A team trains a VAE on 1-D data. Their encoder outputs, for a single input , a Gaussian posterior with and . The prior is .
(a) Write the ELBO for a single datapoint in terms of the reconstruction term and the KL term. State clearly what each term encourages. (3)
(b) For a univariate diagonal Gaussian posterior and standard normal prior, the KL divergence is Compute its numeric value for the given . (4)
(c) The team codes the sampling step as z = mu + sigma * eps where eps ~ N(0,1). Explain precisely why this reparameterization is necessary for training, and what would break if they instead sampled z ~ N(mu, sigma^2) directly inside the graph. (4)
(d) If they scale the KL term by a factor (a -VAE), predict the qualitative effect on latent-space structure and reconstruction quality, and justify. (3)
Question 2 — Diffusion Forward Process (13 marks)
A DDPM uses a forward process with the closed form , where and .
(a) A short schedule uses . Compute . (4)
(b) Using the reparameterization with , and given and a drawn noise , compute . (4)
(c) As , argue what approaches and why this matters for sampling from the trained model. (2)
(d) A practitioner switches from a linear schedule to a cosine schedule. State one concrete benefit for image quality and briefly explain the mechanism. (3)
Question 3 — GAN Objective and Training Dynamics (12 marks)
The original GAN minimax objective is
(a) For a fixed generator, show that the optimal discriminator is (5)
(b) At a point where the generator perfectly matches the data (), evaluate and the value of the objective. (3)
(c) Explain mode collapse operationally: what does the generator do, why does the standard loss fail to punish it, and name one architectural/loss remedy with a one-line reason. (4)
Question 4 — Classifier-Free Guidance (11 marks)
In classifier-free guidance the guided noise prediction is where is the conditioning (e.g. text embedding), is the null/unconditional token, and is the guidance scale.
(a) Suppose at some step and . Compute for and for . (4)
(b) Interpret what and each correspond to. (3)
(c) Explain the practical trade-off of increasing far above 1: what improves and what degrades, and why. (4)
Question 5 — Model Selection Reasoning (10 marks)
A startup must generate high-resolution product photos from text prompts, with a small GPU budget for inference.
(a) Compare a GAN vs a pixel-space diffusion model vs a latent diffusion model on: sample quality, training stability, and inference cost. Recommend one and justify. (6)
(b) They report an FID of 8.2 and an Inception Score of 4.1. Explain what each metric measures and why FID is generally preferred, including the direction (higher/lower better) of each. (4)
End of paper.
Answer keyMark scheme & solutions
Question 1 (14 marks)
(a) (3)
- Reconstruction term (1): encourages decoded samples to match input .
- KL term (1): pulls the posterior toward the prior, regularizing/structuring the latent space (1).
(b) (4) (1); (1); (1). (1)
(c) (4)
- Sampling
z ~ N(mu, sigma²)directly is a stochastic node; gradients cannot flow back through a random draw to (1). - Reparameterization moves randomness to an external variable (1), making a deterministic, differentiable function of parameters (1).
- Without it, backprop to the encoder parameters is impossible / gradient is high-variance (score-function) and training stalls (1).
(d) (3)
- Larger weights the KL more, forcing posterior closer to prior → more disentangled / smoother latent space (1).
- Reconstruction quality degrades because capacity to encode information is penalized (1); risk of posterior collapse where latents become uninformative (1).
Question 2 (13 marks)
(a) (4) (2). (2)
(b) (4) (1); (1). (2)
(c) (2) (1), so ; this lets sampling start from pure Gaussian noise independent of (1).
(d) (3)
- Cosine schedule adds noise more gradually, avoiding the abrupt information destruction of linear schedules near the end (1).
- Keeps more signal in later steps / better distributes difficulty across timesteps (1) → improved sample quality especially at high resolution (1).
Question 3 (12 marks)
(a) (5) For fixed , maximize over the integrand: (1) Pointwise, maximize with (1). (1) (1). (1)
(b) (3) (1). Objective value (i.e. ) (2).
(c) (4)
- Generator maps many/all to a few outputs, ignoring diversity (1).
- Standard loss only rewards fooling ; producing one convincing mode still lowers loss, so limited-diversity outputs aren't penalized (1).
- Remedy e.g. WGAN / Wasserstein loss (1): provides smoother gradients and a distance that reflects distribution overlap, reducing collapse (or minibatch discrimination) (1).
Question 4 (11 marks)
(a) (4) : (2). : (2).
(b) (3)
- : purely unconditional prediction — ignores the prompt (1.5).
- : standard conditional prediction (no extra guidance) (1.5).
(c) (4)
- Larger pushes samples toward stronger alignment with → better prompt fidelity/sharper class features (2).
- But reduces diversity and can cause over-saturation/artifacts and mode narrowing, since predictions are extrapolated beyond the model's learned distribution (2).
Question 5 (10 marks)
(a) (6)
- GAN: high quality, fast single-pass inference, but unstable training / mode collapse (2).
- Pixel diffusion: excellent quality & stable training, but very expensive inference (many denoising steps at full resolution) (2).
- Latent diffusion: diffuses in a compressed latent space → near-diffusion quality, stable, and much cheaper inference. Recommend latent diffusion given the small GPU budget and text-to-image need (2).
(b) (4)
- FID: Fréchet distance between Gaussian-fit features (Inception activations) of real vs generated images; captures quality and diversity; lower is better (2).
- IS: uses classifier confidence + marginal diversity; higher is better but ignores real data statistics and is easily gamed. FID preferred because it compares against real data distribution and penalizes mode collapse (2).
[
{"claim":"KL for N(2,0.25)||N(0,1) = 2.318147","code":"mu=2.0; s2=0.25; val=(mu**2+s2-1-sympy.log(s2))/2; result=abs(float(val)-2.3181471805599454)<1e-6"},
{"claim":"alpha_bar_3 = 0.36","code":"ab=0.9*0.8*0.5; result=abs(ab-0.36)<1e-12"},
{"claim":"x_3 = 1.0 given x0=1, eps=0.5","code":"ab=0.36; x3=sympy.sqrt(ab)*1.0+sympy.sqrt(1-ab)*0.5; result=abs(float(x3)-1.0)<1e-9"},
{"claim":"GAN optimal objective at p_g=p_data equals -2 ln 2","code":"v=sympy.log(sympy.Rational(1,2))+sympy.log(sympy.Rational(1,2)); result=abs(float(v)-(-1.3862943611198906))<1e-9"},
{"claim":"CFG guided eps at w=3 is 1.10","code":"eu=0.20; ec=0.50; w=3; g=eu+w*(ec-eu); result=abs(g-1.10)<1e-9"}
]