Momentum improves stochastic gradient descent when gradients repeatedly point in a consistent direction. It accumulates a velocity term so useful directions produce larger steps while older gradients gradually fade. With learning rate η, gradient g_t, and momentum μ ∈ (0,1), update velocity v using the previous velocity and current gradient, then update parameters with Θ_{t+1} = Θ_t − v_{t+1}. section 5.3.1
The implementation follows three practical ideas:
- Reuse prior update history: each new velocity contains a fraction μ of the previous velocity, so repeated directional agreement builds momentum. section 5.3.1
- Decay old information: because μ is below 1, contributions from increasingly old gradients shrink toward zero. section 5.3.1
- Watch for overshooting: a large accumulated velocity can carry parameters past the desired region before the current gradient redirects them. section 5.3.1
PyTorch SGD with momentum
optimizer = torch.optim.SGD(fc_model.parameters(), lr=eta_0, momentum=0.9, nesterov=False) fc_results_momentum = train_network(fc_model, loss_func, train_loader, test_loader=test_loader, epochs=epochs, optimizer=optimizer, score_funcs={'Accuracy': accuracy_score}, device=device) Setting nesterov=True provides a direct comparison with Nesterov momentum. section 5.3.1
Figure 5.12 The naive optimization is almost stuck oscillating between the top-left and bottom-right directions, but it is slowly and consistently making progress in the top-right direction that leads to the solution. If we could build some momentum in that direction, we would not need so many steps.
Visualizes naive optimization oscillating across directions while making slow progress toward the solution, motivating accumulated momentum. section 5.3.1





