A language model generates its response token by token, and each step is a pass of the model over all requests at once. If requests are gathered into a batch once and the server waits for the whole batch to finish, the GPU sits idle while short requests complete. Continuous batching removes this idle time: a freed slot in the batch is taken up by a new request straight away.
How it works
In one step, the model computes the next token for every sequence in the batch. With static batching, the batch is assembled once: requests start together and keep their memory slots until the longest request in the batch has finished. With continuous batching, the scheduler operates at the iteration level: after each step, finished sequences leave the batch and new ones enter from the queue.
| Aspect | Static batch | Continuous batch |
|---|---|---|
| Batch assembly | once, before generation | at every iteration |
| Slot release | when the longest request finishes | as soon as a request finishes |
| GPU idle time | present: short requests wait for long ones | minimal |
| Limitation | memory is reserved for the maximum | the growing amount of KV cache in the batch |
Example
In a batch of four requests, three finish within 50 tokens and the fourth takes 500. With static batching, after the 50th token three slots sit idle for another 450 steps. With continuous batching, new requests start in those slots straight away, and in the same time the server serves noticeably more requests without increasing the number of GPUs.
Where it is used
Continuous batching is supported by the vLLM, SGLang and TensorRT-LLM inference engines; in Triton Inference Server the same technique is called in-flight batching. The batch size is bounded by the memory set aside for the KV cache, so continuous batching is usually paired with block-based cache storage: the scheduler adds a request only if there is room for its cache.
The technique was introduced by the authors of Orca, presented at the OSDI conference in 2022: they called it iteration-level scheduling and, on GPT-3 175B, showed a 36.9× increase in throughput over NVIDIA FasterTransformer at the same latency.
Sources
the term is written from these pages- Orca: A Distributed Serving System for Transformer-Based Generative Models (OSDI ’22)usenix.org/conference/osdi22/presentation/yu(opens in a new tab)
- vLLM — документация проектаdocs.vllm.ai/en/latest/(opens in a new tab)
- NVIDIA TensorRT-LLM — Executor API и in-flight batchingnvidia.github.io/TensorRT-LLM/advanced/executor.html(opens in a new tab)
Verified 9 Nov