Fine-tuning Large Language Models (LLMs) for specific tasks often yields impressive results, but it comes at a steep cost: memory inefficiency. Standard gradient-based training (backpropagation) requires storing activations for every layer to calculate gradients, often consuming 6 to 12 times more GPU memory than simply running the model for inference.
To address this, researchers recently proposed MeZO (Memory-efficient Zeroth-order optimization). MeZO estimates gradients using only forward passes, meaning it uses almost no extra memory beyond standard inference. However, MeZO has a major flaw: its gradient estimates are inherently "noisy." This noise makes the model difficult to optimize, leading to slow training, extreme sensitivity to learning rates, and suboptimal final accuracy.
In this paper, the authors investigate why this noise is so destructive and introduce Sparse MeZO (S-MeZO), a breakthrough in gradient-free fine-tuning that achieves significantly better performance by updating fewer parameters.
The Power of Small Weights
The authors made a surprising empirical discovery: zeroth-order noise does not affect all parameters equally. When noisy updates are applied to large weights—the "backbone" of the model's learned knowledge—the model tends to diverge or perform poorly. Conversely, small weights are much more resilient to this noise and can act as a safe "buffer" for noisy updates.
Based on this observation, the authors developed Sparse MeZO (S-MeZO), which operates on three core principles:
- Weight Selection: Before training begins, the algorithm identifies a subset of parameters with the smallest magnitudes (e.g., the bottom 20% or 50% of weights in each layer).
- Sparse Perturbation: During training, the algorithm only "perturbs" and updates these small weights. The large, critical weights remain frozen, protecting the model's core representations from being corrupted by inaccurate gradient estimates.
- On-the-fly Masking: Storing a static "mask" to track which weights to update would require as much memory as the model itself. To maintain MeZO's ultra-low memory footprint, the authors implemented an Efficient Implementation (S-MeZO-EI). This approach calculates the mask and applies perturbations dynamically during the forward pass.
Because S-MeZO is significantly more stable, it allows for much higher learning rates than vanilla MeZO without the risk of the model "exploding." This stability is the primary driver behind its faster convergence.
Key Insights
- The Generalization Gap: The authors found that vanilla MeZO's gradient estimates often successfully reduce loss on the current batch of data but actually increase the loss on other batches. It essentially overfits to the noise of the estimate. S-MeZO mitigates this.
- True Inference-Level Training: By computing the mask dynamically during the forward pass, S-MeZO-EI ensures that fine-tuning a massive 30-billion parameter model (LLaMA-30b) is possible on a single A100 GPU. This is a feat usually impossible with standard fine-tuning, or even parameter-efficient methods like LoRA, without specialized hardware setups.
Experimental Results
The researchers evaluated S-MeZO across a wide range of challenging benchmarks, including SuperGLUE (SST-2, RTE, BoolQ, WIC, MultiRC, COPA), Commonsense Reasoning (PIQA, SIQA), and Mathematics (AQuA). They tested the algorithm on popular architectures like LLaMA-7b/30b, Mistral-7B, and OPT-13b.
S-MeZO consistently outperformed vanilla MeZO across the board:
- Accuracy Gains: On the RTE task using LLaMA-7b, S-MeZO achieved an 80.7% accuracy, representing a massive 9% absolute improvement over MeZO's 71.7%.
- Convergence Speed: S-MeZO reached target accuracy levels 3.5x faster than MeZO on the RTE task and 3x faster on BoolQ.
- Memory Efficiency: S-MeZO-EI used the exact same memory as MeZO (approximately 14.6 GB for a 7B model), which is roughly 12 times less memory than full-parameter fine-tuning.
Limitations and Future Work
While S-MeZO significantly narrows the performance gap between zeroth-order and gradient-based optimization, it still slightly trails first-order methods like Adam or LoRA.
Additionally, S-MeZO currently relies on static sparsity, meaning the "small weights" are chosen only once at the start of training. The authors suggest that exploring dynamic sparsity—re-selecting the optimal weights to update during the training process—could yield even better results. Finally, while more stable than MeZO, choosing the optimal "sparsity rate" (the percentage of weights to keep active) still requires some task-specific hyperparameter tuning.
Summary updated