Prefill is the phase where an LLM processes the whole prompt in one parallel pass and fills the KV cache; it is compute-bound and sets time to first token. Decode generates output one token per pass, rereading all the weights each time; it is memory-bandwidth-bound and sets streaming speed.
- Prefill
- Processes all prompt tokens in parallel; compute-bound; sets TTFT
- Decode
- One token per forward pass; memory-bandwidth-bound; sets TPOT
- FLOPs per token
- About 2 × parameters, in both phases
- Decode arithmetic intensity (FP8, batch B)
- About 2 × B FLOPs per byte of weights
- H100 PCIe ridge point (FP8)
- About 757 FLOPs per byte (1,513 TFLOPS ÷ 2.0 TB/s)
- Llama 3.3 70B FP8, 8k-token prefill on H100 PCIe
- About 1.6 s at 50% compute efficiency (estimate)
- Same model, decode
- About 17–21 tokens/s single stream (estimate)
Every LLM request runs in two phases that use the GPU in opposite ways. Prefill reads your prompt and is limited by compute. Decode writes the answer and is limited by memory bandwidth. Most of what looks puzzling in LLM serving follows from that split: why the first token takes a moment, why long answers cost more than long questions, and why batching helps so much.
This guide explains the two phases with worked numbers for Llama 3.3 70B on an H100, then turns them into tuning and cost decisions. All timings are estimates from published specifications. The complete guide to LLM inference gives the wider context.
What are prefill and decode?
Prefill is the phase in which the model processes all prompt tokens in one parallel forward pass, builds the KV cache, and produces the first output token. Decode is the phase in which it generates the remaining output one token per forward pass, each new token attending to the cached keys and values of everything before it.
| Prefill | Decode | |
|---|---|---|
| Tokens per forward pass | All prompt tokens (hundreds to many thousands) | One per sequence |
| How often it runs | Once per request | Once per output token |
| Bottleneck | Compute (tensor core FLOPS) | Memory bandwidth (reading weights and KV cache) |
| Latency metric it sets | Time to first token (TTFT) | Time per output token (TPOT) |
| What batching does | Little: it is already parallel | A lot: one weight read serves many sequences |
| GPU spec that matters | Dense TFLOPS at your precision | TB/s of memory bandwidth |
Both phases do the same arithmetic per token, about 2 FLOPs per parameter, plus attention. The difference is how much data has to move for that arithmetic.
Why is prefill compute-bound and decode memory-bound?
It comes down to arithmetic intensity: FLOPs done per byte read from memory. A GPU is compute-bound when intensity exceeds its ridge point (peak FLOPS ÷ bandwidth) and memory-bound below it.
ridge point = peak dense FLOPS ÷ memory bandwidth
decode intensity (FP8 weights, batch B) ≈ 2 × B FLOPs per byte
prefill intensity (FP8 weights, N tokens) ≈ 2 × N FLOPs per byteRidge points from NVIDIA's published dense (non-sparse) figures:
| GPU | Dense BF16 | Dense FP8 | Bandwidth | Ridge point, FP8 | Ridge point, BF16 |
|---|---|---|---|---|---|
| A100 80GB SXM | 312 TFLOPS | n/a | 2.0 TB/s | n/a | ~153 FLOPs/byte |
| L40S | 362 TFLOPS | 733 TFLOPS | 0.864 TB/s | ~848 | ~419 |
| H100 PCIe | 756 TFLOPS | 1,513 TFLOPS | 2.0 TB/s | ~757 | ~378 |
| H100 SXM | 989 TFLOPS | 1,979 TFLOPS | 3.35 TB/s | ~591 | ~295 |
Decode at batch 1 has an intensity of about 2, hundreds of times below every ridge point, so the tensor cores spend nearly all their time waiting for weights. To reach the H100 PCIe's FP8 ridge from decode alone you would need a batch of roughly 378 sequences, and reading the KV cache pushes that even higher. A prefill of 2,000 tokens has an intensity around 4,000, well above the ridge, so it runs as fast as the tensor cores allow. Prompts shorter than a few hundred tokens are an in-between case: their prefill is quick and partly memory-bound. Specifications are on NVIDIA's H100 page, and memory bandwidth vs FLOPS covers the roofline idea in general.
How long do prefill and decode take? A worked example
For Llama 3.3 70B in FP8 on one H100 PCIe, an 8,000-token prompt takes about 1.6 seconds to prefill. A 300-token answer then takes about 15 seconds to decode for a single user. Here is the arithmetic.
Prefill. Linear layers cost 2 × parameters × tokens. Causal attention adds about 2 × layers × N² × model width, with 80 layers and a width of 8,192 for Llama 3.3 70B. Assume 50% of the 1,513 TFLOPS dense FP8 peak, about 757 TFLOPS effective.
| Prompt length | Linear FLOPs | Attention FLOPs | Total | Prefill time at 757 TFLOPS |
|---|---|---|---|---|
| 500 tokens | 7.0 × 10¹³ | 3.3 × 10¹¹ | 7.0 × 10¹³ | ~0.1 s (memory floor ~0.05 s) |
| 2,000 tokens | 2.8 × 10¹⁴ | 5.2 × 10¹² | 2.9 × 10¹⁴ | ~0.38 s |
| 8,000 tokens | 1.12 × 10¹⁵ | 8.4 × 10¹³ | 1.2 × 10¹⁵ | ~1.6 s |
| 32,000 tokens | 4.48 × 10¹⁵ | 1.34 × 10¹⁵ | 5.8 × 10¹⁵ | ~7.7 s |
At 32k tokens attention adds about 30% on top of the linear layers, and it grows with the square of the prompt length.
Decode. Each token reads about 70 GB of FP8 weights. At 0.6–0.75 × 2,000 GB/s, that gives 17–21 tokens per second, or roughly 48–58 ms per token. A 300-token answer therefore takes about 14–18 seconds for one user.
So for chat, decode dominates what the user waits for. Only very long prompts make prefill the main delay. The tokens per second guide covers how to measure both on your own setup.
Why are input tokens cheaper than output tokens?
Prefill processes tokens in bulk at near-peak compute. Decode spends a full pass over the weights for each step and shares it only across the sequences in the batch. Per token, prefill uses far less GPU time, which is why most hosted APIs charge less for input tokens than for output.
Here is the same comparison in GPU time and money on our H100, for Llama 3.3 70B FP8:
prefill GPU-time per token = 2 × 70 × 10⁹ ÷ 757 × 10¹² ≈ 0.185 ms
decode step at batch 8 = (70 GB + 8 × 0.34 GB KV) ÷ (0.675 × 2,000 GB/s) ≈ 54 ms
decode GPU-time per token = 54 ms ÷ 8 ≈ 6.7 ms| Token type | GPU time per token | GPU-hours per million tokens | Cost per million at $4.99/hr |
|---|---|---|---|
| Input (prefill) | ~0.185 ms | ~0.051 | ~$0.26 |
| Output (decode, batch 8) | ~6.7 ms | ~1.87 | ~$9.33 |
| Output (decode, batch 1) | ~52 ms | ~14.4 | ~$72.06 |
Dollar figures are GPU-hours per million × our live H100 price. The KV figure assumes 2,048 tokens of context per sequence with an FP8 KV cache. Batch 8 is about what an 80 GB H100 can hold for 70B FP8; a larger-memory card batches more and narrows the gap. In this setup an output token costs about 36 times as much GPU time as an input token. H100 cost per million tokens expands this into a full costing.
How do different workloads split between prefill and decode?
The ratio of prompt to output tokens decides which phase you should optimise. Under batched serving, decode time is shared across the batch while prefill is not, so prompt-heavy workloads spend a larger share of GPU time in prefill than single-user timings suggest.
Using the per-token GPU times above (H100, 70B FP8, batch 8):
| Workload | Prompt / output tokens | Prefill GPU time | Decode GPU time | Dominant phase | Optimise |
|---|---|---|---|---|---|
| Chat turn | 500 / 300 | 0.09 s | 2.0 s | Decode | Bandwidth, batching, quantisation |
| Code completion | 2,000 / 100 | 0.37 s | 0.67 s | Mixed | Prefix caching of the file context |
| RAG answer | 8,000 / 200 | 1.5 s | 1.3 s | Prefill (roughly half) | Prefix caching, tighter retrieval |
| Long-document summary | 32,000 / 500 | 7.7 s | 3.4 s | Prefill | Compute, chunked prefill |
| Agent step (growing context) | 12,000 / 150, repeated | 2.2 s per step uncached | 1.0 s | Prefill without caching | Prefix caching is essential |
| Reasoning model | 500 / 4,000 | 0.09 s | 27 s | Decode | Bandwidth, larger batches |
Agents are the case people miss. Each step resends the whole conversation and tool history, so without prefix caching the same tokens are prefilled again and again. With caching, only the new tokens since the last step are prefilled.
How do serving engines handle prefill and decode?
Modern engines schedule the two phases together so that neither starves the other. The main techniques are continuous batching, chunked prefill, prefix caching and, at large scale, disaggregation.
- Continuous batching. New requests join the running batch at any step. Their prefill runs alongside other sequences' decode, so the GPU never idles waiting for a batch to finish.
- Chunked prefill. A long prompt is split into chunks capped by a token budget per step,
--max-num-batched-tokensin vLLM. Without it, one 32k-token prompt would freeze every other user's stream for several seconds. In current vLLM releases chunked prefill is on by default; a larger budget favours TTFT and throughput, a smaller one favours smooth inter-token latency. - Prefix caching. KV blocks for a prompt prefix that was already processed, such as a system prompt, a document or an agent's history, are reused instead of recomputed. vLLM enables it by default in recent versions (
--enable-prefix-cachingon older ones). SGLang's RadixAttention does the same with a radix tree. - Disaggregated prefill and decode. Separate GPU pools handle each phase, and the KV cache is transferred between them. This lets you size compute-heavy prefill nodes and bandwidth-heavy decode nodes independently. vLLM, SGLang and NVIDIA Dynamo support versions of it. It is worth it for large fleets with long prompts, not for one machine.
The vLLM documentation describes each scheduler option. The vLLM vs Ollama vs TGI comparison covers which engines implement which.
What should you tune for prefill-heavy and decode-heavy work?
Match the GPU and settings to the phase you are bound by.
If you are prefill-bound (RAG, summarisation, agents, long system prompts):
- Turn on and verify prefix caching, and keep shared content at the start of prompts so prefixes actually match.
- Retrieve fewer, better chunks rather than stuffing the context.
- Prefer GPUs with more dense FP8 compute, and use FP8 so prefill runs on FP8 tensor cores.
- Raise
--max-num-batched-tokensif TTFT matters more than smooth streaming.
If you are decode-bound (chat, code generation, reasoning models):
- Quantise weights to FP8 or 4-bit, which cuts the bytes read per token.
- Choose bandwidth: an H200 at 4.8 TB/s decodes a 70B model about 2.4 times faster per stream than an H100 PCIe at 2.0 TB/s.
- Maximise batch size with more KV room: an FP8 KV cache, a larger-memory card, or a lower
--max-model-len. See how much GPU memory LLMs need. - Consider speculative decoding for single-user latency.
When renting from Wandering Giants Compute fits
The right GPU depends on which phase your traffic is bound by, and the cheapest way to find out is to run your own prompts on real cards for an hour. Wandering Giants Compute bills by the minute from prepaid credit. You can put the same workload on an H100 at $4.99/hr and an H200 at $9.09/hr, read TTFT and TPOT from vllm bench serve with root access, and keep the card that wins. If you would rather not set up a server, API mode gives you a vLLM-served one-click model behind an OpenAI-compatible endpoint to measure against.
We rent single machines with up to eight GPUs. If you are building disaggregated prefill and decode across a multi-node fleet, you will need a provider with multi-node clusters and fast interconnect.
Frequently asked questions
What is the prefill phase in LLM inference?
Prefill is the first phase of a request, in which the model runs every prompt token through all its layers in parallel and writes their keys and values into the KV cache. It ends by producing the first output token, so its duration is most of the time to first token.
What is the decode phase in LLM inference?
Decode is the loop that generates output: one forward pass per new token, attending to the KV cache of everything before it. Because each pass must read all the active weights to produce one token per sequence, decode speed is limited by memory bandwidth.
Why is prefill faster per token than decode?
Prefill reuses each weight it reads for thousands of prompt tokens at once, keeping the tensor cores busy. Decode reads the same weights to produce just one token per sequence. Per token, prefill can be tens of times cheaper in GPU time, which is why APIs usually price input tokens below output tokens.
What is chunked prefill?
Chunked prefill splits a long prompt into pieces and processes them alongside ongoing decode steps, instead of pausing every other user while one big prompt is processed. It smooths inter-token latency for everyone at a small cost to the long request's time to first token.
What is disaggregated prefill and decode?
Disaggregated serving runs prefill and decode on separate GPUs or machines and transfers the KV cache between them, so each pool can be sized and tuned for its own bottleneck. It pays off at large scale with long prompts; for a single GPU it adds complexity without benefit.
Which matters more for RAG: prefill or decode?
Prefill often matters more. RAG prompts carry thousands of retrieved tokens and answers are short, so time to first token and the GPU time spent on prompts dominate. Prefix caching and keeping retrieved context tight help most.
Rent the GPU for this, by the minute.
Rent an H100 or H200 by the minute and profile prefill and decode on your own prompts, with root access or a ready vLLM endpoint.
Prepaid credit, billed by the minute, stops itself when credit runs out. Prices in £, $, €, ¥, CA$, A$, CHF and S$; UK prices include VAT.
Keep reading
- Complete guideWhat Is LLM Inference? A Complete Technical Guide
- GuideWhat Is Tokens Per Second? Understanding LLM Inference Performance
- GuideUnderstanding GPU Memory Bandwidth, FLOPS and Compute Performance
- GuideHow Much GPU Memory Do You Need to Run LLMs?
- Cost breakdownH100 Cost Per Hour vs Cost Per Million Tokens
- Head to headvLLM vs Ollama vs TGI: Which LLM Serving Framework Should You Use?
About this article. Written by the Wandering Giants Compute team, the people who run Wandering Giants Compute. Hardware figures are the manufacturers’ published specifications. Speeds and costs marked as estimates are worked out from those specifications and our current prices, with the method shown; they are not measured benchmarks. Wandering Giants prices are taken live from our price list each time this page is built.
Last reviewed 25 November 2026.