Source-linked AI summary
Optimizing ML Training with Metagradient Descent
Logan Engstrom, Andrew Ilyas, Benjamin Chen, Axel Feldmann, William Moses, Aleksander Madry
TL;DR
Large-scale model training requires choosing configurations from a vast design space, while existing gradient-based metaparameter methods have not scaled effectively. The paper introduces REPLAY for scalable exact metagradients and a metasmooth training framework, then uses metagradient descent to improve data selection, data poisoning, and learning-rate scheduling. Across these applications, MGD improves dataset selection, strengthens poisoning attacks, and finds competitive schedules.
Problem
Large-scale training requires selecting effective configurations from a vast metaparameter space, but existing gradient-based methods have not scaled beyond relatively small settings.
Source: §1 · p. 1, §2.2 · p. 4Method
The paper combines REPLAY for efficiently and exactly computing metagradients with metasmooth training routines and metagradient descent.
Source: §2.2 · p. 4, §7 · p. 19Results
MGD improves data selection, strengthens accuracy-degrading data poisoning by an order of magnitude, and finds competitive learning-rate schedules across large-scale applications.
Source: §5 · p. 18, §7 · p. 19Takeaways & Limitations
Metagradients become a usable toolkit for configuring large-scale model training across data, poisoning, and per-iteration learning-rate choices.
Source: §5 · p. 18, §7 · p. 19REPLAY remains more expensive than training a model once, requiring 2-3 times the operations of a backwards pass and currently relying on float32/tensorfloat32 operations.
Source: §5 · p. 17
Abstract
from arXiv · showhide
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.
1 Introduction
The paper frames training configuration as a high-dimensional metaparameter optimization problem and asks whether gradients can scale to this setting. It introduces scalable metagradient computation and metasmooth training, then applies metagradient descent across data selection, poisoning, and hyperparameter optimization.
1 Introduction
- Training configuration spans choices such as data, architecture, and initialization, but exhaustive search explores only a small part of the design space.Source: §1 · p. 1
1.1 Contributions
- The proposed recipe makes the objective differentiable, computes scalable metagradients with REPLAY, designs metasmooth training routines, and performs metagradient descent.Source: §1 · p. 1, §1.1 · p. 2
- 2x larger performance improvement than the previous DataComp-small leader is achieved for CLIP pre-training data selection.Source: §1.1 · p. 2
- MGD substantially improves instruction-tuning data selection for Gemma-2B over existing selection methods and full-data training.Source: §1.1 · p. 2
- An order-of-magnitude improvement in DNN data poisoning drops CIFAR-10 accuracy from 92%→78%, versus 91% for the best previous attack [LKY23].Source: §1.1 · p. 2
- MGD efficiently finds a CIFAR-10 learning-rate schedule matching the performance of a schedule found by grid search.Source: §1.1 · p. 2
2 Scalably computing metagradients
The section defines metagradients as gradients through training configurations and develops REPLAY to compute them exactly at large scale with logarithmic storage. It motivates this approach through autodifferentiation, identifies its memory bottlenecks, and explains how lazy replay trades additional computation for reduced storage.
2.1 What is a metagradient?
- The framework models training as an iterative state sequence, where each optimizer update maps the current state and metaparameters to the next state.For gradient descent, the state contains model parameters; for algorithms such as Adam, it also includes gradient moments.Source: §2.1 · p. 3
- A metagradient is the gradient of a training output with respect to continuous metaparameters controlling aspects of the training setup.The setup may include learning rates, weight decay, datasets through continuous relaxations, or other configurable training choices.Source: §2.1 · p. 3
2.2 Warmup: Metagradients via autodifferentiation
- Naive reverse-mode autodifferentiation is impractical because storing intermediates across all training operations can require terabytes even for toy MNIST metagradient computation.Step-wise autodifferentiation reduces the per-step differentiation burden but still stores every optimizer state, remaining too space-intensive at scale.Source: §2.2 · pp. 4–5
- Step-wise autodifferentiation computes the metagradient by traversing optimizer states backward and summing per-step contributions obtained from one-step differentiations.It first stores the training trajectory, then propagates gradients from the final state back to the initial state.Source: §2.2 · pp. 4–5
2.3 REPLAY
- REPLAY computes exact metagradients for large-scale iterative training using O(k log_k(T)) space and additional replayed training computation.It recursively saves and replays optimizer states, balancing storage against recomputation through a lazy k-ary tree.Source: §2.3 · pp. 5–6
- REPLAY uses deterministic training and a lazy k-ary tree to recover optimizer states in reverse order while deleting states that are no longer needed.The method is presented as a rematerialization technique for general, non-reversible learning algorithms rather than relying on state inversion.Source: §2.3 · pp. 5–6
3 Designing metasmooth training routines
Standard training routines can yield non-smooth metaparameter landscapes and unhelpful metagradients, so the paper develops ways to measure and improve metasmoothness for effective optimization.
3 Designing metasmooth training routines
- Standard training routines can produce ±∞-valued and generally unhelpful metagradients because the metaparameter optimization landscape is often non-smooth.This motivates modifying learning algorithms before applying metagradient optimization.Source: §3 · p. 6
3.1 The metaparameter optimization landscape
- Metasmoothness adapts smoothness analysis to metagradients, measuring how rapidly directional derivatives change across metaparameter perturbations.The proposed metric avoids exhaustive searches and metagradient-computation errors, requiring only three training-function evaluations.Source: §3.1 · p. 7
- Empirical metasmoothness compares weighted sign agreement between finite-difference metagradients at nearby metaparameter settings and can be computed with three calls to the learning algorithm.It operates in model-parameter space and yields an interpretable value in [−1, 1].Source: §3.1 · p. 7
3.2 Estimating and improving metasmoothness
- A fixed-menu search over training modifications identifies metasmooth algorithms, with BatchNorm before nonlinearities and final-layer output scaling crucial alongside batch size and width.The considered modifications are not exhaustive.Source: §3.2 · pp. 8–9
- The empirical estimate uses dataset perturbations at z = 0, a random direction, three trained parameter states, finite differences, and parameter-range weighting.This procedure estimates metasmoothness for ResNet-9 trained on CIFAR-10 with perturbations to 1000 training images.Source: §3.2 · p. 8
- Metasmooth models produce qualitatively smoother, more straightforward optimization landscapes than non-metasmooth models.Figure 5 compares perturbations to 1000 training examples and the resulting test-example losses for paired algorithms.Source: §3.2 · p. 9, Figure 5 · p. 9
- The most metasmooth algorithms retain near-optimal accuracy despite no clear metasmoothness–accuracy trend, supporting joint search over smoothness and performance.The paper notes that additional searching might identify more accurate metasmooth models.Source: §3.2 · pp. 9–10
- Metasmoothness strongly predicts metagradient utility: smoother configurations can be optimized more effectively by gradient ascent on validation loss.The experiment uses metagradients computed by REPLAY and measures the resulting change in model loss.Source: Figure 4 · p. 8, §3.2 · p. 10
4 Applications
MGD applies a common smooth-optimization recipe to dataset selection, data poisoning, and hyperparameter search, including multimodal and instruction-tuning data selection and learning-rate schedules. These applications demonstrate its use for optimizing training setups, while motivating higher-dimensional alternatives beyond thoroughly optimized low-dimensional hyperparameters.
4 Applications
- Across applications, MGD frames the task as optimization, makes the learning algorithm smooth, and applies first-order metagradient optimization.The learning-rate application illustrates REPLAY’s flexibility for metaparameters that affect models through optimization trajectories rather than directly changing the loss landscape.Source: §4 · p. 10, §4.4 · p. 16
4.1.3 Results
- MGD dataset selection greatly outperforms the previous state-of-the-art on DataComp-small, with only a few optimization steps needed to surpass prior methods.The improvement over the previous state-of-the-art is roughly as large as that method’s improvement over randomly chosen data.Source: §4.1.3 · p. 12, Figure 6 · p. 12
4.2 Selecting instruction-tuning data
- MGD selects strictly better instruction-tuning datasets than training on all data or LESS [XMG+24], improving accuracy by +1.5% on BBH and +0.8% on MMLU.Validation loss improves over optimization steps but shows signs of overfitting while optimizing 270,679 datapoint-count weights from few test samples.Source: §4.2 · p. 13
4.3.1 Setup
- MGD directly optimizes continuous poisoned samples by maximizing validation loss through metagradients, using projected gradient ascent under a fixed poisoning budget.The poisoning attack replaces a fixed ε-fraction of training samples and projects image-label pairs back into the valid sample space.Source: §4.3.1 · p. 14, §4.3.2 · p. 14, §4.3.3 · p. 15
4.3.3 Evaluation
- 14% accuracy degradation reduces CIFAR-10 test accuracy to 78% when corrupting 2.5% of training data, versus less than 1% for GradCancel [LKY23].The attack modifies 1000 of 40,000 training samples; with a non-metasmooth learner, performance still drops from 92.8% to 82.6%.Source: §4.3.3 · p. 15
4.4 Finding a learning rate schedule
- MGD optimizes learning-rate keypoints from a flat initialization and matches grid search over standard schedules despite naïve starting hyperparameters.The schedule is parameterized by evenly spaced keypoints with linear interpolation; the comparison grid contains over 1,000 one-cycle schedules.Source: §4.4 · p. 16, §4.4.2 · p. 16, §4.4.1 · p. 16
4.4.3 Evaluation
- MGD learned the schedule from a highly suboptimal flat learning-rate schedule by minimizing loss on the reserved 90% of the test set.Final schedules were evaluated on the held-out 10% test set across five unseen random seeds.Source: §4.4.3 · p. 17
- 50 MGD steps matched the state-of-the-art onecycle schedule found by grid search over more than 1,000 configurations.The comparison used Figure 10, but grid search can run in parallel whereas MGD steps run sequentially.Source: §4.4.3 · p. 17
- MGD is not advised for low-dimensional hyperparameters already thoroughly optimized by grid search, such as CIFAR-10 learning-rate schedules [SN17] [LA19].Future work could examine high-dimensional hyperparameters, including per-parameter or per-layer learning rates and weight decays, attention hyperparameters, and gradient preconditioners.Source: §4.4.3 · p. 17
5 Discussion
The discussion identifies computational cost and smooth model training as key constraints on metagradient use, while outlining applications and future research directions.
5 Discussion
- Metagradients remain more expensive than one ordinary training run because they require backward-over-backward computation and currently lack specialized software.The operation requires 2–3 times the operations of a backward pass and float32/tensorfloat32 computation.Source: §5 · p. 17
- Successful metagradient optimization requires smooth model training, motivating further study of metasmoothness and non-smooth optimization alternatives.Future directions include connections to numerical stability, optimizer and architecture design, and non-smooth optimization methods.Source: §5 · p. 17
- Metagradients apply to data poisoning, training-data selection, and the design of training routines and architectures with first-order methods.Small proxy models and engineering improvements are proposed as ways to reduce computational cost.Source: §5 · p. 18
6 Related work
Prior work estimates or directly differentiates through training, but scalability, assumptions, storage, approximation, and numerical-stability constraints limit existing approaches.
6 Related work
- The related-work literature uses metagradient, hyper-gradient, and outer gradient as synonymous terms.These terms describe gradients through the model-training process.Source: §6.1 · p. 18
6.1 Calculating metagradients
- Implicit differentiation can efficiently estimate metagradients under strong convexity but requires restrictive assumptions, inverse-Hessian approximations, and loss-expressed metaparameters.It can differentiate weight decay but not learning rate.Source: §6.1 · p. 18
- Automatic differentiation avoids some implicit-method restrictions but faces storage, compute, reversibility, approximation, and numerical-instability challenges.Prior methods use small settings, forward-mode AD, truncated steps, or reversible algorithms to manage these constraints.Source: §6.1 · pp. 18–19
6.2 Applying metagradients
- Metagradients have been applied to distillation, data selection, meta-learning, learning-rate and weight-decay selection, augmentation, architecture search, and data attribution.Existing applications generally either use direct AD in small settings or implicit-function estimates.Source: §6.2 · p. 19
7 Conclusion
The paper concludes that metagradients can be added to large-scale machine learning by combining scalable computation with metasmooth training, and the appendix details REPLAY’s memory–compute trade-off.
7 Conclusion
- Metagradients were successfully applied to models up to 2B parameters for data selection, Huber data poisoning, and per-iteration learning-rate search.These applications cover CLIP pretraining, instruction fine-tuning, accuracy reduction, and high-dimensional hyperparameter search.Source: §7 · p. 19
A.1 Warmup: Step-wise AD
- Step-wise automatic differentiation stores all T optimizer states and is feasible for small setups because each differentiation call has constant memory overhead.The appendix presents it as a warmup before REPLAY.Source: §A.1 · p. 26
A.2 REPLAY
- REPLAY computes metagradients by reverse-order traversal of optimizer states using deterministic training and a memory–compute trade-off.It uses O(k log_k(T)) space and an additional T log_k(T) model steps.Source: §A.2 · p. 26
A.2.1 Lazy k-ary tree
- The lazy k-ary tree recursively replays training to recover optimizer states in reverse order while deleting states no longer needed.Leaves correspond to training states, and reverse in-order traversal yields them in reverse order.Source: §A.2.1 · pp. 26–27
- The traversal stores at most k log_k(n) optimizer states and requires O(n log_k(n)) replay steps, a multiplicative O(log_k(n)) overhead over training.Storage and compute depend on the tree branching factor k.Source: §A.2.1 · p. 27
B Smooth Model Training
The omitted figures concern factors affecting metasmoothness and additional loss-landscape visualizations, including non-smooth examples.
B.1 Omitted Figures
- Figure 11 examines factors affecting metasmoothness when training a ResNet-9 on CIFAR-10.The caption refers readers to Section 3 for details.Source: Figure 11 · p. 28
- Additional omitted material includes loss-landscape visualizations and examples labeled non-smooth.The supplied passages do not state the visual comparisons or outcomes.Source: Figure 12 · p. 29, §B.1 · p. 29
C Metagradients for DataComp
This section provides the main dataset-selection algorithm in pseudocode and explains implementation details for applying metagradients to CLIP and DataComp.
- The appendix presents pseudocode for the main DataComp dataset-selection algorithm.Source: C Metagradients for DataComp · p. 30
- It explains how metagradients are applied to CLIP models.Source: C Metagradients for DataComp · p. 30
- It also details adaptations specific to the DataComp setting.Source: C Metagradients for DataComp · p. 30
C.1 Dataset Selection Using MGD
MGD applies smooth, differentiable relaxations to dataset selection and scales metagradient computation to large CLIP and DataComp workloads. The implementation combines surrogate losses, checkpointing, sharded data updates, and safeguards against overfitting and storage growth.
C.1 Dataset Selection Using MGD
- MGD adapts the CLIP contrastive loss to incorporate dataweights and produces a surrogate batch loss for metagradient optimization.The appendix notes that the simplified formulation omits cross terms, which are included in the adapted loss.Source: §C.1 · pp. 30–31
- MGD relaxes data selection into a differentiable loss whose metagradients with respect to dataweights remain meaningful, including at zero weights.The relaxation recovers the normal CLIP loss at zero dataweights and models single-example additions correctly.Source: §C.1 · p. 30
- The adapted CLIP loss empirically yields meaningful dataweight metagradients and strong dataset-selection results.Source: §C.1 · p. 31
C.2 Scaling MGD for CLIP and DataComp
- Metagradients are made scalable through manual checkpointing, minibatched embedding computation, and parallelization across GPUs.These choices address the memory cost of CLIP forward passes and their gradients.Source: §C.2 · p. 31
- Data is optimized by selecting and rewriting shards, while retaining the possibility that datapoints removed at one step can return later.The implementation uses eight base shards and computes metagradients over one shard at a time.Source: §C.2 · p. 31
- Top- and bottom-metagradient updates perform better empirically than randomly sampling points to add or remove.Shard sizes are subsequently fixed so sign-based updates do not cause them to grow indefinitely.Source: §C.2 · p. 31
- Eight-way loading preserves randomness and reduces duplicate datapoints within CLIP batches, avoiding contrastive-loss problems from repeated examples.Source: §C.2 · p. 31
- Deleting stale rewritten shards keeps total disk usage constant in the number of optimization steps.The algorithm retains only the eight most recently written shards.Source: §C.2 · p. 31
C.3 Details Pertaining to the DataComp Benchmark
The DataComp benchmark evaluates dataset-selection methods under a fixed CLIP training procedure and broad multimodal evaluation. The experiments account for reproducibility, generalization, incomplete data, and task-specific split limitations.
- DataComp-small selects from 12.8 million candidate samples while fixing the CLIP architecture, learning algorithm, and 12.8 million-sample training budget.Source: §C.3 · p. 32
- The experiments match DataComp-small hyperparameters except for a positive εroot added for numerical stability, with εroot and the metagradient step chosen to maximize metasmoothness.Source: §C.3 · p. 32
- The candidate pool contains only around 80% of the original DataComp pool because broken or changed URLs were removed.All reported results use this incomplete subset.Source: §C.3 · p. 32
- Disjoint target and validation sets were created where possible so metagradients used target data while evaluation measured generalization on validation data.Target splits could not be constructed for every task, and some datasets were excluded or not used for metagradients.Source: §C.3 · pp. 32–33
D Selecting IFT data
The IFT data-selection setting applies MGD to LoRA fine-tuning of Gemma-2B and compares selected data with full-data training and LESS. The method tunes smoothness-sensitive optimization settings, while validation-loss optimization can overfit as iterations increase.
D Selecting IFT data
- MGD selects instruction-fine-tuning data for LoRA adaptation of Gemma-2B from four combined datasets.Source: D Selecting IFT data · p. 34
- MGD selects among iterates and hyperparameters using top validation-loss steps followed by full-training-set accuracy because the validation set is small.The procedure is described as akin to Pareto optimization.Source: D Selecting IFT data · p. 34
- MGD is compared against training on the full dataset and LESS-T data selection.Source: D Selecting IFT data · p. 34
- The MGD runs jointly select learning rate and εroot because both substantially affect training smoothness and metagradient quality.Much larger or smaller maximum learning rates, and much larger εroot values, produce non-smooth training.Source: D Selecting IFT data · p. 34
IFT results
- MGD validation loss improves over metagradient steps, but the optimized-sample loss increasingly separates from validation loss, indicating overfitting with too many iterates.Source: Figure 13 · p. 35
E Accuracy-degrading data poisoning
This section reviews Gradient Cancelling as a poisoning baseline, describes its two-stage construction, and records experimental hyperparameters and learning-rate optimization materials.
E.1 Background on Gradient Cancelling attack
- Gradient Cancelling constructs a malicious parameter target and then poisons data so retraining reaches it.The target is generated independently, while poison values are optimized to induce a near-zero gradient at that target.Source: §E.1 · p. 36
- The parameter-generation phase produces θp with low test accuracy while keeping it close to the clean-training parameter θ0.The target may be generated using Gradient-based Parameter Corruption (GradPC) [LKY23].Source: §E.1 · p. 36
- The poison-crafting phase minimizes the combined clean-and-poisoned loss gradient evaluated at θp.This optimization aims to make the gradient at the malicious parameter approach zero.Source: §E.1 · p. 36
E.2 Metasmooth hyperparameters
- The ResNet-9 [Jor24] CIFAR-10 poisoning experiments use normalization, random horizontal flips, and two-pixel random translations as augmentations.The cited table contains the experiment’s hyperparameters.Source: Table 5 · p. 36
F LR optimization
- The learning-rate optimization grid searches all 528 combinations of the listed hyperparameter values.Figure 14 presents graphs of the learned learning-rate schedules.Source: Table 6 · p. 37, Figure 14 · p. 37
Related papers
This paper cites
- Learning Transferable Visual Models From Natural Language Supervision2021
- Microsoft COCO: Common Objects in Context2014
- DeepSeek-V3 Technical Report2024
- Training Compute-Optimal Large Language Models2022
- FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness2022
- Model-Agnostic Meta-Learning for Fast Adaptation of Deep Networks2017