Module 7 · AI infrastructureLesson 77 of 886 minAdvanced
Continuous batching
Instead of waiting for a whole batch to finish, swap finished sequences out and new ones in at every step.
Try it
Run "Static batch" and watch slots sit idle. Switch to "Continuous" and compare throughput and the wait for the first token.
Static batching wastes GPU time because answers have very different lengths. Continuous batching (also called iteration-level scheduling or in-flight batching) fixes it.
How it works
Generation happens in steps: each step produces one token for each sequence in the batch. A continuous-batching scheduler makes decisions at every step:
- Sequences that just finished are removed and their results returned.
- Waiting requests are added to fill the free slots (their prompts are prefilled).
- The next step runs with the updated batch.
Why it's a big deal
- No padding waste: slots never sit idle waiting for the longest answer.
- Lower wait: a new request joins at the next step instead of waiting for a batch to drain.
- Higher throughput: often several times higher than static batching on real traffic with mixed lengths.
Things the scheduler must balance
- Memory: every sequence in the batch needs KV cache space. Admit too many and memory runs out mid-generation. Paged KV cache (the vLLM lesson) helps a lot.
- Prefill vs decode: adding a long prompt costs a big prefill step that slows everyone else's next token. Schedulers split long prefills into chunks (chunked prefill) to keep token streams smooth.
- Fairness and priority: paying customers, short requests, or interactive users may jump ahead of batch jobs.
Continuous batching is now the default in production LLM serving engines.