TL;DR
Standard AdamW produces different optimization trajectories when you change the mini-batch size, making hyperparameter transfer across cluster scales notoriously difficult. This paper introduces a simple fix: by squaring micro-batch gradients before averaging them into the second-moment buffer ($v_t$), AdamW achieves true batch size invariance under linear learning rate scaling ($\eta \propto B$) without requiring gradient variance to dominate the gradient mean.
What Problem Does This Paper Address?
When scaling up training runs (such as pretraining large language models), tuning hyperparameters directly at large scale is prohibitively expensive. Ideally, practitioners want to tune learning rates and momentum coefficients on small batch sizes and transfer them cleanly to huge distributed runs.
In Stochastic Gradient Descent (SGD), this is well understood: scaling the learning rate linearly with batch size ($\eta \propto B$) maintains consistent optimization trajectories. In Adam and AdamW, however, the second-moment denominator term ($v_t$) tracks the raw second moment of the mini-batch gradient: $$\mathbb{E}[(g')^2] = \mathbb{E}[g']^2 + \text{Var}[g']$$ Because mini-batch variance scales inversely with batch size ($\text{Var}[g'] \propto 1/B$), increasing batch size artificially shrinks $v_t$, uncontrollably inflating the effective step size. Prior attempts to fix this proposed square-root scaling ($\eta \propto \sqrt{B}$), but this heuristic relies on the brittle assumption that gradient variance heavily dominates the squared expected gradient—an assumption that fails both near initialization (where gradients are large) and at very large batch sizes.
Methods
The authors propose Batch Size Invariant AdamW, which alters the update rule directly at the source rather than attempting post-hoc learning rate adjustments:
- Micro-batching: A mini-batch of size $B$ is partitioned into $\kappa$ fixed-size micro-batches (either across distributed workers or via vectorized operations like PyTorch/JAX
vmap). -
Square-Then-Average: Standard AdamW averages micro-batch gradients and squares the result: $$v_t \propto \left(\frac{1}{\kappa} \sum_{k=1}^\kappa g_k\right)^2$$ Batch size invariant AdamW instead squares each micro-batch gradient first, and then averages: $$v_t \propto \frac{1}{\kappa} \sum_{k=1}^\kappa g_k^2$$ Because $\mathbb{E}[\frac{1}{\kappa}\sum g_k^2] = \mathbb{E}[g]^2 + \text{Var}[g]$, the expected denominator remains strictly constant regardless of $\kappa$ or $B$.
-
Linear Hyperparameter Scaling: The effective learning rate and exponential moving average (EMA) coefficients scale linearly with batch size: $$\eta' = \eta_0 \frac{B}{B_{\min}}, \quad \gamma_1' = \gamma_1 \frac{B}{B_{\min}}, \quad \gamma_2' = \gamma_2 \frac{B}{B_{\min}}$$ (where $\beta = 1 - \gamma$).
The authors formally prove via a derivative-based limit formulation ($\delta \to 0$) that a single step of this modified optimizer on a mini-batch of size $\kappa M$ is asymptotically equivalent to taking $\kappa$ consecutive updates of standard AdamW on micro-batches of size $M$.
Datasets
The authors evaluated the method on standard public benchmarks:
- Shakespeare Dataset: Evaluated with a character-level decoder-only transformer (NanoGPT, 6 layers, 6 heads, embedding dimension 384).
- CIFAR-10: Evaluated across three visual architectures: ResNet-18 with BatchNorm, ResNet-18 with LayerNorm (to isolate batch size optimization effects from BatchNorm statistics), and a Vision Transformer (ViT) using patch size 8 and QK-layernorm.
No new datasets were introduced.
Key Insights and Ideas
- Order of operations matters: Changing $(\text{mean}(g))^2$ to $\text{mean}(g^2)$ prevents the gradient variance term from disappearing as mini-batch size grows.
- Linear scaling for adaptive optimizers: Once the second-moment estimator is decoupled from batch size, AdamW naturally obeys linear learning rate scaling ($\eta \propto B$), bringing it into theoretical alignment with SGD.
- Weaker theoretical assumptions: Unlike previous work relying on stochastic differential equations that require $\text{Var}[g'] \gg \mathbb{E}[g']^2$, the authors' equivalence proof holds deterministically for identical data sequences, requiring only that updates remain reasonably small.
Key Results
- NanoGPT on Shakespeare: Batch size invariant AdamW maintained almost identical test loss trajectories across batch sizes $B \in \{64, 128, 256, 512\}$ for base learning rates up to $\eta_0 = 10^{-4}$. In contrast, standard AdamW with $\eta \propto \sqrt{B}$ diverged noticeably even at very small learning rates ($\eta_0 = 10^{-6}$).
- ResNet-18 & ViT on CIFAR-10: Across batch sizes ranging from $B=1{,}000$ to $10{,}000$ (and $500$ to $5{,}000$ for ViT), the proposed optimizer’s training and test trajectories overlapped tightly up to a critical learning rate threshold ($\eta_0 \approx 10^{-5}$ to $10^{-4}$). Standard AdamW exhibited persistent discrepancies across all tested learning rates (even down to $\eta_0 = 10^{-7}$).
Limitations and Future Work
- Critical Learning Rate Ceiling: Invariance holds strictly only in the "small update" regime. Once the base learning rate exceeds a certain critical threshold (e.g., $\eta_0 > 10^{-4}$ in their vision experiments), trajectories across batch sizes begin to diverge.
- Convergence Speed at Small Learning Rates: Because the theoretical guarantees require small step sizes, operating strictly in the invariant regime can correspond to learning rates smaller than those used in standard practice, leading to slower convergence.
- Implementation Overhead: The optimizer requires access to micro-batch-level gradients rather than a single aggregated mini-batch gradient tensor before computing the second moment, which requires integration into gradient accumulation or parallel dispatch workflows.
Summary updated