# Static, Dynamic, and Continuous Batching in Large Language Models Explained

> GPU utilization during LLM inference is often limited by memory bandwidth bottlenecks. Static batching runs fixed batches until the slowest request finishes, while dynamic batching uses timers to reduce idle time. Continuous batching dynamically recomposes sequences at every forward pass and has become the core technique for high-throughput LLM inference in modern systems.

- Source: https://www.waytoagi.com/en/kb/learning-path/static-dynamic-continuous-batching-llm
- Original (Feishu, Chinese): https://waytoagi.feishu.cn/wiki/H6STwP6lViTWUJkPUVTc6Lr0npg
- Updated: 2026-11-24

---

> 🔗 Original Link: [Static vs. Dynamic vs. Continuous Batching in LLMs, clearly explained](https://x.com/akshay_pachaar/status/2094490705024676272)

> Akshay 🚀 · X · @akshay_pachaar · 2026-09-01 02:21

> 📌 This article is a reprint. All copyrights belong to the original author. Please refer to the original link for the full text.

![](https://www.waytoagi.com/api/kb-media/A8nwbqHqWodoTAxy5q5cOsXRnjd)

This article will help you understand why your GPU sits idle under load and which batching strategy can solve the problem. We’ll explore the three strategies from first principles, their respective shortcomings, chunked prefilling, and how to choose the right one for your workload.

---

A modern GPU can perform trillions of floating-point operations per second. Yet when running an LLM on it, you often see only a small fraction of that compute capacity being utilized.

The reason is that generating a single token requires reading every weight of the model from memory. This memory read dominates the time, leaving the compute units waiting most of the time.

Batching bridges this gap. The weights are loaded only once, and by pushing multiple sequences through the same forward pass, the memory cost is amortized across all sequences.

Every inference engine does this. Where they differ is *when* they decide to batch.

- **Static** batching decides the batch once before it begins
- **Dynamic** batching decides on a timer
- **Continuous** batching decides again at every forward pass

The last strategy is responsible for nearly all the throughput gains in modern inference. The first two are worth understanding first, because the shortcomings of each are exactly what the next one fixes.

Today we’ll dive deep into each one and truly understand them.

Let’s get started! 🚀


# Why Batching Exists

An A100 can perform roughly 312 TFLOPS of BF16 math per second and move about 2 TB of data from memory per second. Decoding is almost entirely limited by the second number.

Reading the weights is the dominant cost; the compute units sit idle waiting. This idle compute is essentially free capacity. Therefore, a batch of 60 sequences reads the same weights as a single sequence, delivering much higher throughput while the memory read time remains unchanged.

![](https://www.waytoagi.com/api/kb-media/J8EKbY13LorcbMxdTSlctYEVngf)

Notice that throughput rises sharply with batch size and then plateaus.

- Below the knee, you are **memory-bound** — batching is almost free
- Above the knee, you are **compute-bound** — adding each additional sequence costs real time

The knee point varies with model size, GPU type, and sequence length, so measure it on your own hardware.

![](https://www.waytoagi.com/api/kb-media/O7QZbSJXLoBS5AxJuD5clDHonTe)

Now you might be thinking: if batching is so effective, why not just batch as many sequences as possible?

For LLMs, this turns out to be much harder than it sounds. Let’s understand why.


# What Breaks for LLMs

Batching existed long before LLMs. For classifiers or embedding models, it’s simply a packing problem.

You pad inputs to a common length, stack them into a single tensor, and run one forward pass.

This works because three conditions hold: one forward pass produces the complete answer, rows have no inter-dependencies, and the cost of each row is known before starting.

None of these hold for autoregressive LLMs.

Decoding breaks all three conditions.

1. **One forward pass produces one token, not the full answer.** A 400-token response requires 400 forward passes.
2. **Rows depend on their own history.** Each forward pass writes to that request’s KV cache, and the next forward pass must read it.
3. **The cost is unknown until it ends.** The model decides when to stop by emitting a stop token — which could happen after 12 tokens or after 4000 tokens.

![](https://www.waytoagi.com/api/kb-media/WXjXbKcjNoJfeQxlawOc9iPHnTe)

Padding does not solve this problem. It only equalizes input width, not the actual time each request occupies the GPU.

![](https://www.waytoagi.com/api/kb-media/EV9FbuBAdoMrpEx7GU7cklUSnog)

As a result, a fixed batch at the start runs at the speed of its slowest member. The three batching strategies are three different answers to this problem, ordered by the degree to which they address it.

# Static Batching (Static Batching)

The simplest answer is to do nothing at all. Collect a fixed number of requests, run them together, and return all results when the last one finishes.

The final state looks like this:

![](https://www.waytoagi.com/api/kb-media/PcbTbkGwtotP4pxGDL4cLq6knFb)

R3 stops generating at t=9, but remains occupied on the GPU until t=15 because R2 is still running. This costs you twice:

- The user’s answer has already been generated but waits an extra 6 time units
- A slot that could have been used by a queued request remains occupied

**Waste increases with output variance.** Anyscale measured this on a 40GB A100 with OPT-13B. Increasing the difference in output lengths caused [static batching throughput to drop to roughly 81 tokens per second](https://www.anyscale.com/blog/continuous-batching-llm-inference), while continuous batching maintained throughput an order of magnitude higher.

![](https://www.waytoagi.com/api/kb-media/MhbQb9fito2UbmxDCRjcPEwPnJh)

**Sometimes it is still the right choice.** Static batching only looks bad when output lengths vary. Remove that variable and the “slow member” problem disappears.

Classification, embedding, and scoring tasks are exactly like this. Every output is a fixed size — one label or one vector — so every request in the batch finishes at almost the same time, and none has to wait for a straggler.

For these workloads, static batching is simpler and loses nothing.

Here’s how to configure static batching in vLLM:

```python
from vllm import LLM, SamplingParams

llm = LLM(model="meta-llama/Llama-3.1-8B-Instruct")
outputs = llm.generate(prompts, SamplingParams(max_tokens=64))
```

`llm.generate` hands the entire workload to the engine at once. By setting a `max_tokens` cap and keeping prompt sizes similar, every sequence finishes at roughly the same time.

> 👉 The `batch_size` parameter in Hugging Face’s `pipeline` API is also static batching. It works well for evaluation scripts but is unsuitable for live traffic.


# Dynamic Batching (Dynamic Batching)

Static batching has a second cost: a request may have to wait a long time before it can enter a batch.

If the batch size is 8 but only 5 requests have arrived, those 5 requests sit idle until the other 3 show up.

Dynamic batching adds a timer. A batch is triggered when it either reaches the size limit or the time window expires — whichever comes first.

The final state looks like this:

![](https://www.waytoagi.com/api/kb-media/OAkab1MNMoQnMex4p0GcbewSntc)

Batch 1 is triggered at t=4 (fixed interval) with only R1 and R2, because the window expired before the third request arrived. Both start four time units earlier than they would have under static batching.

**It reduces the wrong kind of waiting.** R1 finishes at t=7 but still has to wait until t=12 because R2 has not finished yet.

Dynamic batching makes one scheduling decision per batch and then hands control to the engine until all members complete. For models with fixed-size outputs, this is a complete solution — which is why Triton offers it.

```json
dynamic_batching {
  preferred_batch_size: [ 4, 8 ]
  max_queue_delay_microseconds: 100
}
```

> 👉 [`preferred_batch_size`](https://docs.nvidia.com/deeplearning/triton-inference-server/user-guide/docs/user_guide/batcher.html) lists the batch sizes the scheduler tries to form. `max_queue_delay_microseconds` limits how long a request is willing to wait for companions.

# Continuous Batching (Continuous Batching)

So far, both of the previous strategies treat a batch as a single unit of work that starts and runs until every request in the batch is complete. It is precisely this assumption that is still costing you performance. Continuous batching abandons that assumption.

The scheduler runs one iteration, relinquishes control, and then makes a new scheduling decision. As soon as a sequence emits its final token, it leaves the batch, and a waiting request immediately takes its slot in the next round.

The batch composition changes on every iteration. This is why it is called **iteration-level scheduling**. No slot waits for the slowest sequence, so the GPU stays saturated even when output lengths vary dramatically.

The final state looks like this:

![](https://www.waytoagi.com/api/kb-media/Kw1kbKvgaoxViOxU8FYcqBjMnmg)

**The limit is memory, not compute.** Every active sequence holds a KV cache that grows with each token, and it is this cache—not the math—that determines how many sequences can fit.

On a 40GB A100 running a 13B model, you can only hold a handful of long sequences at once. When the cache pool is exhausted, the scheduler evicts a running request and recomputes it later.

This looks like running out of GPU memory, but in reality it means the same prefill computation is performed twice.

> 👉 Every engine offers continuous batching under a different name: vLLM, SGLang, and TGI call it exactly that; TensorRT-LLM calls it *in-flight batching*; LMDeploy calls it *persistent batching*.


# Chunked Prefill (Chunked Prefill)

Rebuilding the batch every round solves the “slow member” problem, but it introduces a new one: users experience stuttering.

A newly arrived request performs its entire prefill in a single iteration. A 32K-token prompt is one massive, compute-heavy pass, and all active decoding must wait for it. So when someone pastes a long document, the output breaks mid-sentence.

Here’s what it looks like with and without chunked prefill.

**Full Prefill:**

![](https://www.waytoagi.com/api/kb-media/NKmTbZcPQocgESxzjZxctSHQnEd)

**Chunked Prefill:**

(Request C’s prompt is split into 2k-token chunks)

![](https://www.waytoagi.com/api/kb-media/Q1yhbS4rEoF1D8xLXTocu5Snnpe)

**Splitting the prompt across multiple iterations.** Chunked prefill divides the prompt into fixed-size token ranges and schedules them across several passes, incrementally growing the request’s KV cache.

The attention computation remains correct because later chunks attend to the KV cache entries created by previous chunks. The first generated token arrives only after the final chunk.

Prefill is compute-intensive while decoding is memory-intensive, so a batch that contains both can utilize both parts of the chip effectively.

![](https://www.waytoagi.com/api/kb-media/NpjtbqXj7owwfixuuhtcX6Jrn7e)

When choosing values, keep these trade-offs in mind:

- **Smaller chunks** give the scheduler more opportunities to run decoding steps and reduce peak ITL for active requests.
- **Larger chunks** process new prompts more efficiently, usually improving TTFT, but active decoding may wait longer between tokens.
- **Chunks that are too small** can reduce GPU utilization and increase attention overhead, because later chunks must re-read KV cache entries created by earlier chunks.

Chunked prefill is [enabled by default in vLLM V1](https://docs.vllm.ai/en/stable/configuration/optimization/), where `--max-num-batched-tokens` limits the total number of tokens processed per iteration. SGLang uses `--chunked-prefill-size` (set to -1 to disable).

**vLLM:**

```bash
vllm serve meta-llama/Llama-3.1-8B-Instruct \
  --max-num-batched-tokens 8192
```

**SGLang:**

```bash
sglang serve --model-path meta-llama/Llama-3.1-8B-Instruct \
  --chunked-prefill-size 8192
```

> 👉 There is no universally optimal chunk size. It depends on the model, GPU, your prompt length distribution, and which latency metric your SLOs are measuring.


# Conclusion

These three strategies differ only in *when* they freeze the batch. Each is suited to different workload patterns.

![](https://www.waytoagi.com/api/kb-media/RCynbJaGNoygxMxFXX4cZXHOnre)

For real-time traffic with highly variable output lengths, continuous batching is the only strategy that maintains performance—and every major inference engine now enables it by default.
