Sarathi-Serve Decode Priority and Chunked Prefill
Sarathi-Serve · OSDI 2024 · Medium · 40 minutes
Reserve tokens for every ongoing decode before assigning bounded chunks to FIFO prefills.
One hybrid-batch budget allocation and repeated replay; fixed token budgets and maximum chunks replace the paper performance model.
Functions to implement
hybrid_batch(decodes: list[int], prefills: list[int], budget: int, chunk_size: int) -> dict
Sarathi-Serve Decode Priority and Chunked Prefill
1. Problem
Reserve tokens for every ongoing decode before assigning bounded chunks to FIFO prefills.
One hybrid-batch budget allocation and repeated replay; fixed token budgets and maximum chunks replace the paper performance model.
Source: Taming Throughput-Latency Tradeoff in LLM Inference with Sarathi-Serve · Section 4.1–4.2; Algorithm 3, stall-free batching.
2. Core equations
$$ B_{prefill}=B-|D|,\qquad c_i=\min(r_i,C,B_{remaining}),\qquad |D|+\sum_i c_i\le B. $$
3. From equations to code
hybrid_batch(decodes: list[int], prefills: list[int], budget: int, chunk_size: int) -> dict— Decode IDs, scheduled (prefill_index,token_count) pairs, and remaining tokens.
Subtract one token for every decode first, then process prefills in order. An unfinished long prompt retains the queue head. New prompts cannot displace ongoing decodes or force an unbounded prefill.
4. Conventions
decodes is a list of distinct nonnegative IDs; prefills contains positive remaining token counts in FIFO order. budget>=len(decodes), chunk_size>=1. Every decode runs once. Give the head prefill min(remaining,chunk_size,budget_left); if unfinished, stop admitting later prefills. At most one chunk per request per iteration. Return decodes, prefills as (index,count), and remaining with zeros for completed items.
5. Experiment view
Keep two decodes active with prefill lengths 13, 3 and 9, budget eight and chunk cap four. Consume the queue over multiple iterations and check uninterrupted decodes and conserved prefill work.
The chart is generated by the actual submitted kernel during T3 and by the reference during export. Values are synthetic teaching measurements, not GPU throughput or full-model quality claims.
6. Run your implementation
Complete the functions in the Python editor on the right, then click Run tests. Inspect each failed check, update your implementation, and run again. Passing every required check marks the problem as solved and unlocks the notes.
7. Further study
Read the cited section and explain which dimensions or scheduling constraints the kernel preserves. Then extend the experiment beyond the stated fixture while retaining the existing contract. Larger models, real devices, and communication costs require separate measurement.