NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Optimizing ML Training with Metagradient Descent

Logan Engstrom, Andrew Ilyas, Benjamin Chen, Axel Feldmann, William Moses, Aleksander MadryarXiv 2025 · OpenReview

Abstract

A major challenge in training large-scale machine learning models is configuring the training process to maximize model performance, i.e., finding the best training setup from a vast design space. In this work, we unlock a gradient-based approach to this problem. We first introduce an algorithm for efficiently calculating metagradients -- gradients through model training -- at scale. We then introduce a "smooth model training" framework that enables effective optimization using metagradients. With metagradient descent (MGD), we greatly improve on existing dataset selection methods, outperform accuracy-degrading data poisoning attacks by an order of magnitude, and automatically find competitive learning rate schedules.

Introduction

Training a large-scale machine learning model involves making hundreds of "metaparameter" choices, such as data selection, learning rate schedules, and architectural tweaks. Traditionally, these are solved via grid search or heuristics—essentially guessing and checking. This is highly inefficient because the design space is astronomical; for example, there are $2^n$ possible subsets of a dataset.

While "metagradients" (gradients that flow backward through the entire training process) theoretically allow us to use optimization to find these settings, they have historically failed to scale due to two primary obstacles:

  1. The Memory Wall: Storing every intermediate state of a billion-parameter model over thousands of steps to compute a gradient is impossible for current hardware.
  2. The Smoothness Wall: The landscape of training configurations is often jagged and non-smooth. A small change in a metaparameter might lead to unpredictable swings in final performance, rendering gradients useless.

Methodology

The metagradient framework treats training as a differentiable function from setup to behavior.

To unlock scalable metagradients, we propose a two-part solution: the REPLAY algorithm and a metasmoothing design philosophy.

REPLAY: Scalable Metagradient Computation

Instead of storing every optimizer state (which takes $O(T)$ space), the REPLAY algorithm uses a "lazy $k$-ary tree" structure. It strategically stores a few checkpoint states and "replays" (re-computes) the training steps forward to reconstruct the states needed for the backward pass. This reduces memory requirements to logarithmic space ($O(\log T)$) at the cost of a small, logarithmic increase in computation, enabling exact metagradients for models with billions of parameters.

Metasmoothing

Standard training routines are often not amenable to gradient-based optimization. We introduce metasmoothness, a property measuring how much a metagradient changes when metaparameters are nudged. To achieve this, we recommend specific architectural adjustments: placing Batch Normalization before activations, scaling down final layer outputs, and replacing Max Pooling with Average Pooling.

Experimental Results

We validated Metagradient Descent (MGD) across several high-stakes regimes, including CLIP pre-training (DataComp-small), instruction fine-tuning (Gemma-2B), and CIFAR-10 for data poisoning benchmarks.

MGD achieves state-of-the-art results across CLIP data selection, IFT data selection, and data poisoning attacks.

Key Findings

  • SOTA Data Selection: On the DataComp-small benchmark, MGD achieved a performance boost 2x larger than the previous leader. For Gemma-2B instruction tuning, MGD-selected data outperformed both the full dataset and the previous best selection method (LESS) on reasoning tasks (BBH).
  • Effective Data Poisoning: We demonstrated an accuracy-degrading attack that dropped CIFAR-10 accuracy from 92% to 78% by poisoning only 2.5% of the data. Previous state-of-the-art attacks only managed a drop to 91%.
  • Automatic Learning Rate Schedules: MGD found competitive "one-cycle" learning rate schedules in just 50 optimization steps, matching the performance of a grid search that required over 1,000 configurations.

Discussion and Future Work

While MGD represents a significant step forward, several limitations remain. REPLAY requires 2-3x the computation of a standard training run due to the "backwards pass over a backwards pass." Additionally, current implementations require float32 precision, whereas large-scale training often relies on bfloat16. Future work will focus on optimizing software kernels for double-backwards operations and exploring architectures that are inherently metasmooth, reducing the need for manual design tweaks.

Summary updated

BibTeX
@misc{engstrom2025optimizing,
  author = {Logan Engstrom and Andrew Ilyas and Benjamin Chen and Axel Feldmann and William Moses and Aleksander Madry},
  title = {{Optimizing ML Training with Metagradient Descent}},
  year = {2025},
  eprint = {2503.13751},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2503.13751},
}
Figure