ZO-AdaMU Optimizer: Adapting Perturbation by the Momentum and Uncertainty in Zeroth-order Optimization

Shuoran Jiang, Qingcai Chen, Youcheng Pan, Yang Xiang, Yukang Lin, Xiangping Wu, Chuanyi Liu, Xiaobao Song

Abstract

Lowering the memory requirement in full-parameter training on large models has become a hot research area. MeZO fine-tunes the large language models (LLMs) by just forward passes in a zeroth-order SGD optimizer (ZO-SGD), demonstrating excellent performance with the same GPU memory usage as inference. However, the simulated perturbation stochastic approximation for gradient estimate in MeZO leads to severe oscillations and incurs a substantial time overhead. Moreover, without momentum regularization, MeZO shows severe over-fitting problems. Lastly, the perturbation-irrelevant momentum on ZO-SGD does not improve the convergence rate. This study proposes ZO-AdaMU to resolve the above problems by adapting the simulated perturbation with momentum in its stochastic approximation. Unlike existing adaptive momentum methods, we relocate momentum on simulated perturbation in stochastic gradient approximation. Our convergence analysis and experiments prove this is a better way to improve convergence stability and rate in ZO-SGD. Extensive experiments demonstrate that ZO-AdaMU yields better generalization for LLMs fine-tuning across various NLP tasks than MeZO and its momentum variants.

Introduction

Fine-tuning Large Language Models (LLMs) with billions of parameters is notoriously "memory-hungry." Standard back-propagation requires storing intermediate activations to compute gradients, often consuming up to 12 times the memory needed for a simple forward pass. While Zeroth-Order (ZO) optimization (like the recent MeZO algorithm) bypasses this by estimating gradients using only forward passes, it comes with significant baggage: instability due to random perturbations, over-fitting without momentum regularization, and inefficiency in high-dimensional spaces.

ZO-AdaMU (Zeroth-Order Adaptive Momentum and Uncertainty) aims to bridge the performance gap between memory-efficient ZO methods and memory-intensive first-order optimizers like Adam, while maintaining the low memory footprint of inference.

GPU memory usage comparison across different model sizes. ZO-AdaMU maintains memory efficiency similar to inference (Zero-shot/MeZO) while enabling full-parameter tuning.

Methodology

The core innovation of ZO-AdaMU is a shift in where momentum is applied. Standard optimizers compute a gradient and then apply momentum to it. In the ZO world, gradients are estimated by perturbing model weights with a random vector $z$. ZO-AdaMU instead generates a momentum-centered perturbation.

Key technical components include:

  • Relocated Momentum: The perturbation vector is split into a zero-centered Gaussian (pure noise) and a momentum-centered Gaussian based on the history of successful directions.
  • Adaptive Uncertainty ($\alpha$): A simulated annealing schedule balances these two parts. Early training relies on random exploration, while later stages lean on historical momentum.
  • Second-Order Approximation: The algorithm maintains an exponential moving average (EMA) of squared perturbations to regularize step size, mimicking Adam's behavior.
  • SPSA Framework: It builds on Simultaneous Perturbation Stochastic Approximation, requiring only two forward passes per update.

Key Insights and Results

By injecting momentum into the perturbation itself, the optimizer "smooths" the search direction before the gradient is estimated. This leads to a more stable descent path compared to smoothing a noisy gradient estimate post-hoc. Theoretical analysis demonstrates that this approach reduces the "local effective rank" of the Hessian matrix, making the complex loss landscape of an LLM appear flatter and preventing entrapment in sharp, poor-quality local minima.

Optimization trajectories on benchmark functions. ZO-AdaMU (pink) demonstrates significantly more stable and direct paths to the optimal point compared to MeZO (yellow).

Performance Highlights

  • Superior Generalization: On the OPT-13B model, ZO-AdaMU outperformed MeZO across almost all tasks, particularly in complex reasoning and text generation (e.g., +2.0% on COPA, +1.8% on ReCoRD).
  • Hardware Efficiency: ZO-AdaMU allows for tuning models roughly 11 to 14 times larger than what is possible with Adam on the same hardware (e.g., 30B vs 2.7B parameters on a single GPU).
  • Non-Differentiable Success: As a zeroth-order method, it can optimize non-differentiable objectives like discrete accuracy or F1 scores directly, outperforming MeZO on 4 out of 5 such tasks.

Conclusion

ZO-AdaMU provides a robust solution for memory-efficient LLM fine-tuning. While it introduces a slight memory overhead compared to the bare-bones MeZO (due to storing momentum and variance vectors), it remains significantly leaner than first-order methods. Future work will explore the interaction between this momentum schedule and parameter-efficient fine-tuning (PEFT) techniques like LoRA to further optimize performance and resource usage.

Summary updated

BibTeX
@inproceedings{jiang2024zo,
  author = {Shuoran Jiang and Qingcai Chen and Youcheng Pan and Yang Xiang and Yukang Lin and Xiangping Wu and Chuanyi Liu and Xiaobao Song},
  title = {{ZO-AdaMU Optimizer: Adapting Perturbation by the Momentum and Uncertainty in Zeroth-order Optimization}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2024},
  doi = {10.1609/aaai.v38i16.29796},
}
Figure