FrugalGPT: How to Use Large Language Models While Reducing Cost and Improving Performance

Lingjiao Chen, Matei Zaharia, James Zou · Submission to ICLR 2024 · Rejected

TL;DR

FrugalGPT is an algorithmic framework that slashes Large Language Model (LLM) inference costs by up to 98% while maintaining or even improving performance. It achieves this by "cascading" queries through a sequence of models—starting with cheap, lightweight APIs and only escalating to expensive powerhouses like GPT-4 when a specialized "judge" determines the initial response is insufficient.

The Challenge: Navigating the LLM Marketplace

The current "LLM Marketplace" is a wild west of heterogeneous pricing and performance. Developers can choose from dozens of APIs (GPT-4, Gemini, Claude, etc.) where costs vary by up to two orders of magnitude.

This environment presents two major challenges:

  1. Cost vs. Performance Trade-off: While massive models like GPT-4 generally perform better, they are prohibitively expensive for high-volume applications.
  2. No "Universal" Winner: Surprisingly, the most expensive model isn't always the best for every specific query. Smaller, cheaper models can sometimes provide the correct answer where a larger model hallucinates or errs.

Currently, most practitioners simply pick one "best" model and send all queries to it. This approach is both financially and computationally inefficient.

The FrugalGPT Framework

To address these inefficiencies, the authors propose FrugalGPT, a modular pipeline consisting of three main components:

  1. LLM Router: Instead of relying on a single model, FrugalGPT uses a "cascade." The router determines the optimal order in which to call different LLM APIs (e.g., try Gemini Flash 8B first, then Llama 3 70B, then GPT-4 Turbo).
  2. Generation Scorer: This is the "brain" of the system. It’s a lightweight, specialized model (such as a fine-tuned DistilBERT) that evaluates the quality of a generated response after it’s produced. It is significantly cheaper and faster than the LLMs it judges.
  3. Stop Judger: This component uses the score from the Scorer and compares it against a learned threshold. If the score is high enough, it "accepts" the answer and returns it to the user. If not, it triggers the next, usually more expensive, model in the cascade.
FrugalGPT Overview: Contrasting existing single-model usage with the FrugalGPT cascade, alongside pairwise comparisons and cost-performance tradeoffs.

The Optimization Secret Sauce: Finding the best sequence of models and the right "acceptance" thresholds is an NP-hard problem. The authors developed a specialized optimizer using Search Space Pruning (based on a metric they call Maximum Performance Improvement, or MPI) to efficiently find the best strategy for any given user budget.

Key Insights and Results

The framework was evaluated across several diverse natural language tasks, including financial news classification (HEADLINES), legal statement classification (OVERRULING), and conversational QA (COQA). The results highlight several core advantages:

  • The "Easy Query" Hypothesis: A vast majority of real-world queries are relatively simple. FrugalGPT exploits this by letting inexpensive models (e.g., $1.50/10M tokens) handle the "easy" stuff, reserving the premium models (e.g., $300/10M tokens) for difficult edge cases.
  • Massive Cost Savings: FrugalGPT matched the performance of the best individual models with cost reductions ranging from 52.3% (SCIQ) to a staggering 98.3% (HEADLINES). On the HEADLINES task, FrugalGPT resolved 83.4% of queries using only the cheapest models in the chain.
  • Accuracy Boosts: Because different models have different "blind spots," a cascade can actually outperform the best individual model. When given the same budget as a single high-end model, FrugalGPT improved accuracy by up to 4% by leveraging the collective strengths of multiple models.
  • Post-Query Scoring is Key: Unlike previous methods that tried to guess query difficulty before asking an LLM, FrugalGPT evaluates the actual answer. This "post-query" evaluation is much more reliable for generative tasks.

Limitations and Future Work

While highly effective, FrugalGPT does come with trade-offs:

  • Latency: The primary trade-off is time. If a query is difficult and fails the first two models in a cascade, the user must wait for sequential API calls, increasing latency.
  • Task-Specific Training: The Generation Scorer needs to be trained on labeled data for the specific task at hand to be effective.
  • Black-Box Constraints: The current system treats APIs as black boxes. If providers shared internal signals (like token log-probabilities), the scoring could be even more accurate.

Future iterations of the framework aim to consider other critical factors like fairness, environmental impact, and uncertainty quantification in high-stakes applications.

Summary updated

BibTeX
@misc{chen2023frugalgpt,
  author = {Lingjiao Chen and Matei Zaharia and James Zou},
  title = {{FrugalGPT: How to Use Large Language Models While Reducing Cost and Improving Performance}},
  year = {2023},
  eprint = {2305.05176},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2305.05176},
}
Figure