Back to Deep Learning Mind Map
中文·English
🧠 Deep LearningID: adam-optimizer

Adam & AdamW

Adam/AdamW
🎯Core Definition
Adam (adaptive moment estimation) maintains exponential moving averages of the first moment mtm_t and the second moment (uncentered variance) vtv_t of the gradient, with bias correction: mt=β1mt1+(1β1)gtm_t = \beta_1 m_{t-1} + (1-\beta_1)g_t, vt=β2vt1+(1β2)gt2v_t = \beta_2 v_{t-1} + (1-\beta_2)g_t^2; bias correction m^t=mt1β1t\hat{m}_t = \frac{m_t}{1-\beta_1^t}, v^t=vt1β2t\hat{v}_t = \frac{v_t}{1-\beta_2^t} (the geometric series gives E[mt]=(1β1t)E[g]\mathbb{E}[m_t] = (1-\beta_1^t)\mathbb{E}[g]; for small tt the moments are systematically underestimated, and dividing by 1β1t1-\beta_1^t fixes this); parameter update θt+1=θtηm^tv^t+ϵ\theta_{t+1} = \theta_t - \eta\frac{\hat{m}_t}{\sqrt{\hat{v}_t} + \epsilon}. Defaults: β1=0.9\beta_1 = 0.9, β2=0.999\beta_2 = 0.999, ϵ=108\epsilon = 10^{-8}, base LR η=103\eta = 10^{-3}. The ratio m^t/v^t\hat{m}_t/\sqrt{\hat{v}_t} has magnitude ~1, i.e. per-parameter normalization by gradient RMS: large-gradient directions are scaled down, small ones up, making Adam robust to sparse gradients and ill-conditioning (large κ\kappa). ϵ\epsilon belongs in the denominator: numerical stability (avoid division by zero when v^t0\hat{v}_t \approx 0 early in training) and an implicit step bound η/ϵ\eta/\sqrt{\epsilon}. AdamW decouples weight decay from L2: θt+1=θtη(λθt+m^tv^t+ϵ)\theta_{t+1} = \theta_t - \eta\left(\lambda\theta_t + \frac{\hat{m}_t}{\sqrt{\hat{v}_t}+\epsilon}\right), giving every parameter a constant per-step decay factor 1ηλ1 - \eta\lambda.
💡Use Cases
the default optimizer for Transformers, BERT/GPT and other large models; the first choice for large batches, sparse features and multimodal workloads; interviews always ask to write the four formulas, explain bias correction, quote the default β\betas, and contrast AdamW with Adam+L2.
Key Problems Solved
SGD+momentum shares one learning rate across all parameters, which cannot fit ill-conditioned or sparse gradients; Adam adaptively scales the per-parameter step and bias correction prevents early iterations from being slowed by underestimated moments. AdamW fixes Adam+L2: the L2 term λwt\lambda w_t enters gtg_t and is rescaled by v^t\sqrt{\hat{v}_t}, so the effective decay ηλwt/v^t\eta\lambda w_t/\sqrt{\hat{v}_t} varies with gradient magnitude — large-gradient directions are regularized too much, small ones too little; decoupling yields a constant decay rate per parameter, training more stably and generalizing better.
🎯5 High-Frequency Exam Points
1
Write Adam's four formulas (moment recursions, bias correction, parameter update) and quote the defaults β1=0.9\beta_1 = 0.9, β2=0.999\beta_2 = 0.999, ϵ=108\epsilon = 10^{-8}, η=103\eta = 10^{-3}.
2
Why is bias correction needed? Sum the geometric series to prove E[mt]=(1β1t)E[g]\mathbb{E}[m_t] = (1-\beta_1^t)\mathbb{E}[g], explain why the bias is worst at t=1t=1 (1β1=0.11-\beta_1 = 0.1), and why dividing by 1β1t1-\beta_1^t gives E[m^t]=E[g]\mathbb{E}[\hat{m}_t] = \mathbb{E}[g].
3
Why update by m^t/v^t\hat{m}_t/\sqrt{\hat{v}_t}? Relation to RMSProp/AdaGrad; why must ϵ\epsilon sit in the denominator (numerical stability + step bound η/ϵ\eta/\sqrt{\epsilon})?
4
Adam vs SGD+momentum: use cases and generalization differences (why SGD often wins on CV while large models standardize on Adam); why Adam converges fast early but can be unstable later.
5
Write the AdamW update and compare with Adam+L2: how does dividing the L2 term by v^t\sqrt{\hat{v}_t} distort the effective regularization? Why does decoupling give a constant per-step decay 1ηλ1 - \eta\lambda?
Updated 2026-08-12
🎯
Test Your Knowledge: Practice Questions for "Adam & AdamW"
Single choice pitfall questions with instant feedback and mistake tracking.
🚀 Start Card Practice
Previous CardSGD & MomentumNext CardLearning Rate Scheduling

🔗 More Deep Learning Knowledge Cards

Activation FunctionsAutograd Compute GraphBatch NormalizationClassic CNN Architectures