Introduction
Fine-tuning Large Language Models (LLMs) typically necessitates significant computational resources, primarily due to the memory overhead of backpropagation. While Zeroth-Order (ZO) optimization offers a memory-efficient alternative by relying solely on forward passes, it has historically suffered from high variance and instability, often requiring hand-crafted prompts to maintain convergence. This paper introduces MeZO-SVRG, a variance-reduced zeroth-order method that stabilizes the optimization process, enabling robust fine-tuning with a memory footprint significantly lower than standard first-order methods.
The Memory Bottleneck in LLM Fine-Tuning
Standard fine-tuning utilizes First-Order (FO) optimizers like Adam or SGD. These methods require backpropagation, which is notoriously memory-intensive because it must cache intermediate activations, gradients, and optimizer states. For a model such as OPT-13B, the memory required for fine-tuning can be 12 times greater than the memory required for simple inference.
Zeroth-order optimization addresses this by estimating gradients using only loss evaluations (forward passes). While a recent breakthrough, MeZO, demonstrated the potential of ZO for LLMs, it remained highly unstable with small batches and sensitive to the optimization trajectory. MeZO-SVRG aims to resolve these instabilities, making ZO fine-tuning practical for standard, non-prompted settings.
Methodology: MeZO-SVRG
The researchers developed MeZO-SVRG (Memory-Efficient Zeroth-Order Stochastic Variance-Reduced Gradient) by combining variance reduction with memory-saving implementation tricks.
1. Variance Reduction via SVRG
SVRG is a classic optimization technique that periodically computes a "full-batch" gradient to serve as an anchor. This anchor is used to denoise the mini-batch gradient estimates in subsequent iterations. By reducing the variance of the gradient estimates, MeZO-SVRG achieves much faster and more stable convergence than previous ZO methods.
2. Memory-Efficient Implementation
To ensure the algorithm remains viable for memory-constrained environments, the authors employed several strategies:
- The Resampling Trick: Instead of storing massive random perturbation vectors, the system stores a single random seed and regenerates the vectors on the fly.
- In-place Operations: Parameters are updated directly to minimize new memory allocations.
- Single Perturbation Vector: Unlike standard ZO-SVRG, which might use different random directions for every sample, MeZO-SVRG uses one direction for the entire batch, enabling data parallelism and faster computation.
While standard FO methods require 6–12x the memory of inference, MeZO-SVRG requires roughly 3x inference memory (to store parameters, anchor parameters, and the anchor gradient).
Experimental Evaluation
The method was evaluated across diverse benchmarks and architectures:
- Benchmarks: GLUE (MNLI, QNLI, SST-2, CoLA) and SuperGLUE (BoolQ).
- Models: Masked language models (DistilBert, RoBERTa-large) and autoregressive models (GPT2-XL, OPT-2.7B, and OPT-6.7B).
- Settings: Both full-parameter and partial-parameter fine-tuning.
Key Results and Insights
- Accuracy and Stability: MeZO-SVRG consistently outperformed MeZO, showing up to a 20% increase in test accuracy. It effectively closed the performance gap between zeroth-order and first-order methods to within 5% in many scenarios.
- Efficiency Gains: Despite the additional computation required for anchor gradients, MeZO-SVRG converged so much faster that it reduced total GPU-hours by approximately 2x compared to MeZO.
- Breaking Prompt Dependency: A significant finding was that MeZO-SVRG works well in standard fine-tuning settings. Unlike previous ZO methods that required specific prompts to stabilize the loss landscape, the variance reduction in MeZO-SVRG provides sufficient stability for unprompted tasks.
- Scalability: As batch sizes and context lengths increase, the memory savings of MeZO-SVRG become more pronounced because it avoids storing the massive activation tensors required for backpropagation.
Limitations and Future Directions
While MeZO-SVRG is significantly leaner than Adam, it still requires 3x the memory of inference, whereas the original MeZO requires only 1x. For the largest models at the absolute edge of hardware limits, this 3x requirement may still pose a challenge. Additionally, computing a true full-batch gradient for massive datasets is impractical, necessitating "large-batch" approximations (e.g., 512 or 1024 samples).
Future work involves applying MeZO-SVRG to non-differentiable objectives, such as Reinforcement Learning from Human Feedback (RLHF), and combining it with Parameter-Efficient Fine-Tuning (PEFT) techniques like LoRA to further reduce memory requirements.
Summary updated