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 · DOI

Introduction

Prompt engineering is the primary lever for performance in Large Language Models (LLMs). However, most current optimization methods suffer from two major flaws: task-level myopia and prohibitive costs. Traditional methods search for a single "best" prompt for an entire task, ignoring that a prompt ideal for one query might fail for another. Furthermore, online optimization methods like APE or RLPrompt require thousands of expensive interactions with target LLMs, making them impractical for many researchers.

To bridge this gap, we present QPO (Query-dependent Prompt Optimization). QPO moves beyond "one-size-fits-all" prompts by using multi-loop offline reinforcement learning to generate custom prompts for every individual query, achieving state-of-the-art performance at a fraction of the traditional computational cost.

The QPO Framework

The core of the QPO framework treats prompt generation as a single-step decision-making process within a Reinforcement Learning (RL) context. Instead of using a massive LLM to optimize another, QPO fine-tunes a small, efficient policy model (e.g., GPT-2, 124M parameters) to act as a specialized prompt generator.

The QPO framework utilizes a multi-loop offline reinforcement learning approach to iteratively refine query-specific prompts.

The process is built on Multi-Loop Augmentation (MLA), which involves three key stages:

  1. Offline RL Training: Utilizing the Decision Transformer paradigm, the model learns to predict the best prompt (action) given a specific query (state) and a target reward.
  2. Iterative Augmentation: The policy generates novel prompts for new queries. Only high-potential candidates are evaluated on the target LLM, and these high-quality samples are added back into the training set to bootstrap the model.
  3. Dual-Reward Design: The system uses query-level rewards to measure specific answer correctness (including a perplexity penalty in zero-shot settings to encourage confidence) and task-level rewards to track average performance across the dataset.

Experimental Results

QPO was evaluated across a wide array of challenges, including Natural Language Understanding (NLU) tasks (AG News, BoolQ, IMDB, HellaSwag) and mathematical reasoning (GSM8K, SVAMP). It was tested against various target LLMs, including Llama2, GPT-3.5-turbo, and GPT-4o.

Performance Gains

QPO demonstrated superior accuracy, outperforming baselines like APE and Prompt-OIRL by an average of 7.2% in zero-shot and 3.3% in few-shot scenarios on NLU tasks. In mathematical reasoning, QPO reached an average accuracy of 88.6%, significantly higher than the 85.6% achieved by the next best method.

Radar charts comparing QPO against baselines across multiple NLU tasks in both zero-shot and few-shot settings.

Efficiency and Robustness

Beyond accuracy, QPO is remarkably cost-efficient. In a head-to-head comparison on AG News, QPO required only 0.291 GPU hours for interaction costs, compared to 1.761 hours for APE—a nearly 6x reduction. The system also proved robust, showing consistent gains even when the initial prompt pool was scarce.

Insights and Future Work

A key finding of this research is the power of "mediocre" data; offline RL can capture specific query-prompt relationships that work even if a prompt is suboptimal on average. Furthermore, the policy model exhibits strong cross-model generalization, suggesting it learns fundamental instruction-following logic rather than over-fitting to specific LLM quirks.

While current iterations require ground-truth labels for reward calculation, future work will explore using Inverse Reinforcement Learning to learn reward models directly from data. This could expand QPO's utility to open-ended generative tasks and complex modalities like text-to-image or text-to-video generation.

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