SubZero: Random Subspace Zeroth-Order Optimization for Memory-Efficient LLM Fine-Tuning

Ziming Yu, Pan Zhou, Sike Wang, Jia Li, Hua Huang

Abstract

Fine-tuning Large Language Models (LLMs) has proven effective for a variety of downstream tasks. However, as LLMs grow in size, the memory demands for backpropagation become increasingly prohibitive. Zeroth-order (ZO) optimization methods offer a memory-efficient alternative by using forward passes to estimate gradients, but the variance of gradient estimates typically scales linearly with the model's parameter dimension—a significant issue for LLMs. In this paper, we propose the random Subspace Zeroth-order (SubZero) optimization to address the challenges posed by LLMs' high dimensionality. We introduce a low-rank perturbation tailored for LLMs that significantly reduces memory consumption while improving training performance. Additionally, we prove that our gradient estimation closely approximates the backpropagation gradient, exhibits lower variance than traditional ZO methods, and ensures convergence when combined with SGD. Experimental results show that SubZero enhances fine-tuning performance and achieves faster convergence compared to standard ZO approaches like MeZO across various language modeling tasks.

Introduction

Fine-tuning LLMs is notoriously memory-intensive. Standard first-order (FO) optimizers like Adam or SGD rely on backpropagation, which requires storing intermediate activations for every layer. For models with billions of parameters, this often exceeds the capacity of consumer-grade or even mid-tier enterprise GPUs.

Zeroth-order (ZO) optimization offers a "backprop-free" alternative. Methods like MeZO estimate gradients using only forward passes by perturbing model weights and observing the change in loss. However, ZO methods face a "curse of dimensionality": the variance of the gradient estimate scales linearly with the number of parameters ($d$). In LLMs, where $d$ is massive, this noise makes training slow and unstable. While previous "subspace" methods tried to fix this by projecting perturbations into a smaller space, they usually required storing a massive projection matrix, which ironically defeated the goal of saving memory.

Methodology

The authors introduce SubZero (random Subspace Zeroth-order optimization), which features three key technical innovations:

  1. Layer-wise Low-Rank Perturbation: Instead of perturbing the entire model with one giant vector, SubZero applies perturbations layer-by-layer. For a weight matrix $W_i$, it generates a low-rank perturbation $\tilde{Z}_i = U_i Z_i V_i^T$. Here, $U_i$ and $V_i$ are column-orthogonal matrices (derived via QR decomposition of small random matrices), and $Z_i$ is a small, low-dimensional Gaussian matrix.
  2. Lazy Subspace Updates: To avoid the computational overhead of performing QR decomposition at every training step, SubZero employs a "lazy" strategy. It generates and fixes the subspace (the $U$ and $V$ matrices) for a set number of steps ($F$) before regenerating them.
  3. Reshaping Strategy for PEFT: When applying SubZero to Parameter-Efficient Fine-Tuning (PEFT) methods like LoRA, the authors propose a reshaping trick to ensure the low-rank subspace perturbation remains effective for non-square matrices.

Crucially, SubZero uses the "random seed trick" to regenerate perturbations on the fly, meaning it doesn't need to store the perturbation matrices, keeping memory usage at "inference-level."

Experimental Evaluation

The authors evaluated SubZero across a wide range of standard NLP benchmarks, including SuperGLUE (SST-2, RTE, BoolQ, etc.), Question Answering (SQuAD, DROP), and Language Modeling (MNLI, SNLI). Experiments were conducted on a variety of model architectures, including RoBERTa-large, OPT (1.3B to 13B), LLaMA2-7B, and Mistral-7B.

Results and Discussion

SubZero consistently outperformed MeZO across almost all tasks. For example, in full-parameter tuning of LLaMA2-7B, SubZero improved accuracy by 7.1% over MeZO.

Memory Efficiency

SubZero achieved a 1.6x memory reduction compared to SGD. For an OPT-1.3B model, SubZero required only 6.8GB of VRAM, compared to 11.5GB for SGD, making it feasible to tune on a single consumer GPU.

Memory cost comparison between SGD, MeZO, and SubZero.

Convergence and Variance Reduction

By restricting the perturbation to a subspace of rank $r$, the variance of the gradient estimate depends on $r$ rather than the total parameter count $d$. Since $r \ll d$, the "signal-to-noise" ratio of the estimated gradient improves dramatically. Training loss curves show that SubZero reaches lower loss levels much faster than MeZO, behaving more like a first-order optimizer.

Training loss over wall-clock time for MeZO, SubZero, and SGD.

Conclusion

SubZero is a novel ZO optimization framework that enables memory-efficient fine-tuning of LLMs by estimating gradients within low-dimensional random subspaces. While it introduces a slight computational overhead due to QR decomposition, it significantly reduces gradient variance, achieving faster convergence and higher accuracy than state-of-the-art baselines like MeZO while maintaining a memory footprint nearly identical to inference.

Summary updated

BibTeX
@misc{yu2025subzero,
  author = {Ziming Yu and Pan Zhou and Sike Wang and Jia Li and Hua Huang},
  title = {{SubZero: Random Subspace Zeroth-Order Optimization for Memory-Efficient LLM Fine-Tuning}},
  year = {2025},
  url = {https://openreview.net/forum?id=FK6T0U4Mg1},
  howpublished = {OpenReview},
  note = {Submitted to ICLR 2025},
}
Figure