Skip to content

20.12 Performance experiments and correctness gates

An optimization claim needs a baseline, a fixed workload, a resource budget, and a behavior contract. A high tokens-per-second number without those conditions cannot establish that a model is cheaper or better for its users.

Concepts from other sections (6)

This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.

Learning objectives

  • Separate artifact correctness, numerical behavior, task quality, and system performance.
  • Design controlled experiments for inference controls.
  • Report goodput, errors, and total cost without hiding workload changes.
LayerEvidenceA passing result does not prove
Artifact/APILoad success, model identity, templates, response schema, streaming/stop/cancellation testsCorrect logits or useful answers
Numerical semanticsFixed-prefix logits, masks/positions, cache/full equivalence, batch-invariance matrixHeld-out task quality
Task behaviorFrozen representative tasks plus regression slices and uncertaintyLatency or stable capacity under load
System performanceOpen-loop arrivals, successful goodput, tails, resource/cost measurementsQuality outside the tested tasks or reproducibility on another stack

For precision or quantization changes, set numerical tolerances and task-quality budgets before the comparison. For exact algorithmic transformations, test stronger invariants where feasible: cached versus full attention, grammar validity, rejected-draft rollback, and KV block reclamation. A smoke-test sentence cannot stand in for these checks.

model / adapter / tokenizer / template revisions
device topology, runtime/container and kernel versions, resolved flags
prompt dataset hash, language/task slices, exact input token lengths
requested and actual output length, stop rules, sampler and seeds
shared-prefix distribution, cold/warm cache policy
arrival process and offered rate, concurrency cap, timeout/retry policy
quality suite, numerical criterion, latency SLOs, measurement window

If a request produces a different number of output tokens after a change, report that difference. Faster completion can mean earlier EOS rather than a faster decode kernel. Include failed and rejected requests in the offered-load accounting. Record retries separately instead of presenting only successful attempts.

Measure baseline, one mechanism changed, and combined settings. For prefix reuse, test cold cache, shared exact prefixes, and unique prefixes. For speculative decoding, include the draft’s memory, time, and accepted/rejected tokens. For graphs and compilation, show startup/capture time as well as steady state. For parallelism, keep the total hardware budget visible.

Warm up the intended shapes, then use repeated measurement windows. Interleave baseline and candidate runs when temperature, other tenants, or background load may drift. Select the metric before looking at the result and report uncertainty. Avoid selecting the best of many noisy trials and presenting it as a typical result.

Offered rate is submitted requests per second. Completed throughput counts completions. Goodput counts successful work satisfying the declared SLO and quality conditions; state whether its unit is requests or tokens. TTFT includes queueing and prompt processing, while ITL reveals stalls during generation. Average TPOT can hide a long pause between two tokens, so keep latency distributions and timeout/rejection rates.

In an illustrative 60-second window, 600 requests arrive, 540 succeed, and 480 of those meet both latency SLOs. Offered rate is 10 requests/s, successful throughput 9/s, and SLO goodput 8/s. If the fleet costs USD 12/hour, cost per SLO-compliant request in that window is (12/60)/480≈0.000417(12/60)/480\approx0.000417 USD. This deliberately simple calculation excludes other service costs, and its denominator is explicitly compliant requests.

Use open-loop arrivals to see overload: the generator submits according to a schedule rather than waiting for each response before sending the next. A closed-loop test is useful for a fixed-user scenario but self-throttles as latency rises. A slow load generator can also hide overload; record its scheduling delay and host utilization.

From the repository root:

Terminal window
python3 content/courses/ai-engineering/19-training-methods/code/learning_checks.py
python3 content/courses/ai-engineering/20-inference-engines/04-serving-and-load/code/capacity.py --preset llama-3.1-8b
python3 content/courses/ai-engineering/20-inference-engines/04-serving-and-load/code/loadgen.py \
--mock --rate 8 --num-requests 20 --output-len 8

The mock tests workload generation and measurement plumbing; it models neither real transformer kernels nor task quality. The capacity calculator is a model with stated assumptions, not an allocator measurement. Continue with the local engine lab to run the same process against actual runtimes.

Reject a configuration if it exceeds a correctness or quality budget even when faster. If two configurations meet the contract, compare goodput per total cost and the operational constraints. Keep the raw per-request records so a later workload change can be distinguished from an engine regression. The statistical regression gate shows one comparison method; it is not a replacement for a representative workload.

  • Goodput: successful work meeting declared service criteria per unit time.
  • Coordinated omission: failure to observe delays that would have occurred had load continued arriving during stalls.
  • Quality budget: the maximum allowed regression on a defined evaluation metric and slice.

Validate behavior first, hold the workload and hardware budget fixed, and report successful compliant work with uncertainty and failure counts.

  1. Why can a slower GPU configuration have higher service goodput?

    AnswerBetter scheduling or less interference can allow more requests to meet the SLO despite lower peak kernel throughput.
  2. Why are mock-server results insufficient for a quantization claim?

    AnswerThe mock executes no quantized model kernels and evaluates no model answers. It verifies the measurement path only.