Unit 11 of 12 · about 4 hours · measure
Profiler ranges across the lifecycle and queueing versus execution stalls
Profiles show where time went. Only the queue-versus-execution split says whether to fix scheduling or kernels.
You'll be able to
- Place profiler ranges across encode and decode steps and read prefill versus decode work off a systems timeline.
- Distinguish queueing stalls from execution stalls using queue time, phase intervals and scheduler state.
- Explain one failed bottleneck hypothesis from synchronized trace evidence.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Timelines with phase rangesAI Systems Performance Engineering - Chapter 16, profiling and debugging inference
Profiling with Nsight Systems and Nsight Compute (pp. 969 to 973): NVTX Prefill and Decode step ranges, per-stream transfer and compute naming, and PC sampling before full tracing in production
- Sequential versus overlapped runtime structureAI Systems Performance Engineering companion code - Chapter 16
baseline_runtime_scheduler.pywith sequential CPU preparation, GPU compute and per-token streaming againstoptimized_runtime_scheduler.py; read the overlap structure under NVTX rangesRead the overlap structure, not the milliseconds. The matmul dimensions and the bundled per-architecture expectations are synthetic; re-measure everything on your device.
- Queueing versus execution in metric formvLLM Metrics Design and Production Metrics
Interval Calculations with the queue, prefill, decode and inference intervals; Scheduler Stats with running and waiting counts including waiting by reason
Focus on
- Use the CPU-GPU timelines, NVTX ranges and trace-to-source correlation unit for timeline reading: union of busy lanes, not sums, and a CPU range is not device completion. This unit adds the serving stall split.
- Scope ranges to phases: one Prefill range around encode, one Decode range per step. Phase lengths, overlaps and idle gaps on the timeline are the diagnosis.
- A stall with growing queue time and waiting counts is queueing: fix admission, budget or load. A stall inside prefill or decode intervals with the device busy is execution: profile kernels.
- Preemption looks like execution from one angle and queueing from another. Read the preemption events and the restarted prefill spans before naming the cause.
Common mistakes · 3
- Summing busy times across streams and lanes. Overlapping work counts once; the union is the elapsed time.
- Reading a long CPU-side range as slow device work. Host ranges include launch, synchronization and waiting; only device-side evidence classifies execution.
- Profiling in production with full tracing first. Localize with counters and PC sampling, then trace one case.
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.Prefill kernels take 40 ms inside a 900 ms TTFT with high queue time. Scheduling or kernels?Answer
Scheduling. The kernels are a small fraction; the request waited. Fix admission, budget or load.
2.Decode gaps spike exactly when a new long prompt arrives. What confirms interference over a kernel regression?Answer
The gaps align with the new prefill's iterations on the timeline while decode kernels are unchanged, and per-step instrumentation shows the waits outside model execution.
3.Why scope NVTX ranges to phases instead of wrapping the whole server loop?Answer
Phase ranges separate prefill from decode work on the timeline. One outer range cannot attribute time to either phase.
4.A profile shows all-to-all above 5 ms per iteration on a disaggregated setup. What next?Answer
Treat communication as the hypothesis: verify against the timeline and counters, then test overlap or placement changes. Do not tune attention kernels first.
You're done when
You can take any slow request, split its stall into queueing versus execution from trace evidence, and kill one wrong hypothesis in writing.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 9 more in the section
- 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.
- 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.
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.
- 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 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. - 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.