Momentum (Optimization)
Momentum optimization uses past gradients to accelerate model training, smooth noisy updates, and improve convergence while balancing the learning rate.
Momentum is an optimization technique that gives gradient-based training a memory of previous updates. By combining the current gradient with a decaying history of earlier gradients, it builds speed along consistent directions and reduces back-and-forth movement. This helps machine learning models minimize their training objective more efficiently. Search engine optimization concerns website visibility; momentum concerns numerical updates to model parameters.
How Momentum Works#
During gradient descent, a model moves its weights against the gradient—the direction in which its loss function increases fastest. Classical momentum, also called Polyak momentum or the heavy-ball method, adds inertia to this movement. Boris Polyak introduced it in his 1964 work on accelerating iterative methods.
The optimizer maintains a velocity buffer, with one accumulated value per parameter. Each update multiplies the old buffer by a momentum coefficient, adds the current gradient, and subtracts the resulting buffer multiplied by the learning rate from the weights. In neural networks, backpropagation supplies those gradients; the optimizer retains the buffer between updates.
Momentum is especially useful on elongated loss surfaces, where curvature is steep across a valley and shallow along its floor. Gradients that repeatedly point along the valley accumulate, while alternating components across it partially cancel. With stochastic gradient descent, this memory also smooths fluctuations between mini-batches. Momentum's quadratic-loss dynamics explain both its acceleration and the oscillations it can introduce near a minimum.
Momentum, Learning Rate, and Related Methods#
The momentum coefficient, commonly written as beta or mu, usually lies between zero and one. Zero recovers ordinary gradient descent; values closer to one retain older gradients longer. A coefficient of 0.9 is a common starting point. With an unnormalized velocity buffer and a constant gradient, accumulated velocity approaches ten times that gradient at 0.9, versus 100 times at 0.99. Consequently, momentum and learning rate interact strongly during hyperparameter tuning.
An excessively aggressive combination produces overshoot: updates cross a minimum repeatedly, causing oscillating loss or divergence. This occurs even on smooth quadratic objectives. A learning rate schedule changes update magnitude over training, while momentum determines how much directional history persists.
Two closely related optimization algorithms use this history differently:
- Nesterov momentum evaluates the gradient at a look-ahead position obtained using the retained velocity, allowing the gradient to correct the anticipated movement.
- Adam combines an exponentially weighted gradient average with a squared-gradient average that scales updates separately for each parameter. Its
beta1controls gradient memory.
A Minimal PyTorch Example#
This PyTorch example compares identical starting points and learning rates on an elongated quadratic objective. The official SGD implementation manages the momentum buffer automatically.
import torch
# Curvature is 50 times greater along the second coordinate.
scale = torch.tensor([1.0, 50.0])
for momentum in (0.0, 0.9):
weights = torch.tensor([5.0, 1.0], requires_grad=True)
optimizer = torch.optim.SGD([weights], lr=0.015, momentum=momentum)
for step in range(100):
optimizer.zero_grad()
loss = (scale * weights.square()).sum()
loss.backward()
optimizer.step()
final_loss = (scale * weights.square()).sum().item()
print(f"Momentum {momentum}: loss = {final_loss:.6f}")After 100 updates, the loss is approximately 0.056531 without momentum and 0.000216 with momentum. Accumulated directional history accelerates progress along the shallow coordinate.
Uses in Computer Vision Training#
Momentum supports the training of convolutional neural networks for image classification and object detection. Ultralytics YOLO training enables Nesterov momentum when optimizer="SGD" is selected, and its momentum setting controls retained update history. The trainer implementation passes that coefficient to the optimizer with nesterov=True.
A landmark application is the original ResNet training procedure for ImageNet. Those models used SGD with momentum 0.9, a batch size of 256, weight decay 0.0001, and an initial learning rate of 0.1, divided by ten when error plateaued.










