AdamW 分離型重み減衰の数学的導出
Agent支援工学分析
前提条件
第31-33日の勾配降下法とモメンタム;L2正則化の概念。
学習目標
AdamWの更新式 w_{t+1} = w_t (1 - eta * lambda) - eta * m_hat_t / (sqrt(v_hat_t) + eps) を導出し、従来のAdamにおけるL2正則化の歪み原因を解明する。
手順
標準的なAdamにL2正則化を適用すると、勾配に lambda * w が加算される。適応的な2次モーメント sqrt(v_t) による除算により、過去の勾配が大きい重みは減衰が抑制され、勾配が小さい重みは過剰に減衰される。Loshchilov & Hutter (2019) は重み減衰を勾配スケーリングから分離するAdamWを提案した。w_0 = 1.0, lambda = 0.1, eta = 0.01, g_1 = 0.5, beta_1 = 0.9, beta_2 = 0.999, eps = 1e-8 における第1ステップの更新を手計算せよ。
演習と予測記録
1. L2正則化付きAdamとAdamWの更新式の差異を示せ。
2. 第1ステップにおける m_hat_1, v_hat_1 および更新後の重み w_1 を手計算せよ。
3. 分離型重み減衰がTransformerの汎化性能を著しく向上させる理由は何か?
m_1 = (1 - 0.9) * 0.5 = 0.05 => m_hat_1 = 0.5。v_1 = (1 - 0.999) * 0.25 = 0.00025 => v_hat_1 = 0.25。sqrt(v_hat_1) = 0.5。
1. 従来のAdamは勾配を g + lambda * w に変更する。AdamWは w_{t+1} = w_t * (1 - eta * lambda) - eta * m_hat_t / (sqrt(v_hat_t) + eps) と直接減衰させる。
2. 手計算:
- m_hat_1 = 0.5, v_hat_1 = 0.25, sqrt(v_hat_1) = 0.5
- 減衰項:1.0 * (1 - 0.01 * 0.1) = 0.9990
- 勾配更新項:0.01 * (0.5 / 0.5) = 0.0100
- 更新結果:w_1 = 0.9990 - 0.0100 = 0.9890。
3. AdamWは勾配の大きさに依存せずすべての重みに一定比率の減衰を適用するため、頻繁に更新される埋め込みや射影重みの発散を防ぎ、健全なノルムを保つ。
両更新式を導出し、第1ステップの数値計算を手計算で検証できること。
公式ソースリソースと権利証跡
Decoupled Weight Decay Regularization
該当セクション・タイムスタンプ: Section 2 Decoupling the Weight Decay from the Gradient-Based Update (Algorithm 2, AdamW)
検証バージョンと日付: ICLR 2019 / arXiv:1711.05101v3 (Verified: 2026-10-30)
Foundational primary literature defining AdamW, demonstrating that L2 regularization does not equal decoupled weight decay in adaptive gradient algorithms.
Stochastic gradient descent, L2 regularization, and momentum concepts from Days 31-33.
All update equations and mathematical proofs are self-contained in the curriculum lessons.
比較対象候補リソースと選定評価 (2)
Original Adam algorithm implementing L2 regularization via gradient addition, leading to sub-optimal generalization compared to decoupled weight decay.
Standard library reference; Loshchilov & Hutter provides theoretical mathematical derivations and empirical justification.
nanoGPT: train.py pretraining loop
該当セクション・タイムスタンプ: train.py: optimizer = model.configure_optimizers(weight_decay, learning_rate, (beta1, beta2), device_type)
検証バージョンと日付: Git master commit 71c3905 (Verified: 2026-10-30)
Compact historical code reference for the named implementation functions; CS336 spring2025 provides the lead component exercises. Do not infer top-p, atomic persistence or cloud budget enforcement from nanoGPT.
Python, PyTorch, and Day 46-48 Transformer model architecture.
Runnable pretraining scripts and step-by-step tensor mechanics are fully self-contained in the curriculum lessons.
比較対象候補リソースと選定評価 (2)
Heavy abstraction layer wrapping distributed training; nanoGPT exposes raw PyTorch loops without framework overhead.
High-performance enterprise distributed framework; unsuitable for local educational first-principles comprehension.