LLM Inference Model Selection: Balancing Quality, Cost, and Latency
This article explains how to choose large language models for inference by treating quality, cost, and latency as a three-way tradeoff rather than searching for a single best model. It covers how to split latency into time to first token (TTFT) and output throughput (TPS), how to mitigate slow multi-turn output with prompt reuse, caching, and batching, and how to use tiered routing so different models handle different task complexity. It also outlines a practical evaluation approach based on real sample sets and P95 metrics, with automatic fallback for reliability. The goal is to help teams make model selection decisions based on measurable indicators instead of intuition.
1. The Core Problem: A Set of Tradeoffs, Not a Single “Best” Model
In real engineering decisions, many teams treat model comparison as running a leaderboard and picking the highest score. Production constraints are far more complex than any leaderboard: the same business may include user-facing real-time interactions, offline batch jobs, and scheduled tasks; it may require stable, usable output while also being limited by token budgets and concurrency quotas. So “which model is better” often has no definitive answer. The right question is: within the triangle of quality, cost, and latency, which one am I willing to give up?
The widely accepted cost-quality-latency triangle states that all three are hard to optimize at the same time. Mapping it to lightweight model selection produces a clear comparison table (the table below is a general capability profile, not a specific product benchmark):
| Model positioning | Quality | Cost | Latency |
|---|---|---|---|
| Balanced | Medium | High | Low |
| Quality-first | High | Medium | High |
| Cost-first | Medium | Low | High |
No single tier can fill all three columns at once. A quality-first model works well as a “near-flagship” for complex reasoning; a cost-first model suits high-volume routine work; a balanced model is friendlier for interactive experiences. The art of selection is to first decide which tier the business falls into, then lock in the model accordingly.
2. Split Latency into Two Parts: TTFT and Throughput
What many people call “slow” is actually two different phenomena that must be measured separately; otherwise, optimization efforts go in the wrong direction.
- Time to first token (TTFT): the time from sending a request to receiving the first output token. It shapes the impression of “I clicked and nothing happened” and is critical for real-time interaction.
- Output throughput (TPS): the number of tokens generated per second afterward. It shapes the impression of long text “dribbling out in small steps” and has a major impact on long-form generation and code completion.
One model may have a fast first token but low throughput, showing “a crisp start, then a slowdown”; another may have a high first-token time but acceptable throughput, showing “a wait, then smooth output.” Treating the two as the same thing leads to the vague conclusion that “everything is slow.” In engineering, you should instrument separate metrics for P50/P95 rather than looking only at averages.
# Example: measure time to first token and output throughput separatelyimport timedef measure_stream(client, messages):t0 = time.perf_counter()first_token_at = Nonetokens = 0for chunk in client.stream_chat(messages):if first_token_at is None:first_token_at = time.perf_counter()tokens += 1total = time.perf_counter() - t0ttft = (first_token_at - t0) if first_token_at else float("inf")tps = tokens / (total - ttft) if total > ttft else 0return {"ttft_ms": ttft * 1000, "tps": tps}
3. Engineering the “Small Steps” Problem: Batching, Caching, and Streaming
The so-called preference for “small-step operations” is essentially limited output per request that requires multiple round trips, so accumulated waiting gets amplified. This is not a model defect but a calling-pattern issue, and it can be eased with three approaches:
- Prompt and skill reuse: solidify stable task templates and tool-calling conventions to reduce repeated trial and error, getting usable results in fewer rounds.
- Result caching: cache reusable prefixes, retrieved snippets, and historical answers; a cache hit skips inference and directly lowers average latency and cost.
- Batching and asynchronous processing: for scenarios that do not chase speed, such as scheduled jobs and offline summarization, submit in batches through an asynchronous queue, trading throughput for cost.
Request -> Cache hit? --yes--> return directly|novComplexity check -> simple: cost-first model-> complex: quality-first modelvStream response + instrument (TTFT/TPS) -> write to cache
4. Tiered Routing: Let Different Models Do What They Do Best
If multiple model tiers are available at the same time, the most practical approach is not to choose one but to route. Use a lightweight classifier or rules to judge task complexity, send simple routine work to the cost-first model, send complex reasoning to the quality-first model, and send real-time interaction to the balanced model. This keeps overall cost in the low-to-medium range while safeguarding quality and experience on critical paths. Routing decisions should be observable and reversible to avoid misjudgments that send hard tasks to a weak model.
5. A Practical Evaluation Method: Trust Data, Not Gut Feel
Selection should not rely on the impression from a single trial. It is better to build a small-scale evaluation set and a load-testing process:
- Build a set of real business samples (including long text, code, structured extraction, etc.) with a fixed scoring standard;
- Record four metrics at the same time: quality score, cost per task, TTFT, and TPS;
- Use P95 rather than the mean for capacity planning, leaving room for retries and fallback;
- Set up automatic fallback: switch to a backup tier when the primary model times out or is rate-limited, ensuring availability.
6. Conclusion
Among lightweight models, the quality gap in “routine work” scenarios is often not as large as marketing suggests; what really separates them is cost structure and latency performance. First classify the requirement into one tier of the quality-cost-latency triangle, then use tiered routing, caching, and batching to shore up the weak spots, and you can strike a balance between budget and experience. If stronger engineering support is needed, you can leverage general capabilities such as the container platform, message queue, logging service, and monitoring and alerting offered by Baidu AI Cloud to build an observable, fallback-capable model invocation pipeline, turning selection from “a shot in the dark” into “a decision based on metrics.”
