Skip to content
Inference Academy

Prefill vs decode interview questions

Interview questions on the two phases of LLM inference: why prefill is compute-bound and decode is memory-bound, TTFT and inter-token latency, chunked prefill and disaggregated serving, with model answers.

5 questions·Model answers and follow-upsFree
Share

Almost every inference interview starts here, because everything else (batching, KV cache sizing, speculative decoding, disaggregation) follows from the fact that generating text has two phases with very different bottlenecks. A strong answer names the bottleneck for each phase, puts rough numbers on it and says which latency metric each phase controls.

Question 1

What is the difference between prefill and decode in LLM inference?

Model answer

Prefill processes the whole prompt in one forward pass. Every prompt token goes through every layer at once, the model writes the keys and values for all of them into the KV cache, and the last position gives the logits for the first output token.

Decode then generates one token per forward pass. Each step feeds in only the newest token, reads the KV cache for everything before it, and appends one new key and value per layer.

The cost profile is very different:

  • In prefill the weights are read once and used for hundreds or thousands of tokens, so the GPU does a lot of maths per byte loaded. It is usually compute-bound.
  • In decode the weights are read once per step and used for one token per sequence, so the GPU spends most of the step waiting on memory. It is memory-bandwidth-bound.

Prefill time sets time to first token (TTFT). Decode speed sets inter-token latency (ITL), also called time per output token, and so how fast the answer streams.

Likely follow-up questions

  • Why does prefill produce the first output token rather than only filling the cache?
  • Which phase dominates the cost of a chat request with a 200-token prompt and a 1,000-token answer? And of a RAG request with a 20,000-token prompt and a 100-token answer?
  • What changes in this picture for an encoder-only model such as a BERT classifier?

Question 2

Why is decode memory-bound? Show it with numbers.

Model answer

At batch size 1, each decode step must read every weight once and does about two floating-point operations per parameter (one multiply, one add). For a model with PP parameters stored at bb bytes each:

arithmetic intensity≈2PP⋅b=2b FLOP per byte\text{arithmetic intensity} \approx \frac{2P}{P \cdot b} = \frac{2}{b}\ \text{FLOP per byte}

For BF16 that is 1 FLOP per byte. An H100 SXM offers about 989 TFLOPS of dense BF16 and 3.35 TB/s of HBM bandwidth, so it needs roughly 989/3.35≈295989 / 3.35 \approx 295 FLOP per byte before compute becomes the limit. Decode sits about 300 times below that ridge point.

For an 8B model in BF16 (16 GB of weights):

tmem=16×1093.35×1012≈4.8 ms,tcompute=2×8×109989×1012≈0.016 mst_{\text{mem}} = \frac{16 \times 10^{9}}{3.35 \times 10^{12}} \approx 4.8\ \text{ms}, \qquad t_{\text{compute}} = \frac{2 \times 8 \times 10^{9}}{989 \times 10^{12}} \approx 0.016\ \text{ms}

So the step takes about 4.8 ms however fast the tensor cores are, which caps a single stream near 200 tokens per second. In practice you see 60 to 80 percent of that bound.

Likely follow-up questions

  • How does batching change the arithmetic intensity of decode, and where does it stop helping?
  • Why does INT4 weight quantisation speed up decode by close to the ratio of bytes saved, but barely change prefill?
  • At long context, which other read starts to matter as much as the weights?

Question 3

How do you estimate time to first token for a long prompt?

Model answer

Prefill does about 2P2P FLOPs per prompt token (plus attention, which grows with the square of the prompt length and matters at long context). For an 8B model and a 2,000-token prompt on an H100:

tprefill≈2×8×109×2000989×1012≈32 mst_{\text{prefill}} \approx \frac{2 \times 8 \times 10^{9} \times 2000}{989 \times 10^{12}} \approx 32\ \text{ms}

That is an ideal number. Real kernels reach perhaps 40 to 70 percent of peak, so expect 50 to 80 ms, plus whatever the request spends queueing and in tokenisation. Under load the queue is often the largest part of TTFT, which is why you measure TTFT at a realistic request rate rather than on an idle server.

The useful intuition: a 2,000-token prefill costs about as much wall time as a handful of decode steps, while doing thousands of tokens' worth of work.

Likely follow-up questions

  • How does prefix caching change TTFT for a chatbot with a long fixed system prompt?
  • Why does TTFT grow faster than linearly for very long prompts?
  • If TTFT at p99 is bad but p50 is fine, what would you look at first?

Question 4

What is chunked prefill and why do serving engines use it?

Model answer

In a continuously batched server, decode steps for running requests and prefills for new requests share the same GPU. If a 30,000-token prompt arrives and is prefilled in one go, every running stream stalls for the whole prefill and users see a visible pause in their output. That shows up as a spike in p99 inter-token latency.

Chunked prefill splits a long prefill into chunks (for example 512 to 2,048 tokens) and schedules each chunk in a step alongside the ongoing decodes. Each step has a token budget, and the scheduler fills it with all the decode tokens first and then a prefill chunk.

Benefits:

  • Inter-token latency stays bounded because no single step is huge.
  • The decode tokens ride along with a compute-heavy prefill chunk, so the GPU is better used than running memory-bound decode alone.

Costs: the long request's own TTFT goes up slightly because its prefill is spread over several steps, and very small chunks lose prefill efficiency. The chunk size is the knob that trades TTFT against ITL.

Likely follow-up questions

  • How would you choose the per-step token budget for a latency-sensitive chat product?
  • Does chunked prefill change the model's output? Why or why not?
  • How does chunked prefill interact with prefix caching?

Question 5

What is disaggregated prefill and decode, and when is it worth it?

Model answer

Disaggregation runs prefill and decode on separate GPU pools. A prefill worker processes the prompt, then transfers the KV cache over NVLink, InfiniBand or RDMA to a decode worker, which generates the output tokens.

Why do it:

  • The two phases want different things: prefill wants compute and benefits from large batches of prompt tokens; decode wants memory bandwidth and capacity for many KV caches.
  • Sharing one GPU means prefills interrupt decodes. Separating them lets you tune TTFT and ITL independently and size each pool for its own load.
  • You can even use different hardware or parallelism settings per pool.

Costs and when not to:

  • The KV cache transfer takes time and network bandwidth. For a 70B model at about 320 KiB per token, a 10,000-token prompt is about 3 GB to move.
  • You now run two fleets and a router, and the ratio between them must track the traffic mix.
  • For small models, short prompts or modest traffic, chunked prefill on a single pool is simpler and often good enough.

It pays off at large scale with long prompts and strict latency targets on both TTFT and ITL.

Likely follow-up questions

  • How would you decide the ratio of prefill GPUs to decode GPUs?
  • What happens to the design if prompts share long prefixes across users?
  • Which metric would tell you the KV transfer has become the bottleneck?

The lesson behind these answers · 18 min · free

Prefill, decode and the roofline: predicting inference speed

Worked numbers, step-through diagrams and a quiz, so you can derive the answer in the interview instead of reciting it.

Read the lesson →

Articles on this topic

Related interview questions

All interview topics →