MIT 6.7960 — Lecture 2
How to Train a Neural Net
§ Gradient-Based Optimization
Gradient descent isn't the only gradient-based optimization algorithm. Even if we can compute the gradient of a neural net, what should we do with it to best minimize the objective?
In general, any optimization algorithm must effectively define the following two things.
A surrogate—a local approximation of the loss function.
Example. We might take a first-degree Taylor approximation of the loss.
A trust region—a region in which the surrogate is trustable.
Example. We might take the trust region to be a -radius ball.
If we use the two examples given above, we get exactly gradient descent:
But we can also generalize—if we take the trust region to be a -radius square, we get a different optimizer.

This optimizer is called sign descent because the minimizer looks like this:
We can also set the trust region using the spectral norm of the weight update, which produces spectral descent.
Remark. Lecture did not give any elaboration on what spectral descent is. In short, the spectral norm of a matrix is its largest singular value (see Lecture 19 of 18.701), so is just with every singular value flattened to .
§ Bells and Whistles
It turns out that sign descent and spectral descent (with bells and whistles) both yield commonly-used descent methods.

Stochasticity. The gradient is computed by averaging across only a subset of the data.
Advantages: It's much cheaper, and the noise of the stochasticity serves as an implicit regularizer.
Disadvantages: Higher variance due to gradient approximation.
Momentum. Say the gradient steps are biased to continue in the direction of the previous update.
Expectedly, the constant needs to be tuned carefully, or else advantages may become disadvantages.

§ Gradient Difficulties
Some functions are easier to optimize than others.

Note that even though most of these functions are not differentiable, they all have gradients in PyTorch. Even then, though, PyTorch cannot find a global minimum when there are vanishing gradients, exploding gradients, or local minima.

One fix is to use gradient clipping: if gradients exceed a magnitude , scale them to have magnitude .

Another fix is to choose a direction not by computing the gradient, but by considering small perturbations of in all directions and moving in the direction of lower loss.

§ Backpropagation
See Lecture 13 of 6.790 for an explanation of backpropagation specifically when each layer's computation is a linear layer plus an activation. We give a more general description here. (Below, and are synonymous.)

Notably, for linear layers we have , so it follows that and . So backprop is easy.
In practice, not all layers are linear, of course. For example,

But the nonlinear layers like relu are also easy to deal with—relu's Jacobian is diagonal.
And of course, all of this is compatible with more general features of DAGs, like merges and branches.

Note that parameter sharing (used in CNNs, e.g.) is just a variant of branching.