← Back to Deep Learning Mind Map
🧠 Deep LearningID: weight-decay

Weight Decay & AdamW

权重衰减与 AdamW
🎯Core Definition
L2 regularization adds λ2∥θ∥22\frac{\lambda}{2}\Vert\theta\Vert_2^2 to the loss, turning the update into θ←θ−η(∇L+λθ)\theta \leftarrow \theta - \eta(\nabla L + \lambda\theta); under plain SGD this is exactly equivalent to weight decay θ←(1−ηλ)θ−η∇L\theta \leftarrow (1-\eta\lambda)\theta - \eta\nabla L. With Adam, however, the gradient term is normalized by v^+ϵ\sqrt{\hat{v}} + \epsilon, which divides λθ\lambda\theta by the same factor, so the effective decay varies wildly with gradient magnitude — L2 and weight decay are no longer equivalent. AdamW decouples them by applying weight decay directly to the parameters: θ←θ−ηλθ−ηm^v^+ϵ\theta \leftarrow \theta - \eta\lambda\theta - \eta\frac{\hat{m}}{\sqrt{\hat{v}}+\epsilon}.
💡Use Cases
the standard generalization tool for deep networks under Adam/AdamW training, especially LLM pretraining and finetuning; interviews ask for the SGD equivalence derivation, why it breaks under Adam, and AdamW's improvement.
⚡Key Problems Solved
constrains the parameter norm to prevent overfitting. AdamW (Loshchilov & Hutter 2019) fixes the mis-scaled weight decay under Adam: the decay coefficient is constant and independent of gradient magnitude, improving generalization (the paper reports roughly 2% lower test error) and robustness to learning-rate / weight-decay hyperparameters; LLM pretraining (e.g. LLaMA) standardly uses AdamW with weight decay around 0.01–0.1 (an order of magnitude above naive L2's 5e-4).
🎯Core Interview Exam Points
Fundamentals · Production Scenarios · Deep Dive
Core Def
Explain the core definition, underlying mechanism/math, and key principles of Weight Decay & AdamW.
Use Cases
In production engineering, what are the primary use cases for Weight Decay & AdamW and what core pain points does it solve?
🔥 High-Frequency Deep-Dive Questions
1
Derive the equivalence of L2 regularization and weight decay under plain SGD: write both updates θ←θ−η(∇L+λθ)\theta \leftarrow \theta - \eta(\nabla L+\lambda\theta) and θ←(1−ηλ)θ−η∇L\theta \leftarrow (1-\eta\lambda)\theta - \eta\nabla L and state the equivalence condition.
2
Why are L2 and weight decay inequivalent under Adam? What happens when λθ\lambda\theta is divided by v^+ϵ\sqrt{\hat{v}}+\epsilon?
3
Write the decoupled AdamW update θ←θ−ηλθ−ηm^v^+ϵ\theta \leftarrow \theta - \eta\lambda\theta - \eta\frac{\hat{m}}{\sqrt{\hat{v}}+\epsilon} and explain why it generalizes better than Adam + L2.
4
Hyperparameter scale: what is typical for AdamW weight decay (0.01–0.1)? How does it relate to L2's common 5e-4?
5
Does weight decay drive weights all the way to zero? Why does it mostly constrain the norm rather than zero out parameters?
Updated 2026-08-12
🎯
Verify Mastery: Practice Exam Questions for "Weight Decay & AdamW"
Take pitfall multiple-choice questions with derivation options; mistakes are automatically logged.
🚀 Start Card Practice ➔
← Previous CardLabel SmoothingNext Card →Convolution Basics

🔗 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/weight-decay
中文速览与面试要点

权重衰减与 AdamW (Weight Decay & AdamW)

定义: L2 正则化在损失中加入 2 _2^2, 更新变为 - ( L + ); 对朴素 SGD, 它与权重衰减 (1- ) - L 完全等价。但 Adam 中梯度项会被 v + 归一化, 使 也被除以该因子, 有效衰减随梯度大小剧烈变化——L2 与权重衰减不再等价。AdamW 把权重衰减直接作用到参数上实现解耦: - - m v+ 。 使用场景: 所有深度网络的泛化手段, Adam/AdamW 训练 (尤其大模型预训练/微调) 的标准配置; 面试常问 L2 与 weight decay 在 SGD 下的等价推导、Adam 下为什么不等价、AdamW 的改进。 解决的问题: 约束参数范数、防止过拟合。AdamW (Loshchilov & Hutter 2019) 修复了 Adam 中权重衰减被自适应学习率错误缩放的问题: 衰减系数固定且与梯度大小无关, 提升泛化 (论文报告 test 错误率下降约 2% 量级), 对学习率与 weight decay 超参更稳健; LLM 预训练 (如 LLaMA) 标准用 AdamW, weight decay 典型取 0.01~0.1 (比朴素 L2 的 5e-4 大一个量级)。

核心要点

  • 推导 L2 正则化与 weight decay 在朴素 SGD 下的等价性: 写出 - ( L + ) 与 (1- ) - L 并说明等价条件?
  • 为什么 Adam 下 L2 与 weight decay 不等价? 项被 v+ 除会造成什么后果?
  • 写出 AdamW 的解耦更新公式 - - m v+ 并解释为什么能提升泛化 (相对 Adam+L2)?
  • weight decay 的超参量级: AdamW 下典型取多少 (0.01~0.1)? 与 L2 常用的 5e-4 是什么关系?
  • weight decay 会把权重衰减到 0 吗? 为什么它主要约束范数而非清零参数?