11/04/26: Lect-10
Overview
Joseph Zambreno distinguishes optimization, minimizing training loss, from learning, finding a model that generalizes, then explains why neural-network loss surfaces make optimization difficult. He connects local minima, saddle points, plateaus, and ravines to practical techniques including mini-batch training, batch normalization, momentum, RMSProp, and Adam, and explains why optimizer and learning-rate choices affect training.
Key takeaways
- Minimizing training loss is not the same as learning a model that generalizes: a model can fit its training set well while still having high validation error.
- A small gradient-descent step is justified by a first-order Taylor approximation, but an overly large learning rate can make higher-order effects dominate and cause oscillation or divergence.
- Neural-network loss surfaces can contain saddle points, saturated or dead-unit plateaus, and ravines; each can stall training for a different geometric reason.
- Mini-batches are a hardware trade-off as well as a statistical choice: they enable parallel computation while avoiding the cost of full-batch updates and the noise and inefficiency of single-example updates.
- Batch normalization addresses hidden-layer scale changes by normalizing each mini-batch, learning gamma and beta, and using running-statistic buffers during evaluation.
- Momentum accumulates consistent gradients, while RMSProp tracks squared-gradient magnitude; Adam combines both ideas, but switching optimizers still requires checking the learning rate.
Chapters
- The course has largely relied on `torch.optim.SGD` and Adam after an early from-scratch stochastic gradient descent exercise.
- Exploding and vanishing gradients, discussed for deep networks and recurrent neural networks, are training and optimization problems as well as architecture concerns.
- Understanding optimization matters when real training runs take hours, days, or weeks rather than the five minutes typical of a lab.
- Optimization minimizes a function, here the training loss, by adjusting model parameters.
- Learning aims to find a model that generalizes; low training error does not guarantee low validation or test error.
- Linear and logistic regression have convex loss settings, while adding nonlinearities in multilayer perceptrons makes the optimization problem non-convex.
- A convex function lies below chords between points in its domain; neural-network loss surfaces in millions of parameters cannot be visualized as simple curves.
- A first-order Taylor expansion approximates the loss after a small change in parameters.
- Choosing a step of negative learning rate times the gradient produces a decrease proportional to the squared gradient, provided the step is sufficiently small.
- For the example loss f(x) = x², starting at x = 10 with learning rate 0.2 updates x to 6 and reduces the loss from 100 to 36.
- An excessively large learning rate can make higher-order error dominate, causing oscillation or divergence instead of reliable descent.
- Nonlinear neural networks have non-convex loss surfaces, so gradient descent is not guaranteed to find a global minimum.
- At a local minimum the gradient is zero, leaving gradient descent with no direction to continue, even if a better global minimum exists.
- Permuting hidden units can leave a network's output unchanged, illustrating symmetries that complicate the geometry of neural-network optimization.
- Random restarts can lead to different local minima; in practice, a useful local solution is often sufficient.
- Full-batch gradient descent evaluates all training samples before each parameter update, which can require one million forward passes for a million-example dataset.
- Single-sample stochastic gradient descent updates after each example and produces noisier gradient estimates.
- Mini-batch SGD, often using batches such as 32 examples, balances noisy updates with parallel computation on modern hardware.
- Batch size changes the optimization trajectory and compute efficiency; a textbook comparison shows batch size 100 reaching a reasonable result faster in one example.
- A saddle point has zero gradient without being a local minimum, so training can appear stalled despite available directions for reducing loss.
- For f(x, y) = x² − y², the gradient is zero at (0, 0), while the Hessian has both positive and negative eigenvalues.
- Near saddle points, gradients can be tiny, slowing updates and making escape difficult.
- Random weight initialization helps avoid symmetric starting configurations, such as initializing every parameter to zero.
- Sigmoid and tanh units can saturate near their extremes, where gradients become too small to drive useful updates.
- ReLU units can die when their pre-activation stays negative: their output and gradient are both zero.
- Careful initialization can keep activations within a useful dynamic range; wider networks can also tolerate some inactive units.
- Leaky ReLU retains a small negative-side slope, giving a dead or stalled unit a possible path to resume learning.
- A ravine has sharply different curvature across dimensions, so one learning rate can be too large for one direction and too small for another.
- For the example f(x, y) = 0.1x² + 2y², the Hessian eigenvalues are 0.2 and 4, giving a condition number of 20.
- Gradient descent may zigzag across a steep direction while making slow progress along a shallow one.
- In high-dimensional parameter spaces, mismatched parameter scales can make a single global learning rate ineffective.
- Standardizing inputs to zero mean and unit variance can improve conditioning at the network's first layer.
- Input normalization does not control the scale of hidden activations produced during training, so later layers can still develop poorly conditioned ravines.
- Batch normalization applies normalization layer by layer to each mini-batch, addressing changing hidden-activation scales.
- Normalization can interact with ReLU by shifting activations around zero, motivating learnable scale and shift values.
- Batch normalization centers batch activations and scales them to unit variance, then applies learnable gamma and beta values.
- In common layer layouts, batch normalization follows a linear or convolutional operation and precedes the activation; convolutional statistics are tracked per channel.
- Moving means and variances are buffers, not trainable parameters, and are updated as batches arrive.
- Training mode uses batch statistics and updates running statistics; evaluation mode uses the stored running values, so `model.train()` and `model.eval()` affect this layer's behavior.
- Batch-normalization momentum controls how a running mean or variance balances its previous value against the newest batch statistic.
- SGD momentum instead averages gradients over time and updates parameters using that accumulated velocity rather than only the latest gradient.
- Alternating gradients across a ravine can partially cancel, while consistent gradients along its shallow direction accumulate and speed progress.
- PyTorch SGD uses zero momentum by default; Zambreno suggests testing momentum when training progresses slowly, rather than blindly increasing the learning rate.
- RMSProp tracks a running average of squared gradients to adjust update scale, complementing momentum's tracking of gradient direction.
- Adam combines running averages of gradients and squared gradients, with two beta hyperparameters that usually work reasonably at their defaults.
- Zambreno reports Adam as common for language models and transformers, while SGD remains common for convolutional networks, presenting this as an observation rather than a settled explanation.
- AdamW addresses problems that arise when standard Adam is combined with weight decay; the AdamW correction dates to 2019.
- An optimizer comparison on the same ill-conditioned ravine shows SGD zigzagging or progressing slowly, while momentum smooths updates and RMSProp and Adam produce cleaner paths.
- Adam can overshoot at an unsuitable learning rate, so replacing SGD with Adam should include learning-rate retuning.
- Adaptive scaling lets RMSProp and Adam tolerate learning rates that may be too high for plain SGD.
- Newton-style optimization uses second-order curvature information, but a Hessian for a d-dimensional parameter vector contains d² entries.
- For large neural-network parameter spaces, storing and computing Hessians is impractical compared with first-order gradients.
- RMSProp and Adam track changes in gradient magnitude over time, which provides some curvature-related adaptation without constructing a full Hessian.
- When a project model trains poorly, first check for implementation bugs, then consider whether another optimizer or learning rate better suits the loss surface.
Transcript excerpt
0:00 Actually, this is a fun topic, although it is in some sense a bit of a one-off topic for us in that we're gonna we're going to touch upon it. We're going to kind of dive in. We're going to play through some demos of what we're doing and then we kind of just leave it right there. Um, and the motivation for it is for the most part this semester, you know, we we did learn about stochastic gradient descent. We did to some extent build our own sort of from scratch version of it. But after that initial experiment early in lab number two and in the corresponding class, we pretty much just been calling torch.optim.sgd or in some cases I kind of handwaved and said well for recurrent or language models run torch.optim.atom. And we did look at it but for the most part though we we did take this general approach for granted. This has been a a black box for us this semester. It's
0:48 just been a part of our broader puzzle here. I spent a little too much time looking at the etmology of black box. They the flight data recorders, they they were originally intentionally painted black back in World War II, but now it's the exact opposite. You want to be able to find these things. So they're they're made out of highly visible kind of thing. And the term somewhat uh co-orinated with sort of the systems thinking view of the word. And if you've done programming or just systems engineering, you maybe have used this term before that I'm doing blackbox testing. Um, I'm providing inputs, I'm measuring outputs. I don't necessarily know exactly what's happening on the internals of what's going on. And that does kind of match what we've been doing
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Joseph Zambreno.