Adam Optimizer
Adam is a variant of stochastic gradient descent that combines momentum with adaptive learning rates, its full name being adaptive moment estimation. It simultaneously maintains exponential moving averages of the first and second moments of the gradient and scales the step size individually for each parameter; since its proposal around 2014 it has long been the default optimizer for large-model training, and it is also a node that any understanding of modern training recipes cannot bypass.
Core Principles
Adam maintains two state variables for each parameter: the first moment, the exponential moving average of the gradient, equivalent to momentum; and the second moment, the exponential moving average of the squared gradient, used to estimate the fluctuation scale of the gradient. The update divides the first moment by the square root of the second moment to obtain a per-parameter normalized step size, which is then multiplied by the learning rate.
Because both moving averages are initialized to zero early in training, they produce a bias toward zero. Adam introduces bias correction, dividing the first moment by "one minus the decay coefficient raised to the power of the step count", and the second moment likewise, making early estimates unbiased. This detail is the key to Adam working stably within the first few dozen steps; without it, early updates would be abnormally small.
Adam's intuitive advantage is insensitivity to the scale of the gradient: sparse features also get reasonable step sizes, and the default hyperparameters (first-moment decay 0.9, second-moment decay 0.999, learning rate 0.001, epsilon 1e-8) are directly usable on a wide range of tasks. But its harm to generalization has long been debated: adaptive scaling amplifies or shrinks the weight decay term along with everything else, causing regularization to fail.
AdamW fixes this by taking weight decay out of the gradient and multiplying it directly onto the parameters as decoupled decay, paired with a higher decay coefficient after decoupling. This has become standard for Transformers and diffusion models. In addition, when memory is tight one can use sharded or low-precision state implementations such as ZeRO and 8-bit Adam, which significantly reduce memory usage.
Coordination with Batch Size and Numerical Precision
The magnitude of Adam's updates relates to the level of gradient noise: small batches are noisier, and after second-moment normalization a single step can still be large, so small-batch training often needs a smaller learning rate plus gradient clipping. As the batch grows, gradient noise falls, allowing a linear increase of the learning rate and longer warmup to keep a similar shape of the training curve. Another easily overlooked point is the precision of optimizer state: storing the first and second moments in low precision brings accumulated error, and in practice a compromise of high-precision master weights with sharded or half-precision state is common, skipping the step and rolling back the state when loss becomes infinite. When combined with a learning rate schedule, the decay curve should be defined by steps rather than epochs, otherwise changes in batch size cause the actual decay rhythm to drift.
Key Points
Bias correction: both the first and second moments must be divided by one minus the decay coefficient raised to the power of the step count; it cannot be omitted.
Role of epsilon: prevents division by zero; too large makes updates too soft, too small makes them easily disturbed by noise.
Weight decay: prefer the decoupled form of AdamW, with a decay coefficient typically between 0.01 and 0.1.
Memory overhead: each parameter additionally stores the first and second moments, about three times the memory, which can be eased by sharding or quantization.
Trade-off with stochastic gradient descent: for generalization, try SGD with momentum; for training speed and stability, choose AdamW.
Common Misconceptions
Many conflate Adam and AdamW, thinking it is just a name change, when in fact their regularization behavior differs greatly. Some mistakenly believe that since Adam includes bias correction it needs no learning rate schedule, while large models still need warmup and decay. Others stack a very large weight decay on Adam without realizing it gets distorted by adaptive scaling.
Application Scenarios
Language model pretraining and fine-tuning, Transformer variants, diffusion models, sparse embeddings in recommender systems, generative adversarial networks, value networks in reinforcement learning, and quantized implementations under tight memory.