Unit 5 of 12 · about 4 hours · implement, measure
Decomposing TTFT and decode steps into their components
A single TTFT number cannot tell queueing from execution. Decomposition is what turns a slow request into a named part you can fix.
You'll be able to
- Decompose TTFT and per-token latency into queue, tokenize, schedule, host, model, sample, detokenize and stream parts.
- Implement per-request instrumentation that attributes each part without changing outputs.
- Read a slow request's spans and name the part to fix first.
Covers
Read
In this order, only the parts listed
0 of 3 done
- The five intervals behind every requestvLLM Metrics Design and Production Metrics
Engine Core Events with Interval Calculations: QUEUED, SCHEDULED, PREEMPTED and NEW_TOKENS events with the queue, prefill, decode, inference and inter-token intervals; Frontend Stats Collection for
arrival_timeand end-to-end latency - TTFT, ITL and end-to-end definitionsHands-On LLM Serving and Optimization - Chapter 5 and the Chapter 4 metrics section
Latency Metrics (pp. 150 to 151): Figure 4-9 with TTFT as prefill work, ITL as decode work, and the end-to-end formula over generated tokens
Use the definitions and the final simplified forms. The printed ITL middle expression with a subtracted detokenization term is garbled; read it as one decode step plus its detokenization.
- Bench-side TTFT, ITL and TPOTvLLM Benchmark CLI (v0.31.0)
Understanding the Latency Metrics: bench-side TTFT, per-gap ITL and per-request TPOT with the speculative-decoding bundled-tokens example
Focus on
- Engine-side intervals and bench-side metrics differ by construction. The engine measures queue, prefill and decode between core events; the bench measures TTFT, gaps and TPOT at the client, including network and streaming.
- ITL records each gap between streamed outputs, while TPOT amortizes one request's decode time over its tokens. They agree when each streamed output holds one token and diverge when one output bundles several tokens.
- Sampling, detokenization and streaming sit after the last model kernel of each step. A ragged gap series with fast kernels points at these parts, not at attention.
- Preemption re-enters the intervals: a preempted request restarts prefill, so its TTFT and decode spans include the repeated work.
Common mistakes · 3
- Averaging ITL samples across requests with different output lengths and calling it TPOT. Mean of gaps weights long requests more; per-request TPOT weights requests equally.
- Comparing engine prefill time with bench TTFT directly. TTFT adds queueing, tokenization, network and streaming around the engine spans.
- Trusting TPOT for single-token requests. vLLM records zero TPOT when there is at most one output token, and bench statistics exclude those requests.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.A request generates 5 tokens with TTFT 100 ms and end-to-end 180 ms. What is its TPOT, and how many ITL samples does the bench record?Answer
TPOT is ms per token. The bench records 4 ITL gap samples.
2.With speculative decoding, one streamed output carries three tokens after a 40 ms gap. How do ITL and TPOT treat those tokens?Answer
ITL records one 40 ms gap and adds no zero gaps for the bundled tokens. TPOT divides the request's decode time over all three tokens.
3.Queue time dominates a slow TTFT while prefill time is flat. What do you fix first?Answer
Admission, scheduling or load, not kernels. The model execution is fine; the request waited.
4.Why can two runs of the same prompt show different TTFT with identical prefill time?Answer
TTFT includes queueing, tokenization, scheduling and host overhead, which vary with server state even when the kernels do not.
You're done when
Given any slow request, you split its latency into spans from events you instrumented and name the dominant part with evidence.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 9 more in the section
- 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.
- vLLM Benchmark CLI (v0.31.0)vLLM Project · required
Use
vllm bench latency,vllm bench throughputandvllm bench servefor phase and endpoint baselines. Fix the dataset, lengths, request rate, warmup and sampling, and keep the raw per-request results.
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.
- 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.
- 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.
- 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.
- vLLM SamplingParams API (v0.31.0)vLLM Project · reference
Look up
temperature,seed,max_tokens,ignore_eos,stopandstop_token_idsdefaults when you fix the output contract. The link is pinned to v0.31.0; check the fields against the version you install.