Unit 13 of 13 · about 5 hours · implement, measure
A validated open- and closed-loop load generator with raw records
An unvalidated generator hides overload through coordinated waiting or changed outputs. Validation proves it preserves load and semantics.
You'll be able to
- Build open- and closed-loop generators with deterministic requests, streaming and cancellation.
- Validate the generator against a deterministic fake server with known service and overload behavior.
- Retain per-request raw events and outputs with timestamps.
Covers
Read
In this order, only the parts listed
0 of 4 done
- Benchmark snippets and toolsMachine Learning Engineering Open Book - Inference
Benchmarks with openai
completions.createandstream=Truesnippet (ttft=first-start,decode_thr=(output_toks-1)/(last-first)), TTFT-is-not-prefill caveats,benchmark_throughput.py, k6, aiohttpbackend_request_func.pywith vllm#7935 client fix, and the missing max-concurrency note - Intended send time correctionGil Tene - How NOT to Measure Latency (talk)
Full talk: intended versus actual send time, missing samples under queueing, and why server-side timing alone drops user-visible wait
Use the correction concept in your generator. Do not adopt
wrk,heyorab. - Validation and raw retentionLLM Inference Systems Laboratory - Workload and Baseline
Milestone B for raw arrival and completion records, observer overhead and trace queries over TTFT and every decode gap; Milestone E for micro through endpoint open-loop benchmarks on tuning and final sets; Measurement requirements for arrival, queue, service and stream timing with throughput, goodput and quality behavior
- Load tooling and output checksInference Engineering
Sections 4.5 with 4.5.1 for SGLang Genai-bench, NVIDIA GenAI-Perf and Locust plus eval datasets such as MMLU, gsm8k and HumanEval as varied inputs with spot checks that speed work did not change outputs
Focus on
- Open-loop schedules Poisson arrivals via
random.expovariatefrom intended send times; closed-loop issues next on completion with fixed clients. Count latency from intended time in both. - The Systems saturation unit gives the fake server to copy: 10 ms service with a 500 ms stall on every 200th request at seed 21 for 30 s. Validation must separate the modes there before touching a real engine.
- Retain per request: intended and actual arrival, queue start, prefill done, first token, decode gaps, completion with cancellation or error, outputs with usage, sampling params and manifest version. Aggregates alone cannot yield tails.
- Outputs must match a direct run token for token. Eval spot checks catch a fast path that truncates or retunes generation under load.
Common mistakes · 3
- Validating only on a fast server. Without queueing both modes agree; the slow server with overload is what separates them.
- Keeping aggregates without raw records. Percentiles need retained samples with
n; the generator log is evidence, not scratch. - Changing outputs to meet load. Truncating
max_tokensor retuning sampling under pressure breaks semantics; identical outputs plus spot checks prove preservation.
Try it yourself
Closed-book, before checking anything
random.seed(21), Poisson schedule via random.expovariate, latency from intended send time and one FIFO server with 10 ms service plus a 500 ms stall on every 200th request for 30 s. Confirm the 80 rps row (mean 341.1 ms, p50 341.1 ms, p95 649.5 ms, p99 759.1 ms nearest-rank) and the closed-loop twin with 5 clients (mean 62.1 ms, p99 540.0 ms, 80.5 completed rps), and state which run to trust for tails.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Why validate against a fake server with known service and overload?Answer
It isolates generator bugs from engine variance. Known service gives expected means and tails; overload separates open from closed behavior.
2.Same slow server gives open mean 341.1 ms and closed mean 62.1 ms. Which is honest for tails?Answer
Open-loop. Closed-loop never sent the queued work, so its 540.0 ms p99 omits the wait that open-loop reports as 759.1 ms.
3.What raw events does each request retain?Answer
Intended and actual arrival, queue start, prefill done, first token, decode gaps, completion with cancellation or error, outputs with usage, sampling params and manifest version.
4.How do you prove the generator did not change outputs?Answer
Identical token IDs and checksums versus a direct run at the same manifest plus eval spot checks. Any fast path that alters outputs fails validation.
You're done when
Your generator reproduces the 80 rps row and the closed twin, fake-server validation passes with outputs identical, and raw records yield p50, p95 and p99 with n.
Only when you can do this without notes.
Leads to
Notes
Resources · 4 for this unit, 14 more in the section
- Machine Learning Engineering Open Book - InferenceStas Bekman · required
Use inference/README.md for the prefill/decode distinction, memory formulas, MHA/GQA/MQA/MLA comparison and current glossary. Treat unfinished sections as a reference boundary, not as the main course.
- LLM Inference Systems Laboratory - Workload and BaselineRoadmap-Final · support
Start the immutable workload manifest, deterministic fake server, request-state trace and arithmetic planner. Keep this same repository through INF-9 so later comparisons preserve the contract.
- Inference EngineeringPhilip Kiely (Baseten Books) · support
Read Sections 1.4 to 1.4.2 for TTFT, TPS, percentiles and end-to-end versus inference-only time; Section 4.5 with 4.5.1 for benchmark dimensions, tooling and eval inputs; Section 6.1 for vision encoders, image tokens and longer-context effects.
- Gil Tene - How NOT to Measure Latency (talk)Strange Loop Conference via YouTube · reference
Use for coordinated-omission vocabulary only: closed-loop testers that wait for each reply, the missing samples under queueing, and the correction concept of recording intended send time. Do not adopt
wrk,heyorab; write the small Python generator in the load-generator unit instead.
Also in this section
- How to Scale Your Model - InferenceJAX Team · primary
Read the complete inference chapter for model, KV, batching, parallelism and capacity arithmetic. Reproduce every equation for one fixed model and workload, then use the public serving companion and book overview to connect the quantities to the request lifecycle.
- Hands-On LLM Serving and Optimization - Chapters 2 and 5Chi Wang and Peiheng Hu (O'Reilly) · required
Read Chapter 2 for the decoder walk-through, the KV cache and the prefill and decode phases, and the Chapter 5 sections that estimate model size and KV-cache size. Run the Chapter 2 companion notebooks on a small model and redo every size estimate for the model you will serve.
- Transformer Inference ArithmeticKipply · required
Re-derive weight bytes, KV bytes per token, prefill work, decode work and arithmetic intensity with explicit units. Replace every example constant with your model configuration and compare the estimates with the book.
- LLM Inference: From scratch, one token at a time - Modules 01, 02 and 04Tushar Amrit · support
Work the "Math by hand" and checkpoint parts of The Autoregressive Loop, The KV Cache and Metrics and the Roofline. Redo each worked number for your own model before reading the solution.
- LLM Inference Handbook - Key metrics for LLM inferenceModular · reference
Use the TTFT, TPOT and ITL definitions, and the difference between request-weighted average TPOT and token-weighted average ITL, when you define your own metrics.
- Stanford CS336 - Inference LectureStanford University · support
Watch the inference lecture once after the arithmetic reading. Pause to reproduce its model-memory and phase-bottleneck calculations; advanced serving mechanisms are routed to their later stages.
- 100 Days of LLM Inference - Days 1, 2, 5 and 6Elizabeth Thomas · support
Run only the four named notebooks for request anatomy, model configuration, KV sizing and roofline orientation. Verify every formula independently because this public learning journal is a useful practice supplement, not the authority.
- TensorTonic Language Modeling from Scratch - Plan KV-Cache CapacityTensorTonic · support
Solve after the KV-bytes unit, then check the answer against your own worksheet for the same configuration.
- AI Performance Engineering - Minimum Mental ModelWafer · reference
A curated, dated index. Use Start Here only to find a primary source the other entries lack.
- Hugging Face Transformers - model configuration and revisionHugging Face · reference
Read PreTrainedConfig common attributes (
vocab_size,hidden_size,num_attention_heads,num_hidden_layers) andfrom_pretrainedrevision(branch, tag or commit id, defaultmain). Use the savedconfig.jsonas the identity record beside the book config dumps. - Hugging Face Transformers - chat templatesHugging Face · reference
Read
apply_chat_templatewith role and content dicts, the Mistral versus Zephyr control-token examples, andadd_generation_promptfor starting an assistant reply. Compare the template output token count with the raw prompt count. - Etalon: Holistic Performance Evaluation Framework for LLM Inference SystemsAgrawal et al. · support
Read Sections 2.2, 3.1 and 4.1 with Algorithm 1 and Figures 1 to 3 for TTFT, TBT, TPOT, normalized latency, capacity and fluidity-index; Section 4.2 for black-box and capacity recipes; Section 5.1 for hourly runs over 24 hours and LMSys-Chat-1M medians (417 median, 1418 p90 prefill tokens).
- DistServe: Disaggregating Prefill and Decoding for Goodput-optimized LLM ServingZhong et al. (OSDI 2024) · support
Read Section 1 with Figure 1 for per-GPU goodput: the highest request rate served while a target share of requests meets the TTFT and TPOT SLOs (13B model on one A100 reaches about 1.6 requests per second at 90% attainment).
- Nano-vLLM tiny serving engineGeeeekExplorer · reference
Read
nanovllm/engine/sequence.pyfor request state,scheduler.pyfor waiting and running sets,block_manager.pyfor allocate, append, deallocate and prefix-hash reuse,model_runner.pyfor prefill and decode steps, andllm_engine.pyfor the generate path. Trace one request through these files only; do not adopt the engine for load measurement.