Ultralytics YOLO27: Join the waitlist.
License YOLO
Back to Ultralytics Glossary

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.

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 beta1 controls 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.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Turn drone and aerial imagery into real-time insights for agriculture, aquaculture, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Apply computer vision in aerospace with Ultralytics YOLO for aircraft inspection, runway FOD detection, airport ground operations, and composite defect detection.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning