Large Language Model Evaluation and Selection: Methods and Engineering Practice

    This article explains why "which model is the best overall" is not an answerable engineering question, and how to replace it with a measurable evaluation system. It breaks evaluation into four layers (L1 general capability, L2 domain capability, L3 experience and safety, L4 engineering cost), combines three methods (automated benchmarks, pairwise preference comparison, and shadow traffic in production), and provides a minimal runnable Python evaluation pipeline with repeated sampling and bootstrap confidence intervals. It also covers metric and statistical criteria, common pitfalls, and the cloud infrastructure needed to run evaluation as a continuous regression process. Readers will learn how to decide which configuration is optimal under their own traffic distribution and cost constraints, and whether the observed difference is statistically significant.

    1. Why “Overall Performance” Is the Wrong Question

    In an engineering context, “which model is the strongest overall” has no decidable answer, for three reasons:

    1. Capability dimensions are not commensurable. General understanding, logical reasoning, code generation, long-document summarization, creative writing, and multimodal understanding share no common unit of measurement. A model that leads on code often trails on naturalness of prose.
    2. Public benchmarks diverge from your real traffic. Question style, length, and language distribution in public benchmarks differ sharply from your production traffic, so benchmark scores are only a weak prior.
    3. Engineering usability is usually ignored. API stability, rate-limiting policy, time-to-first-byte, context length limits, adherence to structured output formats, and cost per token are “non-capability” factors that make up a large share of total cost.

    The right approach is to translate the vague goal of “overall performance” into a set of measurable, scenario-specific metrics, then use statistics to decide whether the differences are significant.

    2. Structuring the Evaluation Dimensions

    Split the evaluation into four layers and weight them layer by layer:

    • L1 General capability: language understanding, multi-turn context retention, instruction following, and validity rate of structured output (JSON/tables).
    • L2 Domain capability: tasks tightly coupled to your business, such as code completion and unit test generation, contract/log extraction, and math and multi-step reasoning.
    • L3 Experience and safety: naturalness of prose, reasonableness of refusals, handling of sensitive content, and hallucination rate (share of unsupported assertions).
    • L4 Engineering cost: P50/P95 latency, throughput, retry rate, cost per thousand calls, and vendor lock-in risk.

    A common mistake is to test only L1 and L2 and then draw conclusions. In real projects, L3 and L4 are often what determine user retention and gross margin.

    3. Combining Three Evaluation Methods

    3.1 Objective benchmarks (automated scoring)

    Suitable for tasks with a single correct answer or a programmatically verifiable one: whether code passes unit tests, whether extracted fields match the labels, whether SQL execution results are equivalent. The advantages are zero manual cost and easy regression; the drawbacks are narrow coverage and susceptibility to leaderboard overfitting.

    3.2 Subjective preference (pairwise comparison)

    Suitable for dimensions that cannot be scored automatically, such as writing style, readability, and quality of suggestions. Use anonymous A/B pairwise comparison to avoid the scale drift caused by absolute scoring, then aggregate into relative strength with an Elo or Bradley-Terry model.

    3.3 Scenario-based shadow traffic (online validation)

    Connect candidate models to the production path in shadow mode, logging only and returning nothing, and compare pass rate, human rewrite rate, and average handling time under real traffic. This is the step closest to the truth and the one most often skipped.

    4. A Minimal Runnable Evaluation Pipeline

    The core idea: decouple the task set from the scorers, unify model invocation behind a single abstraction, and persist results so they can be recomputed.

    1. from dataclasses import dataclass, asdict
    2. import json, statistics, random
    3. @dataclass
    4. class Case:
    5. id: str
    6. prompt: str
    7. scorer: str # name of the scorer
    8. meta: dict # scenario tags, difficulty, language
    9. def run_eval(cases, model_client, scorer_registry, repeats=3):
    10. """Run the full task set against a single model and return per-sample results."""
    11. records = []
    12. for c in cases:
    13. for _ in range(repeats): # repeated sampling to observe variance
    14. raw = model_client.generate(c.prompt) # unified abstraction layer
    15. score = scorer_registry[c.scorer](raw, c)
    16. records.append({**asdict(c), "score": score})
    17. return records
    18. def bootstrap_ci(scores, n=2000, alpha=0.05):
    19. """Bootstrap confidence interval for the mean, to avoid small-sample misjudgment."""
    20. means = []
    21. for _ in range(n):
    22. sample = [random.choice(scores) for _ in scores]
    23. means.append(statistics.fmean(sample))
    24. means.sort()
    25. return means[int(alpha / 2 * n)], means[int((1 - alpha / 2) * n)]

    Engineering essentials:

    • A unified abstraction layer is mandatory. Wrapping different model services behind the same generate interface means zero changes to evaluation code when switching candidates, and it lowers lock-in risk.
    • Repeated sampling separates “model capability differences” from “sampling randomness.” If the variance across three repeats of the same model exceeds the mean difference between models, the conclusion does not hold.
    • Results must be persisted as structured data (JSON/JSONL) to enable versioned comparison and audited recomputation.

    5. Metrics and Statistical Criteria

    • Classification/extraction tasks: accuracy, field-level F1, structured output validity rate.
    • Code tasks: unit test pass rate (pass@k), not a human judgment of “looks about right.”
    • Generation tasks: pairwise win rate + hallucination rate + edit distance of human rewrites.
    • For the aggregate metric, prefer cost-effectiveness over absolute scores: business pass rate / cost per thousand calls, with a cap on P95 latency as an additional constraint.
    • Significance: always report confidence intervals for small samples; when the sample is too small, label the result “no significant difference” rather than concluding from a single hands-on trial.

    6. Common Pitfalls

    1. Using public leaderboards instead of your own task set, causing metrics to drop sharply after launch.
    2. Testing only zero-shot, not the real configuration with few-shot examples and business system prompts.
    3. Ignoring prompt sensitivity: rephrasing the same model’s prompt can cause score swings larger than the gap between models.
    4. Using absolute scoring for subjective evaluation, so reviewers apply inconsistent scales and the data is not comparable.
    5. Running a one-off evaluation with no regression mechanism as model services keep iterating.
    6. Counting only token unit price as cost, ignoring retries, long-context usage, and human review.

    7. Running It in the Cloud

    For evaluation to run continuously, it needs infrastructure support, which can be assembled from general-purpose cloud capability categories:

    • Object storage: holds versioned task sets, raw outputs, and evaluation reports, making results recomputable.
    • Message queues: smooth out traffic spikes and distribute large-scale evaluation and shadow traffic tasks asynchronously.
    • Container platform: runs scorers and sandbox execution environments, keeping code evaluation isolated and elastically scalable.
    • Logging, monitoring, and alerting: collect latency, failure rate, and cost, configure threshold alerts, and maintain continuous observation of model quality.
    • Key and configuration management: centrally manage credentials for multiple model services and, together with the unified abstraction layer, support canary rollout and rollback.

    Baidu AI Cloud offers corresponding capabilities in these general categories and can serve as the foundation for such an evaluation and governance system; specific selection should still be based on measured results from your own task set.

    8. Conclusion

    “Overall performance” should be rebuilt into an evaluation system that is scenario-driven, statistically decidable, and observable in engineering terms: first decompose the dimensions across L1–L4, then cross-validate with automated scoring, pairwise preference, and shadow traffic, then decide based on cost-effectiveness and latency constraints, and finally harden the evaluation into a continuously regressed pipeline. The conclusion you get is not “model X is the best,” but “under my traffic distribution and cost constraints, which configuration is optimal, whether the difference is significant, and when re-evaluation is needed” — and that is the answer that can actually guide engineering decisions.