Skip to content

Epochs, Batches and Iterations

Training vocabulary: a batch is the group of examples used for one update, an iteration is one update, and an epoch is one full pass over the training data.

Also epoch · batch size · mini-batch · iteration · training step

Fig. / How it works
stepstepstepepochBatch 1Batch 1Batch 2Batch 2Batch 3Batch 3Batch 4Batch 4
Role · kind
TrainingConcept
Level
Beginner

Reading a 300-page book 30 pages per evening: each evening is a batch, each evening's reading is an iteration, and finishing the whole book once is an epoch. Re-reading it is the second epoch.

Where it fits

+All relationships as a list

See it on the full map

How it works

Training a neural network with gradient descent rarely uses all the data for each update. Three words describe how the data is chopped up:

  • Batch (mini-batch): a small group of examples, often 32 to a few thousand. The gradient is averaged over the batch.
  • Iteration (step): one weight update, computed from one batch.
  • Epoch: one complete pass through the training set. With 50,000 examples and batches of 500, an epoch is 100 iterations.

Typical classic training runs for tens of epochs, reshuffling the data each time and checking validation loss after each one (see early stopping).

Batch size trade-offs:

  • Small batches: noisier gradients (which can even help generalization), less memory, but less efficient use of the GPU.
  • Large batches: smoother gradients and faster per example, but more memory and usually a larger learning rate.

Large language models are different: their datasets are so big that they see most text only once or a few times, so their training progress is measured in tokens rather than epochs.

Everyday use cases

  • Case 01

    Fitting training into GPU memory

    If a model runs out of memory, lowering the batch size is usually the first fix.

Strengths, weaknesses and when to use it

Strengths

  • Shared vocabulary for describing and reproducing any training run.

Weaknesses

  • Batch size interacts with learning rate, so changing one usually means retuning the other.

When to use itEvery time you configure or read about a training run.

Compare with

Check yourself

  1. Q01

    10,000 examples, batch size 100. How many iterations in one epoch?

    Show answer

    B: 100

  2. Q02

    Why shuffle the data each epoch?

    Show answer

    A: So batches are not always the same, which gives less biased gradient estimates

Go deeper