Efficient Contextual LLM Cascades through Budget-Constrained Policy Learning

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

Executive Summary

TREACLE (Thrifty Reasoning via Context-Aware LLM and Prompt Selection) is a reinforcement learning framework designed to intelligently navigate the trade-offs between Large Language Model (LLM) accuracy, latency, and monetary cost. By dynamically selecting the optimal model-prompt combination and using response consistency as a confidence signal, TREACLE achieves up to 85% cost savings while maintaining high performance on complex reasoning tasks.

The Challenge: Navigating the Generative AI Marketplace

Developers today face a "Generative AI marketplace" explosion. They must choose between massive, expensive models like GPT-4 and smaller, cheaper, open-source alternatives like Llama-2. To complicate matters, the way a question is asked—the prompt—significantly impacts both accuracy and cost. For instance, "Chain-of-Thought" (CoT) prompting improves reasoning but consumes more tokens, driving up the bill.

For any given query, it is difficult to know in advance which model or prompt is optimal. Using GPT-4 for a simple addition is a waste of resources, while using a smaller model for a complex logic puzzle often leads to failure. Furthermore, users typically operate under strict total budgets or latency requirements. This paper introduces a method to automate these decisions, treating LLM selection as a strategic, budget-constrained optimization problem.

Introducing TREACLE

The authors propose TREACLE, a framework based on Reinforcement Learning (RL). The system models the problem as a Constrained Markov Decision Process (CMDP), where the objective is to maximize accuracy over a sequence of questions without exceeding a predefined total budget.

The TREACLE framework uses an RL agent to decide whether to return a response, re-query the current model, or escalate to a more powerful one based on state features like budget and response consistency.

Key components of the TREACLE RL agent include:

  • Contextual Awareness: It utilizes query text embeddings to "sense" the difficulty or specific domain of a question.
  • Response Consistency: If a model provides an answer, TREACLE might ask it again (re-query). If the model yields the same answer twice, the agent gains confidence. If the answers vary, it signals that a more capable model might be necessary.
  • Budget Tracking: The agent continuously monitors the remaining budget and adjusts its risk tolerance accordingly.
  • Policy Learning: Using a Deep Q-Network (DQN), the agent learns a dynamic policy: deciding whether to trust a cheaper model's answer or pay for a more expensive, accurate one.

The authors also provide theoretical justification for their "cascade" strategy, proving that ordering models by their cost-normalized accuracy (accuracy per dollar) is the optimal baseline for minimizing total costs.

Key Insights and Performance

The researchers evaluated TREACLE on diverse reasoning benchmarks, including GSM8K (math word problems), CSQA (commonsense reasoning), and LLC (symbolic reasoning), testing against a fleet of models including Llama-2 (7b and 13b), GPT-3.5-turbo, and GPT-4.

  • Re-querying as a "Cheap" Verifier: A standout finding is that asking a mid-tier model the same question twice (with some temperature variance) is often more cost-effective than jumping straight to a top-tier model. Consistent answers from a mid-tier model are highly correlated with correctness.
  • Pushing the Pareto Front: TREACLE does not just pick a single model; it creates a "composite" system that exists on the Pareto front of the accuracy-vs-cost curve, outperforming any individual model-prompt combination.
  • Dynamic Adaptability: Because the state includes the remaining budget, TREACLE naturally becomes more frugal as funds run low and more extravagant when the budget is flush.
TREACLE achieves a superior accuracy-to-cost ratio compared to individual LLMs, effectively pushing the Pareto boundary of what is possible on a budget.

TREACLE consistently outperformed state-of-the-art baselines like FrugalGPT. It achieved cost savings of up to 85% compared to using high-end models exclusively, without significant drops in accuracy. Furthermore, the system proved resilient to distribution shifts; if a test set suddenly became much harder, TREACLE's accuracy remained stable by dynamically allocating more budget to those difficult queries.

Limitations and Future Directions

While highly effective, TREACLE has a few constraints:

  • Reasoning Focus: The current framework focuses on reasoning tasks where answers can be objectively verified or compared for consistency. Extending this to open-ended generative tasks would require new metrics for measuring "consistency."
  • Training Overhead: The RL policy requires an initial collection of query-response pairs to learn the models' characteristics, introducing an upfront computational cost.
  • Privacy Considerations: Future iterations could incorporate privacy into the cost function—for example, assigning a high penalty to sending sensitive data to a remote API versus a lower penalty for local inference.

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