Unit 10 of 11 · about 5 hours · measure
Endpoint workloads, request metrics, baselines and attribution
Endpoints are judged by TTFT, TPOT, memory and goodput on a real mix. Attribution connects one kernel change to those numbers without overclaiming.
You'll be able to
- Derive KV-capacity and latency floors for a stated model and GPU.
- Measure TTFT, TPOT, memory, throughput and goodput on a fixed arrival distribution against strong baselines.
- Attribute a kernel change to request-level effect with shares and explain the residual.
Covers
Read
In this order, only the parts listed
0 of 3 done
- KV, capacity and latency floorsTransformer Inference Arithmetic
kv cache per-token bytes with
kandvacross layers, heads and bytes per value; capacity from weights plus KV; latency calculations for memory-bound versus compute-bound floors; batch sizes and flops counting - Inference profiling and utilization trade-offsAI Systems Performance Engineering - Chapters 13, 15 and 16
Chapter 16, Profiling, Debugging, and Tuning Inference Performance; Profiling with Nsight Systems and Nsight Compute; Maximizing GPU Utilization and Throughput Versus Latency Trade-Offs
- Load test and profiling harnessAI Systems Performance Engineering companion code - Chapters 12 to 16
CompletionRecord,run_load_testwithtarget_qps, warmup phase and percentile summaries ininference_server_load_test.py;MonitoringSystem,DynamicBatcherandPrefixCacheininference_profiling.py
Focus on
- Derive floors before measuring: per-token KV bytes, weight-resident capacity, and memory-bound versus compute-bound latency. A measurement that beats its floor has a boundary error.
- Fix the workload first: shape and arrival distribution, TTFT and TPOT SLOs, memory budget and goodput definition. Goodput counts only requests meeting the SLOs.
- Attribute with shares: a kernel speedup on fraction of step time gives at most end-to-end. Baselines are the production engine and the vendor library, not eager alone.
Common mistakes · 3
- Quoting a friendly-shape kernel speedup as an endpoint win. Request mix, queueing and uncovered shares dilute it.
- Averaging TTFT and TPOT across different lengths and SLOs. Report per-slice percentiles on a fixed distribution.
- Keeping only summary speedups. Retain raw samples, workload, revision and machine state or the result cannot be audited.
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.What do TTFT and TPOT measure?Answer
Time to first token (prefill plus scheduling) and time per output token after the first (steady decode cadence). E2E adds queueing and completion.
2.Why can throughput rise while goodput falls?Answer
Throughput counts all tokens; goodput counts only requests meeting latency SLOs. A faster engine with more SLO misses can raise one and lower the other.
3.What makes an engine baseline weak?Answer
It compares against a weak reference instead of the engine and library the team would actually run. The gap overstates the shippable win.
4.Does a kernel speedup times its profile share equal the endpoint win?Answer
No. Divide only after checking the floor: the win must fit inside the helped share, and the residual needs a timeline or counter cause.
Practice
- Companion code ch16: inference load test with baselines
Run
inference_server_load_test.pywith--duration,--target-qpsand--output-json; compare one custom path against the production-engine and vendor-library baselines on TTFT p50 and p99, TPOT, memory and goodput withCompletionRecordfields retainedKeep captures short. Multi-GPU flags exist but single-GPU runs are enough. No public autograder scores the endpoint; retain arrival mix, baselines and raw samples.
You're done when
Your endpoint report shows TTFT, TPOT, memory and goodput on a fixed mix against strong baselines, with the kernel-to-request attribution reconciled to a timeline.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 11 more in the section
- AI Systems Performance Engineering - Chapters 13, 15 and 16Chris Fregly · primary
Read Chapter 13 on profiling and tuning PyTorch, Chapter 15 on inference parallelism, decoding and routing, and Chapter 16 on profiling and debugging inference. Keep Chapters 17 to 19 for GPU-9 and depth.
- AI Systems Performance Engineering companion code - Chapters 12 to 16Chris Fregly · required
Use compatible examples from
code/ch12throughcode/ch16. Trace whether each optimized path changes a kernel, graph, compiler choice, scheduler or library dispatch, then integrate one bounded custom path into a realistic operator or small endpoint. - Transformer Inference ArithmeticKipply · reference
Read kv cache, capacity, latency calculations, batch sizes and flops counting for per-token KV bytes, weight-capacity arithmetic and memory-bound versus compute-bound latency floors. Use it to derive endpoint bounds before measuring.
Also in this section
- AI Performance Engineering - Inference EnginesWafer · reference
A curated index. Use Section 4 only to find the introducing paper and implementation for the mechanism your measurement points to.
- PagedAttention and vLLMvLLM Authors · required
Study block-based key-value allocation, sharing and scheduling interaction. Trace logical token positions to physical blocks in one engine run and quantify fragmentation and memory-capacity effects.
- SGLangSGLang Authors · support
Read the runtime and RadixAttention design, then inspect the repository path for one kernel or prefix-reuse interaction. Use it as an alternative architecture in the integration defense.
- LeetGPU - Inference Kernel SetAlphaGPU · required
Choose three bottleneck-matched challenges from 74 GPT-2 Block, 83 Fused Residual Add RMS Norm, 84 SwiGLU MLP Block, 87 Speculative Decoding Verification, 93 Llama Transformer Block and 96 INT8 KV Cache Attention. Integrate one result locally rather than stopping at the hosted submission.
- FlashInferFlashInfer Project · support
Use the repository as the serving-kernel baseline and interface reference. Reconstruct workspace planning, layouts, dispatch and stream behavior for one selected operation before comparing your path.
- GPU Microbenchmark and Kernel Suite - IntegrationRoadmap-Final · support
Complete the real tensor or model-operation integration, dispatch and fallback requirements. Report compilation and invocation overhead, workload frequency, correctness or quality and the end-to-end no-benefit regime.
- PyTorch 2.14 ProfilerPyTorch · reference
Read the Overview example plus the API reference for
torch.profiler.profile(activities,schedule,on_trace_ready,record_shapes,with_stack),torch.profiler.record_functionandexport_chrome_trace. Use it for exact profiler and NVTX-range call contracts missing from the book. - Orca (OSDI 2022)USENIX · support
Read Sections 3 to 4 for iteration-level scheduling and selective batching, and Section 6 for the engine microbenchmark and end-to-end latency-throughput method. Use it as the continuous-batching mechanism behind the book summary.
- Sarathi-ServearXiv · support
Read Sections 3 to 4 for chunked-prefill stall-free batching and token-budget selection, and Section 5 for capacity and overhead method. Use it as the chunked-prefill mechanism behind the book summary.
- Fast Inference from Transformers via Speculative DecodingPMLR · support
Read Sections 2 to 3 for the draft-verify-accept loop, the acceptance rule and the walltime-versus-operations analysis. Use it for the verification cost model behind the engine guides.
- vLLM Documentation - Automatic Prefix CachingvLLM Project · reference
Read Automatic Prefix Caching (vLLM v0.31.0) for hash-based block reuse, full-block caching, reverse-order freeing and the multimodal hashing example. Use it for engine behavior the papers do not version.