# DistServe: Disaggregating Prefill and Decoding for Goodput-optimized Large Language Model Serving > **来源**:arXiv > **作者**:Yinmin Zhong, Shengyu Liu, Junda Chen, Jianbo Hu, Yibo Zhu, Xuanzhe Liu, Xin Jin, Hao Zhang > **发布日期**:2024-01-18 > **原文链接**:https://arxiv.org/abs/2401.09670 --- ## 论文元数据 - **arXiv ID**:2401.09670 - **学科分类**:Distributed, Parallel, and Cluster Computing (cs.DC); Artificial Intelligence (cs.AI) - **作者机构**:北京大学(School of Computer Science, Peking University)、StepFun、UC San Diego - **提交历史**:v1: 2024-01-18;v2: 2024-03-19;v3: 2024-06-06 - **DOI**:https://doi.org/10.48550/arXiv.2401.09670 --- Yinmin Zhong  Shengyu Liu  Junda Chen  Jianbo Hu  Yibo Zhu  Xuanzhe Liu   Xin Jin  Hao Zhang School of Computer Science, Peking University StepFun UC San Diego ## 摘要(Abstract) DistServe improves the performance of large language models (LLMs) serving by disaggregating the prefill and decoding computation. Existing LLM serving systems colocate the two phases and batch the computation of prefill and decoding across all users and requests. We find that this strategy not only leads to strong prefill-decoding interferences but also couples the resource allocation and parallelism plans for both phases. LLM applications often emphasize individual latency for each phase: time to first token (TTFT) for the prefill phase and time per output token (TPOT) of each request for the decoding phase. In the presence of stringent latency requirements, existing systems have to prioritize one latency over the other, or over-provision compute resources to meet both. DistServe assigns prefill and decoding computation to different GPUs, hence eliminating prefill-decoding interferences. Given the application’s TTFT and TPOT requirements, DistServe co-optimizes the resource allocation and parallelism strategy _tailored_ for each phase. DistServe also places the two phases according to the serving cluster’s bandwidth to minimize the communication caused by disaggregation. As a result, DistServe significantly improves LLM serving performance in terms of the maximum rate that can be served within both TTFT and TPOT constraints on each GPU. Our evaluations show that on various popular LLMs, applications, and latency requirements, DistServe can serve 7.4× more requests or 12.6× tighter SLO, compared to state-of-the-art systems, while staying within latency constraints for >90%90>90\%> 90 % of requests. ## 1 引言(Introduction) Large language models (LLMs), such as GPT-4 [37], Bard [2], and LLaMA [51], represent a groundbreaking shift in generative AI. They start to reshape existing Internet services, ranging from search engines to personal assistants [4], and enable fundamentally new applications, like universal chatbots [1, 16] and programming assistants [15, 42]. Yet, these advances come with a significant challenge: processing an end-to-end LLM query can be substantially slower than a standard search query [41]. In order to meet the stringent latency requirements of various applications, service providers need to over-provision compute resources, particularly many GPUs, leading to a shortfall in cost efficiency. Therefore, optimizing the cost per LLM query while adhering to high SLO attainment (the proportion of requests that meet the SLOs) is becoming increasingly essential for all LLM services. ![Image 1: Refer to caption](https://arxiv.org/x1.png) Figure 1: Performance when serving an LLM with 13B parameters under a synthetic workload with input length = 512 and output length = 64 on one NVIDIA 80GB A100. Upper: The P90 time-to-first-token (TTFT) latency comparing existing systems vs. a system serving only the prefill phase. Down: The P90 time-per-output-token (TPOT) latency comparing existing systems vs. a system serving only the decoding phase. An LLM service responds to a user query in two phases. The _prefill phase_ processes a user’s prompt, composed of a sequence of tokens, to generate the first token of the response _in one step_. Following it, the _decoding phase_ sequentially generates subsequent tokens _in multiple steps_; each decoding step generates a new token based on tokens generated in previous steps, until reaching a termination token. This dual-phase process distinguishes LLM services from traditional services – an LLM service’s latency is uniquely measured by two key metrics: the _time to first token_ (TTFT), which is the duration of the prefill phase, and the _time per output token_ (TPOT), which represents the average time taken to generate a token for each request (except for the first token)111The overall request latency equals TTFT plus TPOT times the number of generated tokens in the decoding phase.. Different applications place varying demands on each metric. For example, real-time chatbots [1] prioritize low TTFT for response promptness, while TPOT only remains important until it is faster than human reading speed (i.e., 250 words/min). Conversely, document summarization emphasizes low TPOT for faster generation of the summary. Hence, given the application’s TTFT and TPOT requirements, an effective LLM serving system should balance these needs and maximize _per-GPU goodput_, defined as the maximum request rate that can be served adhering to the SLO attainment goal (say, 90%) for each GPU provisioned – higher per-GPU goodput directly translates into lower cost per query. As the prefill and decoding phases share the LLM weights and working memory, existing LLM serving systems typically colocate both phases on GPUs and maximize the overall system throughput – tokens generated per second across all users and requests – by batching the prefill and decoding steps across requests [54, 31]. However, to meet latency requirements, we find these systems must over-provision compute resources. To see this, Figure 1 illustrates how the P90 TTFT and TPOT shift with increasing request rates when serving a 13B LLM using existing systems [32], with workload pattern and two latency constraints set to emulate using LLM to generate a short summary for an article. Under the SLO attainment of 90%, the maximum achievable goodput on a single A100 GPU, which is constrained by the more stringent one of TTFT and TPOT requirements, is about 1.6 requests per second (rps). The performance contrasts sharply when each phase is served independently on a separate GPU, shown by the orange and green curves, which achieve per-GPU goodput of 5.6 rps for the prefill phase and 10 rps for decoding. Ideally, by allocating 2 GPUs for prefill and 1 GPU for decoding, we can effectively serve the model with an overall goodput of 10 rps, or equally 3.3 rps per GPU, which is 2.1x higher than existing systems. The gap in goodput primarily stems from the colocation of the prefill and decoding – two phases with very distinct computational characteristics and latency requirements (§2.1). First, colocation leads to strong _prefill-decoding interference_. A prefill step often takes much longer than a decoding step. When batched together, decoding steps in the batch are delayed by the prefill steps, significantly elongating their TPOT; similarly, the inclusion of decoding steps contributes to a non-trivial increase in TTFT, as evidenced in Figure 2. Even if we schedule them separately, issues persist as they begin to compete for resources. Decoding tasks awaiting GPU execution are subject to increased queuing delays due to ongoing prefill tasks, and vice versa. Prioritized scheduling of one phase risks failing the latency requirements of the other. Second, the prefill and decoding computation differ in latency requirements and preference for different forms of parallelism (§3). Colocating prefill and decoding, however, couples their resource allocation, and prevents implementing different parallelism strategies more suited to meeting the specific latency requirements of each phase. To overcome these challenges, we propose to disaggregate the prefill and decoding phases of LLM inference, assigning them to separate GPUs. Our approach has two benefits. First, operating each phase independently on different GPUs eliminates prefill-decoding interference. Second, it allows to scale each phase independently with tailored resource allocation and model parallelism strategies to meet their specific latency requirements. Although disaggregation causes communication of intermediate states between GPUs, we show that the communication overhead is insubstantial (§3.3) in modern GPU clusters, and when managed appropriately, disaggregation significantly improves per-GPU goodput. Based on the above insights, in this work, we build DistServe 222https://github.com/LLMServe/DistServe, a goodput-optimized LLM serving system by disaggregating the prefill and decoding phases. Given TTFT and TPOT requirements, DistServe first scales each phase independently by co-optimizing the GPU allocation and parallelism strategies of the prefill and decoding phase assuming serving a single model replica. The optimization ensures maximizing the per-GPU goodput and may assign different numbers of GPUs and parallelism strategies to each phase depending on their respective latency requirements. DistServe then scales this allocation to multiple instances via replication until meeting the user-required traffic rate (§4). DistServe also features an algorithm to place the prefill and decoding computation according to their allocation schemes and the cluster’s bandwidth to minimize the overhead of communicating intermediate states between phases. We implement DistServe as an orchestration layer on top of the LLM inference engine. We evaluate DistServe on various LLMs, varying the workloads based on three important real-world LLM applications: chatbots, programming assistant, and document summary. Compared to state-of-the-art solutions, DistServe can serve up to 7.4×7.4 × more requests or 12.6×12.6 × tighter SLO under various latency constraints. Our contributions are: - • Identify the problems of prefill-decoding interference and resource coupling in existing LLM serving systems and propose to disaggregate the two phases. - • Design a novel placement algorithm to choose the goodput-optimal schema for prefill and decoding instances automatically. - • Conduct a comprehensive evaluation of DistServe with realistic workloads. ## 4 方法(Method) We built DistServe to solve the above challenges. Given the model, workload characteristic, latency requirements, and SLO attainment target, DistServe will determine (a) the parallelism strategies for prefill and decoding instances, (b) the number of each instance type to deploy, as well as (c) how to place them onto the physical cluster. We call the solution a placement. Our goal is to find a placement that maximizes the per-gpu goodput. As explained in §3.3, a key design consideration is to manage communications between disaggregated prefill and decoding phases, given varying cluster setups. In this section, we first present two placement algorithms: one for clusters with high-speed cross-node networks (§4.1) and the other for environments lacking such infrastructure (§4.2); the latter introduces additional constraints. We then develop online scheduling optimizations that adapt to the nuances of real-world workloads (§4.3). ### 4.1 Placement for High Node-Affinity Cluster Algorithm 1 High Node-Affinity Placement Algorithm LLM G𝐺Gitalic_G, #node limit per-instance N𝑁Nitalic_N, #GPU per-node M𝑀Mitalic_M, GPU memory capacity C𝐶Citalic_C, workload W𝑊Witalic_W, traffic rate R𝑅Ritalic_R. the placement 𝑏𝑒𝑠𝑡⁢_⁢𝑝𝑙𝑚.𝑏𝑒𝑠𝑡_𝑝𝑙𝑚{best\_plm}.italic_best _ italic_plm . 𝑐𝑜𝑛𝑓𝑖𝑔p,𝑐𝑜𝑛𝑓𝑖𝑔d←∅,∅formulae-sequence← subscript𝑐𝑜𝑛𝑓𝑖𝑔𝑝subscript𝑐𝑜𝑛𝑓𝑖𝑔𝑑 {config_{p}},{config_{d}},_config start_POSTSUBSCRIPT italic_p end_POSTSUBSCRIPT , italic_config start_POSTSUBSCRIPT italic_d end_POSTSUBSCRIPT ← ∅ , ∅ for 𝑖𝑛𝑡𝑟𝑎⁢_⁢𝑜𝑝∈{1,2,…,M}𝑖𝑛𝑡𝑟𝑎_𝑜𝑝12…𝑀{intra\_op}\{1,2,...,M\}italic_intra _ italic_op ∈ { 1 , 2 , … , italic_M } do for 𝑖𝑛𝑡𝑒𝑟⁢_⁢𝑜𝑝∈{1,2,…,N×M𝑖𝑛𝑡𝑟𝑎⁢_⁢𝑜𝑝}𝑖𝑛𝑡𝑒𝑟_𝑜𝑝12…𝑁𝑀𝑖𝑛𝑡𝑟𝑎_𝑜𝑝{inter\_op}\{1,2,...,{N M}{{intra\_op}}\}italic_inter _ italic_op ∈ { 1 , 2 , … , divide start_ARG italic_N × italic_M end_ARG start_ARG italic_intra _ italic_op end_ARG } do if G.s⁢i⁢z⁢e𝑖𝑛𝑡𝑒𝑟⁢_⁢𝑜𝑝×𝑖𝑛𝑡𝑟𝑎⁢_⁢𝑜𝑝