Prefill and Decode
A request does two different jobs. Measured on a real model: what each costs, where the textbook bottleneck fails for a small model, and how a long prompt stalls everyone else.
On the measured RTX 2060 workstation, a cached GPT-2 request with a 16-token prompt produced its first token in about 12 ms, then each later token in about 11 ms. Lengthen the prompt to 1,000 tokens and the first token took about 44 ms, but later tokens still came every 11 ms or so.
Change the reply length and the balance flips:
| Request | Where most of the model-loop time went |
|---|---|
| 16-token prompt, 64 output tokens | About 98% after the first token |
| 1,000-token prompt, 4 output tokens | About 56% before the first token |
One request contains two different workloads. Prefill processes the known prompt in parallel and builds the attention state. Decode makes each new choice depending on the previous one, reusing that state. They respond differently to prompt length, output length, overhead, weight traffic and scheduling, and they interfere with each other. In a two-request simulation, dropping one request’s 1,000-token prefill into the middle of another request’s stream stretched the second request’s longest pause between tokens to 56–73 ms, against a normal gap of 11–13 ms.
(These are local measurements of a cached, greedy GPT-2 loop on one workstation. They are not latencies a client of a real service would see, and the interference result comes from one simple schedule, not a production server.)
You will often hear that prefill is compute-bound and decode is bandwidth-bound. That is a performance model that depends on the workload, not something transformer mathematics guarantees. This chapter tests it on GPT-2 small. As we will see, the short-prompt and per-token timings here look more like a large fixed overhead than either limit, though the experiments cannot pin down which overhead.
Where this sits
Autoregressive Generation separated parallel scoring from serial token selection. Matrix Multiplication and GPU Execution introduced arithmetic intensity, the roofline and host-side overhead. Attention and Its Computational Cost contrasted prefill-shaped and decode-shaped attention. Here those become the two phases of a real request.
This chapter measures the phases; it does not compare cached with uncached execution. The experiments use the Hugging Face KV cache as a black box. (The phases can be defined without a cache, but the cache is what makes a one-position decode step possible without recomputing the prefix.) Key-Value Caching implements caching explicitly, checks numerical agreement and measures the work it saves.
The Inference Lab gains a small vocabulary for measuring requests: request_metrics turns timestamps into latency metrics, phase_share splits time between phases, and chunk_schedule divides a prompt into chunks. (A helper named goodput also exists, but it currently computes something else; see below.)
For the Pi series, agent traffic shows why the split matters. A tool result or retrieved passage often means a long input and a short reply; an assistant writing a long answer to a short question is the opposite. Neither is fixed: repeated history, cache reuse, batch size and queueing all shift the balance. The useful question is what share of a real request’s time goes to each phase under the intended workload.
Two phases
Prefill runs the model over all \(T\) prompt tokens at once. At each layer it projects every prompt position and, with caching on, stores their keys and values. The logits at the last prompt position already give the distribution for the first generated token. No extra forward pass is needed to get it. (The experiments request only that last row, with logits_to_keep=1.)
Decode starts after the first token is chosen. Each step feeds in the newly chosen token, reads the cached keys and values, extends the cache and produces logits for the next token. The matrix work inside a step is parallel, but the steps form a serial chain.
So for \(n\) generated tokens there is one prefill and \(n-1\) decode passes, not \(n\) of each. Counting \(n\) decode passes is a classic off-by-one error.
The shapes differ accordingly. Prefill has \(T\) query positions (and \(T\) rows in every weight projection); a decode step has one. That explains why they scale differently, but shape alone does not tell you whether a real implementation is limited by launches, bandwidth or compute. That takes measurement.
Five things called “latency”
To measure either phase you need to say exactly what you are timing. “Latency” covers five distinct quantities:
| Metric | Definition | Note |
|---|---|---|
| Time to first token (TTFT) | Request submission to receipt of the first output token | This chapter’s timestamps are model-local, so its values are not client TTFT |
| Inter-token latency (ITL) | Each gap between consecutive delivered tokens | \(n\) tokens give \(n-1\) gaps; a distribution, not one number |
| Time per output token (TPOT) | Mean of those gaps, \((t_{\mathrm{last}}-t_{\mathrm{first}})/(n-1)\) for \(n\ge2\) | Undefined for one token |
| End-to-end latency (E2E) | Submission to completion | Distinguish from time spent inside the model loop |
| SLO compliance and goodput | Compliance: the fraction of requests meeting latency targets. Goodput: the rate of compliant requests, per second over a stated window | Need a population of requests |
Two of these are easy to confuse:
- TPOT is a mean; ITL is a distribution. Two streams can have the same TPOT and very different worst pauses (the unit tests construct exactly this). So publish TTFT, mean TPOT and the ITL tail (p95, p99 or maximum, with the sample count). With only a few dozen tokens, a maximum is a useful observation, not a reliable tail estimate.
- Compliance is not goodput. One is a fraction, the other a rate. The Lab’s current
goodput()helper returns the fraction, despite its name, and returns a TPOT of0.0for single-token traces, which must not be read as a real measurement. Both are logged as defects to fix (exercises 3 and 4).
And never derive client-side metrics from GPU timings: queueing, decoding, transport and back-pressure all come in between.
A note on the original example
The book’s original examples/ch09/prefill_decode.py makes two classic mistakes. It counts an extra “first decode step” into TTFT, although prefill already produced the first token’s logits. And its “decode” reruns the whole prefix instead of using the cache. The measured code is examples/ch09/phases.py, which uses past_key_values and takes the first token from prefill. The original file is kept as a historical fixture, not a timing reference.
Prefill
The question. How does prefill time grow with prompt length?
The measurement. The prefill command times the model call for \(T\) synthetic token ids, with caching on and only the last logits row computed. The ids are already on the device, and CUDA timings synchronise. Nothing outside the model call is included: no tokenisation, loading, network or queueing. Ranges are medians from two separate runs of the command (15 timed samples per GPU case, four per CPU case, after warm-up).
| Prompt tokens | GPU fp32 | GPU fp16 | CPU, 1 thread |
|---|---|---|---|
| 1 | 11.5 – 12.2 ms | 11.9 – 12.0 ms | 40 – 45 ms |
| 16 | 11.6 – 12.5 ms | 13.6 – 14.0 ms | 86 – 95 ms |
| 128 | 11.8 – 12.5 ms | 11.8 – 12.9 ms | – |
| 256 | 12.2 – 15.4 ms | 12.4 ms | 1,037 – 1,070 ms |
| 512 | 22.6 – 26.3 ms | 12.1 – 12.5 ms | 2,096 – 2,111 ms |
| 1,024 | 45.1 – 52.0 ms | 16.1 – 18.3 ms | – |
Three regimes appear (though no profiler located the boundaries between them).
A flat floor. On the GPU, fp32 prefill takes about 12 ms for anything from 1 to 128 tokens, and 12.2–15.4 ms at 256. fp16 stays near 12–14 ms right up to 512 tokens. In fp32 on this GPU, 128 tokens took about as long as one. That pattern fits a large fixed cost per call: the per-operation and host-side overheads seen in Matrix Multiplication and GPU Execution, perhaps plus cache and framework bookkeeping. But Python dispatch, kernel launches, synchronisation and GPU computation were not timed separately, so “launch-bound” is a hypothesis.
Rising work. At 1,024 tokens the real work shows through:
| Time | Prompt tokens/s | Nominal matmul TFLOP/s | |
|---|---|---|---|
| fp32 | 45.1–52.0 ms | about 19,700–22,700 | 3.7–4.3 |
| fp16 | 16.1–18.3 ms | about 56,100–63,800 | 10.6–12.0 |
That is far more effective parallel work than at short prompts. It does not by itself show that arithmetic is the limit: the FLOP count is a model estimate, and the elapsed time also includes elementwise work, cache construction and framework overhead.
One CPU thread. For fp32 prefill of 64, 256 and 512 tokens, the CPU sustained about 239–253 prompt tokens/s. At four tokens it took 71–86 ms. The CPU has its own overheads, just not the CUDA submission path. (Evidence about this one-thread configuration, not about CPUs in general.)
Computing less of the output
The Transformer as a Computation predicted that computing logits only for the last position could remove about 30% of matmul arithmetic at short contexts. logits_to_keep=1 does exactly that. Did it save time?
- CPU, 64–512 tokens: about 25–31% saved, close to the prediction.
- GPU fp32, 512 and 1,024 tokens: about 20–21% saved.
- GPU, very short prompts: noisy, sometimes negative.
So trimming unused logits helps, but the prediction is not confirmed at every length, and explaining the gap between the time saving and the FLOP saving would need a finer breakdown. One more caution: changing the output projection’s shape can change floating-point rounding, so numerical equivalence still has to be checked.
Decode
The question. How does each decode step’s time depend on how much context is already cached?
The measurement. For each case, build a cache from a synthetic prompt of 16, 128, 512 or 960 tokens, then run 40 greedy decode steps on the GPU (12 on the CPU). Each step reads the chosen id back to Python with .item(). Report the median step after dropping the first four. (This is a Python loop that synchronises with the host every step, not a pure kernel benchmark. The 960 case stays inside GPT-2’s 1,024-position limit; an earlier attempt at 1,000 + 40 exceeded it and was discarded.) Ranges are over two runs.
| Context at start | GPU fp32 | GPU fp16 | CPU, 1 thread |
|---|---|---|---|
| 16 | 11.1 – 11.2 ms | 11.0 – 12.2 ms | 35 – 43 ms |
| 128 | 11.1 – 11.7 ms | 11.3 – 11.6 ms | 39 – 42 ms |
| 512 | 10.9 – 11.4 ms | 11.1 – 11.4 ms | 41 – 76 ms |
| 960 | 10.9 – 11.4 ms | 10.8 – 11.1 ms | – |
On the GPU, every case sits near 11 ms, in fp32 and fp16 alike, with no trend from 16 to 960 tokens of context.
That does not mean context is free. Attention genuinely reads more cached positions as context grows. It means any extra cost was too small to see above an 11 ms step on this hardware and software.
Is decode bandwidth-bound here? A back-of-the-envelope bound says no, at least not simply:
| Quantity | Value |
|---|---|
| fp32 parameter storage | about 474.7 MiB |
| Parameters plus cache, across the tested contexts | about 476–542 MiB |
| Time to read that once at Chapter 7’s modelled 303 GB/s (a figure Chapter 7 calls partly circular; its 278 GB/s copy rate gives a similar answer) | about 1.6–1.9 ms |
| Measured step time | about 11 ms |
| Nominal bytes ÷ step time, fp32 | 43–52 GB/s |
| Nominal bytes ÷ step time, fp16 | roughly 20–26 GB/s |
If decode were limited only by reading the weights and cache, a step would take about 2 ms. It takes about 11. (The ratios in the last two rows are not measured bandwidth: some reads may be cached, actual traffic may be higher or lower, and other work also takes time.) So an ideal-bandwidth explanation is not enough, though this does not identify what is the limit.
The most plausible explanation is a large fixed cost per step: a sequence of framework calls, GPU launches, cache management, and a forced host readback on every token. The experiment does not split the 11 ms between these. Nor can it say how much the cache saves, because it never runs an uncached loop at matched contexts. The experiment that would settle it is a four-way comparison: cached versus uncached, and per-step .item() versus deferred readback, timed with CUDA events and a profiler trace (exercise 2).
The CPU is noisier: 35–43 ms at 16 tokens of context, 39–42 at 128, and 41–76 at 512. That is too variable to show a reliable trend with context; a clean CPU benchmark would need more repetitions, process isolation and a profile.
What would make decode bandwidth-bound
The balance shifts with model size. Consider a hypothetical 7-billion-parameter model in fp16: its weights alone are about 14 GB (decimal). Reading 14 GB once at Chapter 7’s modelled 303 GB/s takes at least 46 ms per token (about 50 ms at its 278 GB/s copy rate), far more than this workstation’s measured 11 ms step.
This is a thought experiment, not a benchmark. That model would not fit on this 12 GiB card, real kernels may reuse data or move extra bytes, and larger models also change launch counts, cache traffic and parallelism. It shows why weights can dominate decode at scale, not where the crossover lies.
The practical rule: measure before optimising. Compare the measured step with arithmetic and data-movement lower bounds, but do not treat the gap as proof of a particular bottleneck. Before quantising weights, measure latency, GPU time, memory traffic and output agreement. Before attacking launch overhead, compare a synchronised Python loop with CUDA events and a captured or compiled version. The same model can move between regimes as batch size, context and implementation change.
Where the time goes in a request
Now both phases together. cmd_endtoend runs five times per case: synthetic prompts, fp32 GPT-2 on the GPU, last-position prefill logits, cached greedy decode.
What the clock covers. It starts just before the prefill call, with the token ids already on the GPU, and the first-token interval ends after argmax and .item() bring the chosen token back to the host. So this is model-loop TTFT. It leaves out tokenisation, queueing, client transfer, network delivery and rendering. Later timestamps are reconstructed from per-step durations rather than recorded from a real stream. Phase shares come from separately aggregated medians, so they differ slightly from the end-to-end median.
| Prompt | Output | TTFT | TPOT | End to end | Prefill share | Decode share |
|---|---|---|---|---|---|---|
| 16 | 64 | 12.3 ms | 11.2 ms | 720 ms | 1.7% | 98.3% |
| 128 | 64 | 11.8 ms | 11.4 ms | 731 ms | 1.6% | 98.4% |
| 512 | 64 | 23.1 ms | 11.5 ms | 747 ms | 3.1% | 96.9% |
| 512 | 8 | 22.8 ms | 11.4 ms | 102 ms | 22.1% | 77.9% |
| 1,000 | 16 | 43.6 ms | 11.1 ms | 211 ms | 20.6% | 79.4% |
| 1,000 | 4 | 43.9 ms | 11.3 ms | 78 ms | 56.3% | 43.7% |
The pattern is simple. TTFT rises with prompt length once the prompt leaves the flat region; TPOT stays near 11–11.5 ms throughout. So which phase dominates depends almost entirely on the ratio of prompt to output: from 1.6% prefill (128 in, 64 out) to 56.3% (1,000 in, 4 out).
That ratio is a property of the workload, not the model, and batching, longer contexts, sampling and queueing can shift it further. Before deciding which phase to optimise for a retrieval or agent workload, record its real distribution of prompt and output lengths. From Inference Loop to API adds real request and client-delivery boundaries; until then, these figures keep the narrower “model-loop” label.
When one request’s prefill hurts another
The scenario. Request A is streaming tokens after a 32-token prompt. At A’s tenth decode step, request B arrives with a 1,000-token prompt. Both run in one Python process on one GPU, with model calls executed one after another. B’s prompt is processed either in one prefill call, or in cache-preserving chunks with one A decode step between each chunk.
What is measured. A’s gaps between tokens (read back on the host), and the time until B’s last prefill chunk has finished and its final logits exist. That second figure is labelled the B prefill-completion interval, not TTFT, because the harness never samples, emits or delivers B’s first token. (This is a simulated alternation, not a queue with independent arrivals or real token delivery.)
Ranges across three runs:
| B’s prefill chunk (tokens) | Worst local gap in A | Median local gap in A | B prefill-completion interval |
|---|---|---|---|
| 1,000 (unchunked) | 56–73 ms | 11–13 ms | 56–76 ms |
| 512 | 39–51 ms | 11–13 ms | 73–91 ms |
| 256 | 26–34 ms | 11–13 ms | 100–126 ms |
| 128 | 26–34 ms | 11–13 ms | 192–230 ms |
| 64 | 26–35 ms | 11–15 ms | 380–490 ms |
(B’s completion interval includes the A decode steps interleaved between its chunks, roughly one per chunk boundary at about 11 ms each, so it is not pure B compute time.)
Unchunked, B stalls A. A’s worst gap jumped to 56–73 ms, against its usual 11–13 ms: a concrete case of head-of-line blocking. Note that a single long gap barely moves A’s mean TPOT, averaged over many tokens, but it dominates the worst gap. That is why the ITL tail matters. (A user would also see delivery and rendering delays, which are not modelled here. And with about forty tokens, report the maximum with its sample count; don’t infer a p99.)
Chunking trades one request’s delay for the other’s. With 256-token chunks, A’s worst gap fell to 26–34 ms, but B’s prefill took 100–126 ms to complete instead of 56–76. A gets to run between B’s chunks; B pays for the interruptions.
Smaller chunks stopped helping. Below 256 tokens, A’s worst gap stayed around 26–35 ms, while B’s completion grew to 192–230 ms (128-token chunks) and 380–490 ms (64-token chunks). Much of that growth is the interleaved A steps themselves: 64-token chunks put about fifteen A decode steps inside B’s clock. Whether each chunk also carries extra fixed cost on this path was not separated. It does not establish 256 as a universal optimum: the best chunk size depends on arrivals, latency targets, batching, caching, hardware and model.
This reproduces one mechanism behind chunked prefill in Sarathi-Serve, but it is not an implementation or benchmark of that system, which handles batching, scheduling and request-level objectives well beyond this two-request alternation.
Does chunking change the answer?
Chunked prefill must compute the same function: each chunk must run at its true absolute positions, with the earlier chunks’ keys and values available. In the recorded fp32 experiment, B’s final logits from chunked and unchunked prefill differed by about 1.5–1.9 × 10^{-4} at most.
That is a small numerical difference, but it is not proof of identical output: a near-tie could still flip the chosen token. The existing unit test checks a small, randomly initialised GPT-2 on one input to a 1e-4 tolerance; it does not cover the 1,000-token experiment. Longer, multi-chunk tests should compare logits, chosen tokens, cache positions and the generated output (exercise 8).
What this means for a scheduler
A scheduler has to distinguish two kinds of work: processing new prompt tokens, and advancing outputs that are already streaming. Doing too much of the first stalls the second; doing too little delays new requests. Continuous Batching revisits this under continuous batching, Request Scheduling and Admission Control under admission and scheduling objectives, and Prefill/Decode Disaggregation by running the phases on separate hardware. Sarathi-Serve, DistServe and Splitwise provide broader evidence for these designs; this chapter tests only a small piece of that space.
Inference Lab increment
The Lab now has two kinds of addition, and they should be kept apart: portable measurement helpers, and GPU experiments whose timings depend on this device, framework, model and timing boundary.
request_metrics(request_time, token_times)returns local TTFT, per-token ITLs, TPOT, end-to-end time and maximum ITL. It needs at least one timestamp. Its single-token TPOT of0.0is a placeholder, not a measured gap.goodput(metrics, ttft_slo, tpot_slo)currently returns the fraction of traces meeting both targets. It should be renamedslo_compliance_fraction, or given a duration so it can compute true goodput in compliant requests per second, with defined handling of failed, cancelled and one-token requests.phase_share(prefill_seconds, decode_seconds),chunk_schedule(prompt_len, chunk),decode_bytes(...)andbandwidth_utilisation(...)are cost and scheduling helpers. The last two use assumed byte counts, not hardware counters.prefill,decode,endtoendandinterferenceare the GPT-2 experiments.endtoendreconstructs local timestamps;interferenceis a two-request simulation.
Still needed: a client-clock metric path, the synchronised-versus-deferred .item() comparison, regression tests for chunked-prefill cache positions, and a real request-rate goodput calculation.
The metrics module is deliberately separate from the model, so any instrumented execution can submit timestamps. But where a timestamp came from is part of what it means. Label model-loop timestamps as such until an HTTP client supplies real arrival and delivery times. From here on, report the clock boundary, TTFT, TPOT, ITL tail and sample count, with prompt and output lengths, batch size, dtype and device; and when evaluating scheduler capacity, include arrival rate and compliant requests per second. A single undifferentiated “latency” or “goodput” number cannot answer these questions.
Limits of this chapter’s evidence
About the set-up
- One model, one workstation. GPT-2 small on an RTX 2060 under Windows with a display attached. Nothing here qualifies the performance of multi-billion-parameter models.
- Synthetic prompts, greedy selection. Random token ids; no study of answer quality, instruction-tuned behaviour, EOS stopping or realistic conversation lengths.
- Library cache only. It was not compared with an uncached loop here, and its memory growth was not instrumented.
About the measurements
- Few repetitions. Prefill and decode tables come from two runs, end-to-end from five, interference from three, and variation reaches tens of per cent.
- No bottleneck attribution. The flat floors fit dispatch, launch, cache or synchronisation overhead, but no per-kernel profile or traffic counter isolated the cause.
- Nominal bytes, not measured traffic. Byte-per-second ratios assume weights plus cache are each read once.
- Host synchronisation every step. Removing
.item()or capturing the execution graph might change decode latency substantially. - Model-loop timing boundaries. No tokenisation, queueing, network or rendering, and no independently timestamped client stream.
- Too few tokens for tail claims. Maximum gaps are informative; robust p95/p99 across many requests were not measured.
About scope
- The scheduler study is a two-request simulation: no continuous batching, true concurrency, fairness analysis or measured service goodput.
- Chunked-prefill agreement is one input: rare argmax divergence, longer sequences and other precisions were not tested.
What you should now be able to do
- Describe prefill and incremental decode by their tensor shapes, cache state and first-token boundary.
- Compute TTFT, ITL, TPOT and end-to-end latency from timestamps, and say whether the timestamps are model-local or client-observed.
- Distinguish an SLO-compliance fraction from goodput in successful requests per second.
- Explain why a 1,000-token prompt raises the first-token time while later steps stay near 11 ms.
- Compute a nominal weights-plus-cache byte estimate without calling it measured traffic.
- Explain why flat short-input timings are consistent with fixed overhead but do not prove a launch-bound bottleneck.
- Read the longest ITL gap alongside mean TPOT and the sample size.
- Explain the chunked-prefill trade-off from the point of view of both the streaming request and the new one.
- Say which numerical checks are needed before declaring chunked and unchunked prefill equivalent.
- Separate what this GPT-2 experiment shows from what the cited serving papers support.
Throughout this chapter the KV cache was a black box: something the library kept, which made each decode step cheap. Key-Value Caching opens it: why reusing stored keys and values gives the same answer, how big the cache is, what it saves, and what it costs in memory.
Key terms
- Prefill: evaluating a known prompt and, in a cached runtime, retaining its attention keys and values.
- Incremental decode: advancing the model by one position using stored attention state; serial across chosen output tokens.
- TTFT: time from a stated request-start boundary to receipt or availability of the first token; client TTFT includes queueing and transport.
- TPOT / ITL: the mean gap after the first output token / the list or distribution of individual consecutive-token gaps.
- SLO-compliance fraction: completed requests meeting configured latency thresholds divided by the relevant request count.
- Goodput: rate of SLO-compliant completions in requests per second, requiring a measurement window.
- Launch/dispatch overhead: fixed or per-operation work surrounding device execution; observed flat latency alone does not isolate it.
- Chunked prefill: processing a long prompt in successive cache-preserving pieces that may be interleaved with other work.
- Head-of-line blocking: one request’s scheduled work delaying another request’s progress.
- Model-loop versus client latency: different timing scopes; the former omits admission, transport and rendering.
- Nominal bandwidth ratio: estimated input bytes divided by elapsed time, not a measured GPU bandwidth counter.
Reader exercises
- Run
prefillon your hardware in fp32 and fp16. Repeat enough independent process runs to report uncertainty, then locate the interval in which latency starts increasing with prompt length. - Profile a decode step with CUDA events and a CPU trace. Compare four cases: cached versus uncached, and per-step
.item()versus deferred readback. Which component accounts for the observed floor? - Construct two token-delivery traces with equal TPOT but different maximum ITL. Add a one-token trace and decide how its undefined TPOT should be represented in the API.
- Change the
goodputhelper to report both SLO-compliance fraction and compliant requests/s over an explicit duration, including a unit test with cancelled or timed-out requests. - Re-run the
interferencescheduler with B arriving at different A steps. Record A’s maximum gap, B’s prefill completion and the number of opportunities each request gets to run; explain why the last measure is not B’s client TTFT. - Add a second decoding stream to
interference. Test how different chunk sizes affect both streams’ maximum ITLs and B’s completion time. - Derive the nominal weight and cache byte count for GPT-2 at context lengths 16 and 960. Then use GPU hardware counters (if available) to compare nominal bytes with actual external memory traffic.
- Add a long-prompt test that compares unchunked prefill with sizes 512, 256, 128 and 64. Check final logits, chosen token, generated sequence, cache lengths and absolute positions; make the tests parameterised across dtypes.
- Make the end-to-end command record actual token timestamps instead of reconstructing them from step durations. Compare against the existing approximation, then write down the additional timestamps needed for a real client-observed TTFT.
- Given a 50 ms TTFT objective and 15 ms TPOT objective, score the six measured model-loop cases by local threshold compliance. Explain why that is not a service goodput estimate.
References
Three primary systems papers frame the general serving problem; they study different models, resources and scheduling policies from the single-workstation experiment in this chapter:
- Agrawal et al. (2024), Taming Throughput-Latency Tradeoff in LLM Inference with Sarathi-Serve. OSDI 2024. Provides the primary research basis for splitting prefills into chunks and co-scheduling prompt and decode work.
- Zhong et al. (2024), DistServe: Disaggregating Prefill and Decoding for Goodput-optimized Large Language Model Serving. OSDI 2024. Defines a serving-level TTFT/TPOT objective and studies separating the phases onto different GPU resources.
- Patel et al. (2024), Splitwise: Efficient Generative LLM Inference Using Phase Splitting. ISCA 2024. Independently studies phase-specific hardware/resource allocation and the implications for cost, energy and throughput.
Documentation, not a fourth paper: vLLM/GuideLLM goodput schema distinguishes the rate of SLO-compliant requests from raw throughput. Use it to compare benchmark metric names carefully rather than assuming every implementation’s TPOT field has identical boundaries.
Evidence in this chapter
| Claim | Evidence class and boundary |
|---|---|
| A causal prefill computes logits for the first next-token choice; cached decode advances subsequent choices | Established autoregressive computation; implemented using the library cache |
| A prefill can be compute-intensive and decode bandwidth-sensitive in large serving workloads | Literature-supported tendency (Sarathi-Serve, Splitwise); not established for the measured GPT-2 path |
| GPU fp32 prefill stays near 12 ms for short prompts and reaches 45.1–52.0 ms at 1,024 tokens | Book measurement, two process runs |
| Trimming logits can save time | Book measurement: CPU ~25–31% for longer prompts, GPU fp32 ~20–21% at 512/1,024; does not prove equivalent logits at every position |
| Cached GPU decode medians stay near 11 ms for starting contexts 16–960 | Book measurement, 40 steps per GPU case with four dropped, two runs; host .item() each step |
| The decode path is limited by CPU launches/bookkeeping | Hypothesis, not isolated by profiler or hardware counters |
| Estimated parameter-plus-cache bytes / step time is 20–52 GB/s | Calculated nominal ratio, not measured GPU bandwidth or utilisation |
| 7B fp16 weights are roughly 14 GB and ideal 303 GB/s weight streaming takes at least ~46 ms | Hypothetical arithmetic bound; model cannot run on this 12 GiB card |
| Local model-loop TTFT ranges from ~12 to ~44 ms in six measured request shapes | Book measurement, five runs each; excludes tokenisation, queueing, transport and rendering |
| One unchunked 1,000-token B prefill caused A maximum local ITL of 56–73 ms | Book measurement, three runs of a two-request serial alternation |
| Chunk size 256 reduced A maximum local gap to 26–34 ms but increased B prefill-completion interval to 100–126 ms | Book measurement, not service TTFT or production scheduler evidence |
| Chunked and unchunked B logits differ by ~1.5–1.9e-4 | Book measurement on one GPT-2 input; output-token equivalence not established |
goodput() currently computes fraction meeting thresholds |
Verified implementation property; requests-per-second goodput is NOT_IMPLEMENTED |
| Actual memory traffic, client-observed latency, production goodput, batched decode, multi-model scheduling | NOT_MEASURED / NOT_IMPLEMENTED |