Prefill, Decode and Baseline Measurement
Prefill, decode, queueing and host work fail for different reasons. Phase-separated traces and correct asynchronous timing are required before any optimization claim is credible.
Section 2 of 9 · 12 units · about 47 hours
By the end you can Produce separate prefill and decode distributions, classify three workload regimes before profiling, and explain one failed bottleneck hypothesis from synchronized traces without changing the correctness or workload contract.
Units
- Prompt tokenization and preprocessing as request work3h
- Prefill parallelism, the decode dependency and decode shapes4h
- Compute, bandwidth, launch, capacity and queue-bound regimes5h
- Batch size, sequence shape, chunked prefill and phase interference4h
- Decomposing TTFT and decode steps into their components4h
- Device synchronization, warmup, compilation and cold versus warm state4h
- Identical output contracts, seeded sampling and distributional comparison4h
- Single-request baselines, concurrency and rate sweeps, and a shape matrix5h
- Raw timestamps, decode gaps, and memory, utilization and power context3h
- Repeated trials, uncertainty and observer overhead3h
- Profiler ranges across the lifecycle and queueing versus execution stalls4h
- Predictions before profiles, residuals and goodput under latency targets4h
Build it
Mini project · about 10 to 14 hours
Prefill and decode baseline measurement harness
Extend servelab with phase-separated timing, synchronized device measurement and a sweep harness that keeps raw traces for a model that fits your GPU. Predict bottlenecks before profiling and defend goodput under explicit targets, so later changes have an honest baseline.
- 1Instrument per-request spans for tokenize, queue, prefill, first token, decode steps, sampling and streaming in
harness/with a flame graph of the hottest host frame, checked against vLLM interval definitions with traces kept inreports/. - 2Derive decode-step shapes and prefill versus decode work, place both on a roofline for your GPU, and predict interference from an unchunked long prefill, checked with the TensorTonic decode problem and the Hands-On companion batching notebook with plots kept in
reports/. - 3Time device work with stream-ordered events after warmup and capture, fix identical prompts, limits, stop behavior and cache state, and gate every comparison on greedy identity plus distributional agreement checked against the pinned sampling API with contracts kept in
reports/. - 4Build the sweep harness in
harness/with a single-request cell, concurrency and rate ladders and a shape matrix usingvllm bench serveandvllm bench latency, retaining raw arrival and per-token records with aligned memory, utilization and power and the meter boundary inreports/. - 5Repeat key cells with interleaved trials reporting uncertainty, cross-check with a second tool, and measure observer cost with profiling on and off, keeping raw samples and overhead notes in
reports/. - 6Write a dated bottleneck prediction before profiling, explain TTFT and every decode gap from synchronized ranges and scheduler state (
vllm:kv_cache_usage_percandvllm:num_requests_waiting, not memory used), report goodput under stated targets and preserve one failed prediction inreports/.
What you hand in
- Phase-separated harness in
harness/with spans, sweeps and raw per-request records. - Device-timed baseline with warm-state rules, output contracts and uncertainty plus observer checks.
- Dated predictions, residual attributions, goodput report and one preserved failure with trace queries.
How to check it
- Self-grade with the rubric below
- TensorTonic Decode Attention with KV Cache
Solve by hand first, then pass the public cases in your harness.
- Hands-On LLM Serving companion batching notebook
Reproduce batched against single timing, then add your own per-request spans.
How it's graded
Span attribution
Pass: Spans split queueing from execution for a slow request against vLLM intervals with flame-graph evidence.
Great: Every decode gap maps to scheduler or execution evidence and the hottest host frame is named.
Sweep discipline
Pass: Single-request, ladder and matrix cells rerun under identical contracts with raw records and uncertainty.
Great: A second tool agrees within uncertainty and observer cost is measured and kept out of the reported medians.
Prediction honesty
Pass: Dated predictions precede profiles, residuals cite evidence, goodput states targets and one failure remains.
Great: The failed prediction names the disproving observation and revises the regime boundary.
Resources
- Efficiently Scaling Transformer InferenceMLSys
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)
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
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.
- Hands-On LLM Serving and Optimization - Chapter 5 and the Chapter 4 metrics sectionChi Wang and Peiheng Hu (O'Reilly)
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
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
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
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
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
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.
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
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
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.