Continuous Batching
Continuous batching rebuilds an LLM server's batch at every decoding step, so finished requests leave, new ones join, and GPUs stay busy.
Continuous batching, also called iteration-level scheduling or in-flight batching, is a scheduling technique for serving generative models in which the server rebuilds its batch at every decoding step. A sequence that finishes leaves the batch immediately and returns its result, and a waiting request takes its place on the next step. Gyeong-In Yu and colleagues at Seoul National University and FriendliAI introduced the approach in Orca at OSDI 2022, reporting 36.9x higher throughput than NVIDIA FasterTransformer on GPT-3 175B at the same latency. The name continuous batching spread in 2023 as vLLM and Hugging Face Text Generation Inference adopted it, and it is now the default scheduler in the serving engines behind large language models (LLMs).
Why Request-Level Batching Wastes the GPU#
Text generation produces one token per forward pass, and requests need very different numbers of passes: a yes-or-no answer ends after a few tokens, while a code file can run to thousands. With static batching, a group of requests stays together until its longest member finishes. Slots whose sequences ended early sit idle, and new arrivals wait for the whole group to clear, which adds inference latency to every short request queued behind a long one.
Dynamic batching, the request-level scheme in servers such as NVIDIA Triton, collects requests that arrive within a short window and runs them as one batch to completion. That fits models with a fixed cost per input, such as an image classifier or an object detector, because every input finishes in a single forward pass. Ultralytics YOLO predict mode builds request-level batches of YOLO26 inputs from its source: a .streams file of camera URLs runs as one batch holding the newest frame from each stream, so 8 streams run at batch size 8, and the batch argument groups frames from a video, directory, or .txt image list into one forward pass.
How Iteration-Level Scheduling Works#
The scheduler runs one decoding step for every active sequence, then checks each one for an end-of-sequence token or its length limit. Finished sequences are returned and their memory freed, and queued requests are admitted if their KV cache fits. Orca processes (prefills) a newcomer's prompt in the same step that decodes the others, and current engines do the same with chunked prefill.
flowchart TD
A["Run one decoding step for the batch"] --> B{"Any sequence finished?"}
B -->|"No"| D{"Requests waiting?"}
B -->|"Yes"| C["Return it and free its memory"]
C --> D
D -->|"Yes"| E{"Enough free KV cache?"}
D -->|"No"| A
E -->|"Yes"| F["Admit and prefill the new request"]
E -->|"No"| A
F --> AMixing sequences of different lengths needed one more idea, which Orca called selective batching. Operations that treat every token independently, such as the large matrix multiplications in each transformer layer, run on all tokens of all sequences together. Attention runs per sequence, since each has its own context length.
This simulation schedules the same eight requests on a GPU that decodes four sequences at a time:
import heapq
output_lengths = [5, 50, 8, 12, 40, 3, 30, 7] # tokens each queued request will generate
slots = 4 # sequences the GPU decodes together at each step
# Static batching: each group of 4 runs until its longest request finishes
static_steps = sum(max(output_lengths[i : i + slots]) for i in range(0, len(output_lengths), slots))
# Continuous batching: the next request takes the first slot that frees up
slot_free_at = [0] * slots
for length in output_lengths:
start = heapq.heappop(slot_free_at)
heapq.heappush(slot_free_at, start + length)
continuous_steps = max(slot_free_at)
for name, steps in [("static", static_steps), ("continuous", continuous_steps)]:
print(f"{name}: {steps} decode steps, slots busy {sum(output_lengths) / (steps * slots):.0%}")Static batching needs 90 decoding steps and keeps slots busy 43% of the time. Continuous batching finishes in 50 steps, the length of the longest request, with slots busy 78% of the time.
Limits and Companion Techniques#
A larger running batch raises total throughput, but each step takes longer, so time per output token grows. Engines therefore cap the number of concurrent sequences and the tokens processed per step, which vLLM exposes as max_num_seqs and max_num_batched_tokens, and they pair continuous batching with a few related techniques:
- PagedAttention: Allocates the KV cache in small blocks, so a finished sequence frees memory at once and a new one claims only what it uses.
- Chunked prefill: Splits long prompts into pieces so a newcomer's prefill does not stall the decoding of everyone else.
- Speculative decoding: Gains the most at small batch sizes, since large continuous batches already use most of the GPU's compute.










