Introduction
The rapid proliferation of Large Language Models (LLMs) has provided developers with a diverse menu of APIs, ranging from lightweight models like Phi-3 to massive powerhouses like GPT-4o. While ensembling multiple models is a proven strategy for boosting accuracy, it often leads to prohibitive API costs. Developers are frequently forced to choose between a single expensive model or a static ensemble that may overspend on simple queries.
This paper introduces ThriftLLM, a framework designed to navigate this cost-accuracy trade-off. ThriftLLM dynamically selects and aggregates an ensemble of LLMs to maximize classification accuracy under a strict, user-defined budget. By leveraging a surrogate optimization strategy and an adaptive stopping mechanism, the framework achieves state-of-the-art performance while significantly reducing operational expenses.
The Optimal Ensemble Selection (OES) Problem
The authors formalize the challenge of cost-effective LLM usage as the Optimal Ensemble Selection (OES) problem. Given a specific query, a set of available LLMs with known costs, and a hard budget constraint, the goal is to select a subset of models that maximizes the probability of a correct classification.
Unlike previous cascading methods (e.g., FrugalGPT) that often fail to enforce per-query budgets or ignore the potential of aggregating multiple outputs, ThriftLLM treats the problem as a mathematical optimization. The authors prove that the "correctness probability" of an ensemble is non-submodular, meaning it does not follow simple diminishing returns. This makes the OES problem NP-hard, necessitating a more sophisticated approach than standard greedy selection.
The ThriftLLM Framework
ThriftLLM operates through a multi-stage pipeline that combines historical profiling with real-time adaptive execution.
1. Success Probability Estimation
To make informed decisions, ThriftLLM first clusters historical queries using K-means on high-dimensional embeddings. It profiles the performance of candidate LLMs (e.g., GPT-4o, Gemini, Llama-3) on these clusters to estimate a "success probability" for new, semantically similar queries at runtime.
2. Surrogate Optimization (SurGreedyLLM)
To overcome the non-submodularity of the OES problem, the authors designed a submodular surrogate function that serves as a mathematical upper bound for the true correctness probability. They then employ a modified greedy algorithm on this surrogate, providing a guaranteed approximation of the optimal ensemble within the budget.
3. Maximum Likelihood Aggregation
Rather than relying on a simple majority vote, ThriftLLM uses a maximum likelihood approach. It calculates a "belief value" for each possible class based on the specific success probabilities of the models that predicted it, ensuring that more reliable models carry more weight in the final decision.
4. Adaptive Selection and Early Stopping
At runtime, ThriftLLM queries the selected models sequentially. After each response, it evaluates whether the remaining unqueried models could mathematically change the current prediction. If the current "belief" is strong enough that the remaining budget cannot overturn it, the system halts early, saving significant costs without sacrificing accuracy.
Experimental Evaluation
The authors evaluated ThriftLLM across 10 real-world datasets spanning text classification and entity matching. The text classification tasks covered diverse domains including law, science, and banking.
For the evaluation, 12 commercial LLM APIs were used as candidates, including models from OpenAI, Google, Microsoft, Meta, and Mistral AI.
Key Results
- Superior Accuracy-to-Cost Ratio: ThriftLLM consistently outperformed baselines like FrugalGPT and LLM-Blender. It achieved higher accuracy at lower cost tiers across all tested datasets.
- David Beats Goliath: A strategic ensemble of smaller, cheaper models (such as Phi-3 and Llama-3 8B) frequently outperformed a single GPT-4o query. To match ThriftLLM's performance, a single GPT-4o query often required up to 30x the cost.
- Efficiency Gains: The adaptive stopping mechanism saved between 10% and 40% of the allocated budget per query by recognizing when a consensus was reached early.
- Robustness: The system proved resilient to minor errors in success probability estimation, maintaining stable performance even when historical data was imperfect.
Conclusion and Future Work
ThriftLLM demonstrates that intelligent, budget-aware ensembling is a viable and often superior alternative to relying on single high-cost LLMs. By formalizing the OES problem and introducing submodular surrogate optimization, the authors provide a framework that is both mathematically grounded and practically efficient.
Currently, ThriftLLM is optimized for classification tasks with discrete outputs. The authors identify extending this methodology to open-ended generation and regression tasks as the primary frontier for future research.
Summary updated