Learning a Zeroth-Order Optimizer for Fine-Tuning LLMs

Kairun Zhang, Haoyu Li, Yanjun Zhao, Yifan Sun, Huan Zhang

The Memory Bottleneck in LLM Fine-Tuning

Fine-tuning Large Language Models (LLMs) is notoriously memory-intensive. Standard first-order optimizers like Adam require storing gradients and optimizer states, which can consume over 300GB of VRAM for a 30-billion parameter model—far exceeding the memory needed simply to run the model for inference.

Zeroth-order (ZO) optimization, such as the recently proposed MeZO, offers a compelling alternative. By estimating gradients through slight perturbations of model weights and observing the resulting change in loss, ZO methods require only two forward passes and almost no extra memory. However, existing ZO methods rely on hand-crafted, static sampling strategies that apply uniform random noise across all parameters. This ignores the varying "curvatures" and sensitivities of different Transformer components (e.g., embeddings versus attention layers), leading to slow convergence and extreme sensitivity to learning rates.

Introducing ZO-Finetuner

To overcome these limitations, researchers introduce ZO-Finetuner, a learning-based zeroth-order optimizer that automatically learns efficient perturbation strategies. By scaling "Learning to Learn" (L2L) to the foundation-model era without re-introducing massive memory overhead, ZO-Finetuner offers a highly efficient, robust, and adaptable solution.

Key Innovations

  • Block-wise Parameterization: Instead of learning a unique perturbation for every single weight (which would require a second LLM-sized model), parameters are grouped into natural blocks, such as a single attention matrix. The optimizer learns one shared variance ($\sigma$) for each block. This aligns with the theoretical understanding that Transformer Hessians—which describe the "landscape" of the loss function—are approximately block-diagonal.
  • PertNN: Each parameter block is assigned a tiny, two-layer Multi-Layer Perceptron (MLP). This network takes summary statistics of the weights and previous losses to predict the optimal perturbation scale for the next step. Remarkably, this adds less than 2MB of total overhead for a 30B parameter model.
  • "Train Once, Reuse Widely": An optimizer trained on one base model and a simple task (like COPA) generalizes exceptionally well. It can be trained once and then reused to fine-tune that same model on entirely different datasets, or even applied to derivative models (like Llama-3-Instruct).
  • Variance Normalization: To maintain training stability, a fixed total "variance budget" is enforced. This ensures the learned per-block scales represent relative importance, preventing the optimizer from inadvertently exploding the effective learning rate.

Experimental Validation & Results

The researchers evaluated ZO-Finetuner across a diverse suite of LLMs (LLaMA-3.2-1B, LLaMA-3.1-8B, Qwen2.5-14B, and OPT-30B) and tasks, ranging from standard NLP benchmarks (SST-2, SQuAD, BoolQ) to complex reasoning datasets (GSM8K, Math-500).

  • Superior Accuracy: ZO-Finetuner outperformed the strongest zeroth-order baselines (like MeZO and HIZOO) in 82.1% of all model-task combinations, achieving an average 2.5% accuracy improvement over MeZO.
  • Massive Memory Savings: For an OPT-30B model, ZO-Finetuner peaked at just 62GB of VRAM, compared to 312GB for standard Adam. This 5x reduction makes fine-tuning massive models feasible on consumer-grade hardware.
  • Efficiency and Robustness: The computational overhead of running the PertNNs is negligible, adding less than 3.4% to the total training time per step. Furthermore, ZO-Finetuner is much more "plug-and-play" than standard ZO methods, often converging even when the learning rate is set 10x lower than what baselines require.

Limitations and Future Directions

While ZO-Finetuner represents a significant leap forward, it currently assumes perturbations within a block are independent (a diagonal covariance matrix). Exploring non-diagonal structures could capture correlations between parameters, though this might increase memory usage. Additionally, the initial meta-training phase is roughly 2.4x slower than standard first-order training, though this is a one-time investment per base model.

Future work will explore integrating ZO-Finetuner with Parameter-Efficient Fine-Tuning (PEFT) techniques like LoRA or quantization, which could push memory requirements even lower and further democratize the fine-tuning of massive language models.

Summary updated

BibTeX
@inproceedings{zhang2026learning,
  author = {Kairun Zhang and Haoyu Li and Yanjun Zhao and Yifan Sun and Huan Zhang},
  title = {{Learning a Zeroth-Order Optimizer for Fine-Tuning LLMs}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=bRS5iwbqlC},
}
Figure