Homeglossary

Batch Size

Batch size is a machine learning hyperparameter that determines how many training samples a model processes in one forward and backward pass before updating its weights. It directly affects memory use, training speed, and how stable or noisy the learning updates are. The right setting depends on the model, data, hardware, and the goal of the training run.

Build efficient AI apps with Emergent.

What is batch size in machine learning?

Batch size is the number of training samples a machine learning model processes before it updates its weights. In one batch, the model makes predictions in a forward pass, measures error, sends that error backward to calculate gradients, then adjusts its weights. It applies to training, not the number of test samples.

How batch size works during training

Training repeats this cycle until the model has learned from the dataset several times.

  1. Shuffle or select training samples.
  2. Load one batch into memory.
  3. Run predictions and calculate the error.
  4. Backpropagate gradients that show how to reduce error.
  5. Update the model weights once.
  6. Repeat with the next batch.

For example, 10,000 samples with a batch size of 100 create 100 training steps per epoch. Training for 10 epochs produces 1,000 weight updates.

Batch size, epoch, iteration, and global batch size

These terms describe different parts of a training run.

TermMeaning
Batch sizeSamples processed before one update.
EpochOne pass through the training dataset.
Iteration or stepOne batch and usually one weight update.
Global batch sizePer-device batch size multiplied by device count, then multiplied by gradient accumulation steps.

Benefits of a larger batch size

Larger batches can make efficient use of accelerators.

  • They may improve GPU or TPU throughput.
  • They create fewer updates per epoch.
  • They usually produce less variable gradient estimates.
  • They can shorten elapsed training time, though not always time to desired model quality.

Limits of a larger batch size

A batch that is too big can create new problems.

  • It can exhaust accelerator memory and cause out-of-memory errors.
  • It reduces the number of learning updates in each epoch.
  • It can change optimization behavior and validation quality.
  • It often requires learning-rate retuning rather than a simple size increase.

What should my batch size be?

There is no universal best value. Powers of two are convenient for hardware, not a requirement.

  1. Start with a size that reliably fits memory.
  2. Record throughput and validation results as a baseline.
  3. Increase the size gradually.
  4. Compare training speed and validation quality.
  5. Retune the learning rate when results change.
  6. Keep the smallest batch that meets the training objective.

Training batch size versus inference and API batching

The same word describes different technical workflows.

ContextPrimary concern
TrainingMemory, learning behavior, and convergence.
InferenceLatency for each user versus total throughput.
API batchingLower request overhead while handling payload limits, retries, ordering, and partial failures. See Batch API.

Using batch size in AI application development

Batch size also matters when an AI app processes imports, background jobs, or bulk model requests. Teams should test realistic batch limits and failure handling as part of app design and development. Emergent helps teams build and test full-stack AI applications where these workload choices can be validated before release.

Start Building
on Emergent today
Start Building