Unit 7 of 12 · about 4 hours · explain, implement

Identical output contracts, seeded sampling and distributional comparison

Comparisons with different outputs compare different amounts of work. Fixed prompts plus fixed sampling are what make two timings comparable at all.

You'll be able to

  • Fix identical prompts, output limits, stop behavior and cache state before any timing comparison.
  • Implement greedy and seeded-sampling comparisons, including a distributional check for sampled outputs.
  • Explain why batch invariance and determinism are vocabulary to verify, not guarantees to assume.

Covers

Identical prompt, output-limit and stop contractsGreedy, seeded sampling and distributional comparisonBatch-invariant kernels and deterministic inference vocabulary
1

Read

In this order, only the parts listed

0 of 3 done

  1. The sampling contract in one classvLLM SamplingParams API (v0.31.0)

    SamplingParams attributes with defaults: temperature at 1.0 with 0 meaning greedy, seed at None, max_tokens at 16, ignore_eos at False, and stop with stop_token_ids

  2. Fixed workloads and sampling flagsvLLM Benchmark CLI (v0.31.0)

    Running With Sampling Parameters with the temperature, top-p and top-k example

  3. The fairness checklistTime to First Token - Measurement and Load-Testing Sessions

    Before-you-publish checklist: fixed input and output lengths, p50 with p95 and p99, TTFT and ITL kept separate, pinned versions with exact commands

2

Focus on

  • Build on the Proving the cache correct unit: token identity plus a logits tolerance is the correctness gate, and this unit adds the serving comparison contract around it.
  • Greedy means temperature=0 exactly: vLLM clamps any positive value below 1e-2 up to 1e-2. Sampled comparisons run many requests over a fixed list of seeds on both sides and compare output distributions, not single outputs.
  • Output limits and stop strings change the amount of work. Fix max_tokens, ignore_eos, stop and stop_token_ids identically, or the faster run may simply have generated less.
  • Batch sizes, kernel paths and cache states can move outputs and timings. State them in the contract and re-verify identity whenever any of them changes.
Common mistakes · 3
  • Assuming the bench seed fixes engine sampling. vllm bench serve --seed 0 samples the dataset; engine sampling needs its own seed in SamplingParams(temperature=0.8, seed=1) or the server vllm serve --seed 1 argument.
  • Comparing a run that stopped early on EOS with one that ran to the token limit. Different output counts mean different decode work, not different speed.
  • Claiming determinism from one identical rerun. Greedy identity needs repeats across the batch sizes and cache states you will actually compare.
3

Try it yourself

Closed-book, before checking anything

Closed-book, write the full comparison contract for two engine settings: identical prompts, SamplingParams(temperature=0) for the greedy gate and SamplingParams(temperature=0.8, seed=s) over a fixed seed list for the sampled check, fixed max_tokens and stop behavior, and declared cache state. Then show greedy token identity across reruns and distributional agreement across the seed list.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Why must max_tokens and stop behavior match before comparing TPOT?Answer

    They set how many decode steps run. A shorter output does fewer steps, so its TPOT can differ without any execution change.

  2. 2.How do you compare two sampled configurations without requiring identical tokens?Answer

    Run many requests per configuration over the same list of seeds and compare output distributions, such as length or score histograms, with identical prompts, limits and cache state.

  3. 3.Greedy outputs match at batch size 1 but differ at batch size 8. What broke?Answer

    The comparison contract. A kernel path, scheduling or cache behavior changed with batch size, so identity must be re-established there, not assumed.

  4. 4.What does vLLM do with a small positive temperature below 1e-2?Answer

    It warns and clamps it up to 1e-2. Use exactly 0 for greedy and a fixed seed for reproducible sampling.

You're done when

Any two timings you compare share a written contract, greedy reruns are token-identical under it, and sampled reruns agree distributionally.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 9 more in the section
  • vLLM Benchmark CLI (v0.31.0)vLLM Project · required

    Use vllm bench latency, vllm bench throughput and vllm bench serve for phase and endpoint baselines. Fix the dataset, lengths, request rate, warmup and sampling, and keep the raw per-request results.

  • Time to First Token - Measurement and Load-Testing SessionsPatchy631 · support

    Use only Week 3 and Week 5 as a practical checklist for Prometheus, Grafana and request-rate sweeps. Follow the competency gate rather than its calendar, and replace fixed concurrency goals with your hardware-safe saturation range.

  • vLLM SamplingParams API (v0.31.0)vLLM Project · reference

    Look up temperature, seed, max_tokens, ignore_eos, stop and stop_token_ids defaults when you fix the output contract. The link is pinned to v0.31.0; check the fields against the version you install.

Also in this section

  • Efficiently Scaling Transformer InferenceMLSys · primary

    Read the prefill and decode cost, memory, batching and parallelism sections. Use its models to predict phase bottlenecks before measurement and record which assumptions fail on the selected model, engine and GPU.

  • AI Systems Performance Engineering - Chapter 16, profiling and debugging inferenceChris Fregly (O'Reilly) · required

    Read the first part of Chapter 16: monitoring system metrics, profiling with Nsight Systems and Nsight Compute, the troubleshooting recipes and debugging correctness. Treat every quoted speedup as a hypothesis for your own hardware.

  • AI Systems Performance Engineering companion code - Chapter 16Chris Fregly · required

    Begin with inference_profiling.py, inference_server_load_test.py, monitoring_bundle.py and runtime scheduler instrumentation. Run only hardware-compatible targets, retain raw artifacts and re-measure all bundled expectations on your own device.

  • Hands-On LLM Serving and Optimization - Chapter 5 and the Chapter 4 metrics sectionChi Wang and Peiheng Hu (O'Reilly) · required

    Read Chapter 5 on GPU specifications, model loading and arithmetic intensity in the prefill and decode phases, and "Measuring Performance in LLM Serving" in Chapter 4. Turn each claim into a prediction for one short-prompt and one long-prompt workload.

  • vLLM Metrics Design and Production MetricsvLLM Project · required

    Map scheduler and cache events to exported request, queue, TTFT, inter-token and generation metrics. The link is pinned to v0.31.0; check the definitions against the version you install.

  • TensorRT-LLM Benchmarking GuideNVIDIA · support

    Use Before Benchmarking and Online Serving Benchmarking as a reproducibility checklist. Borrow environment capture and startup metrics even if TensorRT-LLM is not the selected engine.

  • LLM Inference Systems Laboratory - InstrumentationRoadmap-Final · support

    Complete Milestone B: correlate request, iteration, KV, scheduler, kernel and resource events, quantify observer overhead, and retain raw arrival and completion records.

  • Taming Throughput-Latency Tradeoff in LLM Inference with Sarathi-ServeAgrawal et al. · support

    Read arXiv v3, Chunked-prefills and Stall-free batching for the chunked-prefill vocabulary and the prefill-decode interference argument, and Overhead of chunked-prefills for the cost of splitting. Treat the reported capacity gains as the paper's result on its hardware.

  • py-spy - sampling profiler for PythonBen Frederick · support

    Use py-spy record to take CPU flame graphs of tokenizer and detokenizer work, and py-spy top to watch the hot functions live. Launch the profiled process under py-spy.