When Gradient Descent Meets Derivative-Free Optimization: A Match Made in Black-Box Scenario

Chengcheng Han, Liqing Cui, Renyu Zhu, Jianing Wang, Nuo Chen, Qiushi Sun, Xiang Li, Ming Gao

Abstract

Large pre-trained language models (PLMs) are increasingly deployed as "Model-as-a-Service" (MaaS), where internal parameters and gradients are inaccessible to users. This "black-box" nature hinders traditional gradient-based fine-tuning, necessitating derivative-free optimization (DFO) methods which often suffer from lower efficiency and performance. We present GDFO (Gradient Descent and Derivative-Free Optimization), a hybrid framework that bridges the performance gap between gradient-based and gradient-free tuning. By leveraging knowledge distillation to create a differentiable student model, GDFO enables gradient-based prompt generation while simultaneously utilizing DFO to refine prompts against the target black-box model. Our experiments across seven benchmark datasets demonstrate that GDFO consistently outperforms state-of-the-art black-box methods and even some gradient-based baselines in few-shot settings.

Introduction

As large-scale pre-trained language models like GPT-3 and ERNIE become central to NLP, they are frequently served via APIs in a "Model-as-a-Service" (MaaS) paradigm. In this scenario, the model is a black box: users can query the model with inputs and receive outputs, but they cannot access internal parameters or gradients. Standard fine-tuning, which relies on backpropagation, is impossible without white-box access.

Current solutions typically rely on Black-Box Tuning (BBT), which uses derivative-free optimization (DFO) to find optimal "continuous prompts"—vectors added to the input. However, DFO is generally less efficient than gradient descent, leading to a significant performance gap compared to traditional "white-box" tuning.

Methodology: The GDFO Framework

GDFO addresses the limitations of pure DFO by introducing a two-step hybrid approach to optimize task-specific continuous prompts.

Step 1: Knowledge Distillation

Since the teacher model (the black box) is not differentiable, GDFO first trains a local, smaller student model (e.g., BERT-Large) to mimic the teacher's output distributions. This student model serves as a differentiable proxy, capturing the teacher's behavior and allowing for gradient-based training.

Step 2: Hybrid Optimization

GDFO optimizes a final prompt $p$ by combining two distinct components:

  1. $p_{GD}$: A prompt generated by a "Prompt Generator" network, which is trained via gradient descent through the differentiable student model.
  2. $Az$: A prompt component optimized via CMA-ES (a popular derivative-free evolution strategy) by directly querying the black-box teacher model.

The final prompt is a weighted sum: $p = \alpha p_{GD} + (1 - \alpha)(p_0 + Az)$. This hybrid approach allows the system to benefit from the fast convergence of gradient descent while receiving direct, corrective feedback from the actual target model via DFO.

The overall architecture of GDFO, illustrating the two-step process of knowledge distillation and hybrid prompt optimization.

Experimental Setup

The researchers evaluated GDFO on seven benchmark datasets covering four types of NLP tasks: sentiment analysis (SST-2, Yelp Polarity), topic classification (AG’s News, DBPedia), natural language inference (SNLI, RTE), and paraphrasing (MRPC). All experiments were conducted in a 16-shot setting, where the model only had access to 16 training examples per class.

Results and Discussion

GDFO consistently outperformed previous state-of-the-art black-box methods and even some gradient-based methods in the few-shot regime.

Performance Gains

GDFO achieved an average accuracy of 81.85% across all tasks, surpassing the best gradient-free baseline, BBTv2 (79.01%), and the best gradient-based baseline, LoRA (78.01%). Notably, on the SNLI dataset, GDFO outperformed BBTv2 by 5.26%, demonstrating its effectiveness on complex reasoning tasks.

Accuracy comparison on AG's News and DBPedia datasets. GDFO (red) consistently outperforms pure gradient-free (BBT) and gradient-based (Adapter, LoRA) methods.

Key Insights

  • Distillation as a Bridge: Knowledge distillation acts as a way to "unlock" gradient descent for black-box models by creating a differentiable "map" of the teacher's behavior.
  • Hybrid Synergy: Gradient descent provides a strong global direction based on the student's knowledge, while DFO provides local corrections based on the teacher's actual behavior.
  • Architecture Sensitivity: GDFO performs best when the student and teacher share similar architectures (e.g., both encoder-only), as the student can more accurately capture the teacher's inductive biases.

Conclusion

GDFO presents a novel way to optimize black-box models by combining the strengths of gradient descent and derivative-free optimization. While it introduces some initial computational overhead due to student model training, its superior performance in few-shot settings makes it a compelling choice for MaaS applications. Future work will explore extending this hybrid approach to sequence labeling and text generation tasks.

Summary updated

BibTeX
@inproceedings{han2023when,
  author = {Chengcheng Han and Liqing Cui and Renyu Zhu and Jianing Wang and Nuo Chen and Qiushi Sun and Xiang Li and Ming Gao},
  title = {{When Gradient Descent Meets Derivative-Free Optimization: A Match Made in Black-Box Scenario}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
  doi = {10.18653/v1/2023.findings-acl.55},
}
Figure