Batch Size
Batch size is the number of training examples that are processed together in a single forward and backward pass before the model parameters are updated. Rather than updating weights after every individual example (stochastic gradient descent) or after the full dataset (batch gradient descent), most deep learning training uses mini-batches — a middle ground that balances update frequency against gradient estimate quality. The gradient computed over a mini-batch is an approximation of the true gradient over the full dataset; larger batches produce more accurate estimates but require proportionally more memory and offer diminishing returns in practice.
Think of it like proofreading a document. You could correct the manuscript one sentence at a time (very slow and choppy), read the entire book before making any edits (requires holding everything in mind at once), or work through it chapter by chapter — which is roughly what mini-batch training does.
A typical training loop makes the batch size explicit:
for epoch in range(num_epochs):
for batch in dataloader: # dataloader yields batches of size 32
optimizer.zero_grad()
outputs = model(batch["inputs"])
loss = criterion(outputs, batch["labels"])
loss.backward()
optimizer.step()
Batch size is a Hyperparameter that significantly affects training dynamics. Small batches introduce noise that can help escape sharp loss minima, sometimes improving generalisation. Very large batches (in the thousands, used with distributed training across many GPUs) tend to converge faster in wall-clock time but may require adjusting the learning rate — often by the linear scaling rule — to avoid instability.
Batch size interacts with the Loss Function (averaged over the batch), Backpropagation (which runs once per batch), Gradient Descent (which receives the averaged gradient), and Overfitting (regularisation from stochastic noise decreases as batch size grows). Memory constraints on the accelerator hardware are usually the practical upper bound.
You will encounter batch size as a key training configuration in every deep learning framework, and it is one of the first settings adjusted when a training run runs out of GPU memory or converges more slowly than expected.