Manuscript Offprint

arXiv:2610.12566

Sample-Adaptive Zeroth-Order Post-Training

Haiyuan Wan, Yanyi Li, Weicheng Lin, Cong Fang

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

Zeroth-order (ZO) optimization offers a memory-efficient alternative to backpropagation for fine-tuning large language models. However, existing ZO methods typically sample training examples uniformly, overlooking their evolving importance and leaving avoidable estimation variance. To address this limitation, we propose Sample-Adaptive Zeroth-Order Optimization (SAZO), which learns sample importance online and adaptively allocates queries to accelerate convergence. SAZO extracts gradient-norm information from existing directional differences to estimate sample importance without access to true gradients. Furthermore, to track evolving importance from sparse minibatch feedback, SAZO maintains per-example exponential moving averages that aggregate observations across updates. The method requires no additional model evaluations and only O(N)O(N) additional scalar state compared with MeZO. We prove that SAZO asymptotically matches the leading convergence term of the minimum-variance sampling oracle, and achieves a strictly faster convergence rate than standard methods. Extensive experiments across four model families demonstrate improved average downstream performance and up to 6×6\times faster convergence to the same training loss in terms of query count.

1 Introduction

Fine-tuning adapts pre-trained large language models (LLMs) to diverse downstream tasks, including sentiment analysis, natural language inference, and question answering (Devlin et al., 2019). However, standard fine-tuning incurs substantial memory overhead from stored activations, gradients, and optimizer states (Li et al., 2026), requiring up to 12×12\times the inference memory in the settings evaluated by Malladi et al. (2023). Parameter-efficient fine-tuning (PEFT), including prefix tuning (Li and Liang, 2021) and low-rank adaptation (LoRA) (Hu et al., 2021), reduces trainable parameters but still stores activations for backpropagation. To overcome this remaining activation-memory bottleneck, zeroth-order (ZO) methods such as MeZO bypass backpropagation and estimate updates from two forward evaluations, achieving a memory footprint close to inference (Malladi et al., 2023). This memory advantage comes with an optimization challenge: the resulting gradient estimates remain noisy, limiting the convergence speed of ZO fine-tuning (Nesterov and Spokoiny, 2017).

Inspired by first-order adaptive optimizers such as Adam (Kingma and Ba, 2015), mainstream approaches to accelerating ZO optimization focus on adaptation in parameter space. HiZOO (Zhao et al., 2025c) and PaZO (Zhao et al., 2025b) use Hessian-informed preconditioning, ZO-AdaMM (Chen et al., 2019) and R-AdaZO (Shu et al., 2025) adapt coordinate-wise update scales using historical moment estimates, and LOZO (Chen et al., 2025) exploits low-rank perturbation subspaces. However, ZO methods face a fundamental information bottleneck: each directional query reveals only a scalar projection rather than a full gradient. Identifying an unrestricted d-dimensional adaptation vector requires Ω(d)\Omega(d) such observations, so the cost of learning reliable parameter-wise adaptation can offset its intended acceleration. We therefore ask:

∗^{*}Corresponding author: fangcong@pku.edu.cn.

A PREPRINT

(a) SST-2 gradient norms

Figure

(b) Cumulative regret

Figure

(c) Optimization

Figure

Figure 1: From sample heterogeneity to allocation regret and optimization. (a) Per-example gradient norms on SST-2 at initialization, 10K, and 30K updates, normalized by the initial median. Points retain the sample order induced by the initial norms, showing both cross-sample heterogeneity and temporal changes. (b) Sampling regret is the excess gradient-estimator variance over the variance-minimizing allocation (see Appendix E.5 for definitions and detailed settings); SAZO reduces this quantity versus uniform and fixed initial-oracle sampling. (c) The improved allocation accelerates loss reduction.

A. Is there additional information in ZO queries that current optimizers leave untapped?

B. If so, how can we adaptively exploit this information to accelerate ZO convergence?

Since each update uses only a small subset of the training data, its effectiveness depends in part on which examples are selected. Our empirical analysis identifies an untapped source of information: the evolving importance of individual training examples. Their gradient norms differ substantially and change during training (Figure 1(a); Appendix E.5), suggesting that queries need not be equally valuable across examples. Uniform sampling overlooks this heterogeneity, leaving avoidable estimation variance. To use this information for query allocation, a natural approach is importance sampling, inspired by first-order methods (Katharopoulos and Fleuret, 2018; Borsos et al., 2018; El Hanchi and Stephens, 2020): allocate more queries to examples with larger gradient norms. Although sampling heterogeneity also exists in first-order methods, we argue that zeroth-order algorithms are more sensitive to it, since the estimated gradient variance of zeroth-order methods using only function-value access is much larger than that of first-order methods 2^{2}.

However, applying importance sampling principle to ZO fine-tuning presents two challenges. First, sample importance is not directly observable. The variance-minimizing allocation depends on per-example gradient norms, pi,t⋆∝∥∇fi(xt)∥p_{i,t}^{\star} \propto \|\nabla f_i(x_t)\|, whereas ZO queries reveal only random directional measurements. We therefore use the scaled magnitudes of existing directional differences to estimate these norms; their expectations approach the corresponding gradient norms as the perturbation radius vanishes, requiring no additional queries. Second, evolving importance must be tracked from sparse minibatch feedback. Each update reveals importance information only for examples in the sampled minibatch, while the importance of all examples may change as the model evolves. We therefore maintain per-example exponential moving averages to combine newly observed information with historical estimates, allowing importance tracking across intermittent observations. Uniform exploration provides opportunities to refresh infrequently sampled examples.

Together, these designs yield Sample-Adaptive Zeroth-Order Optimization (SAZO). The learned scores guide sampling, while inverse-probability weighting preserves the expected full-data finite-difference update. SAZO requires no additional model evaluations and only O(N)O(N) scalar state for N training examples. The benefit of tracking rather than fixing this allocation is visible in Figure 1(b): SAZO incurs lower relative cumulative sampling regret than uniform sampling and an oracle allocation fixed at initialization. This improved allocation also translates into faster training-loss reduction in Figure 1(c), connecting the recovered sample information to optimization progress.

Our main contributions are:

• We propose SAZO, which estimates sample importance from existing directional differences without extra model evaluations and tracks its evolution from sparse minibatch feedback using per-example exponential moving averages, requiring only O(N)O(N) scalar state.

2^{2}The variance is actually Ω(d)\Omega(d) times larger in the worst case.

A PREPRINT

• We prove that SAZO asymptotically matches the leading convergence term of the minimum-variance sampling oracle, and achieves a strictly faster convergence rate than standard methods.

• We conduct extensive experiments across four model families, demonstrating improved average downstream performance at MeZO-like memory and per-update cost. SAZO achieves up to 6×6\times query-count speedup over MeZO at the same training loss.

References (71)