Papers › Fine-Tuning Language Models with Just Forward Passes

Fine-Tuning Language Models with Just Forward Passes

27 May 2023NeurIPS 2023 11arXiv:2305.17333archive 2025-07-28

Sadhika Malladi, Tianyu Gao, Eshaan Nichani, Alex Damian, Jason D. Lee, Danqi Chen, Sanjeev Arora

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.

PaperPDFConference PDFCodeCode Syntology ran

In Syntology View this paper on Syntology: its repositories, every harvested function with whether it ran, its licence and the call to fetch it.

Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2305.17333")

Code

Syntology Ran 9 of 17 code samples harvested from 2 repositories linked to this paper; 8 have no recorded run. Of those that ran: 2 ran · our draft was wrong; 7 ran with no contract checked.

By repository: official repository: 14 samples from 1 repository, 7 ran; community (archive-listed): 3 samples from 1 repository, 2 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

princeton-nlp/mezo officialmentioned in paperpytorchMIT report
liangyuwang/zo2 mentioned on GitHubpytorch report
mathisall/zo-adamu mentioned on GitHubpytorch report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

17 samples harvested; 9 ran; 0 honoured the contract we drafted; 8 have no recorded run. Read from Syntology's graph 2026-09-25; that is when this build read the record, not when the samples ran.

2ran · our draft was wrong
7ran
8unverified

Licence: 0 of the 17 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from 2 repositories linked to this paper, official or community; each sample names its own and says which. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

encode_prompt princeton-nlp/mezo/large_models/utils.py official repository ran MIT (permissive) · 7c5d9ba063f6642c · report
find_module princeton-nlp/mezo/large_models/lora.py official repository ran · our draft was wrong MIT (permissive) · b5adfd6ac99a1b18 · report
forward_wrap_with_option_len princeton-nlp/mezo/large_models/utils.py official repository ran MIT (permissive) · 54a6124d697bc2c2 · report
input_example_to_string princeton-nlp/mezo/medium_models/src/dataset.py official repository ran MIT (permissive) · e768e25ca95f70cd · report
input_example_to_tuple princeton-nlp/mezo/medium_models/src/dataset.py official repository ran MIT (permissive) · fbef70dc7c700501 · report
normalize_answer princeton-nlp/mezo/large_models/metrics.py official repository ran · our draft was wrong fingerprinted MIT (permissive) · e7e75981cb464788 · report
tokenize_multipart_input princeton-nlp/mezo/medium_models/src/dataset.py official repository ran MIT (permissive) · 9a62fa939fc563a4 · report
attn_forward_hook princeton-nlp/mezo/large_models/prefix.py official repository unverified MIT (permissive) · bdb460cb247501dc · report
calculate_metric princeton-nlp/mezo/large_models/metrics.py official repository unverified MIT (permissive) · 84c658f2c9252878 · report
f1 princeton-nlp/mezo/large_models/metrics.py official repository unverified MIT (permissive) · b989d4bce26f77ce · report
get_task princeton-nlp/mezo/large_models/tasks.py official repository unverified MIT (permissive) · f7c384f1e681ea7a · report
prepare_inputs_for_generation princeton-nlp/mezo/large_models/prefix.py official repository unverified MIT (permissive) · 84920a8095dca4fa · report
tensor_all_gather princeton-nlp/mezo/medium_models/src/linearhead_trainer.py official repository unverified MIT (permissive) · c239cb1add74b809 · report
varsize_tensor_all_gather princeton-nlp/mezo/medium_models/src/linearhead_trainer.py official repository unverified MIT (permissive) · 734d0491ecbc7841 · report
BaseOptimizer liangyuwang/zo2/zo2/optimizer/mezo_sgd/zo.py community (archive-listed) ran Apache-2.0 (permissive) · 506b0c89834f1424 · report
MeZOSGD liangyuwang/zo2/zo2/optimizer/mezo_sgd/zo.py community (archive-listed) ran · metamorphic tier: deterministic Apache-2.0 (permissive) · f9a6c1b932010ab6 · report
MeZOSGDConfig liangyuwang/zo2/zo2/optimizer/mezo_sgd/zo.py community (archive-listed) unverified Apache-2.0 (permissive) · 00b3e776ab20cb69 · report

Tasks

In-Context LearningMultiple-choice

1 archive task tag without a task page not shown.

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections