Continuous batching lets an LLM server add and remove requests between model iterations. It can admit a new prompt as soon as a slot and enough KV cache are available, even while older requests are still generating. To estimate how many requests will fit, track the cached tokens that coexist at each step and round each request up to whole cache blocks.
In the worked example below, two requests are active at the memory peak and occupy 216 MiB of KV cache. A three-request total would overstate the peak because B finishes before C enters. The example is a sizing calculation for a hypothetical model and traffic trace. Each step shows when a request waits, when a cache block is added, and when blocks become reusable.
How continuous batching changes the memory calculation
With static batching, a fixed group runs together. Dynamic batching commonly refers to collecting arrivals over a short window to form a group before execution. Continuous batching can change the group during execution. The Orca paper, OSDI 2022 describes this idea as iteration-level scheduling. A server can decode for an existing request while processing a chunk of another request's prompt, subject to its scheduling policy.
Keep three limits separate when sizing the deployment.
| Limit | What it counts | What happens when it binds |
|---|---|---|
| Active sequence slots | Sequences scheduled together. One user request can create more than one sequence with some decoding modes. | New work waits for a slot or follows the engine's admission policy. |
| Scheduled tokens per iteration | Work submitted to one model iteration, such as a prompt chunk and decode inputs. | Some prompt work can be split across iterations or deferred. |
| Resident KV cache | Key and value state retained for token positions that attention needs later. | A request may wait, or the engine may preempt eligible work according to its policy. |
An existing request can add one cached token in a decode iteration while retaining hundreds or thousands from earlier iterations. A small per-iteration token cap therefore tells you little about the cache already occupied. The vLLM optimization guide documents the distinction between max_num_seqs, max_num_batched_tokens and KV cache pressure for vLLM. Use the documentation matching your installed engine version when applying these settings.
Set a cache budget for the scheduling trace
Use the same hypothetical model as the ModelFit PagedAttention guide so its per-block calculation carries over. One GPU serves 32 full-attention layers with 8 KV heads, a head dimension of 128 and BF16 cache elements at 2 bytes each. Keys and values together take 2 × 32 × 8 × 128 × 2 = 131,072 bytes per cached token. A 16-position block holds 2 MiB of KV payload. At each step, round up cached positions ÷ 16 for each admitted request. The PagedAttention paper, SOSP 2023 describes the underlying allocation model.
This example assumes no prefix sharing, sliding-window eviction, offload, or speculative decoding. Each request holds its own blocks through its final iteration, and they become reusable before the next iteration. For multi-GPU, hybrid attention, quantized KV, or other cache layouts, confirm per-device cache allocation and any extra overhead in the engine. The simple formula does not include weights, activations, temporary workspaces, graph buffers, or allocator bookkeeping.
Work through three arriving requests
Assume two sequence slots and an iteration budget of at least 1,000 scheduled tokens, which is enough for the work shown below. A arrives at step 0 with a 1,000-token prompt and a five-token output. B arrives at step 1 with a 319-token prompt and a three-token output. C arrives at step 2 with a 710-token prompt and a four-token output.
In this trace the prompt pass produces the first output token. Subsequent decode passes feed earlier outputs into the model and add one cached position per pass. The final sampled output is returned without a further pass through the model. Values in the table are resident positions after each pass and before any release at that step. Steps show scheduler order, without assigning a duration in milliseconds.
| Step and scheduled work | Cached positions (A / B / C) | Blocks used | KV occupied |
|---|---|---|---|
| 0. Prefill A | 1,000 / 0 / 0 | 63 | 126 MiB |
| 1. Decode A, prefill B | 1,001 / 319 / 0 | 83 | 166 MiB |
| 2. Decode A and B. C waits. | 1,002 / 320 / 0 | 83 | 166 MiB |
| 3. Decode A and B. B finishes. | 1,003 / 321 / 0 | 84 | 168 MiB |
| 4. Decode A, prefill C. A finishes. | 1,004 / 0 / 710 | 108 | 216 MiB |
| 5. Decode C | 0 / 0 / 711 | 45 | 90 MiB |
| 6. Decode C | 0 / 0 / 712 | 45 | 90 MiB |
| 7. Decode C. C finishes. | 0 / 0 / 713 | 45 | 90 MiB |
B moves from 20 to 21 blocks when it goes from 320 to 321 cached positions. At the peak, A occupies 63 blocks and C occupies 45. Their 1,714 logical token positions use 214.25 MiB of KV data. The allocated blocks occupy 216 MiB, leaving 14 unused positions across their last blocks. You can reproduce the peak directly as (ceil(1004 / 16) + ceil(710 / 16)) × 2 MiB.
With the same arrivals, compare when C can first run. This isolates the reason for waiting.
| Policy in this example | Earliest start for C | Binding condition |
|---|---|---|
| Continuous, two slots, 108 cache blocks | Step 4 | Both slots were occupied until B finished. |
| Continuous, two slots, 100 blocks, whole prompt required | Step 5 | After B exits, A still uses 63 blocks. C needs 45 and only 37 are free. |
| Fixed group A and B launched at step 1, same work per later step | Step 6 | The next group waits for A to finish. A's first decode moves from step 1 to step 2. |
The fixed-group comparison assumes a token budget large enough for both prompts in step 1 and holds the initial group open through its last decode. Its step counts describe this scheduling policy with these arrivals. They cannot predict a time-to-first-token difference in milliseconds.
With chunked prefill, the engine may make partial progress on C earlier. At that point, 37 free blocks could hold up to 592 prompt positions in this layout, even if the iteration's compute budget can handle all 710. The engine can impose further admission limits. When the engine reserves a cache pool up front, device memory readings can stay flat while occupied blocks move from 83 to 108 and back down to 45.
Turn the trace into a deployment check
- Start with a replayable workload. Capture arrival times, prompt lengths and output lengths in tokens. Preserve bursts and overlap between long requests. For a conservative ceiling, use output limits and test a burst of long sessions, too.
- Find the usable cache pool for the model on each GPU. Start with the ModelFit KV cache calculator and context window guide. Cross-check with the engine's reported pool after it accounts for model weights and runtime reserves.
- Replay admissions at candidate limits. At each step, record both scheduled tokens and the sum of rounded resident blocks. Track when requests queue, cross page boundaries, or finish. Include outstanding prompts or cached prefixes in the budget if your engine holds blocks for them.
- Tune against service targets under load. Record queue depth, KV occupancy, preemptions, time to first token, and inter-token latency alongside throughput. Compare a steady workload with a burst at the same configuration. Change one limit at a time and keep the replay fixed so the next run shows the effect. The vLLM metrics guide describes the metrics available for that engine.
Continuous batching capacity depends on which requests overlap. Start with the observed peak in occupied cache blocks, keep room for longer bursts, and use the ModelFit VRAM calculator to check the rest of the GPU memory budget. See ModelFit's sizing methodology for the assumptions behind the calculators.
Prepared by the ModelFit Team. The trace and memory values are hypothetical and were checked with CPU arithmetic. They report no GPU measurements.
