Batching

Batching is grouping several inputs so a model processes them in one pass on the hardware, which uses chips far more efficiently and is central to the cost of serving AI.

GPUs are built to do many calculations at once. A single request to a language model rarely keeps one busy, because generating each token means reading the model's huge set of weights from memory for a comparatively small amount of arithmetic. If the server handles 32 requests together, it reads the weights once per step and does 32 times the useful work. That is batching, and it is the main reason one GPU can serve many users at a reasonable cost.

The simple version, often called static batching, collects a group of requests, runs them together and returns them all when the last one finishes. For language models this wastes a lot. Answers vary in length, so a two-word reply sits waiting for a 2,000-word essay in the same batch, and new requests queue until the whole batch is done.

The fix is now standard. In a 2022 paper at the OSDI conference, Gyeong-In Yu and colleagues described iteration-level scheduling in a system called Orca: instead of scheduling a whole batch, the server schedules one generation step at a time, so finished requests leave and new ones join after every token. On a 175 billion parameter GPT-3 model they reported up to 36.9 times the throughput of NVIDIA's FasterTransformer at the same latency. The technique is now widely called continuous batching. The vLLM project, described at SOSP in 2023, paired it with PagedAttention, a way of managing the memory each request needs, and reported two to four times the throughput of earlier systems.

Batching is a trade between throughput and latency. Bigger batches serve more users per chip, which lowers the cost of each answer, but each user's tokens may arrive a little more slowly. Providers tune that balance constantly, and it is one reason the same model can be priced differently depending on how quickly the answer is needed.

In training, the word batch means something related but different: the set of examples used in one update of the model's parameters. The two ideas share the same root, that hardware is more efficient working on many inputs at once.

Common questions

What is continuous batching?

Continuous batching lets a server add and remove requests from a running batch after every generation step, instead of waiting for the whole batch to finish. Short answers return as soon as they are done and new requests start straight away. It was introduced as iteration-level scheduling in the Orca paper in 2022 and is now built into most language model servers.

Why does batching make AI cheaper?

Generating text is limited mostly by how fast the chip can read the model's weights from memory. Batching lets one read of those weights serve many requests at once, so the same hardware produces many more tokens per second and each token costs less.

Does batching make responses slower?

It can, a little. Larger batches mean each step takes longer and each user shares the chip with more people, so tokens may arrive more slowly. Serving systems set batch sizes to keep latency within targets while keeping the hardware busy.

Is batching the same as batch inference?

No. Batching is a technique used inside almost every model server, including real-time chat services. Batch inference is a way of submitting large jobs to be processed later, usually at a discount. Batch inference relies on batching, but batching happens whether or not you choose a batch service.

Finding more

Search for "continuous batching", "iteration-level scheduling", "Orca OSDI 2022" and "PagedAttention vLLM" to understand how modern servers batch requests. The most reliable sources are the original systems papers from conferences such as OSDI and SOSP and the documentation of open-source inference engines. Throughput figures in vendor benchmarks depend heavily on the model, hardware and settings chosen.

Working out what this means for your business?

Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.