Bayesian Subspace Gradient Estimation for Zeroth-Order Optimization of Large Language Models
Jian Feng, Zhihong Huang
TL;DR
This work addresses the memory bottleneck in fine-tuning extremely large language models by adopting zeroth-order optimization. It introduces Bayesian Subspace Zeroth-Order Optimization (BSZO), which reframes gradient estimation as Bayesian inference over a projected gradient in a k-dimensional subspace and uses Kalman filtering to fuse multiple finite-difference measurements. The method includes a residual-based adaptive mechanism for perturbation scales and proves a convergence-rate improvement by a factor of $k/\gamma$, with only $O(k^2)$ additional memory. Empirically, BSZO outperforms MeZO, MeZO-Adam, and HiZOO across masked and decoder-only LLM benchmarks, achieving up to $6.67\%$ absolute average gains (e.g., OPT-13B) while keeping memory close to inference-only baselines, and showing stability across reduced-precision settings.
Abstract
Fine-tuning large language models (LLMs) with zeroth-order (ZO) optimization reduces memory by approximating gradients through function evaluations, but existing methods rely on one-step gradient estimates from random perturbations. We introduce Bayesian Subspace Zeroth-Order optimization (BSZO), a ZO optimizer that applies Kalman filtering to combine finite-difference information across multiple perturbation directions. By treating each finite-difference measurement as a noisy observation, BSZO builds a posterior distribution over the projected gradient and updates it through Bayesian inference, with a residual-based adaptive mechanism to adjust perturbation scales. Theoretical analysis shows that BSZO improves the convergence rate by a factor of $k/γ$ compared to standard ZO methods. Experiments on RoBERTa, Mistral, and OPT models show that BSZO outperforms MeZO, MeZO-Adam, and HiZOO across various tasks, achieving up to 6.67\% absolute average improvement on OPT-13B while keeping memory usage close to inference-only baselines (1.00$\times$--1.08$\times$ of MeZO).
