Gradient Penalties and Convergence

Dive into Deep Learning · §16.4

Minimax Game Dynamics and Gradient Penalties
the Dirac-GAN · rotational vector fields · outward spirals & limit cycles · zero-centered R_1 & R_2 penalties · dual Sobolev filtering · R3GAN

Equilibrium Existence vs. Gradient Convergence

Motivation

  • Static optimum vs. coupled dynamics: Sections 16.1–16.3 assumed D sits at D^\star, but in practice both players take incremental gradient steps that shift each other’s objective.
  • Minimal counterexample (Mescheder et al., 2018): Even on a two-parameter minimax game with a unique equilibrium at (0, 0), taking 300 simultaneous gradient steps (h = 0.2) from (1, 1) doubles the distance to (0, 0) from 1.41 to 2.87.
  • Key question: How do zero-centered penalties (R_1, R_2) make the equilibrium locally exponentially stable?

The Dirac-GAN: A Two-Parameter Minimax System

Minimal Analytical Model

V(\theta, \psi) = \ell\big(D_\psi(0)\big) + \ell\big(-D_\psi(\theta)\big) = \ell(0) + \ell(-\psi\theta)

  • Two scalar parameters (Mescheder et al., 2018): True data p = \delta_0, generator q_\theta = \delta_\theta (q_\theta = p \iff \theta = 0), and linear critic D_\psi(x) = \psi x.
  • Discontinuous best response: For any \theta \neq 0, maximizing over \psi sends \psi\theta \to -\infty, yielding a flat value \sup_\psi V(\theta, \psi) = \ell(0) with zero slope.

Continuous-Time Gradient Flow Orbits on Circles

Rotational Vector Field

\dot{\theta} = -\partial_\theta V = \psi\,\ell'(-\psi\theta), \qquad \dot{\psi} = +\partial_\psi V = -\theta\,\ell'(-\psi\theta)

  • Exact conservation of radius: Because velocity \mathbf{u}(\theta, \psi) = \ell'(-\psi\theta)(\psi, -\theta) is orthogonal to (\theta, \psi), \frac{d}{dt}(\theta^2 + \psi^2) = 0.
  • Imaginary Jacobian eigenvalues: Linearizing at (0, 0) gives J = \left(\begin{smallmatrix} 0 & \ell'(0) \\ -\ell'(0) & 0 \end{smallmatrix}\right) with eigenvalues \nu_{1,2} = \pm i\,\ell'(0)—a linear center whose trajectories orbit on circles forever.

Discrete Time: Outward Spirals vs. Limit Bands

Discretization Hazards

\|(\theta, \psi) + h\,\mathbf{u}\|^2 = \|(\theta, \psi)\|^2 + h^2\|\mathbf{u}\|^2 > \|(\theta, \psi)\|^2

  • Simultaneous Euler steps spiral outward for all h > 0: Since \mathbf{u} \perp (\theta, \psi), every step increases the radius (eigenvalues 1 \pm i\,h\,\ell'(0) have modulus > 1).
  • Alternating steps preserve area: Composing the \psi and \theta half-steps yields a 2 \times 2 matrix with \det = 1, trapping iterates in a bounded annulus without converging.

Phase Portraits of Unpenalized and Penalized Flow

Numerical Integration

Integrating the Dirac-GAN from (\theta_0, \psi_0) = (1, 1) (initial radius \sqrt{2} \approx 1.41) confirms all four dynamical regimes:

  • Left (flow): Continuous RK4 integration orbits on the circle of radius 1.41.
  • Middle (steps, h = 0.2): 300 simultaneous steps spiral out to radius 2.87, while 2{,}000 alternating steps orbit in [1.34, 1.42].
  • Right (penalized, h = 0.2): Adding a zero-centered critic penalty drives simultaneous Euler steps directly to (0, 0) (reaching radius 6.5 \times 10^{-4} at \gamma = 0.3 and 7 \times 10^{-12} at \gamma = 1.0).

flow, RK4: 1.41 -> 1.41 in 800 steps; second half in [1.41, 1.41]
steps, simultaneous: 1.41 -> 2.87 in 300 steps; second half in [2.44, 2.87]
steps, alternating: 1.41 -> 1.36 in 2000 steps; second half in [1.34, 1.42]
penalized, gamma = 0.3: 1.41 -> 0.000652 in 300 steps; second half in [0.000652, 0.0396]
penalized, gamma = 1: 1.41 -> 6.97e-12 in 300 steps; second half in [6.97e-12, 2.33e-05]

Zero-Centered Gradient Penalties (R₁ and R₂)

Damping the Critic

R_1 = \frac{\gamma}{2}\,\mathbb{E}_{x \sim p}\Big[\big\|\nabla_x D(x)\big\|^2\Big], \qquad R_2 = \frac{\gamma}{2}\,\mathbb{E}_{x' \sim q}\Big[\big\|\nabla_{x'} D(x')\big\|^2\Big]

  • Why penalize input gradients? At q = p, the optimal log-ratio critic D^\star(x) = \log(p/q) = 0 is completely flat (\nabla_x D^\star = \mathbf{0}), so penalizing \|\nabla_x D\|^2 does not shift the equilibrium q = p.
  • Combined mixture penalty: Maximizing V_\ell(D) - R_1 - R_2 subtracts R_1 + R_2 = \gamma\,\mathbb{E}_{x \sim m}[\|\nabla_x D(x)\|^2].

Eigenvalues and Three Oscillator Damping Regimes

Damped Harmonic Oscillator

J_\gamma = \begin{pmatrix} 0 & \ell'(0) \\ -\ell'(0) & -\gamma \end{pmatrix}, \qquad \nu_{1,2} = -\frac{\gamma}{2} \pm \sqrt{\frac{\gamma^2}{4} - \ell'(0)^2}

  • Exponential local stability for all \gamma > 0: \operatorname{Re}(\nu_{1,2}) < 0 across all three oscillator regimes (underdamped 0 < \gamma < 2\ell'(0), critically damped \gamma = 2\ell'(0), and overdamped \gamma > 2\ell'(0)).
  • Overdamping pitfall (\gamma \gg 1): The slow eigenvalue \nu_{\textrm{slow}} \approx -\ell'(0)^2/\gamma \to 0 slows generator convergence when \gamma is excessively large.

Local Network Convergence and Penalty Design

Generalization & Design Rules

  • Local exponential convergence (Mescheder et al., 2018): Near q_{\theta^\star} = p where D_{\psi^\star} is flat on \operatorname{supp}(p), simultaneous and alternating updates with R_1/R_2 converge exponentially.
  • Zero-centered (R_1, R_2) vs. one-centered (WGAN-GP): WGAN-GP forces unit slope \|\nabla_x D\| = 1 even at q = p. The Dirac-GAN then never reaches the origin: it parks at |\theta| = \gamma for \gamma \geq 2 and cycles for smaller \gamma.
  • Why R_1 + R_2 beats R_1 alone: Far from equilibrium (p = \delta_0, q = \delta_1), a quadratic critic D_c(x) = -cx^2 has R_1 = 0 at x = 0 and lets c \to \infty; adding R_2 caps c^\star < 1/(8\gamma).

Effect of Penalties on the Local Value Function

Quadratic Expansion & Gaussian Shift

How does subtracting R_1 + R_2 = \gamma\int m\,\|\nabla_x D\|^2 modify the divergence near equilibrium? Expanding \ell(t) \approx \ell(0) + \ell'(0)t - \frac{1}{2}|\ell''(0)|t^2 to second order in D gives:

V_\ell(D) - R_1 - R_2 \approx 2\ell(0) + \ell'(0)\,\langle p - q,\, D\rangle - |\ell''(0)|\int m\,D^2 - \gamma\int m\,\|\nabla_x D\|^2

  • 1D Gaussian shift (p = \mathcal{N}(0, 1), q = \mathcal{N}(\mu, 1), linear critic D(x) = cx): For small \mu, maximizing -\ell'(0)\mu c - (|\ell''(0)| + \gamma)c^2 under the logistic loss (\ell'(0) = \frac{1}{2}, |\ell''(0)| = \frac{1}{4}) shrinks both the optimal slope and local value by 1 + 4\gamma: c^\star = -\frac{\mu}{1 + 4\gamma}, \qquad V_\gamma(D^\star) - 2\ell(0) \approx \frac{\mu^2}{4 + 16\gamma}

Effect of Penalties on the Local Value Function (check)

Quadratic Expansion & Gaussian Shift

Solving the penalized game exactly on a grid (Newton ascent on D) and comparing with the local value \mu^2/(4 + 16\gamma) and the large-\gamma value \mu^2/(16\gamma):

mu 0.2, gamma    0: exact 9.950e-03, local 1.000e-02 (1.00x), large-gamma inf (infx)
mu 0.2, gamma 0.01: exact 9.566e-03, local 9.615e-03 (1.01x), large-gamma 2.500e-01 (26.13x)
mu 0.2, gamma    1: exact 1.996e-03, local 2.000e-03 (1.00x), large-gamma 2.500e-03 (1.25x)
mu 0.2, gamma   10: exact 2.438e-04, local 2.439e-04 (1.00x), large-gamma 2.500e-04 (1.03x)
mu   1, gamma    0: exact 2.228e-01, local 2.500e-01 (1.12x), large-gamma inf (infx)
mu   1, gamma 0.01: exact 2.135e-01, local 2.404e-01 (1.13x), large-gamma 6.250e+00 (29.27x)
mu   1, gamma    1: exact 4.818e-02, local 5.000e-02 (1.04x), large-gamma 6.250e-02 (1.30x)
mu   1, gamma   10: exact 6.120e-03, local 6.098e-03 (1.00x), large-gamma 6.250e-03 (1.02x)
mu   3, gamma    0: exact 1.054e+00, local 2.250e+00 (2.14x), large-gamma inf (infx)
mu   3, gamma 0.01: exact 1.012e+00, local 2.163e+00 (2.14x), large-gamma 5.625e+01 (55.57x)
mu   3, gamma    1: exact 3.909e-01, local 4.500e-01 (1.15x), large-gamma 5.625e-01 (1.44x)
mu   3, gamma   10: exact 6.862e-02, local 5.488e-02 (0.80x), large-gamma 5.625e-02 (0.82x)

Dual Sobolev Norm and Spatial Low-Pass Filtering

Multiscale Interpretation

\sup_D V_\gamma(D) - 2\ell(0) \approx \frac{\ell'(0)^2}{4}\Big\langle p - q,\; \big(|\ell''(0)|\,m + \gamma\mathcal{L}_m\big)^{-1}(p - q)\Big\rangle

  • Interpolating JS and dual Sobolev norm: With \mathcal{L}_m D = -\nabla \cdot (m\nabla D), the local value transitions from 2\,\mathrm{JS}(p, q) as \gamma \to 0 to \frac{\ell'(0)^2}{4\gamma}\|p - q\|_{\dot{H}^{-1}(m)}^2 as \gamma \to \infty.
  • Spatial low-pass filter: Attenuates Fourier wavenumber \omega by (|\ell''(0)| + \gamma\omega^2)^{-1} below cutoff length scale 2\sqrt{\gamma} (\gamma has units of squared length).

Implementing Differentiable R₁ + R₂ Penalties

Higher-Order Autograd

Because each sample’s critic score D(x_i) depends only on row x_i (provided batch normalization is omitted), differentiating the sum \sum_i D(x_i) with respect to the input batch x computes every sample’s input gradient \nabla_{x_i} D(x_i) in a single backward pass:

def r1_r2_penalty(critic, real, fake):
    """Per-sample squared critic input gradients on real (R1) and fake (R2),
    before the gamma/2 scale."""
    def sq_grad_norm(x):
        x = x.detach().requires_grad_(True)
        grad, = torch.autograd.grad(critic(x).sum(), x, create_graph=True)
        return grad.reshape(x.shape[0], -1).pow(2).sum(dim=1)
    return sq_grad_norm(real), sq_grad_norm(fake)

Computational cost: Keeping the input gradient in the autodiff graph so the optimizer can differentiate \|\nabla_x D(x)\|^2 with respect to the critic’s parameters makes each penalized critic update cost roughly two backward passes.

The R3GAN Critic and Generator Step Functions

Training Recipe in Code

R3GAN (Huang et al., 2024) pairs the relativistic pairing loss (rpgan_loss_D, rpgan_loss_G) with R_1 + R_2. critic_step updates net_D on loss_D + gamma / 2 * (r1 + r2).mean() and returns the unscaled batch means of R_1 and R_2 for logging:

def critic_step(net_D, opt_D, loss_D, real, fake, gamma, y=None):
    """One critic step on loss_D + gamma/2 (R1 + R2); return the loss and
    the batch means of R1 and R2."""
    critic = net_D if y is None else lambda x: net_D(x, y)
    fake = fake.detach()  # the generator is held fixed
    r1, r2 = r1_r2_penalty(critic, real, fake)
    loss = loss_D(critic, real, fake)
    opt_D.zero_grad()
    (loss + gamma / 2 * (r1 + r2).mean()).backward()
    opt_D.step()
    return loss.detach(), r1.mean().detach(), r2.mean().detach()

The R3GAN Critic and Generator Step Functions (cont.)

Training Recipe in Code

generator_step takes one step on the generator’s loss against the current critic:

def generator_step(net_G, opt_G, loss_G, net_D, real, z, y=None):
    """One generator step on loss_G against the critic; return the loss."""
    critic = net_D if y is None else lambda x: net_D(x, y)
    loss = loss_G(critic, real, net_G(z) if y is None else net_G(z, y))
    opt_G.zero_grad()
    loss.backward()
    opt_G.step()
    return loss.detach()

Mode-Coverage Benchmark: 25 Gaussians on a 5×5 Grid

Experimental Setup

  • 5 \times 5 Gaussian grid (spacing 2.0, \sigma = 0.05): 3-layer ReLU MLP generator (64 \to 256 \to 256 \to 2) and leaky-ReLU critic trained for 10{,}000 steps with Adam \beta_1 = 0, \beta_2 = 0.99.
  • 2 \times 2 factorial design (3 seeds per arm): Crosses objective (NS vs. pairing) with penalty (\gamma = 0 vs. \gamma = 1), plus an overdamped \gamma = 10 control.
  • Four quantitative metrics: Covered modes (out of 25), on-mode fraction (within 3\sigma = 0.15), mean distance to nearest center, and critic steepness \mathbb{E}_q[\|\nabla_x D(x')\|^2].

25-Gaussian Results: Penalties Drive Coverage

Quantitative Comparison

Evaluating 10{,}000 samples at step 10{,}000 isolates the role of each ingredient:

arm                          run  modes  on-mode  distance  E_q|grad D|^2
NS                             0  16/25     0.70      0.20        1.7e+01
NS                             1  25/25     0.90      0.10        2.2e+00
NS                             2  24/25     0.76      0.16        5.6e+00
NS + R1 + R2                   0  25/25     0.77      0.15        8.9e-04
NS + R1 + R2                   1  25/25     0.83      0.13        6.8e-04
NS + R1 + R2                   2  25/25     0.86      0.11        3.6e-04
pairing                        0  25/25     0.82      0.13        3.9e+00
pairing                        1  15/25     0.76      0.17        1.2e+01
pairing                        2  23/25     0.80      0.15        5.1e+00
pairing + R1 + R2              0  25/25     0.86      0.12        3.3e-04
pairing + R1 + R2              1  25/25     0.89      0.09        1.9e-04
pairing + R1 + R2              2  25/25     0.85      0.12        5.0e-04
pairing + R1 + R2, gamma=10    0  23/25     0.19      0.46        1.2e-04
  • Gradient penalties (R_1 + R_2 at \gamma = 1) drive mode coverage: Without penalties (\gamma = 0), critic gradients remain steep (\mathbb{E}_q\|\nabla_x D\|^2 \in [0.7, 17]) and mode coverage is unreliable (12\text{--}25 modes). With \gamma = 1, critic steepness drops by three orders of magnitude (\sim 10^{-3}) and every run covers all 25 modes under both NS and pairing.

Visualizing Mode Coverage and Overdamping

Spatial Distributions

  • Penalized vs. unpenalized: Both \gamma = 1 arms (NS + R1 + R2 and pairing + R1 + R2) populate all 25 grid centers, whereas unpenalized runs drop modes or leave clusters uneven.
  • Why filaments connect neighboring modes: A continuous ReLU generator maps the connected Gaussian latent space \mathcal{N}(0, I_{64}) onto a connected surface, leaving thin bridges between modes.
  • Overdamping (\gamma = 10): Over-flattening the critic (\mathbb{E}_q\|\nabla_x D\|^2 \sim 10^{-4}) slows convergence, leaving only 20\text{--}30\% of samples within 3\sigma of a mode after 10{,}000 steps.

Diagnostic Pitfall: Calm Losses Certify Nothing

Monitoring Hazard

Comparing the on-mode sample fraction against the critic loss across all 8 checkpoints (every 1{,}250 steps) reveals a critical monitoring hazard:

on-mode fraction of run 0 at every 1,250 steps
  NS                           0.01 0.03 0.08 0.16 0.29 0.54 0.69 0.72
  NS + R1 + R2                 0.02 0.03 0.09 0.08 0.26 0.64 0.68 0.79
  pairing                      0.02 0.07 0.17 0.31 0.50 0.73 0.74 0.82
  pairing + R1 + R2            0.02 0.01 0.04 0.16 0.50 0.74 0.81 0.86
  pairing + R1 + R2, gamma=10  0.02 0.03 0.02 0.05 0.09 0.09 0.16 0.21
critic loss of run 0 at every 1,250 steps
  NS                           1.35 1.21 1.04 1.00 1.01 1.03 1.05 1.07
  NS + R1 + R2                 1.38 1.37 1.36 1.37 1.38 1.38 1.38 1.38
  pairing                      0.68 0.65 0.57 0.57 0.60 0.62 0.63 0.64
  pairing + R1 + R2            0.68 0.68 0.67 0.68 0.69 0.69 0.69 0.69
  pairing + R1 + R2, gamma=10  0.69 0.70 0.69 0.69 0.69 0.69 0.69 0.69

Why an equilibrium critic loss does not certify convergence: In every penalized run, the critic loss sits at its exact equilibrium value (2\log 2 \approx 1.38 for NS; \log 2 \approx 0.69 for pairing) from the very first checkpoint at step 1{,}250—when only 1\text{--}3\% of generated samples lie on a mode. Because R_1 + R_2 forces D(x) to remain nearly flat everywhere, an equilibrium critic loss only confirms that the critic is damped, never that q matches p.

Concept Check: Minimax Dynamics and Penalties

Check Your Understanding

Test your understanding of minimax rotational dynamics and zero-centered gradient penalties:

  1. Discrete Euler stability threshold: On the penalized Dirac-GAN with logistic loss (\ell'(0) = \frac{1}{2}), the continuous Jacobian eigenvalues are \nu_{1,2} = -\frac{\gamma}{2} \pm i\sqrt{\ell'(0)^2 - \gamma^2/4} in the underdamped regime \gamma < 1. What is the maximum step size h for which simultaneous discrete Euler steps converge (|1 + h\nu_{1,2}| < 1), and what is its numerical value at \gamma = 0.3?
  2. Penalized Gaussian shift: For p = \mathcal{N}(0, 1) and q = \mathcal{N}(\mu, 1) with small shift \mu = 0.2 under the logistic loss, by what factor does \gamma = 1 shrink the optimal linear critic slope c^\star compared to \gamma = 0?

Answers:

  1. Since \nu_1 \nu_2 = |\nu|^2 = \ell'(0)^2 and 2\operatorname{Re}(\nu) = -\gamma, we have |1 + h\nu|^2 = 1 - h\gamma + h^2\ell'(0)^2 < 1 \iff h < \frac{\gamma}{\ell'(0)^2} = \mathbf{4\gamma}. At \gamma = 0.3, simultaneous Euler steps converge for h < 1.2.
  2. Since c^\star = -\frac{\mu}{1 + 4\gamma}, setting \gamma = 1 shrinks both the critic slope and the local quadratic value \frac{\mu^2}{4 + 16\gamma} by a factor of 1 + 4(1) = \mathbf{5\times}.

Concept Check: Minimax Dynamics and Penalties (cont.)

Check Your Understanding

  1. Pairing on the Dirac-GAN: Does replacing the single-sample logistic loss with the relativistic pairing loss \ell(D_\psi(0) - D_\psi(\theta)) change the unpenalized Dirac-GAN vector field?

Answer:

  1. No. Because D_\psi(0) = 0, the pairing objective \ell(D_\psi(0) - D_\psi(\theta)) = \ell(-\psi\theta) differs from the single-sample objective \ell(0) + \ell(-\psi\theta) only by the constant \ell(0), producing the exact same rotational vector field.

Summary: Dynamics, Gradient Penalties, and R3GAN

Key Takeaways

Dynamical Regime / Mechanism Mathematical Form Jacobian Eigenvalues / Value Training Behavior & Practical Role
Unpenalized Dirac-GAN Flow \dot{\theta} = \psi\ell'(-\psi\theta), \dot{\psi} = -\theta\ell'(-\psi\theta) \nu_{1,2} = \pm i\,\ell'(0) (linear center) \frac{d}{dt}(\theta^2 + \psi^2) = 0; orbits on constant-radius circles
Discrete Simultaneous Steps (\theta, \psi) \mapsto (\theta, \psi) + h\,\mathbf{u}(\theta, \psi) 1 \pm i\,h\,\ell'(0) (|\lambda| = \sqrt{1 + h^2\ell'(0)^2} > 1) Spirals outward for every step size h > 0
Discrete Alternating Steps Critic half-step \to generator half-step \det = 1; on unit circle for h\ell'(0) \le 2 Area-preserving shears; orbits in a bounded band
Zero-Centered Penalties (R_1, R_2) R_1 + R_2 = \gamma\,\mathbb{E}_m[\|\nabla_x D(x)\|^2] \nu_{1,2} = -\frac{\gamma}{2} \pm \sqrt{\frac{\gamma^2}{4} - \ell'(0)^2} (\operatorname{Re} < 0) Exponential local convergence for all \gamma > 0
Local Penalized Value \frac{\ell'(0)^2}{4}\langle p - q, (|\ell''(0)|m + \gamma\mathcal{L}_m)^{-1}(p - q)\rangle Shrinks Gaussian shift by 1 + 4\gamma Low-pass filters p - q below cutoff scale 2\sqrt{\gamma} (\dot{H}^{-1}(m))
R3GAN Recipe \operatorname{softplus}(D(x') - D(x)) + \frac{\gamma}{2}(R_1 + R_2) Paired with Adam \beta_1 = 0 & no BatchNorm Damps critic steepness 1000\times; covers all 25 modes