Per-example gradients: a new frontier for understanding and improving optimizers
Vincent Roulet, Atish Agarwala
TL;DR
This work makes per-example gradient statistics tractable at scale by using computational-graph surgery and JAX/vmap prototyping to access quantities like $\mathbb{E}[\nabla f(\theta; X)]$, $\mathbb{E}[\nabla f(\theta; X)^2]$, and $\mathbb{E}[\operatorname{sign}(\nabla f(\theta; X))]$. It demonstrates that non-linear gradient averages can be computed with minimal overhead in many architectures and shows how these statistics can illuminate optimizer behavior. Key findings include the optimal late placement of the sign in SignSGD (SignEMA) for stability, and that Adam’s preconditioner benefits from being dominated by $\mu^2$ rather than $\sigma^2$, motivating new Adam variants (MicroAdamVar, MicroAdamMSQ). Overall, the work expands the optimization-design space by enabling analysis and development of per-example gradient transformations, with practical demonstrations on transformer-scale models and implications for training stability and scaling.
Abstract
Training algorithms in deep learning usually treat a mini-batch of samples as a single object; they average gradients over the mini-batch, and then process the average in various ways. Computing other statistics beyond the average may have been seen as prohibitively resource intensive in automatic differentiation (AD) frameworks. We show that this is not the case. Generally, gradient statistics can be implemented through a surgery of the AD graph, which, in some cases, incur almost no computational and memory overheads compared to the mini-batch gradient computation. Additionally, we show that in certain classes of models, including transformers, JAX's vectorization transformation offers a viable implementation for prototyping and experimentation. We then revise our understanding of two nonlinear operations in optimization through the lens of per-example gradient transformations. We first study signSGD and show that the optimal placement of the sign operation in the gradient processing chain is crucial to success and can be predicted with a simple signal-to-noise ratio argument. Next we study per-example variations of the Adam preconditioner, and show that optimization is best served when the preconditioner is dominated by the mean rather than the variance of the gradient distribution - in contrast to conventional wisdom. Overall we demonstrate that per-example gradient information enables new analyses and possibilities for algorithm design.
