TL;DR
TREACLE is a reinforcement learning-based framework that dynamically routes user queries to the most cost-effective combination of Large Language Model (LLM) and prompting strategy. By treating LLM selection as a budget-constrained policy optimization problem, it achieves up to 85% cost savings compared to single high-end models while maintaining near-peak accuracy.
What Problem Does This Paper Address?
The current LLM landscape is highly fragmented and heterogeneous. Proprietary models like GPT-4 offer top-tier accuracy but come with high monetary costs and latency, while open-source alternatives like Llama-2 are free to run locally but less capable. Furthermore, an LLM's performance depends heavily on the prompting strategy used (e.g., standard vs. Chain-of-Thought).
For users processing a long sequence of queries under a fixed monetary budget or strict latency constraints, choosing the right model and prompt for each individual question is an open challenge. Existing routing methods typically use fixed thresholds and linear cascades without considering the full context of the query, the remaining budget over time, or the option to re-query a model to verify response consistency.
Methods
The authors introduce TREACLE (Thrifty Reasoning via Context-Aware LLM and Prompt election), which models the routing problem as a Constrained Markov Decision Process (CMDP) and solves it using a Deep Q-Network (DQN).
Unlike static routing systems, TREACLE's state vector incorporates rich contextual features:
- Query Text Embeddings: To capture question type and difficulty.
- Response Consistency: Tracking the history and frequency of previous answers for the current query.
- Input/Output Length: To anticipate token costs.
- Normalized Remaining Budget: To adjust risk-tolerance dynamically as the budget depletes.
TREACLE can take three actions for a given query:
- $a_1$: Return the current response and move to the next question.
- $a_2$: Re-query the same model-prompt pair (with a higher temperature to check consistency).
- $a_3$: Escalate to the next, more powerful model-prompt pair in a pre-sorted cascade.
The authors mathematically prove that sorting the cascade options by their cost-normalized accuracy ($\frac{p_k}{c_k}$) minimizes total cost (Proposition 1).
Datasets
The framework was evaluated on three distinct reasoning benchmarks:
- GSM8K: Grade school math word problems requiring multi-step logical reasoning.
- CSQA (CommonsenseQA): Multiple-choice questions testing everyday commonsense knowledge.
- LLC (Last Letter Concatenation): A symbolic manipulation task requiring string concatenation.
Key Insights and Ideas
- The Power of Re-querying: One of the most striking insights is that allowing the system to re-query the same model at a higher temperature to check for answer consistency significantly boosts accuracy at a low cost. The authors prove that a simple "2-consistent" policy (stopping when the same answer appears twice) provides a strong lower bound on optimal performance.
- Dynamic Budget Awareness: TREACLE doesn't just look at the current question; it "thinks ahead." If the remaining budget is high, it gracefully escalates to more powerful models like GPT-4. If the budget is tight, it strategically relies on cheaper models or opts to skip highly uncertain questions to preserve resources for easier ones.
- Cost-Normalized Sorting: Instead of placing the most accurate model first or last blindly, ordering the cascade strictly by the ratio of accuracy to cost yields the theoretical minimum expenditure for a target accuracy.
Key Results
- Massive Cost Reductions: TREACLE achieves up to 85% cost savings compared to using individual high-end models like GPT-4 while matching or exceeding their accuracy boundaries on the Pareto front.
- Outperforming Baselines: It consistently outperforms state-of-the-art cascading baselines like FrugalGPT and standard majority voting across various budget constraints.
- Robustness and Adaptability: TREACLE demonstrates excellent sample efficiency. When new models are introduced or API prices drop, it can adapt via fine-tuning with as few as 300 samples rather than retraining from scratch.
Limitations and Future Work
- Scope of Tasks: The current implementation focuses primarily on reasoning and classification tasks where answer correctness or consistency can be easily quantified (e.g., exact match or multiple choice). Extending this to open-ended generative tasks (like essay writing or code generation) will require more sophisticated semantic similarity metrics to evaluate response consistency.
- Training Data Costs: The RL policy relies on an offline dataset of query-response pairs across all candidate models, the collection of which incurs an upfront cost not accounted for in the online operational budget.
- Future Extensions: The authors plan to incorporate additional dimensions into the cost function, such as data privacy constraints and time-varying network latencies.
Summary updated