Fair LLM Evaluation in a Unified Runtime Environment: A Practical Guide

    This guide explains how to run fair comparisons of large language models in a unified runtime environment. It covers defining evaluation goals, fixing controlled variables, building a unified access layer and centralized configuration, designing task sets and metrics, and analyzing results. Readers get a step-by-step method for comparing models in a reproducible way.

    1. Define the Evaluation Goals

    Before starting an evaluation, answer three questions: which capabilities are being measured, what decisions the results will support, and which variables are allowed to change.

    Common capability dimensions include:

    • Code generation and repair: whether a model can write runnable code from a requirement, and whether it can locate defects in existing code.
    • Tool calling: whether a model can build arguments correctly from a function signature, and whether it can keep state across multi-step tasks.
    • Long-context understanding: whether a model can retrieve information from long materials and complete reasoning based on it.
    • Instruction following: whether the output conforms to format constraints.

    When the goal is unclear, evaluation results often reduce to a single overall score, which cannot guide actual model selection.

    2. Isolate Variables and Fix Controls

    In a fair comparison, only the models themselves should differ. The variables that must be fixed include:

    1. Runtime framework: scheduling, retry, and timeout policies stay the same.
    2. Tool set: tool names, descriptions, and parameter schemas are identical.
    3. Prompts: the same template is used, word for word.
    4. Sampling parameters: temperature, maximum output length, and similar settings are unified. If a model supports only its default setting, note this in the report.
    5. Runtime environment: the same machine or a container with the same specifications, and the same network conditions.

    Default inference modes differ across vendors and are not equivalent. If one model enables a deeper reasoning process by default and another disables it, comparing latency and cost directly will produce bias. In that case, report results under both the default mode and a unified mode, so readers can see the differences in conditions.

    3. Build the Evaluation Pipeline

    3.1 Unified Access Layer

    API formats differ across vendors. Wrap vendor-specific logic in an adapter inside the framework, and expose a single interface to upper layers. Business code then does not depend on the underlying protocol.

    1. class ModelAdapter:
    2. def __init__(self, cfg: dict):
    3. self.model_name = cfg["model_name"]
    4. self.client = build_client(
    5. base_url=cfg["base_url"],
    6. api_key=os.environ[cfg["api_key_env"]],
    7. )
    8. def complete(self, messages, tools, **options):
    9. """Unified return structure: text, tool_calls, usage, latency_ms"""
    10. raw = self.client.chat(
    11. model=self.model_name,
    12. messages=messages,
    13. tools=tools,
    14. **options,
    15. )
    16. return normalize(raw)

    Read API keys from environment variables. Do not store them in configuration files, and do not print them to logs.

    3.2 Centralized Configuration

    Keep all variables in a single configuration file. This makes the setup easier to audit and reproduce.

    1. eval:
    2. seed: 42
    3. repeats: 3
    4. max_output_tokens: 4096
    5. tool_set: standard_v1
    6. prompt_template: prompts/task_v1.txt
    7. models:
    8. - id: candidate_a
    9. base_url: https://<provider-endpoint>/v1
    10. model_name: <model-identifier>
    11. api_key_env: PROVIDER_A_KEY
    12. - id: candidate_b
    13. base_url: https://<provider-endpoint>/v1
    14. model_name: <model-identifier>
    15. api_key_env: PROVIDER_B_KEY

    The configuration file should record only environment variable names, never the keys themselves. Each run should write a hash of the configuration file into the results report, so the setup can be verified later.

    3.3 Task Set Design

    The task set sets the upper limit on how much the evaluation conclusions can be trusted. Pay attention to the following points:

    • Group tasks by capability dimension, and collect enough tasks in each group. Small samples amplify random variation, and the outcome of a single task can change a ranking.
    • Provide a standard answer or an automatic judging script for every task, and define the judging rules in advance.
    • Check how much the tasks overlap with public data. If a model has seen the original questions during training, its scores will be inflated.
    • Version the task set. Any change must come with a new version number, so historical results remain comparable.

    3.4 Repeated Runs

    Model outputs are random, so running each task once does not provide enough evidence. Run each task several times, and report the mean pass rate and its range of variation. For tasks with highly deterministic outputs, you can reduce the number of runs, but the report should explain the reason.

    4. Metric Design

    Record the following metrics together:

    • Task pass rate: calculated according to the judging rules.
    • Tool call success rate: the share of calls that have correctly formatted parameters and usable returned results.
    • Average number of steps: the number of interaction turns needed to complete a task.
    • Time to first token and total latency: record these separately, because they reflect different user experiences.
    • Token usage: count input and output tokens separately, then convert them to cost using the billing unit price.
    • Failure type distribution: count format errors, logic errors, timeouts, refusals, and other failures separately.

    A single average score can hide real problems. For example, a model may have a high overall pass rate while its multi-step tool call failures cluster in one type of scenario. That information matters just as much for model selection.

    5. Notes on Result Analysis

    1. Report confidence intervals. With small sample sizes, a gap of a few percentage points between two models may be random variation.
    2. Separate capability differences from configuration differences. If default reasoning modes differ, the conclusion must state these preconditions.
    3. Check the accuracy of judging scripts. Automatic judging may mark semantically equivalent correct answers as wrong, so sample results for manual review.
    4. Read failure cases one by one. Failure cases often show a model’s weaknesses more clearly than aggregate numbers.
    5. Avoid overgeneralizing. Results on one type of task cannot be applied directly to all business scenarios.

    6. Recommendations for Implementation

    Evaluation should be part of the daily development process, not a one-time activity. Specifically:

    • After each model version or framework version update, run the baseline task set automatically.
    • Maintain a historical results table that records the model version, configuration hash, task set version, and each metric, so trends are easy to see.
    • Keep evaluation scripts and configuration under version control, so every conclusion can be reproduced.
    • When publishing results externally, include the full experimental conditions: framework version, prompt template, sampling parameters, and task set version.