Two phases of a response #

When a request arrives, the model first processes its prompt. This prefill phase can work on many prompt positions together. During decoding, the newly chosen token becomes part of the input to the next step. Work from different users can be combined, but generating a particular user’s eventual hundredth token normally depends on choices made in the preceding steps.

A serving system typically keeps the attention keys and values for earlier positions. This key–value cache allows a later position to attend to the earlier ones without rebuilding all their keys and values. It occupies memory throughout the request and grows with its context. The model’s shared weights may fit comfortably while the combined caches of many active conversations exceed the available space.

Section sources [1] [2] [3]

Choosing who runs next #

Imagine three visitors submitting questions together. Two answers end after ten tokens, while the third continues for two hundred. A scheduler that treats the batch as indivisible may leave slots empty until the longest answer ends. Orca schedules at the level of an iteration, allowing completed requests to leave and new requests to join across model iterations.

A long prompt can create another conflict. Processing it immediately may delay the next token for everyone already reading a streamed answer. Leaving it in the queue preserves the rhythm of existing responses while increasing the new visitor’s wait. Sarathi-Serve explores splitting prefill work into chunks and scheduling them alongside ongoing decodes. Appropriate chunk size depends on the hardware, workload and service target.

Section sources [1] [3]

Allocating memory as an answer grows #

The final length of an answer is usually unknown in advance. Reserving a contiguous array for every request’s maximum length can leave substantial memory idle. PagedAttention addresses the problem by mapping logical stretches of a sequence to blocks of physical cache memory. Blocks are allocated as needed. Requests with identical cached prefixes can sometimes share blocks, with separate storage when their continuations diverge. An allocator balances the bookkeeping cost of small blocks against the unused space in partially filled large ones.

Section sources [2]

Throughput with a deadline #

Use both time to first token and time between output tokens. A novelist may tolerate a slow start to a long passage, while a conversational interface may become awkward after a long silent pause. Quoting aggregate tokens per second alone conceals that difference. A repeatable comparison uses the same distribution of prompt lengths, output lengths and arrival times, then reports the fraction of requests meeting stated deadlines. Faster training, a faster single-stream demonstration and greater capacity to serve many people are separate achievements. Test-time computation can spend more of the serving budget on a difficult question. Reporting cost per accepted answer makes that choice visible alongside raw output speed.

Section sources [1] [2] [3] [5]

Putting the two phases on separate machines #

DistServe, developed by Yinmin Zhong and colleagues, assigns prompt processing and token-by-token decoding to different GPUs. The operator can then give each group the amount of capacity its delay target requires. This introduces a handoff. The decoding machine needs the attention keys and values already computed for the prompt. Sending them across a slow link can consume the time that separating the workloads was meant to save.

The authors illustrate the scale of the transfer with a 512-token request to OPT-66B, whose cached keys and values occupy about 1.13 gigabytes in their example. Ten such arrivals per second require moving about 11.3 gigabytes each second before allowing for other traffic. A benchmark using two well-connected devices can therefore give a different answer from one using devices across a congested network. The relevant result is how many requests meet both the first-token and subsequent-token targets once the handoff is included.

Section sources [4]

Sources

  1. Gyeong-In Yu and colleagues · Orca: A Distributed Serving System for Transformer-Based Generative Models (2022) usenix.org
  2. Woosuk Kwon and colleagues · Efficient Memory Management for Large Language Model Serving with PagedAttention (2023) arxiv.org
  3. Amey Agrawal and colleagues · Taming Throughput-Latency Tradeoff in LLM Inference with Sarathi-Serve (2024) usenix.org
  4. Yinmin Zhong and colleagues · DistServe: Disaggregating Prefill and Decoding for Goodput-optimized Large Language Model Serving (2024) usenix.org
  5. Charlie Snell et al. · Scaling LLM Test-Time Compute Optimally can be More Effective than Scaling Model Parameters (2024 preprint) arxiv.org