Inference Trade-offs Explained

Chapter 01 · Batching

Batching policy and chunked prefill

Which requests share a forward pass: prompts first, running decodes first, or prompts cut into chunks that ride along with the decodes. Below, the mechanism as the simulator ran it, step by step; then what it measured, why it behaves that way, and the papers.

Check yourself ↓ three questions and what to remember, at the end

Loading the batching animation…

Its row of the matrix

Loading the matrix…

Three ways to fill a forward pass

Every step of a serving engine is one forward pass of the model over a batch of rows. A row is either part of a prompt being prefilled or one decoding request asking for its next token. The policy decides which rows share a pass, and the animation shows the three the simulator implements, on the same six requests.

Prefill-priority (the baseline, the original vLLM scheduler) runs a waiting prompt as soon as it can, whole, in a pass of its own. Every decoding request waits for that pass: in the animation the longest gap between two tokens of a request (ITL p99) is 292.5 ms. Decode-priority admits new prompts only when the running batch has drained, so the tokens flow evenly (ITL p99 9.6 ms) and the newcomers wait instead: their median time to first token is 767.8 ms, against 111.4 ms. Chunked prefill (Sarathi-Serve) cuts each prompt into pieces that fit what is left of the step's token budget τ after every decode row has its token: with the smallest budget ITL p99 falls to 23.0 ms while TTFT p99 stays close to prefill-priority's (264.1 ms against 242.2 ms). The larger the budget, the more prompt each pass carries and the more it stalls the decodes.

Why chunking is nearly free here

A decode pass reads every weight of the model to produce one token per row, so it is memory-bound: its arithmetic intensity sits far below the ridge point of the roofline. Prompt tokens that ride along in the same pass reuse the weights already being read, and use compute that would otherwise idle, until the pass becomes compute-bound. That is why piggy-backing costs the decodes little, and why the same weights can feed many rows at once (the reuse a systolic array is built for).

The simulator's roofline makes chunking almost free: splitting one long prompt into chunks of 512 costs at most 0.4% more time than one pass. The paper measured far more (Chunking overhead at most ~25% with 512-token chunks, negligible at 2,048 (section 5.4.1, Fig. 14)), because real kernels pay for every extra launch and for partly filled tiles; the simulator has neither, so it understates the cost of small budgets (results.md section 22 records the gap).

PolicyTTFT p50TTFT p99ITL p99TPOT p99J/token
prefill-priority249.4 ms 1,194 ms 246.1 ms 37.2 ms 0.288
decode-priority496,500 ms 879,491 ms 10.0 ms 9.9 ms 0.916
chunked 256273.6 ms 1,229 ms 26.3 ms 19.5 ms 0.308
chunked 512268.3 ms 1,185 ms 51.1 ms 27.1 ms 0.297
chunked 2048264.7 ms 1,198 ms 189.2 ms 34.4 ms 0.289
Recorded in results.md section 19: Mistral-7B on one A100, ShareGPT-like lengths, at a fixed load. ✓ / ✗: better or worse than prefill-priority.

Which workloads it helps

In the sweep (Llama-3-70B, eight H100s, at each configuration's own capacity under its workload's SLOs) a 512-token budget raises goodput per GPU by +94% on long-context RAG, +60% on real-time voice and +28% on chat: there the decode stalls behind long prompts were what broke the TPOT SLO. It costs -5% on offline batch, which has no latency to protect, and -24% on the coding agent, whose prompts open with a 6,144-token shared prefix: without prefix caching every prompt is prefilled in full, a small budget spreads it over many passes that each re-read the weights, and its TTFT p99 rises +16% under the agent's tighter TTFT SLO. Prefix caching (chapter 3) removes most of that work, which is why the combined configurations (chapter 13) chunk with a larger budget.

Decode-priority loses on every workload (goodput -100% on chat): smooth tokens are worth nothing when the requests behind them miss their TTFT SLO.

Against the paper

Under the paper's strict SLO the simulator's capacity gain from chunking is 3.24x against the paper's Capacity gain over vLLM, strict SLO: Mistral-7B "2.6x" (abstract), "3.5x" at 100 ms with a 512 budget (section 5.2) (Reproduces (inside the paper's range)); the qualitative picture (prefill-priority stalls decodes, decode-priority starves prompts, chunking keeps ITL low at a small TTFT cost) reproduces too.

What the sweep measured, lever by lever

Decode-priority batching

Change from the baseline on H100, at capacity for goodput, cost and energy, at the reference load for latency. Run it live

Workloadgoodput$/M tokJ/tokTTFT p99TPOT p99ITL p99
Chat-100% – $– +170844% -44% -91%
Coding agent-87% +696% $+250% +757% -48% -3%
Offline batch-100% – $– +1130% -93% -90%
Long-context RAG-86% +633% $+230% +14636% -55% -8%
Real-time voice-86% +619% $+266% +944% -33% -1%

Chunked prefill, 512-token budget

Change from the baseline on H100, at capacity for goodput, cost and energy, at the reference load for latency. Run it live

Workloadgoodput$/M tokJ/tokTTFT p99TPOT p99ITL p99
Chat+28% -21% $-11% +8% -19% -80%
Coding agent-24% +31% $+17% +16% -19% +142%
Offline batch-5% +6% $+5% +18% -83% -75%
Long-context RAG+94% -48% $-22% +19% -22% +140%
Real-time voice+60% -38% $-23% +8% -16% +132%

Chunked prefill, 2,048-token budget

Change from the baseline on H100, at capacity for goodput, cost and energy, at the reference load for latency. Run it live

Workloadgoodput$/M tokJ/tokTTFT p99TPOT p99ITL p99
Chat+13% -11% $-7% +23% -6% -33%
Coding agent-9% +10% $+5% +7% -4% +712%
Offline batch+2% -2% $-0% +1% -38% -11%
Long-context RAG+12% -11% $-5% +6% -12% +719%
Real-time voice+16% -14% $-9% -3% -11% -0%

Caveats on these numbers

  • $Prices per GPU-hour are illustrative. Cost per million tokens uses round illustrative prices (H100 $3.00, H200 $3.50, B200 $5.00 per GPU-hour), not quotes. Cost scales linearly with them, so the ranking of levers on one device does not depend on them; comparisons across devices do.

✓ better than the baseline, ✗ worse, by more than ±2%. Every lever on every metric and device: the matrix; on any two metrics: the explorer.

Check yourself

Commit to an answer before you reveal it: a wrong guess you can explain teaches more than a right one you skimmed. Every number in the answers comes from the same tested model as the chapter’s.

Q1Which policy keeps the tokens flowing evenly but makes newcomers wait for their first token?
Reveal the answer

Answer: Decode-priority

Decode-priority admits prompts only when the running batch drains: ITL p99 is 9.6 ms, but the median first token waits 767.8 ms.

Three ways to fill a forward pass →

Pick one, then reveal.

Q2In the animation, what is the ITL p99 with chunked prefill at the smallest token budget, in ms?
Reveal the answer

Answer: 23.0 ms (counted right within 10%)

Against 292.5 ms under prefill-priority: no decode waits for a whole prompt, because each pass carries only a slice of one.

Three ways to fill a forward pass →

Commit to a number, then reveal.

Q3Why does riding prompt tokens along in a decode pass cost the decodes so little?
Reveal the answer

Answer: Because a decode pass is memory-bound: the extra rows reuse weights already being read

A decode pass reads every weight for one token per row, so its compute idles; prompt rows use that idle compute until the pass turns compute-bound. On chat, a mid-sized budget raises goodput per GPU by +28%.

Why chunking is nearly free here →

Pick one, then reveal.

Papers and sources