Evaluating Large Language Model Inference: A Practical Guide to Balancing Accuracy, Latency, and Cost
This article breaks down a methodology for evaluating large language models across accuracy, efficiency, and cost instead of relying on benchmark scores alone. Using a sample evaluation of roughly 15,000 questions, it explains the four core metrics to track, how gains distribute across specific capability dimensions, and how to run a reproducible evaluation loop with frozen datasets and unified decoding parameters. It also shows how to convert token usage into a per-1,000-call cost, and offers deployment recommendations such as tiered routing, context governance, streaming output, observability, and canary releases. Readers will learn how to tell a genuine inference optimization from a result bought with extra resources.
1. Background: Why Accuracy and Speed Must Be Evaluated Together
Once large language models move into core business workflows, model selection is no longer as simple as picking the highest benchmark score. A model that leads by two percentage points on an offline leaderboard but pushes single-call latency from just over 50 seconds to over 60 seconds often means a higher timeout rate, amplified retries, and user churn in production. Conversely, an extremely fast model with insufficient accuracy shifts cost to manual review, making the total cost higher instead of lower.
For this reason, the industry commonly adopts a three-dimensional joint evaluation of effectiveness, efficiency, and cost: effectiveness looks at accuracy, efficiency looks at end-to-end latency and token consumption, and cost looks at actual spend converted from the per-call price. This article uses a sample evaluation of roughly 15,000 questions to abstract a vendor-agnostic evaluation and tuning methodology.
2. Metrics: The Engineering Meaning Behind Four Numbers
A rigorous evaluation needs to fix at least four categories of metrics, none of which can be skipped.
- Accuracy (overall score): the proportion of correct answers across all questions, reflecting the overall capability ceiling.
- Average latency: the wall-clock time from sending a request to receiving the complete result for a single call, which directly determines user experience and the timeout budget.
- Average tokens: the total input plus output tokens consumed per call, the shared source of both cost and context pressure.
- Cost per 1,000 calls: derived from the output unit price and average tokens, used to compare the real spend of different models side by side.
The sample data shows that the new version reaches 74.8% accuracy on roughly 15,000 questions, with an average latency of 53 seconds, an average of 3,157 tokens, and a cost of about RMB 250.5 per 1,000 calls; the previous generation reached 72.5% accuracy, 64 seconds average latency, and 3,119 average tokens. The key takeaway from these numbers: accuracy rose by 2.3 percentage points, latency dropped by 11 seconds, and tokens increased by only 38, which indicates the optimization comes from the inference pipeline itself rather than from “spending more tokens to buy accuracy.”
3. Breakdown by Dimension: Gains Are Not Uniform
The overall score is only the entry point; the real guidance comes from the sub-dimensions.
- Language and instruction following: up about 4.9 percentage points to 72.4%, meaning fewer omissions and deviations when facing multi-constraint, long-chain Chinese instructions.
- Reasoning and math: up about 3.3 percentage points to 85.1%, in the first tier, suitable for data reconciliation and logic-checking tasks.
- Education scenarios: up from 64.8% to 68.6%, a gain of about 3.8 percentage points.
- Finance, legal, and administrative/government affairs: a small increase, an improvement in stability.
- Medical and mental health: holding at a high 88.7%, indicating this dimension is already near the evaluation set’s ceiling and further gains require harder questions.
The engineering implication is direct: if your bottleneck is instruction following, this iteration delivers the largest benefit; if your bottleneck is medical Q&A, you should not expect a noticeable change and should instead focus effort on retrieval augmentation and knowledge updates.
4. Evaluation Method: Making Results Reproducible
The credibility of an evaluation depends on whether the process is frozen. The recommended minimum spec is as follows:
- Fix and version the question set, recording the number of questions, domain distribution, and difficulty distribution.
- Unify decoding parameters (such as temperature and max output length) to avoid randomness contaminating the comparison.
- Record the latency, input/output tokens, and number of failed retries for each call.
- Count timeouts and exceptions separately; they cannot simply be scored as errors.
- Run the same model at least two rounds and check whether the fluctuation range is smaller than the difference between versions.
A schematic evaluation main loop can be written as:
def run_eval(model, dataset, temperature=0.0, max_tokens=2048):rows = []for item in dataset: # dataset is versioned and frozent0 = time.perf_counter()try:resp = call_model( # unified call wrappermodel=model,messages=item["prompt"],temperature=temperature,max_tokens=max_tokens,)ok = grade(item["answer"], resp.text)rows.append({"ok": ok,"latency": time.perf_counter() - t0,"tokens": resp.usage.total_tokens,})except TimeoutError:rows.append({"ok": False, "latency": None, "tokens": 0, "timeout": True})n = len(rows)return {"accuracy": sum(r["ok"] for r in rows) / n,"avg_latency": mean(r["latency"] for r in rows if r["latency"]),"avg_tokens": sum(r["tokens"] for r in rows) / n,"timeout_rate": sum(r.get("timeout", False) for r in rows) / n,}
5. Cost Conversion: Turning Unit Price into a Business Account
The logic for calculating cost per 1,000 calls is not complex: multiply the average tokens by the output-side unit price, then multiply by one thousand. Its value is turning “is the model expensive or not” into a comparable number. In the sample, average tokens increase by only about 1.2% while accuracy rises by 2.3 percentage points, so the cost per unit of effectiveness actually decreases. For capacity planning, it is recommended to layer on two more coefficients: a retry coefficient (extra calls caused by timeouts and rate limiting) and a cache hit rate (frequent repeated requests can significantly dilute cost).
6. Deployment Recommendations: Completing Selection and Rollout on Baidu AI Cloud
- Tiered routing: send simple requests to a lightweight model and complex reasoning or long instructions to a stronger model, splitting traffic with rules or a small classifier.
- Context governance: compress prompts and trim history to keep average tokens within budget, the most direct way to cut cost.
- Async and streaming: for latency-sensitive scenarios, use streaming output to return the first token first and then fill in the rest, improving perceived experience.
- Observability: use monitoring, alerting, and logging services to build dashboards and thresholds for accuracy sampling, latency distribution, and failure rate.
- Elastic capacity: run evaluation and batch inference tasks on a container platform, store question sets and results in object storage, and use a message queue to smooth out peaks and fill valleys.
- Canary release: roll out the new version to 5% of traffic first, and only go full rollout after comparing that accuracy and latency have not degraded.
7. Conclusion
The most worthwhile lesson from this iteration is not any specific score but the evaluation method itself: only by using a fixed question set and unified parameters, and comparing accuracy, latency, tokens, and cost in the same table, can you judge whether an upgrade is a “genuine optimization” or “buying scores with resources.” When accuracy rises while latency drops and tokens stay roughly flat, you can confidently proceed with a canary rollout; otherwise, you should re-evaluate the context strategy and routing rules.
