In machine learning training, batch size determines how many examples are grouped for a computation. With standard mini-batch gradient descent, the model processes a batch, calculates a loss, computes gradients, and updates its parameters. A batch size of one corresponds to processing individual examples, while full-batch gradient descent uses the entire training dataset for an update. Most deep learning workloads use intermediate sizes to balance computational efficiency and learning behavior.
Batch size, epochs, and steps describe different parts of the training process. An epoch is one pass through the training dataset. A step often means an optimizer update, although some frameworks also use the term for an individual batch-processing iteration. With 10,000 examples, a batch size of 100, and no gradient accumulation, one epoch contains 100 updates. Increasing the batch size to 200 reduces that to 50 updates. Consequently, keeping the number of epochs unchanged does not keep the number of parameter updates unchanged. When the dataset is not evenly divisible by the batch size, the final batch may be smaller or discarded, depending on the data loader configuration.
In the cloud, engineers configure batch size in training scripts, framework data loaders, or supported algorithm hyperparameters. The selected instance must accommodate model parameters, optimizer state, activations, and other runtime allocations. Larger batches generally require more activation memory and can improve accelerator utilization, but throughput eventually reaches a limit. If training fails with an accelerator out-of-memory error, reducing the per-device batch size is a common first adjustment. Larger instances, mixed precision, or activation checkpointing may also help, but each changes cost or execution characteristics.
Smaller batches generally produce noisier gradient estimates, while larger batches generally reduce sampling variability. Neither guarantees better accuracy. Large batches can require changes to learning rate, warmup, or training duration to reach comparable validation performance. Learning-rate scaling rules are starting points rather than universal guarantees. Compare configurations using validation metrics and elapsed time or cost to reach a target quality level, rather than assuming that the highest examples-per-second rate is the best result.
Distributed training introduces a distinction between local and effective batch size. In ordinary synchronous data-parallel training, effective batch size equals the per-device batch size multiplied by the number of data-parallel workers and the number of gradient accumulation steps. For example, four data-parallel GPUs processing eight examples each and accumulating gradients over four iterations produce an effective batch size of 128 examples per optimizer update. GPUs used only for model parallelism do not independently multiply this value. Gradient accumulation allows a larger effective batch without holding all examples' activations simultaneously, but it does not necessarily reproduce every behavior of a physically larger batch, especially with batch-dependent operations.
For foundation model fine-tuning, sequence length also strongly affects memory requirements. Two batches containing the same number of examples can require different memory when their token counts differ. Padding, sequence packing, and token-based batching therefore matter alongside example counts. Training batch size should also not be confused with inference batching: inference groups requests for execution efficiency but does not compute training gradients or update model weights. Record the batch-size definition, accumulation settings, worker count, and sequence-length configuration so that experiments remain reproducible.