Fine-Tuning Language Models with Just Forward Passes

Sadhika Malladi, Tianyu Gao, Eshaan Nichani, Alex Damian, Jason D. Lee +2 more
5/27/2023
cs.LGcs.CL

No official code found. Best implementation: princeton-nlp/MeZO (1,171 stars, MIT, last commit 2024-01-11). 1 more below.

Abstract

Fine-tuning language models (LMs) has yielded success on diverse downstream tasks, but as LMs grow in size, backpropagation requires a prohibitively large amount of memory. Zeroth-order (ZO) methods can in principle estimate gradients using only two forward passes but are theorized to be catastrophically slow for optimizing large models. In this work, we propose a memory-efficient zerothorder optimizer (MeZO), adapting the classical ZO-SGD method to operate in-place, thereby fine-tuning LMs with the same memory footprint as inference. For example, with a single A100 80GB GPU, MeZO can train a 30-billion parameter model, whereas fine-tuning with backpropagation can train only a 2.7B LM with the same budget. We conduct comprehensive experiments across model types (masked and autoregressive LMs), model scales (up to 66B), and downstream tasks (classification, multiple-choice, and generation). Our results demonstrate that (1) MeZO significantly outperforms in-context learning and linear probing; (2) MeZO achieves comparable performance to fine-tuning with backpropagation across multiple tasks, with up to 12x memory reduction and up to 2x GPU-hour reduction in our implementation; (3) MeZO is compatible with both full-parameter and parameter-efficient tuning techniques such as LoRA and prefix tuning; (4) MeZO can effectively optimize non-differentiable objectives (e.g., maximizing accuracy or F1). We support our empirical findings with theoretical insights, highlighting how adequate pre-training and task prompts enable MeZO to fine-tune huge models, despite classical ZO analyses suggesting otherwise.

View on arXivView PDF

Code Implementations(2)

princeton-nlp/MeZOCommunity100%
MIT

[NeurIPS 2023] MeZO: Fine-Tuning Language Models with Just Forward Passes. https://arxiv.org/abs/2305.17333

1,17189Shell, PythonMay 22, 20232 years agoMIT
vvvm23/mezo-jaxCommunity62%
Apache-2.0

JAX implementation of "Fine-Tuning Language Models with Just Forward Passes"

192PythonJun 1, 20233 years agoApache-2.0

Similar Papers

Cite this paper

@article{malladi2023finetuning,
  title  = {Fine-Tuning Language Models with Just Forward Passes},
  author = {Sadhika Malladi and Tianyu Gao and Eshaan Nichani and Alex Damian and Jason D. Lee and Danqi Chen and Sanjeev Arora},
  year   = {2023},
  eprint = {2305.17333},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2305.17333v3},
  journal = {NEURIPS 2023 2023}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2305.17333.svg)](https://codeofpaper.com/paper/2305.17333)

Discussion