Memory-Efficient Gradient Unrolling for Large-Scale Bi-level Optimization

Qianli Shen, Yezhen Wang, Zhouhao Yang, Xiang Li, Haonan Wang, Yang Zhang, Jonathan Scarlett, Zhanxing Zhu, Kenji Kawaguchi

Bi-level optimization (BO) has emerged as a critical framework for solving hierarchical problems in machine learning, such as hyperparameter optimization, meta-learning, and neural architecture search. However, as models scale to billions of parameters, traditional BO methods encounter severe bottlenecks. This paper presents (FG)²U (Forward Gradient Unrolling with Forward Gradient), a novel approach that achieves unbiased meta-gradient estimates with memory requirements that remain constant relative to the number of parameters and unrolling steps.

Challenges in Bi-level Optimization

The standard BO problem consists of an outer objective (the meta-task) that depends on the optimal solution of an inner objective. Solving this typically involves two main strategies, both of which struggle at scale:

  1. Gradient Unrolling (GU): This treats the inner optimization steps as a differentiable computational graph. Reverse-mode unrolling (Backpropagation Through Time) requires storing all intermediate activations, leading to $O(T \times M)$ memory, where $T$ is the number of steps and $M$ is the parameter count. Forward-mode unrolling avoids storing activations but requires tracking a Jacobian matrix of size $M \times N$, which is computationally prohibitive for large $N$ (meta-parameters).
  2. Implicit Function (IF) Methods: These rely on the Implicit Function Theorem, assuming the inner problem reaches an exact stationary point. In practice, deep learning models rarely converge fully within reasonable timeframes, introducing significant "approximation bias" and poor performance.

The (FG)²U Method

The proposed method, (FG)²U, circumvents these issues by integrating Forward Gradient Unrolling with the "forward gradient" (or directional derivative) trick.

The Forward Gradient Trick

Instead of computing the full Jacobian matrix, (FG)²U computes the derivative of the inner solution along a random direction vector $v$ sampled from a distribution. Mathematically, it calculates $\nabla h(\phi)v$. This transformation converts a matrix-vector product into a vector-vector operation, which is significantly more efficient.

Recursive Efficiency and Memory

By applying this trick to the standard forward unrolling recursion, the authors can track the evolution of the meta-gradient using only $O(M)$ memory—equivalent to the memory needed to store the model parameters themselves. This decoupling of memory from the unrolling depth $T$ and the number of meta-parameters $N$ allows the method to scale to architectures previously unreachable by unrolling methods.

Unbiased Estimation

A key advantage of (FG)²U is that it provides an unbiased estimate of the true meta-gradient. By averaging directional derivatives over multiple random directions (Monte Carlo sampling), the estimate converges to the true gradient. Furthermore, because these samples are independent, the computation is embarrassingly parallel; more GPUs can be used to reduce variance without increasing the memory load on any single device.

Zeroth-Order Variant ((FG)²U-ZO)

The authors also introduce a zeroth-order variant for scenarios where the inner solver is non-differentiable or a "black box," such as a legacy physics simulator. This version uses finite differences to estimate the directional gradient, requiring only two forward passes of the inner solver.

Experimental Evaluation

The authors evaluated (FG)²U across three distinct domains to demonstrate its versatility and scalability:

  • Large-Scale Language Model Adaptation: The authors applied (FG)²U to fine-tune large language models, including DistilGPT2 (82M), GPT2-Large (774M), and GPT2-XL (1.5B). While standard Reverse Gradient Unrolling (RGU) consistently triggered Out-of-Memory (OOM) errors on these scales, (FG)²U successfully completed the meta-training.
  • Data Condensation: On benchmarks like CIFAR-10 and CIFAR-100, (FG)²U outperformed existing large-scale methods. For instance, in a CIFAR-10 "Images Per Class" (IPC 1) task, (FG)²U achieved 29.37% accuracy, significantly higher than the 20.78% achieved by Truncated Reverse Gradient Unrolling (TRGU).
  • Physics-Informed ML: Using the (FG)²U-ZO variant, the authors tackled the discovery of parameters for partial differential equations (PDEs) such as the Burgers and Allen-Cahn equations. By nesting a traditional numerical solver within the BO loop, the method achieved higher accuracy and faster convergence than Physics-Informed Neural Networks (PINNs).

Discussion and Limitations

While (FG)²U solves the memory bottleneck, it introduces a trade-off between variance and computational cost. The directional derivative estimate can have high variance; reducing this requires increasing the number of sampled directions ($b$), which increases FLOPs. Additionally, forward-mode AD is roughly 2-3x the cost of a standard forward pass.

To optimize performance, the authors suggest a Two-Phase Paradigm: using a fast, biased method (like TRGU) to reach the vicinity of a solution, followed by (FG)²U to refine the result with high-accuracy, unbiased gradients.

Conclusion

(FG)²U represents a significant step forward for bi-level optimization in the era of large-scale machine learning. By reducing memory overhead to $O(M)$ and providing unbiased estimates, it enables the application of meta-learning and hyperparameter optimization to models with billions of parameters and complex, non-differentiable inner loops.

Summary updated

BibTeX
@inproceedings{shen2024memory,
  author = {Qianli Shen and Yezhen Wang and Zhouhao Yang and Xiang Li and Haonan Wang and Yang Zhang and Jonathan Scarlett and Zhanxing Zhu and Kenji Kawaguchi},
  title = {{Memory-Efficient Gradient Unrolling for Large-Scale Bi-level Optimization}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=MI8Z9gutIn},
}
Figure