Zeroth-Order Fine-Tuning of LLMs with Extreme Sparsity

Wentao Guo, Jikai Long, Yimeng Zeng, Zirui Liu, Xinyu Yang, Yide Ran, Jacob R. Gardner, Osbert Bastani, Christopher De Sa, Xiaodong Yu, Beidi Chen, Zhaozhuo Xu

TL;DR

This paper introduces a method for fine-tuning Large Language Models (LLMs) on consumer-grade hardware (like laptops or 8GB GPUs) by combining Zeroth-Order (ZO) optimization with extreme sparsity. By identifying and updating only the top 0.1% most "sensitive" parameters while quantizing the rest to 4-bit, the authors achieve performance comparable to full fine-tuning with significant speedups and a drastically reduced memory footprint.

What Problem Does This Paper Address?

Fine-tuning LLMs is notoriously memory-intensive. Beyond the model weights themselves, standard first-order (FO) training requires storing optimizer states, gradients, and activations for backpropagation. While Zeroth-Order (ZO) optimization—which estimates gradients using only forward passes—eliminates the need for gradient and activation caching, it still typically requires the model to be in full precision.

This creates a bottleneck for "on-device personalization," where a user might want to fine-tune a model like Llama2-7B on a mobile phone or a mid-range laptop. Even with ZO, a 7B model in 16-bit precision exceeds the 8GB VRAM limit common in consumer devices. The challenge is: Can we push sparsity and quantization to the extreme so that ZO fine-tuning becomes feasible on edge devices without sacrificing accuracy?

Methods

The authors propose a framework that leverages Fisher-Informed, Transferable Sparsity.

  1. Sensitive Parameter Identification: They define "sensitive parameters" as those with the largest squared gradients (a proxy for the diagonal of the Fisher Information Matrix).
  2. Extreme Sparsity: Instead of updating all parameters, they update only a tiny fraction (e.g., 0.1%).
  3. ZO-SGD with SPSA: They use Simultaneous Perturbation Stochastic Approximation (SPSA) to estimate gradients. Because they only update 0.1% of parameters, the random perturbations are restricted to this tiny subset, which theoretically and empirically improves convergence rates.
  4. Quantization Integration: The non-sensitive parameters (99.9% of the model) are quantized to 4-bit using methods like SqueezeLLM. The sensitive 0.1% are kept in 16-bit for precise updates.
  5. Transferable Masks: Crucially, they found that the "sensitivity" of parameters is largely determined during pre-training. This allows them to generate a sparsity mask once (using a general dataset like C4) and reuse it for various downstream tasks.
Figure 4: On-device LLM personalization workflow via integrating sensitive sparse ZO optimization with quantization.

Datasets

The researchers evaluated their approach using several LLM families: Llama2-7B, Mistral-7B, and OPT-6.7B. For fine-tuning and evaluation, they used a suite of downstream tasks from the GLUE and SuperGLUE benchmarks:

  • SST-2 (Sentiment Analysis)
  • RTE, CB, BoolQ (Natural Language Inference)
  • WSC, WiC, COPA (Reasoning and Word Sense Disambiguation)
  • C4 (Used as the surrogate pre-training dataset to identify sensitive parameters)

Key Insights and Ideas

  • The 0.1% Rule: The authors observed that roughly 0.1% of parameters in an LLM contribute to about 50% of the total gradient norm square. This "extreme sparsity" suggests that the vast majority of weights are essentially spectators during fine-tuning.
Cumulative normalized sum of gradient squares showing that a tiny fraction of parameters does the heavy lifting.
  • Pre-training as a Guide: Sensitivity isn't task-specific. A mask derived from the pre-training data (C4) is highly effective for downstream tasks like sentiment analysis or logic puzzles. This is a huge win for privacy and efficiency, as the "cloud" can provide the mask without ever seeing the user's private fine-tuning data.
  • Sparsity Fixes ZO Convergence: One of the biggest headaches with ZO optimization is that the variance of the gradient estimate scales with the number of parameters ($d$). By reducing $d$ by 1000x (from full model to 0.1%), the authors significantly stabilize and accelerate the optimization process.

Key Results

  • Performance Parity: Fine-tuning just 0.1% of sensitive parameters often outperformed full ZO fine-tuning. For example, on Llama2-7B, the sparse method achieved an average accuracy of 75.2%, matching the "Sensitive (task, static)" baseline and beating full fine-tuning (74.2%).
  • Memory Efficiency: By combining 0.1% sparsity with 4-bit quantization, they successfully fine-tuned Llama2-7B on a GPU with less than 8GiB of memory.
  • Wall-Clock Speedup: The method achieved a 1.2x to 2.5x speedup in total training time compared to full ZO fine-tuning. This is because updating fewer parameters reduces the computational overhead of perturbations and optimizer steps.
Training and inference speed comparisons showing significant gains from the sensitive sparse method.

Limitations and Future Work

  • Sparse Kernel Optimization: While the theory is sound, the authors note that the latency benefits of sparsity are hardware-dependent. Current deep learning libraries are highly optimized for dense matrix multiplication; achieving the full theoretical speedup of 99.9% sparsity requires more specialized sparse kernels.
  • Mask Refinement: The study primarily uses a static mask. While they show dynamic masks (updating which parameters are "sensitive" during training) provide a slight edge, the overhead of re-calculating sensitivity is currently too high for edge devices.
  • Scaling to Larger Models: While tested on 7B models, the behavior of sensitive parameters in 70B+ models remains an open question.

Summary updated

BibTeX
@misc{guo2024zeroth,
  author = {Wentao Guo and Jikai Long and Yimeng Zeng and Zirui Liu and Xinyu Yang and Yide Ran and Jacob R. Gardner and Osbert Bastani and Christopher De Sa and Xiaodong Yu and Beidi Chen and Zhaozhuo Xu},
  title = {{Zeroth-Order Fine-Tuning of LLMs with Extreme Sparsity}},
  year = {2024},
  eprint = {2406.02913},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2406.02913},
}
Figure