The industry-standard optimization algorithm used to train neural networks, which dynamically adapts the learning rate for every individual parameter based on the history of its gradients.
A smart learning algorithm for AI. Instead of updating all parts of the AI’s “brain” at the same speed, Adam looks at how much each specific part contributed to the last mistake and adjusts its learning speed individually. AdamW is a slightly improved version that prevents the AI from becoming overly complex.
Adam combines the benefits of two other extensions of stochastic gradient descent: AdaGrad (which works well with sparse gradients) and RMSProp (which works well in online and non-stationary settings). It computes individual adaptive learning rates for different parameters from estimates of first and second moments of the gradients. AdamW (Adam with Weight Decay) decouples weight decay from the gradient update, which has been proven to yield better generalization and training stability, especially for Transformers.
Navigating a rocky downhill path. A standard optimizer takes the same size step with both feet. Adam is like an experienced hiker who takes small, careful steps on steep, unstable rocks (high gradient variance) and large, confident strides on flat, smooth ground (low gradient variance).
# Conceptual: Using AdamW in PyTorch
import torch
import torch.nn as nn
model = nn.Linear(10, 1)
# AdamW is the standard for training Transformers and modern LLMs
optimizer = torch.optim.AdamW(model.parameters(), lr=3e-4, weight_decay=0.01)
# In a training loop:
# loss.backward()
# optimizer.step() # Updates weights using adaptive, per-parameter learning rates