Adaptive Optimizers in Large Language Model Pre-Training: How AdamW, Adafactor, and Lion Scale Gradient Updates Across Billions of Parameters
Large language model pre-training requires optimizing billions of parameters over trillions of tokens across distributed GPU clusters. Standard stochastic gradient descent (SGD) fails in this regime because Transformer loss landscapes are severely ill-conditioned, with gradient magnitudes differing by orders of magnitude across layers and token positions.
To train deep autoregressive models stably, modern deep learning relies on adaptive optimizers that scale update steps coordinate-by-coordinate using running gradient statistics. However, tracking historical moments introduces a steep memory and compute tax. Across large model architectures, optimizer states often consume more High Bandwidth Memory (HBM) than the model weights themselves.
Understanding how optimizers balance convergence speed, numerical stability, and memory overhead is central to scaling modern foundation models.

The Ill-Conditioned Landscape of Transformer Gradients
Stochastic gradient descent updates parameters along the negative gradient vector:
SGD assumes that a single global learning rate is appropriate for all dimensions in parameter space. In multi-layer Transformer architectures, this assumption breaks down due to three structural factors:
- Extreme Curvature Anisotropy: The loss landscape exhibits an ill-conditioned Hessian matrix , where the condition number (the ratio of the largest to smallest eigenvalue, ) frequently exceeds . Updates with a fixed learning rate oscillate along high-curvature ravines while making negligible progress along flat directions.
- Sparse vs. Dense Activation Dynamics: Embedding layers and unembedding projection heads receive sparse updates because only tokens present in a given batch generate non-zero gradients. In contrast, self-attention projection weights (Query, Key, Value, Output) and feed-forward gating layers receive dense activations on every token pass.
- Heavy-Tailed Gradient Distributions: Gradients in deep attention layers frequently experience sudden magnitude spikes caused by softmax score concentrations and layer normalization interactions.
Coordinate-wise adaptive optimizers solve this by tracking past gradient history per parameter, effectively approximating a diagonal pre-conditioner that normalizes the step size across every dimension.
The Anatomy of Adam and the Weight Decay Fix
The foundation of modern LLM optimization is Adam (Adaptive Moment Estimation), introduced by Diederik Kingma and Jimmy Ba in 2014 (Kingma & Ba, 2014). Adam tracks two moving averages for every parameter:
- First Moment (): The exponentially smoothed mean of past gradients (momentum), which dampens high-frequency oscillations.
- Second Raw Moment (): The exponentially smoothed uncentered variance of past gradients, which estimates the squared scale of each coordinate.
Because and are initialized to zero vectors, they are biased toward zero in the initial training steps. Adam corrects this using step-dependent bias correction factors:
The parameter update is then computed coordinate-wise:
Here, (typically to ) prevents division by zero, and are decay coefficients (conventionally set to and or ).
Standard Adam vs. Decoupled AdamW Parameter Updates
[Adam with L2 Regularization]
g_t' = g_t + λ * w_t
v_t = β2 * v_{t-1} + (1 - β2) * (g_t')^2
w_{t+1} = w_t - η * m_t / (sqrt(v_t) + ε)
(Problem: Parameters with large gradient scale receive LESS weight decay)
[AdamW with Decoupled Weight Decay]
v_t = β2 * v_{t-1} + (1 - β2) * (g_t)^2
w_{t+1} = w_t - η * λ * w_t - η * m_t / (sqrt(v_t) + ε)
(Result: Uniform weight shrinkage rate η*λ across all coordinates)Why L2 Regularization Broke Adam
In standard SGD, adding an penalty to the loss function is mathematically identical to weight decay:
In adaptive gradient methods, this equivalence fails. When regularization is incorporated by modifying the gradient input (), the regularization term is divided by :
As demonstrated by Ilya Loshchilov and Frank Hutter in 2017 (Loshchilov & Hutter, 2017), this causes severe distortions:
- Parameters with frequent, large gradients (high ) experience suppressed weight decay because the penalty is scaled down by .
- Parameters with small or sparse gradients (low ) experience disproportionately large weight decay penalties.
The AdamW Formulation
AdamW resolves this distortion by decoupling weight decay from the gradient update step. The decay is applied directly to the parameter vector before or after the adaptive step:
Decoupled weight decay ensures that every parameter shrinks at a uniform rate proportional to , regardless of gradient variance. This separation restored the generalization performance of adaptive methods to match or exceed tuned SGD on complex benchmarks, establishing AdamW as the industry standard for LLM pre-training.
The Memory Tax of Optimizer States
In 16-bit mixed-precision pre-training (using BF16 or FP16 for forward and backward passes), model parameters and gradients each consume 2 bytes per parameter.
However, accumulating gradient moments directly in 16-bit formats leads to severe underflow, gradient stall, and numerical divergence. Consequently, standard implementations maintain optimizer states in full 32-bit floating point (FP32):
| Component | Precision | Bytes per Parameter | | :--- | :--- | :--- | | Model Weights | BF16 / FP16 | 2 bytes | | Gradients | BF16 / FP16 | 2 bytes | | Master Weights (FP32 copy) | FP32 | 4 bytes | | First Moment Buffer () | FP32 | 4 bytes | | Second Moment Buffer () | FP32 | 4 bytes | | Total Memory per Parameter | - | 16 bytes |
Memory Allocation per Parameter in Standard Mixed-Precision Training (16 Bytes Total)
┌──────────────┬──────────────┬─────────────────────────────┬─────────────────────────────┬─────────────────────────────┐
│ Weights │ Gradients │ Master Weights (FP32) │ First Moment m_t (FP32) │ Second Moment v_t (FP32) │
│ (BF16) │ (BF16) │ │ │ │
│ 2 Bytes │ 2 Bytes │ 4 Bytes │ 4 Bytes │ 4 Bytes │
└──────────────┴──────────────┴─────────────────────────────┴─────────────────────────────┴─────────────────────────────┘
└─────────────────────────────────────────────────────────────────────────────────────────┘
Optimizer State: 12 Bytes (75% of static memory)For a 70-billion-parameter model:
- Model weights: 140 GB
- Gradients: 140 GB
- Optimizer states: 840 GB (FP32 master weights + + )
- Total static memory footprint: 1.12 TB
Even when using distributed sharding techniques like ZeRO-1 or FSDP (which shard the 12 bytes of optimizer state across GPUs), optimizer state memory remains the primary constraint dictating cluster sizing and per-device batch limits.
Sublinear Memory via Factorization: Adafactor
To break the memory scaling of second-moment tracking, Noam Shazeer and Mitchell Stern introduced Adafactor at ICML 2018 (Shazeer & Stern, 2018).
Low-Rank Matrix Decomposition
In a Transformer, the majority of parameters reside in 2D weight matrices (e.g., attention projection matrices and MLP layers).
Instead of maintaining a full matrix of second moments , Adafactor decomposes into row-wise and column-wise exponential moving averages:
Here, and are all-ones vectors of dimension and . At update time, Adafactor reconstructs an estimate of the full second-moment matrix by minimizing the generalized Kullback-Leibler divergence (I-divergence):
Adafactor 2D Matrix Factorization
Full Second-Moment Matrix V (r x c) Factorized Representation
┌───────────────────────────────────┐ Row Sums R (r x 1) Column Sums C (1 x c)
│ v_11 v_12 ... v_1c │ ┌───────┐ ┌─────────────────────┐
│ v_21 v_22 ... v_2c │ => │ R_1 │ x │ C_1 C_2 ... C_c │
│ ... ... ... ... │ │ R_2 │ └─────────────────────┘
│ v_r1 v_r2 ... v_rc │ │ ... │
└───────────────────────────────────┘ │ R_r │
└───────┘
Memory: O(r * c) Memory: O(r + c)
Example: 8192 x 8192 = 67.1M floats Example: 8192 + 8192 = 16.38K floats
(268.4 MB in FP32) (65.5 KB in FP32, a 99.97% reduction)This reduces the memory requirement for the second moment from to . For an weight matrix:
- Full matrix storage (): floats (268.4 MB in FP32).
- Factorized storage (): floats (65.5 KB in FP32), representing a 99.97% reduction.
Dynamic Decay and Momentum Removal
Adafactor incorporates two additional architectural design choices:
- Non-Constant Second-Moment Decay ( Schedule): Adafactor replaces constant with a dynamic schedule:
This places higher weight on recent gradients early in training and gradually stabilizes as steps accumulate.
- Optional Momentum-Free Updates: To maximize memory savings, Adafactor can operate without maintaining a first-moment buffer (), using gradient clipping via root-mean-square (RMS) normalization:
Running momentum-free reduces optimizer state memory to less than 1 byte per parameter, enabling the training of models like T5 (Raffel et al., 2020) and PaLM (Chowdhery et al., 2022) under severe HBM constraints.
Lion: Symbolic Discovery and Uniform Step Magnitudes
In 2023, Xiangning Chen, Chen Liang, Da Huang, and collaborators at Google Brain and UCLA used symbolic program search over mathematical operations to discover Lion (evoLved Sign Momentum, Chen et al., 2023).

The Lion Algorithm
Lion discards second-moment tracking entirely and operates using only a single momentum buffer . The update rule is defined by two separate interpolation operations:
Standard default parameters are , .
Lion Update Lifecycle
Gradient g_t ──────┐
▼
Momentum m_{t-1} ──► Interpolate (β1=0.9) ──► sign(·) ──► Direction c_t ──► Update: w_{t+1} = w_t - η*c_t - η*λ*w_t
│
▼
Interpolate (β2=0.99) ──► Stored Momentum m_tKey Differences from AdamW
- Two Separate Splittings: Lion decouples the momentum used for computing the update direction (, weighted by ) from the momentum preserved in state (, updated with ). Because , Lion incorporates more of the instantaneous gradient into the directional step while maintaining a smoother history in memory.
- The Sign Operator: Unlike AdamW, which scales steps inversely with , Lion computes updates using . Consequently, every coordinate moves by exactly (prior to weight decay). This makes update magnitudes completely invariant to gradient scales across layers.
- Implicit Regularization: The binary quantization introduces stochasticity into update directions, acting as a natural regularizer that enhances generalization on out-of-distribution benchmarks.
- 50% State Memory Reduction: Because Lion only tracks (and no ), its optimizer state requires 4 bytes per parameter in FP32, compared to AdamW's 8 bytes.
Operational Constraints
Because every coordinate moves by , Lion's update norm is for a -dimensional parameter tensor, whereas AdamW's update norm is bounded by the variance ratio. To prevent destabilization:
- Lion requires a learning rate roughly to smaller than AdamW (e.g., vs. ).
- Weight decay must be set to larger to maintain equivalent regularization strength ().
- Lion benefits from larger batch sizes (e.g., tokens per batch) where sign-quantized gradient noise averages out smoothly.
Second-Order Approximations and Quantized Optimizers
Beyond standard first-order moment trackers, two additional paradigms have emerged for scaling LLM training:
Sophia: Second-Order Clipped Stochastic Optimization
First-order methods like AdamW normalize updates by gradient variance, but variance is only a coarse proxy for loss curvature. In 2023, Hong Liu, Zhiyuan Li, Percy Liang, and Tengyu Ma introduced Sophia (Liu et al., 2023).
Sophia estimates the diagonal of the Hessian matrix periodically (every steps) using Hutchinson's randomized estimator with Rademacher vectors :
Sophia then updates parameters using an exponentially smoothed Hessian estimate combined with coordinate-wise clipping:
By bounding the maximum step size by , Sophia prevents catastrophic updates in regions with near-zero or negative curvature, achieving a reported speedup over AdamW in training steps on GPT-style architectures.
8-Bit Optimizers via Block-Wise Quantization
Rather than altering optimizer mathematics, Tim Dettmers and collaborators (Dettmers et al., 2021) introduced 8-bit Adam using block-wise non-linear dynamic quantization.
8-bit Block-Wise Quantization Workflow
FP32 Buffer (m_t or v_t)
┌─────────────────────────────────────────────────────────────┐
│ Block 0 (2048 floats) │ Block 1 (2048 floats) │ ... │
└─────────────────────────────────────────────────────────────┘
│ │
▼ ▼
Find Block Max c_0 Find Block Max c_1
Quantize to 8-bit FP Quantize to 8-bit FP
│ │
▼ ▼
┌─────────────────────────────────────────────────────────────┐
│ 2048 Bytes + 4B scale │ 2048 Bytes + 4B scale │ ... │
└─────────────────────────────────────────────────────────────┘
Total Memory: 1 Byte per parameter + 0.2% scale metadata (75% savings)Standard FP32 optimizer tensors are partitioned into independent blocks of 2048 elements. Each block is dynamically scaled by its local absolute maximum and quantized into custom 8-bit non-linear floating-point bins.
During the optimizer step:
- The 8-bit states are de-quantized to FP32 in GPU registers.
- The standard AdamW step is computed.
- The updated moments are quantized back to 8-bit memory.
Because the de-quantization and update are fused in GPU SRAM, 8-bit Adam reduces optimizer state memory from 8 bytes to 2 bytes per parameter (75% reduction) with zero degradation in pre-training perplexity.
Architectural Comparison of LLM Optimizers
| Dimension | AdamW | Adafactor | Lion | Sophia-G | 8-bit AdamW | | :--- | :--- | :--- | :--- | :--- | :--- | | State Memory per Param | 8 bytes () | bytes () | 4 bytes () | 8 bytes () | 2 bytes () | | Per-Step Compute Cost | Baseline | Low (No momentum) | Lowest (No sqrt/div) | Baseline Hessian | Low (Fused dequant) | | Update Magnitude | Variable () | Variable (RMS scaled) | Uniform () | Clipped () | Variable () | | Curvature Sensitivity | Gradient variance | Factorized variance | None (Sign-based) | Diagonal Hessian | Gradient variance | | Batch Size Tolerance | High () | High () | Best at Large () | High () | High () | | Primary Risk | Memory footprint | Factorization error | Step size tuning | Hessian compute spikes | Negligible |
Practical Implementation and Tuning Recipes
When configuring adaptive optimizers for large-scale pre-training pipelines, several empirical rules govern stability and efficiency:
1. The Epsilon Stability Threshold
In FP16 and BF16 mixed-precision training, the AdamW hyperparameter plays a critical role in preventing loss spikes. While standard deep learning frameworks default to , large Transformers often require setting or .
When gradients become small in deeper layers, an excessively small causes the denominator to collapse toward zero, amplifying numerical noise and generating unbounded gradient updates.
2. Beta-2 Calibration for Extended Token Horizons
For standard training runs under 100 billion tokens, or provides rapid adaptation to changing loss gradients. However, when scaling runs beyond 1 trillion tokens, maintaining a higher or ensures that the second-moment estimate averages over thousands of iterations, preventing premature convergence and stabilizing gradient steps across massive batch sizes.
3. Fused Kernel Implementations
Standard PyTorch implementations of AdamW launch separate CUDA kernels for momentum updates, variance updates, weight decay, and parameter additions, saturating GPU memory bandwidth.
Production training frameworks (such as Megatron-LM, DeepSpeed, and PyTorch torch.optim.AdamW(fused=True)) fuse the entire optimizer step into a single GPU kernel. By keeping model parameters and optimizer states in on-chip SRAM during computation, fused optimizers deliver a to speedup in optimizer step latency.
Sources
- Kingma, D. P., & Ba, J. (2014). Adam: A Method for Stochastic Optimization. arXiv:1412.6980
- Loshchilov, I., & Hutter, F. (2017). Decoupled Weight Decay Regularization. arXiv:1711.05101
- Shazeer, N., & Stern, M. (2018). Adafactor: Adaptive Learning Rates with Sublinear Memory Cost. arXiv:1804.04235
- Chen, X., Liang, C., Huang, D., Real, E., Wang, K., Liu, Y., Pham, H., Dong, X., Luong, T., Hsieh, C. J., Lu, Y., & Le, Q. V. (2023). Symbolic Discovery of Optimization Algorithms. arXiv:2302.06675
- Liu, H., Li, Z., Hall, D., Liang, P., & Ma, T. (2023). Sophia: A Scalable Stochastic Second-order Optimizer for Language Model Pre-training. arXiv:2305.14342
- Dettmers, T., Lewis, M., Shleifer, S., & Zettlemoyer, L. (2021). 8-bit Optimizers via Block-wise Quantization. arXiv:2110.02861
- Raffel, C., et al. (2020). Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer. arXiv:1910.10683



