Why batching raises efficiency

In a neural-network layer, the weights are the same for every input. With batch size 1, a fully connected layer is a matrix-vector product: each weight is fetched from memory for a single multiply-add, giving an arithmetic intensity of about 1 FLOP/byte in FP16, so compute units mostly wait for memory. With batch size B, the layer becomes a matrix-matrix product: weight traffic stays the same while operations grow B-fold, so intensity rises roughly B-fold and the workload moves from memory-bound toward compute-bound. Servers exploit this by grouping requests from many users.

The latency and memory cost

A bigger batch raises total throughput but not individual speed. Requests may wait for others to arrive, and each batch takes longer to compute, so per-request latency grows; interactive services raise the batch only as far as their response-time targets allow. Memory grows too. In LLM (large language model) inference the KV cache, which stores attention keys and values of earlier tokens so they are not recomputed, scales with layers, key and value dimensions, tokens, batch size and bytes per element. With long contexts or many requests it can reach tens of gigabytes, more than the weights.

Typical numbers in LLM decoding

During decoding at batch size 1, every generated token requires reading all the weights. A model with about 14 GB of FP16 weights on a GPU with 2 TB/s of bandwidth therefore needs at least14 GB2 TB/s=7 ms14 GB ÷ 2 TB/s = 7 msper token, at most about 140 tokens per second. Quantizing weights to 4 bits, about 3.5 GB, lowers the per-token time bound to about 1.75 ms. A larger batch generates several tokens per weight read, multiplying aggregate throughput until compute or KV-cache memory becomes the limit. KV-cache pressure is eased by lower-precision caches, sharing keys and values across heads and block-based memory management.

Batch size in training

In training, the batch (mini-batch) is the set of samples whose gradients are averaged for one weight update. Larger batches use hardware more efficiently and need fewer update steps per pass over the data (an epoch), but activation memory for backpropagation grows with batch size and model depth. Gradient checkpointing counters this by storing only some activations and recomputing the rest for roughly one extra forward pass. Changing the batch size substantially usually means retuning the learning rate, since it changes gradient noise.

Try it: questions about Batch size

Why does a fully connected layer (a weight-matrix-by-vector product) tend to be memory-bound with a single input (batch size 1)?

  1. AThe vector has too many elements to fit in the arithmetic units
  2. BGPUs cannot compute matrix-vector products
  3. CEach weight read from memory is used in only one multiply-add, so arithmetic intensity is very low
Show answer and explanation

Answer: C. Each weight read from memory is used in only one multiply-add, so arithmetic intensity is very low

In a matrix-vector product, each element of the weight matrix is read once and used for a single multiply-add with one input element. In FP16 that is two operations per 2 bytes, an arithmetic intensity of about 1. Reading the weights takes most of the time while the arithmetic units mostly wait. Grouping inputs so the same weights serve several of them (a larger batch) raises arithmetic intensity.

Why does increasing the batch size (the number of inputs processed together) tend to improve inference efficiency?

  1. AMore inputs reduce the computation per input
  2. BA larger batch reduces the number of weights
  3. CWeights read once serve several inputs, raising arithmetic intensity and keeping the arithmetic units busy
Show answer and explanation

Answer: C. Weights read once serve several inputs, raising arithmetic intensity and keeping the arithmetic units busy

With batch size B, multiplying the weight matrix by B vectors becomes a product of the weight matrix and a B-wide matrix. Weight reads stay the same while operations grow B-fold, so arithmetic intensity rises roughly B-fold and the workload moves from memory-bound toward compute-bound. Server inference uses GPUs efficiently by batching requests from many users together.

FAQ

Does a larger batch size make inference faster?

It increases total throughput because each weight read serves more inputs, but each individual request usually waits longer, so latency gets worse.

Why does increasing batch size increase GPU memory use?

Activations, and in LLMs the KV cache, are stored per input, so they scale linearly with batch size while the weights stay the same.

What is the difference between batch size and epoch?

Batch size is how many samples are processed per step or weight update; an epoch is one full pass over the training dataset, which takes dataset size divided by batch size steps.

Questions that mention Batch size (5)

Batch size appears in 7 practice questions across 1 topic, including AI Hardware & Software Stack.

  1. What is a drawback of making the inference batch size too large?
  2. A model with about 14 GB of FP16 weights decodes at batch size 1 on a GPU with 2 TB/s memory bandwidth. What is closest to the lower bound on time per generated token?
  3. What is the role of the KV cache in LLM inference?
  4. When LLM inference handles long contexts or large batches, what tends to become a problem?
  5. Which describes gradient checkpointing (activation recomputation) used in training?

Books on AI Hardware & Software Stack Ad

As an Amazon Associate I earn from qualifying purchases.

Comparisons that include this term

Semiconductor, Electronics and Computing Calculators

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary