Speed Benchmark

Rank LLM deployments by generation speed before you fine-tune or ship

Send the same request N times to each deployment and get a ranked table — fastest first — of throughput and latency.

Diagram

praisonai-train benchmark

🎯 Targets

📝 Fixed prompt

⚡ Parallel HTTP

📊 Aggregate

✅ Ranked table

Compare deployments before you fine-tune — pip install praisonai-train is enough, no GPU or [llm] extras needed.

Quick Start

  1. Benchmark two deployments

    Pass one or more --deployment flags. Endpoint and key are read from the AZURE_OPENAI_ / OPENAI_ environment.

    bash
    pip install praisonai-train
    
    praisonai-train benchmark -d gpt-4o -d gpt-4o-mini

    Each target prints as it finishes, then a table ranks them by rows/min:

    measured gpt-4o: 87 rows/min, 4123 tok/s, ok=24/24
    measured gpt-4o-mini: 142 rows/min, 5210 tok/s, ok=24/24
  2. Drive it from a YAML config

    Put the deployments and knobs in a file and point --config at it — the same idiom as generate and validate.

    bash
    praisonai-train benchmark --config benchmark.yaml
    yaml
    # benchmark.yaml
    deployments:
      - gpt-4o
      - gpt-4o-mini
    n: 24
    concurrency: 8
    azure: true
    api_version: "2024-10-21"
    output: bench_results.json

How It Works

The benchmark reuses the data generator’s own HTTP path (build_chat_request / resolve_cfg), so measurements reflect a real generation workload — no duplicated request code.

Diagram
Deployment endpointThreadPool (concurrency)benchmark_deploymentsbenchmark CLIDeployment endpointThreadPool (concurrency)benchmark_deploymentsbenchmark CLIloop[each target]targets, n, concurrencysubmit n identical requestschat completion × nlatency + completion_tokensraw timings + ok countBenchResult (live callback)results sorted by rows/min desc
MetricMeaning
rows/minThroughput per wall-clock minute — the ranking key
tok/sCompletion tokens per second (counted for ok=True only)
avg_lat / p50 / p95Per-request latency in seconds
out_tokAverage output tokens per successful request
okSuccessful requests over total (ok/n)

Which json_mode?

json_mode sends a response_format={"type":"json_object"} hint. Turn it off for endpoints that don’t support JSON mode so you measure speed, not JSON-mode support.

Diagram

Azure OpenAI / OpenAI-native

OpenAI-compatible
without JSON mode

Endpoint type?

json_mode: true
the default

json_mode: false
–no-json-mode


CLI Flags

FlagShortYAML keyTypeDefaultDescription
--config-c—pathnoneYAML config file
--deployment-ddeployments / targetsstr (repeatable)requiredDeployment/model to benchmark
--n-nnint24Requests per deployment
--concurrency—concurrencyint8In-flight requests per deployment
--api-version—api_versionstr"2024-10-21"Azure OpenAI api-version
--max-tokens—max_tokensint2048max_completion_tokens per request
--recipe-rrecipestr"tamil"Recipe supplying the default prompt
--json-mode / --no-json-mode—json_modeboolTrueSend the JSON-mode hint; disable for endpoints without it
--output-ooutputpathnoneWrite ranked results as JSON

YAML-only keys: endpoint, api_key, azure, prompt (a {system, user} dict), and request_timeout (default 180).


Python API

Call benchmark_deployments directly for notebooks, dashboards, or CI gates.

python
from praisonai_train.data import benchmark_deployments, BenchResult

results: list[BenchResult] = benchmark_deployments(
    ["gpt-4o", "gpt-4o-mini"],
    n=24,
    concurrency=8,
    json_mode=True,
)

for r in results:  # already ranked fastest-first
    print(r.deployment, r.rows_per_min, "rows/min")

BenchResult is a dataclass — serialise any result with .as_dict().

FieldTypeDescription
deploymentstrDeployment name
nintRequests sent
okintSuccessful requests
wall_sfloatWall-clock seconds for the batch
rows_per_minfloatThroughput (ranking key)
compl_tok_per_sfloatCompletion tokens per second
avg_latency_sfloatMean per-request latency
p50_s / p95_sfloatLatency percentiles
avg_out_tokfloatAverage output tokens per success

Common Patterns

Benchmark across endpoints in one run

Each target may be a dict overriding endpoint, api_key, azure, or api_version — compare an Azure deployment against a self-hosted OpenAI-compatible server side by side.

python
from praisonai_train.data import benchmark_deployments

results = benchmark_deployments(
    [
        {"deployment": "gpt-4o", "azure": True},
        {"deployment": "llama-3.1-70b", "endpoint": "https://my-host/v1", "azure": False},
    ],
    n=24,
    json_mode=False,  # the OpenAI-compatible host has no JSON mode
)

Use your real prompt

Set an explicit prompt so the benchmark exercises the exact shape you generate with.

python
results = benchmark_deployments(
    ["gpt-4o"],
    prompt={"system": "You generate concise answers.",
            "user": "Write one short factual paragraph about photosynthesis."},
)

Stream progress with a callback

on_result fires as each target finishes — ideal for a live dashboard.

python
benchmark_deployments(
    ["gpt-4o", "gpt-4o-mini"],
    on_result=lambda r: print(f"{r.deployment}: {r.rows_per_min} rows/min"),
)

Best Practices

Match concurrency to your provider quota

concurrency is in-flight requests per deployment. Raise it to saturate a high-quota deployment; lower it to stay under a rate limit. Throughput is measured per wall-clock second, so it already reflects the concurrency you set.

Disable json_mode for OpenAI-compatible endpoints

Set --no-json-mode (or json_mode: false) for servers without JSON-mode support, otherwise a rejected response_format shows up as failures rather than a speed number.

Keep n representative, not huge

The default n=24 is enough to stabilise p50/p95 without a large bill. Raise it only when you need tighter tail-latency numbers.

Write JSON output for regressions

Pass --output bench.json (or output: in YAML) and diff runs over time to catch a deployment slowing down.


Related