← Back to Deep Learning Mind Map
🧠 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=β1mt−1+(1−β1)gtm_t = \beta_1 m_{t-1} + (1-\beta_1)g_t, vt=β2vt−1+(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, ϵ=10−8\epsilon = 10^{-8}, base LR η=10−3\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^t≈0\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.
🎯Core Interview Exam Points
Fundamentals · Production Scenarios · Deep Dive
Core Def
Explain the core definition, underlying mechanism/math, and key principles of Adam & AdamW.
Use Cases
In production engineering, what are the primary use cases for Adam & AdamW and what core pain points does it solve?
🔥 High-Frequency Deep-Dive Questions
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, ϵ=10−8\epsilon = 10^{-8}, η=10−3\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
🎯
Verify Mastery: Practice Exam Questions for "Adam & AdamW"
Take pitfall multiple-choice questions with derivation options; mistakes are automatically logged.
🚀 Start Card Practice ➔
← Previous CardSGD & MomentumNext Card →Learning Rate Scheduling

🔗 More Deep Learning Knowledge Cards

引用出处: TalentMe 450+ 工业级 AI 架构考点知识库 (Tech Vault) · 遵循 CC-BY-4.0 知识共享协议
URL: https://talentme.airsota.com/resources/tech/roadmap/mindmap/DL/card/adam-optimizer
中文速览与面试要点

Adam/AdamW (Adam & AdamW)

定义: Adam(Adaptive Moment Estimation)对梯度维护一阶矩 m_t 与二阶矩(未中心化方差)v_t 的指数移动平均,并做偏差修正: m_t = _1 m_t-1 + (1- _1)g_t,v_t = _2 v_t-1 + (1- _2)g_t^2;偏差修正 m_t = m_t1- _1^t, v_t = v_t1- _2^t(由几何级数可证 E[m_t] = (1- _1^t) E[g],t 小时矩被系统性低估,除以 1- _1^t 修正);参数更新 _t+1 = _t - m_t v_t + 。默认超参 _1 = 0.9、 _2 = 0.999、 = 10^-8、基准学习率 = 10^-3。比值 m_t/ v_t 量级约 1,相当于按梯度 RMS 逐参数归一化: 大梯度方向自动缩小步长、小梯度方向自动放大步长,对稀疏梯度与病态条件数( 大)鲁棒。 必须放分母: 一是数值稳定、防止 v_t 0 时除以零(训练早期),二是给步长设上界 / 。AdamW 把权重衰减从 L2 中解耦: _t+1 = _t - ( _t + m_t v_t+ ),每参数每步衰减率恒为 1 - 。 使用场景: Transformer/BERT/GPT 等大模型训练的默认优化器,大批量、稀疏特征、多模态场景首选;面试必考“默写 Adam 四个公式”“为什么需要偏差修正”“β 默认值”“AdamW vs Adam+L2”。 解决的问题: SGD+动量对所有参数共享一个学习率,病态曲率或稀疏梯度下步长难以兼顾;Adam 逐参数自适应缩放,且偏差修正保证早期迭代不被低估的矩拖慢。AdamW 修正 Adam+L2 的缺陷: L2 项 w_t 进入 g_t 后被 v_t 缩放,有效衰减 w_t/ v_t 随历史梯度幅度变化——大梯度方向被正则得太多、小梯度方向被正则得太少;解耦后每个参数获得恒定的衰减率,训练更稳、泛化更好。

核心要点

  • 默写 Adam 四个公式(矩估计、偏差修正、参数更新),并指出默认 _1 = 0.9、 _2 = 0.999、 = 10^-8、 = 10^-3。
  • 为什么需要偏差修正?用等比数列求和证明 E[m_t] = (1- _1^t) E[g],说明 t=1 时偏差最严重(1- _1 = 0.1),为什么除以 1- _1^t 后 E[ m_t] = E[g]。
  • 为什么更新用 m_t/ v_t?与 RMSProp/AdaGrad 的关系;为什么 必须放在分母(数值稳定 + 步长上界 / )。
  • Adam vs SGD+动量: 各自的适用场景与泛化差异(为什么 CV 上 SGD 常更好、而大模型标配 Adam);Adam 早期收敛快但后期可能不稳的原因。
  • 写出 AdamW 更新式并对比 Adam+L2: L2 项被 v_t 缩放如何扭曲有效正则强度?解耦 weight decay 后每步衰减率为何恒为 1 - ?