Adaptive Optimization with Examplewise Gradients

Julius Kunze, James Townsend, David BarberarXiv 2021

Abstract

We propose a new, more general approach to the design of stochastic gradient-based optimization methods for machine learning. In this new framework, optimizers assume access to a batch of gradient estimates per iteration, rather than a single estimate. This better reflects the information that is actually available in typical machine learning setups. To demonstrate the usefulness of this generalized approach, we develop Eve, an adaptation of the Adam optimizer which uses examplewise gradients to obtain more accurate second-moment estimates. We provide preliminary experiments, without hyperparameter tuning, which show that the new optimizer slightly outperforms Adam on a small scale benchmark and performs the same or worse on larger scale benchmarks. Further work is needed to refine the algorithm and tune hyperparameters.

Introduction

Standard machine learning training typically relies on the mean gradient of a data batch to update model parameters. However, modern hardware accelerators like GPUs and TPUs compute individual gradients for every example in a batch before averaging them. By focusing solely on the batch mean, current optimizers discard valuable statistical information regarding the gradient distribution.

This loss of information is particularly relevant for adaptive optimizers like Adam, which scale updates using the inverse square root of the gradient's second moment. Relying on the batch mean can lead to unstable variance estimates, especially in the early stages of training, resulting in noisy step sizes. This paper investigates whether leveraging individual, examplewise gradients can produce more stable and accurate variance estimates to improve the learning process.

The Eve Optimizer

The authors introduce Eve, an adaptation of the Adam optimizer designed to utilize a batch of independent gradient estimates per iteration. While Adam estimates the second moment based on the batch mean, Eve calculates the exponential moving average of the examplewise second moments.

Algorithm 1: The Eve optimization procedure.

Mathematically, this approach yields a standard deviation estimator that is more stable than Adam’s by a factor of $\sqrt{B}$, where $B$ is the batch size. In practice, this leads to significantly more consistent parameter updates; on the CIFAR-10 benchmark, the standard deviation of Eve's step size was 25% lower than that of Adam.

Practical Implementation

Historically, extracting examplewise gradients required specialized, layer-specific backward passes. Eve bypasses this complexity by utilizing modern automatic differentiation tools, specifically JAX's vmap function, to vectorize gradient computation. This makes the optimizer model-agnostic and compatible with standard architectures like CNNs, LSTMs, and Transformers. To manage memory overhead, examplewise gradients are computed sequentially during backpropagation and discarded once layer statistics are extracted, ensuring peak memory usage is limited by the largest single layer rather than the entire network.

Experimental Evaluation

Eve was evaluated across a variety of tasks, including image classification (CIFAR-10), sequence modeling (Synthetic Addition), machine translation (WMT), reinforcement learning (Atari Pong), and generative modeling (PixelCNN++).

Benchmark Performance

Using Adam's default hyperparameters without additional tuning, Eve demonstrated competitive performance. It slightly outperformed Adam on CIFAR-10 (69.0% vs. 68.0% accuracy) and Atari Pong (20.8 vs. 20.5 reward), while performing comparably on Seq2Seq tasks and slightly trailing on WMT (70.8% vs. 71.4% accuracy).

Scaling with Batch Size

A key finding is that Eve’s advantages become more pronounced as batch sizes increase. The stability provided by examplewise gradients allows for better performance in large-batch regimes where standard Adam may struggle.

Comparison of accuracy between Eve and Adam across varying batch sizes on CIFAR-10.

Discussion and Future Work

While Eve provides mathematically more accurate variance estimates, the authors note that the "noise" in Adam’s unstable estimates might occasionally act as a regularizer, helping models escape local minima. This suggests a trade-off between stability and exploration that warrants further study.

Future work will focus on hyperparameter tuning specifically for Eve, as the current results rely on settings optimized for Adam. Additionally, the availability of examplewise gradients opens a new design space for robust optimization, such as using the median or mean absolute deviation to handle noisy data and outliers more effectively.

Summary updated

BibTeX
@misc{kunze2021adaptive,
  author = {Julius Kunze and James Townsend and David Barber},
  title = {{Adaptive Optimization with Examplewise Gradients}},
  year = {2021},
  eprint = {2112.00174},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2112.00174},
}
Figure