Schedule requests through explicit iteration-boundary states
Track waiting, prefill progress, decode eligibility, completion, preemption, and cancellation without treating an active batch as an immutable set.
On this page
The question for today
What you’ll understand
- Describe legal state transitions at scheduler iteration boundaries.
- Distinguish a request's lifecycle from its current batch membership.
- Define invariants for token progress and resource ownership.
Continuous batching changes the active set as generation progresses. A short request can finish while another keeps decoding, and a newly eligible request can enter a later iteration. That flexibility requires an explicit state machine. The scheduler must know which prompt work is complete, which next token can be computed, which resources remain owned, and which terminal result has already been reported. A count of active requests cannot substitute for those per-request facts.
Separate waiting, prompt progress, and decode eligibility
A request can be accepted into a waiting queue without owning all resources needed for execution. Admission and scheduling are therefore different transitions. During a chunked prompt, record how many prompt tokens have been computed and which KV state is valid. Ordinary next-token decode becomes eligible only after the required prompt context is available. A scheduler can combine different requests' eligible work, but it must preserve each request's dependency chain and the serving engine's supported iteration semantics.
Orca introduced iteration-level scheduling as a way to change batch membership between model iterations. That does not imply arbitrary interruption within a running kernel. The versioned vLLM 0.10.2 scheduler source is a concrete implementation with request progress, running and waiting sets, and resource decisions; its names are implementation details rather than a universal state schema. Derive an abstract lifecycle first, then map its transitions to the actual engine events and counters used in the deployment.
Completion and removal must preserve ownership invariants
After an iteration, a request may produce an output token, finish by EOS or a limit, continue, become preempted, or be canceled according to the supported policy. A terminal request should no longer be selected for new ordinary decode work. Its exclusively owned memory can be released only when safe with respect to in-flight operations; shared cache blocks need correct reference handling. Completion delivery and resource release are related events, not necessarily the same instant.
Preemption introduces another distinction between logical output progress and currently resident KV state. A request can retain already delivered output while losing cache residency and later recomputing context. Recompute consumes work but must not duplicate committed output or terminal notifications. Use stable request identity, transition reasons, and versioned progress records to test races among completion, cancellation, and a new scheduling decision. An entry disappearing from one queue is not proof that every downstream worker stopped owning its resources.
Test the transition, not only final text
Create a deterministic small fixture with different requested output lengths, one queued arrival, and one cancellation. Inspect the active set after each boundary, prompt progress, emitted token sequence, finish reason, and allocation ownership. Verify that a completed slot can be reused without delaying the completed response until the longest request ends. Also test a preempted request's reentry so logical continuation is distinguished from restarting the entire external request.
The Markov lab provides only a hypothetical pending-to-terminal probability process. Reset, set both p=0.5 for state 0→1 and q=0 for 1→0, predict pending probability 1/16 after four Steps, then inspect the exact readout. Reset and set both p=0.25,q=0 for a separate comparison. The terminal state is absorbing in this model. There are no arrivals, token dependencies, batch membership, cache blocks, or sampled request trajectories; the lab illustrates a declared state transition without claiming to simulate continuous batching.
Work it through
Update one running set
At a safe boundary the running set is {A,B,C}. A finishes, B is preempted, and D has completed admission checks and becomes eligible. C remains eligible. Assume no request appears in conflicting transition sets and no resource limit is exceeded.
Remove terminal A from future execution selection. Record its one terminal outcome and the separate safe-release evidence for its owned resources.
Remove preempted B from the resident running set while retaining its logical request identity and committed progress. C remains running.
Add D to obtain the next running set {C,D}. B is not a new duplicate request; it can later reenter according to the recomputation and residency policy.
The next set is {C,D}, but a correct implementation also preserves A's completion, B's logical progress, and every relevant resource-ownership transition.
The living notebook
Explore the model
Interactive lab · markov
Inspect an absorbing terminal state in a tiny probability model
Reset → set both p=0.5,q=0; predict pending probability 1/16 after four Steps. Reset → set both p=0.25,q=0 for comparison. Exact probabilities start in state 0; no sampled requests, arrivals, prompt progress, KV resources, or continuous-batching engine are represented.
- P(state 1) at step 0
- 0%
- Stationary P(state 1)
- 60%
- Chain behavior
- Monotone convergence
Exact finite-step probabilities for a two-state chain starting in state 0, not sampled trajectories. Playback advances two transitions per second. When p = q = 0 every distribution is stationary; when p = q = 1 the chain alternates forever. A single zero transition creates an absorbing state. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forExplicit states clarify permitted transitions, while real scheduling additionally needs progress and ownership invariants.
Pause & reason
Check your understanding
Your turn
Try it yourself
A request has processed 600 of 1,000 required prompt tokens. Another request is ready for decode. May the first request be treated as an ordinary decode-ready sequence merely because it occupies a batch slot?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Batch membership is a scheduling choice; eligibility depends on each request's completed context and the engine's execution contract.
Compare with the solution
No. Under the stated ordinary autoregressive dependency, the first request still needs four hundred prompt tokens before the full required context is available. It may receive another supported prefill chunk while the other request decodes, if resources and engine semantics permit. The scheduler must track its actual prompt progress rather than infer readiness from slot occupancy. Alternative generation schemes would need their own explicit dependency contract.
Keep the idea
Take it with you
- Continuous batching changes membership at supported execution boundaries.
- Logical progress, residency, completion delivery, and safe resource release are distinct state facts.
- Transition fixtures should test races and ownership rather than only final output text.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.