Search

Search papers and lessons

DistServe: Disaggregating Prefill and Decoding for Goodput-optimized Large...

Yinmin Zhong, Shengyu Liu, Junda Chen et al. · 2024

DistServe splits LLM serving into a prefill stage and a decoding stage on separate GPUs, sized and placed by a search, and serves up to 7.4 times more requests than colocated systems within latency targets.

On this page

  • Colour = topic mix
  • Systems
  • Discrete math
  • Calculus
  • Neural network basics
  • Linear algebra
  • Probability
  • ReadReady to readNot yet

TL;DR

Serving a large language model means answering a user in two phases: first the prompt is read to produce the first token, then the rest of the reply is generated one token at a time. The paper DistServe shows that running both phases on the same GPUs makes them slow each other down, so it puts them on separate GPUs and chooses the number of GPUs and the parallelism for each phase by a search. On the workloads the authors test, it serves up to 7.4 times more requests than a colocated system, while keeping at least 90 percent of requests within their latency limits.

Builds on: Continuous Batching, Model Parallelism, KV Cache · Leads to: the later serving systems that split prefill and decoding (no lesson yet)

Why it mattered

Most LLM serving engines in use when the paper appeared, including vLLM, colocated the two phases and batched them together. That approach maximises total tokens per second, but it makes latency hard to control. DistServe showed that the best unit to optimise is not total throughput but goodput per GPU: the highest request rate a single GPU can sustain while most requests meet their latency targets. Lower goodput per GPU means more GPUs for the same traffic, and so a higher cost per query.

The paper names two other concurrent works that also split prefill and decoding, Splitwise and TetriInfer. Its front end exposes an OpenAI API-compatible interface.

The problem

A user's request has two latency measures. The time to first token (TTFT) is the wait before the first token appears, which is the prefill phase. The time per output token (TPOT) is the average gap between later tokens, which is the decoding phase. A chatbot cares most about a low TTFT, while a document summariser cares most about a low TPOT. The end-to-end latency is TTFT plus TPOT times the number of tokens decoded after the first.

The phases have very different costs. Prefill processes the whole prompt in parallel, so it is usually limited by arithmetic. Decoding produces one token per step, so each step moves the model's weights and the cached keys and values through memory and is limited by memory bandwidth (see GPU Memory Hierarchy).

When both run on the same GPU, a long prefill slows every decoding step that shares the batch. The paper calls this prefill-decoding interference. Its Figure 1 shows the effect on a 13B model on one A100 GPU: at 90 percent SLO attainment, a colocated system reaches about 1.6 requests per second, a rate limited by the stricter of the TTFT and TPOT targets. A GPU that serves only prefill reaches 5.6 requests per second, and one that serves only decoding reaches 10. Splitting the two, with 2 prefill GPUs and 1 decoding GPU, gives 3.3 requests per second per GPU, which the paper states is 2.1 times the colocated system.

The paper identifies three problems in colocated systems. Interference slows both phases. Scheduling the phases one after the other does not remove the interference, because the decoding jobs then wait in queues behind the prefill jobs. And the two phases share one parallelism setting, so the GPUs must be sized for whichever latency target is harder, which wastes capacity on the other.

How it works

Follow one request through DistServe. The request asks for a 512-token prompt and a 64-token reply, which is the synthetic workload of the paper's Figure 1.

  1. The request reaches a controller. A central controller takes all incoming requests and serves them first come, first served. It sends the request to the prefill instance with the shortest queue. Check: the request now waits only for the prefill GPUs, not for any decoding work.

  2. The prefill instance reads the prompt. It processes all 512 prompt tokens together in one step, and that step produces the first output token. The time from arrival to this token is the TTFT. Check: one token is out, and 63 remain to be generated.

  3. The prefill GPU keeps the cache. The keys and values for the 512 prompt tokens are kept in the prefill GPU's memory. The paper gives a figure for a larger model: a 512-token request on OPT-66B needs about 1.13 GB of cache. Check: this cache is what the decoding instance needs, so it must reach a decoding GPU.

  4. The decoding instance pulls the cache. When a decoding instance has room in its batch, it fetches the cache from the prefill instance. The paper calls this a pull rather than a push, so that a burst of requests cannot overload the decoding GPUs' memory. The prefill GPU can keep working on new prompts while the cache waits. Check: the prefill GPU's memory acts as a queue for the cache.

  5. The decoding instance generates the rest. It produces one token per step for this request, together with the other requests in its batch. Each step is cheap, because no prefill work shares the GPU. The average gap between these steps is the TPOT. Check: after 63 steps the request has 64 output tokens.

  6. The latency adds up. The total is TTFT plus TPOT times 63, the number of tokens decoded after the first. The service meets its target when enough requests keep both numbers under their limits. Check: a fast prefill and a fast decoding phase are both needed, and they are measured separately.

Before any of this runs, an offline step chooses how many prefill and decoding instances to deploy, and how each is split across GPUs. The chosen plan is then copied across the cluster until it matches the traffic.

flowchart LR
  C[Controller, FCFS] --> P1[Prefill instance 1]
  C --> P2[Prefill instance 2]
  P1 -- KV cache, pulled on demand --> D1[Decoding instance]
  P2 -- KV cache, pulled on demand --> D1
  D1 --> O[Tokens streamed to the user]

The math

Latency of one phase: the queue model

Suppose requests arrive at random, at an average rate of RR per second. Each prefill takes the same time DD on one GPU, and the GPU serves one request at a time. The utilisation is ρ=RD\rho = RD, and the condition RD<1RD \lt 1 says that work arrives more slowly than the GPU can finish it. A queue with random arrivals and fixed service times is called an M/D/1 queue in queueing theory. Its average time to first token is the paper's Equation 1:

Avg_TTFT=D+RD22(1−RD).\mathrm{Avg\_TTFT} = D + \frac{R D^{2}}{2(1 - RD)}.

The first term is the time to run the prefill. The second term is the average time spent waiting in the queue. It grows without bound as RDRD approaches 1.

Check the formula with numbers: take D=0.2D = 0.2 s and R=3R = 3 requests per second. Then RD=0.6RD = 0.6, RD2=0.12RD^2 = 0.12, and 2(1−RD)=0.82(1 - RD) = 0.8. The queue term is 0.12/0.8=0.150.12 / 0.8 = 0.15 s, so the average TTFT is 0.2+0.15=0.350.2 + 0.15 = 0.35 s.

Two GPUs, two ways

The paper compares two ways of using two GPUs for one prefill instance. With inter-operator parallelism, the layers are split into two stages, and each stage takes half the time of the slowest stage. Each request still takes about DD from start to finish, but the GPUs can start the next request sooner. The paper's Equation 2 is

Avg_TTFTinter=D+RD24(2−RD).\mathrm{Avg\_TTFT}_{\text{inter}} = D + \frac{R D^{2}}{4(2 - RD)}.

With intra-operator parallelism, each layer's matrix multiplications are split across the two GPUs, so one request finishes sooner. If KK is the speedup, with 1<K<21 \lt K \lt 2 because communication costs something, the paper's Equation 3 is

Avg_TTFTintra=DK+RD22K(K−RD).\mathrm{Avg\_TTFT}_{\text{intra}} = \frac{D}{K} + \frac{R D^{2}}{2K(K - RD)}.

Check these with D=0.2D = 0.2 s, R=3R = 3, and an assumed K=1.6K = 1.6, which lies inside the paper's range. Inter-operator: 0.2+0.124⋅1.4≈0.2210.2 + \frac{0.12}{4 \cdot 1.4} \approx 0.221 s. Intra-operator: 0.21.6+0.122⋅1.6⋅1.0=0.125+0.0375=0.1625\frac{0.2}{1.6} + \frac{0.12}{2 \cdot 1.6 \cdot 1.0} = 0.125 + 0.0375 = 0.1625 s. At this low rate the intra-operator split is faster, because it shortens each request. The paper finds that as the rate rises, the queue term matters more and the inter-operator split becomes the better choice. The exact crossover depends on KK and on the model.

Goodput

Let f(r)f(r) be the fraction of requests that meet both the TTFT and TPOT targets when the rate is rr. The goodput of one instance is the largest rr with f(r)≥0.9f(r) \ge 0.9, and the goodput per GPU is that rate divided by the number of GPUs. DistServe maximises this quantity for each phase separately, then combines the phases.

Worked examples

Example
Tiny: the queue term at two loads

Take a prefill of D=1D = 1 second.

  1. At R=0.5R = 0.5 requests per second, RD=0.5RD = 0.5 and RD2=0.5RD^2 = 0.5.
  2. The queue term is 0.52(1−0.5)=0.51=0.5\frac{0.5}{2(1 - 0.5)} = \frac{0.5}{1} = 0.5 seconds.
  3. The average TTFT is 1+0.5=1.51 + 0.5 = 1.5 seconds.
  4. At R=0.8R = 0.8, RD=0.8RD = 0.8 and RD2=0.8RD^2 = 0.8. The queue term is 0.82(0.2)=0.80.4=2\frac{0.8}{2(0.2)} = \frac{0.8}{0.4} = 2 seconds.
  5. The average TTFT is 1+2=31 + 2 = 3 seconds.

Interpretation: the service time stays at 1 second, but raising the arrival rate from 0.5 to 0.8 doubles the average TTFT. Waiting in the queue, not the computation, is what the operator must control to meet a latency target.

Example
Standard: the paper's own splitting example

Figure 1 reports that a colocated 13B system on one A100 reaches 1.6 requests per second per GPU at the 90 percent attainment level. A prefill-only GPU reaches 5.6 requests per second, and a decoding-only GPU reaches 10 requests per second.

  1. Assign 2 GPUs to prefill and 1 GPU to decoding.
  2. The prefill side can take 2×5.6=11.22 \times 5.6 = 11.2 requests per second, and the decoding side can take 1010. The system is limited by the smaller one, so it serves 1010 requests per second.
  3. Per GPU, the system serves 10/3≈3.3310 / 3 \approx 3.33 requests per second.
  4. Compare with the colocated system: 3.33/1.6≈2.083.33 / 1.6 \approx 2.08.

Interpretation: the paper's stated ratio of 2.1 is reproduced by these numbers. The gain comes from matching the number of GPUs in each phase to the work each phase needs, which the colocated system cannot do.

Example
Realistic: a chatbot with a tight time per token

Table 1 of the paper sets a chatbot target for OPT-13B of TTFT at most 0.25 s and TPOT at most 0.1 s, on the ShareGPT conversation dataset. Suppose a request has 200 tokens of prompt and produces 201 output tokens in total, so it has 200 tokens to decode after the first.

  1. The first token must appear within 0.25 s. If the prefill takes 0.1 s and the queue is empty, the TTFT is 0.1 s, which meets the target.
  2. Each later token must come within 0.1 s on average. Over 200 decoded tokens, the decoding phase may take at most 200×0.1=20200 \times 0.1 = 20 s.
  3. The whole reply therefore needs at most 0.1+20=20.10.1 + 20 = 20.1 s.
  4. In a colocated system, a long prefill from another user can stall this request's decoding steps. If a stall adds 0.3 s to a single decoding step, the TPOT target is missed for that step. Over many requests, enough such stalls push the attainment below 90 percent.
  5. Under DistServe, the decoding GPUs run no prefill work, so this stall does not occur.

Interpretation: the chatbot's binding constraint is the per-token gap, which is exactly what interference damages. Step 4 uses an invented stall length to show the mechanism; the paper's own results are in the next section.

Try it: A summariser has TTFT at most 15 s and TPOT at most 0.15 s, the Table 1 values for LongBench on OPT-66B. Which phase should get more GPUs, and why? Answer: the decoding phase, because the TPOT target is strict and the TTFT target is loose, so the decoding instances need the capacity to keep each token under 0.15 s, while a long prompt can still take up to 15 s to start.

Results

The paper evaluates DistServe on OPT models from 13B to 175B, using three workloads: a chatbot on the ShareGPT dataset, code completion on HumanEval, and summarisation on LongBench. The testbed has 4 nodes with 8 A100 80GB GPUs each. GPUs within a node are linked by NVLink, and the cross-node bandwidth is 25 Gbps. The comparison systems are vLLM, which colocates the phases and uses continuous batching and paged attention, and DeepSpeed-MII, which uses chunked prefill.

The main findings, all at 90 percent SLO attainment, are:

  • Abstract: DistServe serves up to 7.4 times more requests, or meets a tighter SLO by up to 12.6 times, than state-of-the-art systems, with more than 90 percent of requests within their latency limits.
  • Chatbot, ShareGPT: 2.0 to 4.6 times the request rate of vLLM, and 1.6 to 7.4 times that of DeepSpeed-MII. The SLO can be made 1.8 to 3.2 times more stringent than vLLM's.
  • Code completion, HumanEval on OPT-66B: 5.7 times the request rate of vLLM, and a 1.4 times more stringent SLO.
  • Summarisation, LongBench on OPT-66B: 4.3 times the request rate of vLLM, and a 12.6 times more stringent SLO.
  • Transmission cost: for OPT-175B, moving the KV cache takes less than 0.1 percent of total latency, and over 95 percent of requests see a transfer delay under 30 ms, because the placement algorithm requires each prefill and decoding instance to keep the same stage on one machine, so transfers use intra-node NVLink.
  • Simulator accuracy: the simulator's SLO attainment differs from the real system by less than 2 percent in the paper's comparison (Table 2).
  • Search time: the placement search takes under 1.3 minutes in the largest setting the authors tried.

The limits are as important as the gains. The SLOs were set empirically for each application, because the authors knew of no published SLO settings for these applications, so the gains depend on those targets. The tests use OPT models, which use classic multi-head attention; the authors chose them to stress transmission, and expect better results on models with grouped-query or multi-query attention, which have smaller caches. The method is aimed at large clusters, and the authors say its design space is limited in resource-constrained settings with only a few GPUs. The paper also does not implement preemption, so a long request can still block short ones in the prefill queue (the convoy effect).

Reading guide

  • Section 1, Introduction. Read for TTFT and TPOT and the 1.6, 5.6 and 10 requests-per-second figures. It needs Autoregressive Model and Transformer for the idea of generating one token at a time.
  • Section 2, Background. The cache and continuous batching are here. It needs KV Cache, Continuous Batching and Model Parallelism. The paragraph on intra-operator and inter-operator parallelism is where the communication cost of splitting a layer is discussed.
  • Section 3, Tradeoff analysis. This is the queue mathematics. The walkthrough of the M/D/1 formula in "The math" above is enough to follow it, and Poisson Distribution and Queue give background on random arrivals and waiting lines.
  • Section 4, Method. The placement algorithm enumerates parallel configurations, simulates each one, and uses Binary Search to find the largest rate that meets the target. Read Algorithm 1 for the search and Section 4.3 for the runtime.
  • Section 5, Implementation. Skim this. It lists the code size and the components.
  • Section 6, Evaluation. Read Table 1 for the SLOs, then Section 6.2 for the results and Section 6.3 for the transmission cost.
  • Section 7, Discussion. Read this for the limits, especially for offline, throughput-only work, where the authors suggest chunked prefill may fit better.

Check yourself

QuestionWhich latency measure does the prefill phase control, and which does the decoding phase control?Show answer

Prefill controls the time to first token (TTFT), the wait before the first output token. Decoding controls the time per output token (TPOT), the average gap between later tokens.

QuestionA prefill takes D=0.25D = 0.25 seconds and requests arrive at R=2R = 2 per second. Using the queue model, what is the average time to first token?Show answer

RD=0.5RD = 0.5, so RD2=2⋅0.0625=0.125RD^2 = 2 \cdot 0.0625 = 0.125. The queue term is 0.1252(1−0.5)=0.1251=0.125\frac{0.125}{2(1 - 0.5)} = \frac{0.125}{1} = 0.125 seconds. The average TTFT is 0.25+0.125=0.3750.25 + 0.125 = 0.375 seconds.

QuestionWhy does a long prefill in a colocated system slow down decoding for other users, even when the decoding work is small?Show answer

The two phases share a batch and a GPU. A prefill step takes much longer than a decoding step, so the decoding steps in that batch wait for it, which raises their TPOT. The decoding requests are slowed by work that is not theirs, which is the interference the paper describes.

QuestionFor a code-completion assistant, the paper sets stringent targets for both TTFT and TPOT. Why might a system that matches GPUs to each phase still help, and what limits its gain?Show answer

Each phase can be given the GPUs and parallelism that meet its own target, instead of one setting that serves the harder of the two. The gain is limited by the workload: the paper reports 5.7 times the request rate of vLLM for code completion, but the SLOs were set empirically for that application, so the figure depends on those targets.

Sources

Read the full paper

Yinmin Zhong, Shengyu Liu, Junda Chen et al., 2024. arXiv:2401.09670