Prompts Forms Resume Reports ★ Saved ★ Saved★ + Submit a tool
Core concepts

Optimizer

About 4481 characters Updated Nov 30, 2026 30 views AI wiki

An optimizer is an algorithm that updates model parameters based on gradients; it decides "which direction to move, how large a step to take, and whether to carry momentum". The loss function provides the terrain, backpropagation provides the slope, and the optimizer takes the actual step; it is one of the core variables determining whether training converges stably and how well it generalizes, and also the part most sensitive to tuning in practice.

Core Principles

The most basic is stochastic gradient descent, which updates parameters along the negative gradient direction scaled by the learning rate and estimates the gradient from a small batch of data each time. Its advantages are small memory footprint and often robust generalization; its drawback is oscillation back and forth in narrow valleys under ill-conditioned terrain, with slow convergence.

The momentum method adds a velocity term to the update, accumulating historical gradients into inertia, which accelerates progress in consistent directions and damps oscillation. Nesterov momentum first probes a step in the momentum direction and then computes the gradient, giving it a look-ahead quality. Adaptive methods go further and maintain an independent learning rate for each parameter: AdaGrad scales by the accumulated sum of squared historical gradients, which suits sparse features but lets the learning rate decay monotonically to a standstill; RMSProp replaces this with an exponential moving average to solve the decay problem; Adam combines momentum with second-moment estimation and applies bias correction, and has long been the default first choice.

In recent years, AdamW has corrected the problem in Adam where regularization is distorted by adaptive scaling, by decoupling weight decay from the gradient update, and has become the standard configuration for Transformer training. The other line is second-order approximation and curvature information, such as K-FAC and Shampoo, which are faster at certain scales but complex to engineer.

Recommendations for Choice

Empirically, small models and computer vision tasks often use stochastic gradient descent with momentum plus cosine annealing and tend to generalize better; large models, Transformers and sparse-gradient tasks prefer AdamW; when the dataset is small or generalization is extremely sensitive, stochastic gradient descent with momentum can be tried for final fine-tuning. When switching, the learning rate should be reset or adjusted proportionally rather than copied over.

Second-Order Information and the Trade-offs of Distributed Training

First-order methods use only the gradient, while second-order methods try to exploit curvature to converge in fewer steps, but the full Hessian cannot be stored. Approximate schemes include diagonal, block-wise and low-rank approximations; the latter, such as Shampoo, have demonstrated efficiency on recommendation and language model tasks but are complex to implement and awkward to combine with mixed precision. Distributed training adds another dimension: with data parallelism gradients require an all-reduce and the optimizer states take up enormous memory, which has produced techniques such as sharded optimizer states and parameters and compressed gradient communication. When choosing an optimizer, besides the convergence curve, one must weigh memory usage, communication overhead and debugging difficulty, and the three often constrain each other.

A practical diagnostic is to watch the effective learning rate, that is, the ratio of the update magnitude to the parameter scale. If the ratio is too large training is unstable, and if too small progress is slow; recording it periodically often reveals problems earlier than watching the loss curve alone.

Key Points

The learning rate is the primary hyperparameter: it affects the result more than the choice of optimizer, and usually requires a grid search or a logarithmic search scaled to the loss.

Momentum coefficient: commonly 0.9, coupled with the learning rate; larger momentum is smoother but may overshoot.

Weight decay: the decoupled form in AdamW is stable, with a typical magnitude between one hundredth and one thousandth.

Gradient clipping: clipping by global norm prevents a few batches from exploding the gradient and is practically standard for large models.

Batch size: when it changes, the learning rate and warm-up steps must be adjusted accordingly, and a linear scaling rule of thumb exists.

Common Misconceptions

Many believe adaptive optimizers are always better, yet on tasks such as image classification they often generalize worse than well-tuned stochastic gradient descent with momentum. Another misconception is to carry Adam's regularization straight over to AdamW, or to assume that switching the optimizer removes the need to tune the learning rate. Some also ignore gradient clipping and, when the loss spikes mid-training, misdiagnose it as a data problem.

Application Scenarios

Pretraining and fine-tuning of deep networks, large-scale language model training, embedding learning in recommender systems, policy updates in reinforcement learning, adversarial training of generative models, and click-through rate prediction on sparse features in advertising.