Slides · Inference engineering
Scheduling and decoding
1 / 33
Scheduling and decoding
Which work goes into each engine step, in what order, and how many tokens to try per step: batching, chunked prefill, admission control, speculative decoding and disaggregation.
By the end you can compare batching modes, size a token budget, bound sustainable load with Little’s law, compute a speculative-decoding speedup, and judge when to split prefill from decode.
Concept
The scheduler decides what runs in each step
- Lessons 1 to 3 made one engine step cheaper. The scheduler decides what goes into it.
- It picks which requests are in the batch, how many prompt tokens to process beside the decoding ones, when to admit or reject a request, and how many tokens to speculate.
- Poor scheduling wastes the hardware you just optimised.
- Two complaints are scheduling problems, not hardware problems: “the stream froze when someone sent a big document” and “p95 first-token time triples at peak”.
Compare
Four ways to batch
| Strategy | What happens | Problem |
|---|---|---|
| No batching | One request at a time | The GPU is mostly idle during memory-bound decode (lesson 1) |
| Static | Wait for N requests, run until all finish | Short requests wait for the longest; padding waste; waiting to fill a batch delays first token |
| Dynamic | Batch what arrives in a time window, then run it as a static batch | Still tied to the slowest request |
| Continuous (iteration-level) | Re-form the batch at every decode step | Needs per-sequence cache management |
- The Orca paper (OSDI 2022) calls the last row iteration-level scheduling: the scheduler runs one model iteration at a time instead of whole requests.
- Early finishers return at once, and new arrivals do not wait for the whole batch.
- Orca also introduced selective batching, which batches only some transformer operations so batching and per-iteration scheduling can coexist.
- The abstract reports 36.9 times the throughput of NVIDIA FasterTransformer at the same latency on a GPT-3 175B model, in the authors’ own evaluation. The mechanism matters more than the number: sequences now start and end at arbitrary steps, which is why it pairs with paged cache management (lesson 2).
Source[1] Orca: A Distributed Serving System for Transformer-Based Generative Models
Worked example
A toy comparison: 12 requests, 4 slots
Output lengths in decode steps: 90, 15, 30, 10, 25, 40, 20, 15, 35, 10, 60, 20 (total 370). Assume every step costs the same and ignore prefill (a simplification).
| Mode | Steps to finish all 12 | Slot use |
|---|---|---|
| Static, groups of 4 in arrival order | 190 (groups of 90, 40, 60) | 49 percent |
| Continuous, refill a slot the moment it frees | 115 | 80 percent |
- Slot use is 370/(4×steps): 48.7 and 80.4 percent.
- Continuous batching therefore needs cache space handed out and returned per sequence as requests start and end at arbitrary steps, not fixed slabs reserved up front.
- Static batching holds three slots idle while the 90-step request finishes. Continuous batching refills them.
- A joining request still has to be prefilled, and that prefill shares the step with everyone’s decode. The next slides show the cost.
Check yourself
Check: count the steps
Six requests need 50, 10, 20, 10, 40 and 10 decode steps, and the engine has 3 slots. Ignore prefill and give every step the same cost. How many steps does static batching in groups of three (arrival order) need, how many does continuous batching need, and what is the slot use of each?
Answer
Static: groups of 50, 10, 20 and 10, 40, 10 take 50 and 40 steps, so 90 steps and 140/(3×90)=52% slot use. Continuous: a slot is refilled the moment it frees, and the six requests finish in 60 steps (the first slot frees at step 10 and takes a 10-step request, and two slots are free at step 20, one of which takes the 40-step request), so 140/(3×60)=78%. The gap comes from slots held idle while the longest request in a group finishes.
Worked example
A big prefill stalls every decode
An 8B model, dense BF16 peak of about 990 TFLOPS as in lesson 1, and 2P FLOPs per prompt token, with P=8×109.
| Prompt | FLOPs | Floor at peak |
|---|---|---|
| 200 tokens | 3.2×1012 | 3.2 ms |
| 16,000 tokens | 2.56×1014 | 259 ms |
| 32,000 tokens | 5.12×1014 | 517 ms |
- Run the 32,000-token prompt as one step and every running decode waits at least 517 ms for its next token. Real engines are slower than the floor.
- Short prompts queued behind it wait too. This is head-of-line blocking, and the schedule causes it, not the model.
Concept
Chunked prefill limits the work per step
- The scheduler sets a token budget per iteration, gives each running decode one token, and spends the rest on a chunk of a waiting prompt.
- Sarathi-Serve splits each prefill into near-equal chunks and adds new requests without pausing running decodes, which it calls stall-free scheduling.
- Its abstract reports 2.6 times the serving capacity of vLLM for Mistral-7B on one A100 and up to 3.7 times that of vLLM for Yi-34B on two A100s. It also reports up to 5.6 times end-to-end serving capacity for Falcon-180B with pipeline parallelism, and names no baseline for that last figure.
- Those results come from the authors’ systems and workloads.
Source[3] Taming Throughput-Latency Tradeoff in LLM Inference with Sarathi-Serve
Diagram
One iteration with a token budget
Worked example
Sizing the budget for a 32,000-token prompt
Same 8B model and peak as before. Floor per step is 990×10122×8×109×tokens.
| Token budget | Steps (budget all for the prompt) | Compute per step, at least |
|---|---|---|
| 32,000 (one step) | 1 | 517 ms |
| 4,096 | 8 | 66 ms |
| 1,024 | 32 | 16.5 ms |
- If 100 running decodes each take one token of a 4,096 budget, the prompt gets 3,996 per step and needs 9 steps, not 8.
- A smaller budget gives running decodes smoother, shorter steps but stretches the long prompt over more of them. The long prompt’s first token arrives later than if it had the engine alone.
Compare
The budget is a trade, per the engine’s guide
| Direction | Effect (vLLM optimization guide, read 24 October 2026) |
|---|---|
Smaller max_num_batched_tokens (for example 2048) | Better inter-token latency, because fewer prefills slow down decodes |
| Larger value | Better time to first token, because more prefill tokens fit in a batch |
- The guide says chunked prefill is enabled by default in V1 whenever possible, and recommends
max_num_batched_tokensabove 8192 for best throughput, with the gain largest for smaller models on large GPUs. - Chunked prefill does not make prefill faster. It protects other users’ decode.
- Re-measure both time to first token and inter-token latency after every change.
Check yourself
Check: pick a budget
On the 8B model above, the inter-token latency target for running decodes is 40 ms per step, and a 24,000-token prompt arrives. Floor per step is 990×10122×8×109×tokens. Which of 1,024, 2,048, 4,096 and 8,192 meets the target on compute alone, and how many steps does the best fit take?
Answer
Floors: 1,024 gives 16.5 ms, 2,048 gives 33.1 ms, 4,096 gives 66.2 ms, 8,192 gives 132 ms. The target allows 2,048 at most. With 2,048 the prompt needs 24,000/2,048=11.7, so 12 steps (possibly one more if running decodes take part of the budget). Real step times are above the floor, so leave headroom and measure.
Concept
Little’s law bounds sustainable load
L=λ×WAverage in flight = admission rate × time holding a slot.
λmax=mean time per requestconcurrency limit| Symbol | Meaning |
|---|---|
| L | Average number of requests holding a slot |
| λ | Arrival rate, requests per second |
| W | Average time a request holds its slot, from admission to last token (queue wait excluded) |
- Little’s law applies to the requests being served. Time spent waiting in the queue is a separate cost that grows once the ceiling is passed.
- Above λmax the queue grows without limit, however good the batching is.
Worked example
An overloaded service
A cache pool allows 96 concurrent sequences. A typical request holds its slot for 15 seconds. Peak arrival is 9 requests per second.
| Quantity | Value |
|---|---|
| λmax=96/15 | 6.4 requests per second |
| Excess at peak, 9−6.4 | 2.6 requests per second |
| Queue growth over one minute at peak | about 156 requests |
- Waiting time keeps rising for the whole peak, so latency targets fail for everyone, not just the extra requests.
- The same law sizes capacity: 5 requests per second at 12 seconds each needs 5×12=60 slots in flight.
Diagram
Decide at the door
The Mooncake paper describes an early rejection policy driven by load predictions, for heavily overloaded periods in a production service.
Source[5] Mooncake: A KVCache-centric Disaggregated Architecture for LLM Serving
Compare
Policies when demand exceeds capacity
| Policy | What it does | Cost |
|---|---|---|
| First come, first served | Simple and fair | Long requests block short ones |
| Priority and SLO-aware | Interactive ahead of batch; per-tenant quotas | Starvation of low priority needs a guard |
| Admission control | Cap running sequences and queue length; reject early | Some users see errors, with a retry hint |
| Preemption | Free cache by pausing the newest or lowest-priority sequence | Recompute or swap cost on resume |
| Cancellation on disconnect | Abort generation when the client leaves | Needs the disconnect signal to reach the engine |
- vLLM’s optimization guide describes preemption when cache space runs short: preempted requests are recomputed later, and preemption can hurt end-to-end latency. The other rows are general policies, not claims about one engine.
- Goodput counts only requests that meet the target, so rejecting some quickly can beat serving all late.
- Slow consumers of a stream need timeouts, or open streams hold resources.
Check yourself
Check: how much faster must each request be?
A team’s pool holds 72 concurrent sequences and a request holds its slot for 16 seconds on average. Peak arrival is 6 requests per second. Work out the ceiling, then the average hold time that would let 72 slots carry 6 requests per second, and the percentage cut that needs.
Answer
λmax=72/16=4.5 requests per second, below the 6 arriving. For 72 slots to carry 6 per second, the hold time must be 72/6=12 seconds, a cut of 4 seconds or 25 percent (for example through a faster decode path).
Concept
Speculative decoding uses the idle arithmetic
- Small-batch decode is memory-bound (lesson 1): reading the weights costs the same whether a step scores one token or several.
- A cheap draft proposes
gammatokens. The large target model scores all of them plus one more in a single forward pass. - Tokens are accepted in order while they pass the check; at the first mismatch the target supplies its own token and the step ends.
- The abstract reports a 2 to 3 times speedup on T5-XXL with identical outputs. Its Table 4 lists measured improvement factors from 1.4 to 3.4 times across tasks, temperatures and draft sizes.
Source[6] Fast Inference from Transformers via Speculative Decoding
Diagram
One speculative step
Code
Why the output distribution is unchanged
Accept a drafted token x with probability min(1,p(x)/q(x)); on rejection, sample from norm(max(0,p−q)). Excerpt of one step; the wrong variant in the table differs only in the last line, resampling from q.
Python
def step(p, q, rng):
x = rng.choice(len(q), p=q) # draft proposes
if rng.random() < min(1, p[x] / q[x]):
return x # accepted
r = np.maximum(p - q, 0)
return rng.choice(len(p), p=r / r.sum()) # corrected sampleTest: 5 tokens, p = .5 .2 .15 .1 .05, q = .4 .1 .1 .1 .3, 200,000 steps, seed 7 | Observed frequencies | Largest gap from p |
|---|---|---|
| Correct rule | .4993 .2007 .1499 .0999 .0502 | 0.0007 |
Wrong: on rejection, resample from q | .4993 .1256 .1256 .1251 .1245 | 0.0745 |
- The correct rule reproduces the target’s distribution whatever
qis. The wrong rule does not. - The paper proves this for any draft. vLLM’s page says the guarantee holds in theory for the standard rejection sampler, with hardware numerical precision as the limit, and notes that floating-point and batch-size effects can still vary outputs (lesson 3).
Sources[6] Fast Inference from Transformers via Speculative Decoding[7] Speculative Decoding
Math
The speedup formulas
expected tokens per target step=1−a1−ag+1speedup=(1−a)(gc+1)1−ag+1| Symbol | Meaning |
|---|---|
| a | Chance a drafted token is accepted, assumed independent per token (an idealisation) |
| g | Draft length, tokens proposed per step |
| c | Time of one draft step relative to one target step |
- The formulas are the paper’s equation 1 and Theorem 3.8. For a=1 the expected count is g+1.
- The paper’s T5 experiments list c between 0.02 and 0.11.
Source[6] Fast Inference from Transformers via Speculative Decoding
Worked example
Working the formula
Illustrative values, computed from the formulas above.
| a | g | c | Expected tokens | Speedup |
|---|---|---|---|---|
| 0.9 | 6 | 0.08 | 5.22 | 3.53 |
| 0.7 | 6 | 0.08 | 3.06 | 2.07 |
| 0.5 | 6 | 0.08 | 1.98 | 1.34 |
| 0.4 | 4 | 0.2 | 1.65 | 0.92 |
- Acceptance rate dominates: at g=6 and c=0.08, going from 0.9 to 0.5 cuts the speedup from 3.53 to 1.34.
- The last row is slower than not speculating at all: a poor draft that is expensive costs more than the tokens it saves.
- For a=0.9 and c=0.08, speedup by draft length: 1.76 at 1, 3.10 at 4, 3.53 at 6, 3.82 at 11, 3.65 at 16, 3.18 at 24. There is an optimum.
Check yourself
Check: find the draft length
A draft model has acceptance rate 0.85 and costs 0.06 of a target step. Compute the speedup for g=2 and g=7, and say what the formula leaves out that could shrink the longer draft’s lead.
Answer
g=2: expected tokens (1−0.853)/0.15=2.57, divided by 2×0.06+1=1.12, about 2.30. g=7: expected tokens (1−0.858)/0.15=4.85, divided by 7×0.06+1=1.42, about 3.42. The longer draft wins on the formula, but the formula assumes each token is accepted independently at the same rate and that verifying more tokens is free; real acceptance falls along a draft and verification costs more as the batch grows, so measure in your traffic.
Worked example
Why the gain fades at high load
- The formula assumes scoring g+1 tokens costs about one decode step. That holds only while the step is memory-bound.
- A step for a batch of B sequences scores (g+1)×B tokens, so intensity is roughly (g+1)×B for BF16 weights.
- With the H100 ridge near 295 of lesson 1 (a derived figure from the NVIDIA product page’s bandwidth and a halved dense BF16 estimate), g=6 reaches it at B=295/7, about 42 sequences.
- vLLM’s page says speculative decoding targets lower inter-token latency when traffic is medium to low and the workload is memory-bound, and that simple methods such as n-gram and suffix decoding give modest speedups without adding work at peak traffic.
- Benchmark on your own traffic and watch the acceptance rate.
Sources[7] Speculative Decoding[2] NVIDIA H100 Tensor Core GPU
Compare
Where the drafts come from
| Method | Draft source | Notes |
|---|---|---|
| Separate draft model | A small model | Needs a compatible tokenizer and one more model to serve |
| Medusa | Extra decoding heads on the target | Reports over 2.2 times speedup (Medusa-1) and 2.3 to 2.8 times (Medusa-2) |
| EAGLE | Drafting at the feature level of the target | Reports 2.7 to 3.5 times latency speedup on LLaMA2-Chat 70B |
| N-gram or prompt lookup | Spans already in the prompt | No training; helps when output repeats the input |
- EAGLE and Medusa both appeared at ICML 2024. The speedups are the authors’ own, and the Medusa figure is from its ICML abstract.
- vLLM says the biggest latency reductions come from the model-based methods: EAGLE, MTP and draft models.
Sources[8] Medusa: Simple LLM Inference Acceleration Framework with Multiple Decoding Heads[9] EAGLE: Speculative Sampling Requires Rethinking Feature Uncertainty[7] Speculative Decoding
Concept
Splitting prefill from decode
- Prefill is compute-bound and decode is bandwidth-bound, so one pool must compromise on batch size, parallelism and scheduling.
- Disaggregation runs them on separate pools: prefill machines build the cache and send it over a fast link to decode machines.
- DistServe’s abstract says it can serve 7.4 times more requests or a 12.6 times tighter latency target (SLO) than state-of-the-art systems.
- Splitwise reports 1.4 times the throughput at 20 percent lower cost, or 2.35 times the throughput at an unchanged cost and power budget.
- Mooncake describes a cache-centred version that separates prefill and decoding clusters for the Kimi service. The arXiv pages of Splitwise and Mooncake list no venue.
Sources[10] DistServe: Disaggregating Prefill and Decoding for Goodput-optimized Large Language Model Serving[11] Splitwise: Efficient generative LLM inference using phase splitting[5] Mooncake: A KVCache-centric Disaggregated Architecture for LLM Serving
Diagram
The two-pool layout
Worked example
What the transfer costs
The 70B model of lesson 2 stores 320 KiB of cache per token. Link at full line rate of 400 Gb/s; real transfers are slower.
| Context | Cache size | Transfer at line rate |
|---|---|---|
| 4,096 tokens | about 1.34 GB | about 27 ms |
| 32,768 tokens | about 10.7 GB (85.9 gigabits) | about 215 ms |
- The handoff adds delay between the prefill pool finishing and the decode pool streaming. Whether that lands on the first token or the second depends on the design, so check which pool emits the first token in the system you use.
- 27 ms is small against a half-second budget but is about 2.7 decode steps of 10 ms; 215 ms is about 21 of them.
- Add the operating cost: two pools to size, a router that balances both, and idle capacity when the traffic mix shifts.
Check yourself
Check: how fast must the link be?
The 70B model stores 320 KiB of cache per token, and prompts of 32,768 tokens are common. The handoff from prefill pool to decode pool may add at most 100 ms. Compute the cache size in gigabits, the transfer time at 400 Gb/s and at 100 Gb/s at line rate, and the minimum line rate that meets the 100 ms limit. Express the 400 Gb/s time in 30 ms decode steps.
Answer
The cache is 320 KiB×32,768≈10.7 GB, 85.9 gigabits. At 400 Gb/s that takes about 215 ms, and at 100 Gb/s about 859 ms, so neither meets 100 ms. The limit needs at least 85.9/0.1≈859 Gb/s, even before real-link overhead. The 215 ms is about 7 decode steps of 30 ms. So for long prompts the link, not the GPUs, can decide whether splitting is feasible; shorter contexts, a smaller cache per token or a faster interconnect change the answer.
Concept
Constrained decoding at a glance
- To force output to match a JSON schema, regex or grammar, the engine masks tokens that would break validity before sampling.
- Costs: computing the mask each step, compile time for complex grammars, and mismatches between character-level grammars and token boundaries.
- XGrammar reports splitting tokens into context-independent ones checked in advance and context-dependent ones checked at run time, and up to 100 times speedup over existing solutions.
- vLLM’s page (October 2026) names xgrammar and guidance as backends and says describing the schema in the prompt also helps.
- Valid is not correct. Combining a mask with speculative decoding is a design question, not something the cited sources settle.
Sources[12] XGrammar: Flexible and Efficient Structured Generation Engine for Large Language Models[13] Structured Outputs (vLLM documentation)
Summary
Recap
- Continuous batching re-forms the batch every step; it needs cache allocated per sequence.
- A big prefill stalls decodes; a token budget spreads it. Smaller budget, smoother steps; larger budget, faster first token for long prompts.
- Little’s law: sustainable rate is concurrency divided by time per request. Beyond it, queues grow and admission control or capacity is the answer.
- Speculative decoding keeps the target’s distribution; speedup is the expected tokens divided by gc+1; acceptance rate dominates and the gain fades as the batch nears the ridge.
- Disaggregation adds a cache transfer and a second pool; try chunked prefill first.
References
References & Sources (1 of 3)
Orca: A Distributed Serving System for Transformer-Based Generative Models (opens in a new tab)
Gyeong-In Yu, Joo Seong Jeong, Geon-Woo Kim, Soojeong Kim, et al.2022OSDI 2022Paper
https://www.usenix.org/conference/osdi22/presentation/yu
Used for Iteration-level scheduling and selective batching, and the reported 36.9 times throughput over FasterTransformer on a GPT-3 175B model.
NVIDIA H100 Tensor Core GPU (opens in a new tab)
NVIDIA2026Documentation
https://www.nvidia.com/en-us/data-center/h100/
Used for The H100 SXM memory bandwidth and the halved dense BF16 estimate behind the 990 TFLOPS and 295 FLOP-per-byte figures, as in lesson 1.
Taming Throughput-Latency Tradeoff in LLM Inference with Sarathi-Serve (opens in a new tab)
Amey Agrawal, Nitin Kedia, Ashish Panwar, Jayashree Mohan, et al.2024OSDI 2024Paper
https://www.usenix.org/conference/osdi24/presentation/agrawal
Used for Chunked prefills in near-equal chunks, stall-free scheduling, and the reported capacity gains: 2.6 times and up to 3.7 times over vLLM for Mistral-7B and Yi-34B, and up to 5.6 times for Falcon-180B, for which the abstract names no baseline.
Optimization and Tuning (opens in a new tab)
vLLM project2026Documentation
https://docs.vllm.ai/en/latest/configuration/optimization.html
Used for Chunked prefill on by default in V1 where possible, the max_num_batched_tokens trade between inter-token latency and time to first token, and preemption of requests with recompute when cache space runs short (read 24 October 2026).
Mooncake: A KVCache-centric Disaggregated Architecture for LLM Serving (opens in a new tab)
Ruoyu Qin, Zheming Li, Weiran He, Mingxing Zhang, et al.2024Preprint
arXiv 2407.00079 (opens in a new tab)https://arxiv.org/abs/2407.00079
Used for A prediction-based early rejection policy for overloaded periods, and a disaggregated architecture for the Kimi service.
References
References & Sources (2 of 3)
Fast Inference from Transformers via Speculative Decoding (opens in a new tab)
Yaniv Leviathan, Matan Kalman, Yossi Matias2023ICML 2023 (PMLR 202)Paper
arXiv 2211.17192 (opens in a new tab)https://proceedings.mlr.press/v202/leviathan23a.html
Used for The accept and corrected-sample rule, the expected-tokens formula, the speedup formula, the T5 range of draft cost ratios, the abstract's 2 to 3 times speedup, and Table 4's measured 1.4 to 3.4 times range.
Speculative Decoding (opens in a new tab)
vLLM project2026Documentation
https://docs.vllm.ai/en/latest/features/speculative_decoding/
Used for Theoretically lossless up to hardware numerics for the standard rejection sampler, the medium-to-low load target, and model-based against simple methods (read 24 October 2026).
Tianle Cai, Yuhong Li, Zhengyang Geng, Hongwu Peng, et al.2024ICML 2024Paper
arXiv 2401.10774 (opens in a new tab)https://proceedings.mlr.press/v235/cai24b.html
Used for Medusa-1 over 2.2 times and Medusa-2 2.3 to 2.8 times speedup, as reported in the abstract on the ICML 2024 (PMLR) page.
EAGLE: Speculative Sampling Requires Rethinking Feature Uncertainty (opens in a new tab)
Yuhui Li, Fangyun Wei, Chao Zhang, Hongyang Zhang2024ICML 2024Paper
arXiv 2401.15077 (opens in a new tab)https://proceedings.mlr.press/v235/li24bt.html
Used for EAGLE's reported 2.7 to 3.5 times latency speedup on LLaMA2-Chat 70B with the output distribution preserved.
Yinmin Zhong, Shengyu Liu, Junda Chen, Jianbo Hu, et al.2024OSDI 2024Paper
arXiv 2401.09670 (opens in a new tab)https://www.usenix.org/conference/osdi24/presentation/zhong-yinmin
Used for Disaggregating prefill and decoding onto different GPUs, with 7.4 times more requests or 12.6 times tighter latency targets reported.
References
References & Sources (3 of 3)
Splitwise: Efficient generative LLM inference using phase splitting (opens in a new tab)
Pratyush Patel, Esha Choukse, Chaojie Zhang, Aashaka Shah, et al.2023Preprint
arXiv 2311.18677 (opens in a new tab)https://arxiv.org/abs/2311.18677
Used for Phase splitting with 1.4 times throughput at 20 percent lower cost, or 2.35 times throughput under the same cost and power.
Yixin Dong, Charlie F. Ruan, Yaxing Cai, Ruihang Lai, et al.2024Preprint
arXiv 2411.15100 (opens in a new tab)https://arxiv.org/abs/2411.15100
Used for Structured generation by splitting tokens into context-independent and context-dependent ones, with up to 100 times speedup reported.
Structured Outputs (vLLM documentation) (opens in a new tab)
vLLM project2026Documentation
https://docs.vllm.ai/en/latest/features/structured_outputs/
Used for xgrammar and guidance backends, and the advice to describe the schema in the prompt as well (page footer dated 24 October 2026).
Keys: ← → move, Home End first and last, F full screen.