The scheduler
Two lists, one GPU, one choice per step.
Chapter 5 ended here: a newcomer's prefill stretching everyone's decode step. Engines don't run the two together by default. They split the work into two kinds of batch and pick one each step. That's the scheduler.
The scheduler’s arithmetic, once
A prefill batch of tokens takes about ; a decode step takes . With prefill-first, a newcomer gets and everyone else sees a gap of that plus one decode step. Capping prefill batches at tokens and alternating gives
Mixing a chunk of into each decode step removes the gap entirely and gives . In SGLang: chunked_prefill_size is , enable_mixed_chunk turns on mixing, schedule_policy orders the waiting list, and the loop above is Scheduler.get_next_batch_to_run(), which tries to build a prefill batch first and falls back to the running decode batch.