TREACLE: Thrifty Reasoning via Context-Aware LLM and Prompt Selection

Xuechen Zhang, Zijian Huang, Ege Onur Taga, Carlee Joe-Wong, Samet Oymak, Jiasi Chen · OpenReview

Abstract

Recent successes in natural language processing have led to the proliferation of large language models (LLMs) by multiple providers. Each LLM offering has different inference accuracy, monetary cost, and latency, and their accuracy further depends on the exact wording of the question (i.e., the specific prompt). At the same time, users often have a limit on monetary budget and latency to answer all their questions, and they do not know which LLMs to choose for each question to meet their accuracy and long-term budget requirements. To navigate this rich design space, we propose TREACLE (Thrifty Reasoning via Context-Aware LLM and Prompt Selection), a reinforcement learning policy that jointly selects the model and prompting scheme while respecting the user's monetary cost and latency constraints. TREACLE uses the problem context, including question text embeddings (reflecting the type or difficulty of a query) and the response history (reflecting the consistency of previous responses) to make smart decisions. Our evaluations on standard reasoning datasets (GSM8K, CSQA, and LLC) with various LLMs and prompts show that TREACLE enables cost savings of up to 85% compared to baselines while maintaining high accuracy. Importantly, it provides the user with the ability to gracefully trade off accuracy for cost.

Introduction

The current generative AI landscape offers a vast array of Large Language Models (LLMs), ranging from lightweight open-source models like Llama-2 to powerful proprietary models like GPT-4. These models exhibit significant variance in monetary cost and latency. Furthermore, the prompting strategy—such as "Chain-of-Thought" (CoT)—can drastically alter both the accuracy and the token-based cost of a response.

Users typically operate under budget constraints, seeking maximum accuracy for a sequence of queries without exceeding a total monetary or time limit. Existing solutions, such as simple model cascades, often overlook the specific context of the question, the impact of diverse prompting strategies, or the dynamic management of a remaining budget. TREACLE addresses these gaps by intelligently navigating the trade-off between accuracy and cost through joint model and prompt selection.

Methodology: Reinforcement Learning for LLM Selection

TREACLE treats the problem of LLM and prompt selection as a Constrained Markov Decision Process (CMDP). Instead of relying on static rules, it employs a Reinforcement Learning (RL) policy—specifically a Deep Q-Network—to make dynamic decisions for each query.

The TREACLE framework uses an RL agent to choose between returning a response, re-querying for consistency, or escalating to a more powerful model based on the current state.

The RL agent makes three primary decisions:

  1. Action $a_1$ (Return Response): Finalize the current answer and proceed to the next question.
  2. Action $a_2$ (Re-query): Query the same model-prompt pair again to evaluate response consistency.
  3. Action $a_3$ (Escalate): Move to a more powerful and expensive model-prompt combination within a pre-defined cascade.

The decision-making process is informed by a comprehensive State Vector, which includes query text embeddings to capture difficulty, response consistency metrics, the remaining budget, and input/output lengths to estimate costs.

Experimental Setup

The framework was evaluated across three diverse reasoning benchmarks:

  • GSM8K: Grade school math word problems requiring multi-step reasoning.
  • CSQA: Commonsense multiple-choice questions.
  • LLC (Last Letter Concatenation): A symbolic reasoning task.

Key Insights and Results

A central finding is that joint selection of the model and prompt is significantly more efficient than selecting them independently. For instance, a smaller model utilizing a complex prompt (like CoT) can often outperform a larger model using a simple prompt for specific tasks.

TREACLE pushes the Pareto front, achieving a superior accuracy-to-cost ratio compared to individual LLM configurations.

Key results include:

  • Cost Efficiency: TREACLE achieves cost reductions of up to 85% compared to using high-end models exclusively, with minimal impact on accuracy.
  • Consistency as a Proxy for Truth: The "re-querying" mechanism allows the system to stop early if a cheaper model provides consistent answers, reserving the budget for more ambiguous cases.
  • Dynamic Budget Awareness: By monitoring the remaining budget, the RL agent adapts its strategy mid-stream, allowing for more "extravagant" spending on difficult questions if earlier queries were resolved cheaply.
  • Superior Performance: TREACLE consistently outperforms state-of-the-art baselines like FrugalGPT by leveraging full question context and re-querying capabilities.

Conclusion and Future Work

TREACLE demonstrates that context-aware RL policies can effectively manage the complexities of the LLM marketplace. While currently focused on tasks with verifiable answers, future work could extend this to open-ended generative tasks by developing new consistency metrics. Additionally, the framework's cost function could be expanded to include privacy constraints, favoring local models for sensitive data.

Summary updated

BibTeX
@inproceedings{zhang2024treacle,
  author = {Xuechen Zhang and Zijian Huang and Ege Onur Taga and Carlee Joe-Wong and Samet Oymak and Jiasi Chen},
  title = {{TREACLE: Thrifty Reasoning via Context-Aware LLM and Prompt Selection}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=aDQlAz09dS},
}
Figure