Bookmarks

Continuous batching

A way a language model inference server works: the batch of requests is reassembled after every generation step, without waiting for the other requests in the batch to finish.

Also: iteration-level scheduling, dynamic batching, in-flight batching

checked 9 Nov

All terms

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.

AspectStatic batchContinuous batch
Batch assemblyonce, before generationat every iteration
Slot releasewhen the longest request finishesas soon as a request finishes
GPU idle timepresent: short requests wait for long onesminimal
Limitationmemory is reserved for the maximumthe 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

Verified 9 Nov