Skip to content
Inference Academy

Inside vLLM's scheduler: token budget, chunked prefill and preemption

How vLLM's V1 scheduler at v0.34.0 builds each batch: one rule for prefill and decode alike, a token budget, running requests before waiting ones, chunked prefill and the long-prefill threshold, preemption by recompute, the FCFS and priority policies, and what async scheduling changes. Read the code with a guide and predict the scheduler's choices.

By

Key takeaways

  • vLLM's scheduler has no separate prefill and decode phases. Each request has tokens it still needs computed, and each step hands out a token budget to close those gaps.
  • Running requests are served first, in order. Waiting requests are admitted only with the budget left, and not at all in a step that had to preempt.
  • Chunked prefill falls out of the same rule: a long prompt simply gets part of its tokens this step and the rest later.
  • When a block cannot be allocated, the scheduler preempts the most recently admitted request (FCFS) and later recomputes it, helped by the prefix cache.
  • max_num_batched_tokens and max_num_seqs are the two main knobs, and their defaults depend on the GPU at v0.34.0.
30 min · verified 2026-113 animated diagramsPro
Share

Goal: understand how vLLM decides what runs in each step, well enough to predict its choices for a given workload and to explain metrics such as waiting requests, preemptions and TTFT from the code.

You need: a checkout of vLLM at v0.34.0 (see the map of vLLM). No GPU. Background: scheduling, chunked prefill and preemption.

Honest limits. The file this lesson reads, vllm/v1/core/sched/scheduler.py, is about 3,900 lines at v0.34.0. Most of it supports features this lesson skips: KV connectors for disaggregated serving, encoder inputs for multimodal models, Mamba and sliding-window layers, pipeline and data parallelism, streaming input sessions. The sketches below are simplified from the code, not copies of it; read the real thing alongside.

#One rule instead of two phases

A comment at the top of Scheduler.schedule() sets out the design. There is no prefill phase and no decode phase. Every request has a number of tokens it knows (prompt, output so far, and any speculative draft tokens) and a number whose KV is already computed. Each step, the scheduler hands out tokens so the computed count catches up with the known count.

That one rule covers:

  • Prefill: a new request has thousands of known tokens and none computed.
  • Decode: a running request has one new known token (the last sampled one).
  • Chunked prefill: a long prompt gets part of its gap this step and the rest later.
  • Prefix caching: cached blocks count as computed before the first step.
  • Speculative decoding: draft tokens are known tokens that need verifying.

In code, the fields are request.num_computed_tokens and request.num_tokens_with_spec, and the gap is what the scheduler fills.

Static vs continuous batching
Animated
Static batchingstep 0
Continuous batchingstep 0

Same hardware, same requests

Gaps are wasted GPU time. Continuous batching (used by llama.cpp server, vLLM and others) finishes sooner and keeps the GPU busier, which is how one machine serves many users.

Six requests (lengths 4, 9, 3, 6, 5, 2 steps = A to F) share 3 slots. Static batching waits for the slowest request in each batch. Continuous batching refills a slot the moment it frees up.

The rest is Pro

Keep reading the rest of this lesson

Pro unlocks the rest of this lesson, including 2 animated diagrams, every advanced lesson, the hands-on labs and completion certificates.

One year

$25

365 days, no auto-renewal

Lifetime Best value

$75

pay once, keep it forever

7-day refund, no questions asked. One payment, no auto-renewal.Compare plansHave a licence key?

Sandip MaityBuilt by Sandip Maity, who runs self-hosted LLM inference in production.

Not ready? Keep learning free

Free lessons from vLLM Internals, no sign-up. Or follow the free roadmap →

Not ready? Take the free 5-day email course

One short email a day for five days, each built on a free lesson, then the occasional new lesson or offer. Unsubscribe in one click.

Still to come in this lesson

  1. The shape of schedule()
  2. After the step: update_from_output()
  3. Async scheduling
  4. The knobs, and their defaults at v0.34.0
  5. Predict the scheduler
  6. Exercises in the code
  7. Where to go next

You will be able to answer

  • A step has a token budget of 2,048. Thirty requests are decoding and one 10,000-token prompt is waiting. With chunked prefill on, what happens this step?
  • Under the default FCFS policy, which request does the scheduler preempt when it cannot allocate a block?
  • In a step where the scheduler had to preempt a running request, what happens to the waiting queue?
  • With async scheduling, the scheduler plans step N+1 before step N's tokens exist. How does it account for them?