Efficient Contextual LLM Cascades through Budget-Constrained Policy Learning

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

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 and the response history to make smart decisions. Our evaluations on standard reasoning datasets (GSM8K, CSQA, and LLC) show that TREACLE enables cost savings of up to 85% compared to baselines while maintaining high accuracy.

Introduction: Navigating the Generative Marketplace

The current AI landscape is a "generative marketplace" filled with models of varying capabilities and costs—from lightweight, open-source models like Llama-2 to expensive, high-performance APIs like GPT-4. Furthermore, the way you ask a question (the prompt) significantly impacts both the cost (token count) and the accuracy (e.g., Chain-of-Thought reasoning).

Users face a difficult optimization problem: How do you choose the right model and the right prompt for every single query to stay under budget while getting the best possible answers? Existing "LLM cascades" typically route queries from cheap to expensive models based on simple thresholds. However, they often ignore the impact of different prompting schemes, lack a mechanism to handle long-term budget constraints across thousands of queries, and don't effectively use the "context" of the question to make routing decisions.

Methodology: The TREACLE Framework

The authors propose TREACLE (Thrifty Reasoning via Context-Aware LLM and Prompt Selection), which treats LLM routing as a Constrained Markov Decision Process (CMDP).

The TREACLE framework architecture: An RL agent selects (model, prompt) pairs based on query context, response history, and remaining budget.

Key components include:

  • The State Space: Unlike simple cascades, TREACLE looks at the "full context": the text embedding of the question (to gauge difficulty), the history of previous responses (to check for consistency), the remaining budget, and current token lengths.
  • Joint Selection: TREACLE doesn't just pick a model; it picks a (Model, Prompt) pair. It considers options like "Standard," "Domain Expert," and "Chain-of-Thought (CoT)" prompts.
  • Policy Learning: They use a Deep Q-Network (DQN) to learn a policy that decides whether to return the current answer, re-query the same model (to check for consistency), or upgrade to a more powerful model/prompt combination.
  • Optimal Ordering: Theoretically, the authors prove that the most efficient way to order a cascade is by cost-normalized accuracy (accuracy divided by cost). TREACLE follows this ordering to minimize "excess cost."

Experimental Evaluation

The framework was evaluated on three diverse reasoning benchmarks: GSM8K (grade school math), CSQA (commonsense multiple-choice), and LLC (symbolic reasoning). The models used in the experiments included Llama-2 (7b, 13b), GPT-3.5-turbo, and GPT-4/GPT-4-turbo.

Key Results and Insights

TREACLE demonstrates that intelligent routing can significantly lower the barrier to high-performance AI.

Accuracy vs. Total Cost: TREACLE (blue line) provides a superior trade-off curve, achieving high accuracy at significantly lower costs than individual high-end models.
  • Massive Cost Reduction: TREACLE achieved up to 85% cost savings on GSM8K compared to individual high-end LLMs while maintaining high accuracy.
  • The Power of Consistency: One of the most effective signals for "truth" is consistency. If a model gives the same answer twice, it is highly likely to be correct. TREACLE learns to exploit this, often re-querying a cheaper model rather than immediately jumping to an expensive one.
  • Context Matters: By using query embeddings, TREACLE can "sense" if a question is particularly difficult. If the budget is healthy, it might skip the "cheap" models entirely for a hard math problem, saving the latency of multiple failed attempts.
  • Graceful Trade-offs: TREACLE provides a "Pareto front" for users. You can explicitly set a budget, and the RL policy will automatically become more "thrifty" or "generous" with model selection to meet that target.

Conclusion and Future Work

While TREACLE excels at reasoning tasks with verifiable answers, future work will focus on expanding to open-ended generative tasks where consistency is harder to define. Additionally, the authors suggest incorporating privacy into the cost function—preferring local models for sensitive data—and accounting for the training costs of the RL policy itself.

Summary updated

BibTeX
@inproceedings{zhang2024efficient,
  author = {Xuechen Zhang and Zijian Huang and Ege Onur Taga and Carlee Joe‐Wong and Samet Oymak and Jiasi Chen},
  title = {{Efficient Contextual LLM Cascades through Budget-Constrained Policy Learning}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=aDQlAz09dS},
}
Figure