QPO: Query-dependent Prompt Optimization via Multi-Loop Offline Reinforcement Learning

Yilun Kong, Hangyu Mao, Qi Zhao, Bin Zhang, Jingqing Ruan, Li Shen, Yongzhe Chang, Xueqian Wang, Rui Zhao, Dacheng Tao

Introduction

Prompt engineering is essential for guiding Large Language Models (LLMs) toward accurate outputs. However, conventional methods typically rely on task-level optimization, seeking a single "best" prompt for an entire dataset. This approach is often suboptimal because individual queries within a task may require different instructions or contextual hints. Furthermore, existing "online" optimization methods, such as APE or RLPrompt, incur significant costs due to thousands of trial-and-error interactions with expensive target LLMs like GPT-4.

To address these challenges, this paper introduces QPO (Query-dependent Prompt Optimization). QPO shifts the paradigm from task-level to query-specific strategies by utilizing a multi-loop offline reinforcement learning (RL) framework. By fine-tuning a small policy model, QPO generates optimal prompts tailored to specific inputs, achieving state-of-the-art performance while drastically reducing interaction costs.

Methodology: Multi-Loop Offline RL

QPO treats prompt optimization as a query-dependent decision process. The framework utilizes a small "policy model" (e.g., GPT-2, 124M) trained via offline reinforcement learning to act as a prompt generator.

The QPO framework workflow, illustrating dataset construction, offline RL policy training, and multi-loop augmentation.

Key Components

  • Decision Transformer (DT) Formulation: Prompt generation is modeled as a single-step decision process. The policy model takes a query and a "target reward" as input to autoregressively predict optimal prompt tokens.
  • Multi-Faceted Reward Design: The reward function incorporates query-level correctness, a perplexity penalty to ensure linguistic coherence, and task-level average accuracy.
  • Multi-Loop Augmentation (MLA): This "bootstrapping" mechanism allows the policy model to generate new, high-quality prompts for unseen queries. These are evaluated by the target LLM and integrated back into the training set, enabling efficient exploration of the prompt space without continuous real-time feedback.

Experimental Results

The researchers evaluated QPO across diverse benchmarks, including Natural Language Understanding (NLU) tasks (AG News, BoolQ, IMDB, etc.) and mathematical reasoning (GSM8K, SVAMP). Target models included Llama2-7b-chat for NLU and GPT-3.5-turbo/GPT-4o for math tasks.

Zero-Shot and Few-Shot accuracy comparison across various NLU and reasoning benchmarks, showing QPO's consistent performance gains.

Performance and Efficiency

  • Superior Accuracy: In zero-shot NLU settings, QPO achieved an average accuracy of 70.9%, outperforming task-level optimizers like APE (62.9%) and previous offline methods like Prompt-OIRL (68.5%).
  • Mathematical Reasoning: On the GSM8K benchmark, QPO reached 90.3% accuracy with GPT-3.5, surpassing standard Chain-of-Thought (88.0%).
  • Cost Efficiency: QPO demonstrated a nearly 6x improvement in efficiency. For the AG News task, QPO required only 0.291 GPU hours of interaction cost, compared to 1.761 GPU hours for APE.
  • Generalization: Policy models trained on data from one LLM (e.g., Llama2) successfully generalized to other models like Vicuna, suggesting that the learned prompting strategies have universal utility.

Conclusion and Future Work

QPO demonstrates that query-dependent prompt generation significantly raises the performance ceiling for LLMs compared to one-size-fits-all instructions. By leveraging offline data and multi-loop augmentation, it provides a cost-effective alternative to online optimization. Future research may explore multi-step MDP formulations for complex reasoning and the application of QPO to multi-modal domains where inference costs are even higher.

Summary updated

BibTeX
@article{kong2025qpo,
  author = {Yilun Kong and Hangyu Mao and Qi Zhao and Bin Zhang and Jingqing Ruan and Li Shen and Yongzhe Chang and Xueqian Wang and Rui Zhao and Dacheng Tao},
  title = {{QPO: Query-dependent Prompt Optimization via Multi-Loop Offline Reinforcement Learning}},
  journal = {Trans. Mach. Learn. Res.},
  year = {2025},
  url = {https://openreview.net/forum?id=DZu4gLIZ6o},
}
Figure