Back to AI Math Mind Map
中文·English
📐 AI MathID: adamw-math

Adam/AdamW Math

Adam/AdamW 偏差修正推导
🎯Core Definition
Adam = exponential moving averages of the first moment mtm_t and second moment vtv_t, plus bias correction. With gradient gtg_t: 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. Expanding mtm_t as a geometric series: mt=(1β1)i=1tβ1tigim_t = (1-\beta_1)\sum_{i=1}^{t}\beta_1^{t-i}g_i, so older gradients get weight β1ti\beta_1^{t-i}, decaying exponentially. Bias derivation: assuming stationary gradients E[gi]=E[g]\mathbb{E}[g_i] = \mathbb{E}[g], we get E[mt]=(1β1)E[g]k=0t1β1k=(1β1)E[g]1β1t1β1=(1β1t)E[g]\mathbb{E}[m_t] = (1-\beta_1)\mathbb{E}[g]\sum_{k=0}^{t-1}\beta_1^k = (1-\beta_1)\mathbb{E}[g]\cdot\frac{1-\beta_1^t}{1-\beta_1} = (1-\beta_1^t)\mathbb{E}[g]. For small tt this factor is far below 1 (at t=1t=1 it is 1β1=0.11-\beta_1 = 0.1), so early moments are systematically underestimated; dividing by 1β1t1-\beta_1^t gives m^t=mt1β1t\hat m_t = \frac{m_t}{1-\beta_1^t} and v^t=vt1β2t\hat v_t = \frac{v_t}{1-\beta_2^t} (since E[vt]=(1β2t)E[g2]\mathbb{E}[v_t] = (1-\beta_2^t)\mathbb{E}[g^2]), so E[m^t]=E[g]\mathbb{E}[\hat m_t] = \mathbb{E}[g]. Full update: wt+1=wtηm^tv^t+ϵw_{t+1} = w_t - \eta\frac{\hat m_t}{\sqrt{\hat v_t} + \epsilon}.
💡Use Cases
the default optimizer for Transformers, diffusion models and other large-batch / sparse-gradient workloads; interviews frequently ask why bias correction is needed and how AdamW differs from Adam with L2.
Key Problems Solved
vs SGD+momentum, Adam adaptively scales the per-parameter step by m^t/v^t\hat m_t/\sqrt{\hat v_t} (scale ~1), which is robust to ill-conditioning (κ\kappa large) and sparse gradients, while bias correction prevents slow early steps from underestimated moments. AdamW decouples weight decay from L2: in Adam+L2 the term λwt\lambda w_t enters gtg_t and gets 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 historical gradient magnitude — large-gradient directions are regularized too much, small ones too little; AdamW applies wt+1=wtη(λwt+m^tv^t+ϵ)w_{t+1} = w_t - \eta\left(\lambda w_t + \frac{\hat m_t}{\sqrt{\hat v_t}+\epsilon}\right), giving every parameter a constant per-step decay factor 1ηλ1 - \eta\lambda, which trains more stably and generalizes better.
🎯5 High-Frequency Exam Points
1
Write Adam's moment recursions, expand mt=(1β1)i=1tβ1tigim_t = (1-\beta_1)\sum_{i=1}^{t}\beta_1^{t-i}g_i and explain how historical weights decay.
2
Prove the bias: sum the geometric series to show E[mt]=(1β1t)E[g]\mathbb{E}[m_t] = (1-\beta_1^t)\mathbb{E}[g] and explain why the bias is worst at t=1t=1 (1β1=0.11-\beta_1 = 0.1).
3
Why divide by 1β1t1-\beta_1^t? Prove E[m^t]=E[g]\mathbb{E}[\hat m_t] = \mathbb{E}[g] after correction; why must the second moment v^t\hat v_t be corrected and square-rooted?
4
Compare Adam+L2 vs AdamW: how does dividing λwt\lambda w_t by v^t\sqrt{\hat v_t} distort the effective regularization, and what does decoupling fix?
5
Write the full update wt+1=wtηm^tv^t+ϵw_{t+1} = w_t - \eta\frac{\hat m_t}{\sqrt{\hat v_t}+\epsilon}; why does ϵ\epsilon belong in the denominator rather than the numerator?
Updated 2026-08-12
🎯
Test Your Knowledge: Practice Questions for "Adam/AdamW Math"
Single choice pitfall questions with instant feedback and mistake tracking.
🚀 Start Card Practice
Previous CardMatrix Calculus & Softmax GradientNext CardConvex Optimization & KKT

🔗 More AI Math Knowledge Cards

Bayesian InferenceBias-Variance DecompositionBootstrapCausal Inference (Rubin)