Unit 5 of 11 · about 3 hours · measure
Chunked prefill, decode interference and long-context regimes
Long prompts stall every decode sharing the iteration. Chunking and placement bound that stall without changing the attention bill.
You'll be able to
- Explain chunked prefill, decode interference and the token-budget rule.
- Predict per-iteration latency and KV-transfer cost for a stated chunk size and live batch.
- Identify the long-context regime where chunking or disaggregation stops paying.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Chunked scheduling and interferenceAI Systems Performance Engineering - Chapters 13, 15 and 16
Chapter 16, Stall-Free Scheduling (Chunked Prefill); Chapter 15, Prefill-Decode Interference and Impact on Latency (TTFT) and Throughput (TPOT)
- Stall-free batching mechanismSarathi-Serve
Sections 4.1 to 4.3, chunked-prefills, stall-free batching with Algorithm 3, and token-budget selection; Figure 9, coalescing cost
- Staged versus peer KV handoffAI Systems Performance Engineering companion code - Chapters 12 to 16
HostStagedPrefillDecodeDisaggBenchmarkandPeerPrefillDecodeDisaggBenchmark, both defined inprefill_decode_disagg_common.pyand instantiated inbaseline_prefill_decode_disagg.pyandoptimized_prefill_decode_disagg.py
Focus on
- Chunked prefill splits a long prompt into fixed-size chunks that join decode iterations. Total attention work is unchanged; per-iteration latency is bounded by the token budget.
- Stall-free batching never pauses decodes to admit a prefill. The scheduler picks a chunk size that fits the token budget alongside live decodes.
- Long-context prefill is compute-bound with large activation memory while decode stays memory-bound. Placement and KV-transfer cost decide whether disaggregation pays.
Common mistakes · 3
- Calling chunked prefill cheaper in total FLOPs. It bounds latency per iteration; the attention bill stays the same.
- Measuring TTFT on an empty server and promising it under load. Interference appears only with live decodes sharing iterations.
- Ignoring KV-handoff cost in a disaggregation win. Transfer and scheduling can exceed the stall saved.
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.Does chunking reduce total prefill FLOPs?Answer
No. The same query-key pairs are scored; they are spread across iterations so one iteration never carries the full prefill.
2.What is prefill-decode interference?Answer
It stalls latency-sensitive decodes behind one long compute-bound prefill, raising time per output token. Chunking bounds that stall.
3.When does disaggregation stop paying?Answer
When transfer plus scheduling overhead exceeds the interference saved, or when the live batch is too small to fill the freed iterations.
Practice
- Companion code ch15: disaggregated prefill-decode pair
Run
python -m cli.aisp bench run --targets ch15:prefill_decode_disagg --profile minimal(plainpython -m ch15.compareruns every pair in the chapter); compareHostStagedPrefillDecodeDisaggBenchmarkagainstPeerPrefillDecodeDisaggBenchmarkon one prompt length and live batch, and report TTFT, TPOT and handoff costSingle-GPU emulation is enough. No public autograder scores the handoff; retain the length, batch, TTFT, TPOT and transfer notes.
You're done when
You can set a chunk size and token budget for a stated mix and defend the choice with measured TTFT and TPOT.
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. - 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.
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.
- 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.
- 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.