Home / Learn / AI Infrastructure / Prefill vs Decode Disaggregation
On this page
The two phasesHow they differWhy running both together causes troubleWhat disaggregation doesBenefitsThe cost: moving the cacheWhen it helps and when it does notScheduling and routingHardware implicationsRelation to other techniquesCommon questionsRelated guidesPrefill vs Decode Disaggregation
Language model inference has two phases with different hardware needs. Prefill processes the whole input prompt at once and is limited by computing power. Decode generates output one token at a time and is limited by memory. Disaggregation means running the two phases on separate resources, each suited to its phase, instead of on the same accelerator. It can raise throughput and make response times more consistent, at the cost of moving state between the two.
The two phases
Prefill. When a request arrives, the model reads the entire prompt. All of its tokens are processed together, in parallel. The model builds a cache of intermediate results, known as the KV cache, and produces the first output token.
Decode. The model then generates the remaining output tokens one after another. Each step takes the previous token, consults the cache, produces the next token and extends the cache.
How they differ
| Prefill | Decode | |
|---|---|---|
| Input | The whole prompt at once | One token at a time |
| Parallelism | High, across all prompt tokens | Low within a request |
| Main limit | Compute | Memory bandwidth and capacity |
| Duration | One burst, proportional to prompt length | Many small steps, proportional to output length |
| User-facing metric | Time to first token | Time between tokens |
| Batching behavior | A few large jobs | Many small steps from many requests |
Prefill resembles a short, intense calculation. Decode resembles a long series of small memory-heavy operations.
Why running both together causes trouble
On a shared accelerator, the two kinds of work interfere.
- A large prefill stalls ongoing decodes. When a long prompt arrives, its prefill occupies the accelerator. Users who are in the middle of receiving a response see their text pause.
- Batching is compromised. Prefill is best done with a few requests at a time. Decode is best done with many. A single configuration cannot be ideal for both.
- Hardware is mismatched. An accelerator chosen for compute is under-used during decode. One chosen for memory is slow at prefill.
- Response times become unpredictable. Both time to first token and time between tokens vary with whatever else happens to be running.
What disaggregation does
The system is divided into two pools.
- Prefill workers receive incoming prompts, process them and build the cache.
- Decode workers receive the cache and generate the output.
A request goes first to a prefill worker. When prefill is complete, the cache is transferred to a decode worker, which streams the response to the user.
Each pool can be scaled, configured and equipped independently.
Benefits
- Less interference. Decode steps are no longer interrupted by incoming prefills, so the flow of tokens is steadier.
- Better batching for each phase.
- Independent scaling. If prompts are long and responses short, more prefill capacity can be added, and the reverse.
- Hardware matched to the work. Compute-dense accelerators for prefill, memory-rich ones for decode.
- More controllable service levels. Time to first token and time between tokens can be managed separately.
- Higher overall throughput for the same hardware, when the workload suits it.
The cost: moving the cache
Disaggregation only works if the cache can be handed from the prefill worker to the decode worker quickly. The cache is large, and for long prompts it can be many gigabytes.
If the transfer is slow, the delay it adds to the first token cancels the benefit. Several approaches are used.
- A fast network between the pools, with direct memory-to-memory transfer.
- Shared memory or storage that both pools can access.
- Placing pools close together, within the same server or rack.
- Compressing the cache before sending it.
This makes the data path between workers a central part of the design.
When it helps and when it does not
Disaggregation is not always worthwhile.
It helps most when
- Prompts are long, so prefill is substantial
- Traffic is heavy, with many requests competing
- Consistent response time matters
- The mix of prompt and output lengths varies
- A fast path exists for transferring caches
It helps least when
- Prompts are short and prefill is trivial
- Traffic is light, so interference is rare
- The transfer path is slow relative to the cache size
- The added operational complexity outweighs the gain
Some systems decide per request: short prompts are handled entirely on a decode worker, and only long ones are sent to the prefill pool.
Scheduling and routing
Running two pools adds decisions.
- Which prefill worker should take a new request?
- Which decode worker should receive its cache, given current load and where related caches already sit?
- How large should each pool be, and how should that change as traffic shifts?
- When is it better not to disaggregate a given request?
A routing layer makes these choices, usually with awareness of cache location. If part of a prompt’s cache already exists, for instance from an earlier turn in the same conversation, the system can reuse it and prefill only the new part.
Hardware implications
Disaggregation opens the door to more specialized hardware.
- Prefill rewards high arithmetic throughput. It is closer in character to a batch computation.
- Decode rewards memory bandwidth and capacity, and efficient handling of many small steps.
A chip or system designed for one phase can omit what only the other needs. This is an example of a broader trend in AI infrastructure: breaking a workload into stages and matching each to suitable resources.
Relation to other techniques
- KV cache offloading moves idle caches to cheaper tiers. It relies on the same fast data paths.
- Prompt caching avoids prefill altogether for content that has been seen before.
- Chunked prefill breaks a long prefill into pieces interleaved with decode steps. It is an alternative way to reduce interference without separate pools.
- Distributed inference spreads a model across several accelerators.
Common questions
What is the difference between prefill and decode?
Prefill is the phase in which the model processes the entire input prompt and builds its cache. Decode is the phase in which it generates output tokens one at a time using that cache.
Does disaggregation make responses faster?
It can make the flow of tokens steadier and raise total throughput. The first token may arrive slightly later because of the cache transfer, unless the transfer path is very fast.
Is disaggregation always the better design?
No. For short prompts or light traffic, the extra transfer and complexity may not pay off. It is most valuable with long prompts and heavy load.