Unit 7 of 13 · about 4 hours · explain, derive

The request contract and its latency metrics

Users feel first token, gaps and total; averages hide stalls. The contract decides what counts as done.

You'll be able to

  • Explain the streaming, sampling, stop and timeout fields that define when a request is done.
  • Define TTFT, TPOT, ITL and end-to-end latency with request- versus token-weighted averages.
  • Interpret p50, p95 and p99 from raw samples with n, keeping end-to-end apart from inference-only time.

Covers

Streaming, sampling, stop and timeout contractsTTFT, TPOT, inter-token latency and end-to-end latencyp50, p95 and p99 latency interpretation
1

Read

In this order, only the parts listed

0 of 4 done

  1. TTFT, TPOT, ITL and request versus token weightingLLM Inference Handbook - Key metrics for LLM inference

    TTFT with chatbot under 500 ms and code under 100 ms; Token Generation Time as E2EL - TTFT with 2200 minus 80 is 2120 ms; TPOT as (E2EL - TTFT)/(N - 1) with 2120/219 is 9.68 ms; Average TPOT request-weighted versus Average ITL token-weighted; Mean, Median and P99

  2. Sampling, percentiles and benchmark caveatsMachine Learning Engineering Open Book - Inference

    Decoding methods with Temperature (scaled_logits=logits/temperature, t==0 uses explicit greedy mode, rank-invariant, Top-K and Top-p effects); Key metrics with TPOT table and Simplified prefill and decode throughput; Percentiles with p50 to p99 and the k6 example; Benchmarks with TTFT as first non-empty chunk and decode_thr=(output_toks-1)/(last-first) plus TTFT-is-not-prefill caveats

  3. Streaming contract with abortHands-On LLM Serving and Optimization - Chapters 2 and 5

    Chapter 2, LLM Streaming Serving Basics (pp 60-61): llm.generate blocks, AsyncLLMEngine with SamplingParams(temperature=0.0, max_tokens=100, stop=["\n"]) (the 128-token example with temperature=0.8 is the earlier blocking call), engine.generate with request_id, async for request_output with chunk.text, and engine.abort(request_id)

  4. Percentiles and end-to-end timeInference Engineering

    Sections 1.4 to 1.4.2 for TTFT with Perceived versus Total TPS and ITL at 10 ms as 100 TPS; P50, P90, P95 and P99 table with right-skewed Figure 1.5; End-to-End Metrics for inference-only versus end-to-end with network and queue time

2

Focus on

  • Streaming returns tokens as generated. Blocking llm.generate waits for all; engine.generate yields RequestOutput chunks; engine.abort stops by request_id.
  • Sampling sets temperature, top_p, top_k, seed, stop strings and ids, max_tokens and min_tokens. Zero temperature means greedy via an explicit mode, not division.
  • TTFT covers scheduling plus prefill plus transport and queue, not prefill alone. TPOT divides decode time by output count; mean ITL equals TPOT for one request but request-weighted and token-weighted averages differ across requests.
  • Percentiles need raw samples with . End-to-end includes network and queue; inference-only does not. A fast GPU with slow end-to-end points at infrastructure.
Common mistakes · 3
  • Treating TTFT as prefill time. It includes transport, queue, scheduling and generation start; a batched chunk is not one token.
  • Averaging TPOT across requests as system ITL. Request-weighted treats requests equally; token-weighted lets long responses dominate. Use the first for per-request latency and the second for system streaming speed.
  • Setting one static TTFT SLO across lengths. Prefill grows about quadratically; fit per-length targets or split scheduling from processing.
3

Try it yourself

Closed-book, before checking anything

Closed-book, score the playground request with E2EL 2200 ms, TTFT 80 ms and 220 output tokens: Token Generation Time ms and TPOT ms per token. Then state the request-weighted versus token-weighted formulas for two requests with different lengths.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.E2EL is 2200 ms, TTFT is 80 ms, output is 220 tokens. What are Token Generation Time and TPOT?Answer

    2120 ms and ms per token. The divisor is output minus one because the first token arrived with TTFT.

  2. 2.When do Average TPOT and Average ITL disagree?Answer

    When output lengths differ. Average TPOT weights requests equally; Average ITL weights by tokens, so long responses dominate the latter.

  3. 3.Why is prompt tokens divided by TTFT not prefill throughput?Answer

    TTFT includes queue, scheduling, transport and generation start. Server instrumentation is needed to isolate prefill; the quotient mixes all of them.

  4. 4.What goes wrong with temperature=0 as division?Answer

    Division by zero is undefined. Engines use an explicit greedy mode; the rank order is invariant but Top-K probs and Top-p membership still change with temperature above zero.

You're done when

You derive 2120 ms and 9.68 ms without notes and can read request- versus token-weighted off two requests with different lengths.

Only when you can do this without notes.

Leads to

Notes

Resources · 4 for this unit, 14 more in the section
  • 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.

  • 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 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.

  • 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.

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.

  • 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.

  • 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.

  • 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.

  • Hugging Face Transformers - model configuration and revisionHugging Face · reference

    Read PreTrainedConfig common attributes (vocab_size, hidden_size, num_attention_heads, num_hidden_layers) and from_pretrained revision (branch, tag or commit id, default main). Use the saved config.json as the identity record beside the book config dumps.

  • Hugging Face Transformers - chat templatesHugging Face · reference

    Read apply_chat_template with role and content dicts, the Mistral versus Zephyr control-token examples, and add_generation_prompt for 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.py for request state, scheduler.py for waiting and running sets, block_manager.py for allocate, append, deallocate and prefix-hash reuse, model_runner.py for prefill and decode steps, and llm_engine.py for the generate path. Trace one request through these files only; do not adopt the engine for load measurement.

  • 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, hey or ab; write the small Python generator in the load-generator unit instead.