Optimizers: Adam, AdamW, LION & Beyond
The mathematics of neural network optimization: Adam's moment estimation, weight decay vs L2 regularization, LION's sign-based updates, Sophia's second-order information, learning rate scheduling, and optimizer selection.
Prerequisites
Table of Contents
- Learning Objectives
- Notation
- Core Intuition
- SGD with Momentum
- Adam: Adaptive Moments
- AdamW: Decoupled Weight Decay
- LION: Sign-Based Optimization
- Sophia: Second-Order Information
- Learning Rate Scheduling
- Optimizer Selection Guide
- Common Pitfalls
- Summary
- Exercises
Learning Objectives
- Derive Adam from first principles (moment estimation + bias correction).
- Explain why AdamW differs from Adam + L2 and when it matters.
- Describe LION's memory-efficient sign updates.
- Analyze Sophia's diagonal Hessian approximation.
- Design learning rate schedules for different training phases.
Notation
- — first moment (gradient mean)
- — second moment (gradient variance)
- — decay rates for moments
Core Intuition
SGD takes the same step size in every direction — inefficient when gradients vary wildly across parameters (common in deep networks). Adam adapts the step size per parameter based on gradient history: parameters with consistently large gradients get smaller steps (already optimized); parameters with small, noisy gradients get larger steps (need more exploration). This makes training much faster and more stable.
Interactive: Learning Rate Schedules
Schedules:
SGD with Momentum
Vanilla SGD: .
With momentum:
Effect: Accelerates in consistent gradient directions; dampens oscillations in inconsistent directions.
Nesterov momentum: Look ahead before computing gradient:
Adam: Adaptive Moments
Kingma & Ba (2015):
Bias correction:
Update:
Interpretation: Step size is . Parameters with large gradient variance get smaller steps (cautious). Parameters with small variance get larger steps (confident).
Standard hyperparameters: .
Memory: 2x model size (stores and ).
AdamW: Decoupled Weight Decay
Loshchilov & Hutter (2019): L2 regularization in Adam is NOT the same as weight decay:
Adam + L2 (wrong):
The term gets divided by — different parameters decay at different rates.
AdamW (correct):
Weight decay is applied DIRECTLY to parameters, not through the adaptive mechanism.
Why it matters: AdamW gives consistent regularization across parameters. Empirically better for transformers (0.5-1% improvement over Adam + L2).
Standard : 0.01-0.1 for transformers.
LION: Sign-Based Optimization
Chen et al. (2023, Google Brain): Uses only the SIGN of the gradient:
Key properties:
- Memory efficient: Only stores (1x model size vs 2x for Adam).
- Uniform update magnitude: Every parameter changes by exactly per step.
- Better on large models: Matches or exceeds AdamW on ViT and LLMs.
When to use: Large models where memory is constrained; works especially well for vision transformers and LLMs above 7B.
Sophia: Second-Order Information
Liu et al. (2023): Use diagonal Hessian to adapt step size:
where is the diagonal Hessian estimate (curvature).
Hessian estimation (Hutchinson): computed cheaply via one extra backward pass per steps.
Advantage: In high-curvature directions (sharp minima), takes smaller steps. In flat directions, takes larger steps. More informed than Adam's variance-based adaptation.
2x speedup over AdamW in wall-clock time for reaching the same loss (fewer steps needed due to better step sizes).
Learning Rate Scheduling
Warmup + cosine decay (standard for transformers):
WSD (Warmup-Stable-Decay): Warmup → constant → cooldown:
- Warmup: 1-5% of training.
- Stable: 80-90% at peak LR.
- Decay: 10-15% cosine to .
- Advantage: Can resume training from the stable phase without schedule mismatch.
Typical values:
- Peak LR: for pre-training; for fine-tuning.
- Warmup: 2000 steps (pre-training); 100 steps (fine-tuning).
- : 0.1 × .
Optimizer Selection Guide
| Scenario | Recommended | Reason |
|---|---|---|
| LLM pre-training | AdamW or LION | Proven at scale |
| LLM fine-tuning | AdamW | Stable, well-understood |
| Vision Transformer | LION or AdamW | LION saves memory |
| CNN (ResNet) | SGD + momentum | Still competitive |
| Memory-constrained | LION (1x state) | 33% memory savings |
| Maximum speed | Sophia | 2x fewer steps |
Common Pitfalls
Pitfall 1. Using Adam without weight decay for transformers. Without weight decay, transformers overfit significantly. Always use AdamW with -.
Pitfall 2. Skipping warmup. Without warmup, initial large gradients (random initialization) cause Adam's second moment to miscalibrate, leading to unstable early training.
Pitfall 3. Using the same learning rate for all model sizes. Optimal LR decreases with model size: approximately. A 70B model needs lower LR than a 7B model.
Summary
- Adam: Adaptive per-parameter LR via gradient moments; standard choice.
- AdamW: Decoupled weight decay (correct regularization for transformers).
- LION: Sign-based; 33% less memory; competitive quality.
- Sophia: Diagonal Hessian; 2x fewer steps; more compute per step.
- LR schedule: Warmup + cosine/WSD is the universal recipe.
- Optimizer choice matters most at scale (pre-training). Less impact at fine-tuning.
Exercises
Exercise 1. Derive Adam's bias correction (equation 4) from the assumption that .
Exercise 2. For a parameter with gradient history : compute Adam vs SGD updates and explain why Adam is more conservative on the outlier step.
Exercise 3. Compute the memory savings of LION vs AdamW for a 70B model in BF16.
Exercise 4. Design a WSD learning rate schedule for a 2T-token pre-training run. Specify warmup, stable, and decay durations and LR values.
Exercise 5. Explain why SGD still outperforms Adam for ResNets on ImageNet (hint: implicit regularization of large-batch SGD).