AI Training Epochs: Steps and Updates Explained
In this article
In AI training, an epoch is one full pass over the entire training dataset, a step is a single update of the model's weights using one batch of data, and an update is the actual adjustment of weights performed after each step. The number of updates per epoch equals the number of batches, which is the dataset size divided by the batch size. This article explains how these concepts relate, how to calculate them, and how they affect model training.
Background: Why Epochs, Steps, and Updates Matter
When training a neural network, the goal is to minimize the loss function by adjusting the model's weights. This is done iteratively: the model makes predictions, compares them to true labels, computes the loss, and updates weights using a gradient descent algorithm. The terms epoch, step, and update describe different granularities of this process:
- Epoch: one complete pass over the entire training dataset.
- Step: one iteration where the model processes a batch of data and performs a weight update.
- Update: the actual adjustment of weights after computing gradients from a batch.
In practice, 'step' and 'update' are often used interchangeably, but understanding the distinction helps in configuring training runs and interpreting logs.
How Training Iterations Work
Modern deep learning uses mini-batch gradient descent. Instead of computing the gradient on the whole dataset (which is often too large to fit in memory), the data is split into small batches. For each batch:
- Forward pass: compute predictions and loss.
- Backward pass: compute gradients of the loss with respect to weights.
- Update: adjust weights using an optimizer like SGD or Adam.
This sequence is one step. After all batches are processed, one epoch is complete. The optimizer's learning rate and momentum (if any) control how much weights change per update.
Calculating Steps per Epoch
The number of steps per epoch is simply the number of batches:
steps_per_epoch = ceil(N / batch_size)
where N is the total number of training samples. The ceiling is used because the last batch may be smaller if N is not divisible by batch_size. For example, with 10,000 samples and a batch size of 32, steps per epoch = ceil(10000/32) = 313.
Some frameworks allow you to drop the last incomplete batch, in which case you use floor division. Most frameworks default to keeping the remainder, so the ceiling is standard.
Total Updates Across All Epochs
If you train for E epochs, the total number of updates (steps) is:
total_updates = E × steps_per_epoch
Using the previous example, training for 10 epochs gives 10 × 313 = 3,130 updates. This total is what you see in training logs as 'iterations' or 'global steps'.
Note that if you use gradient accumulation (simulating a larger batch by accumulating gradients over several steps before updating), the number of actual weight updates per epoch is reduced. For instance, with accumulation steps of 4, you update weights every 4 batches, so actual updates per epoch = steps_per_epoch / 4.
Choosing the Number of Epochs
The number of epochs is a hyperparameter you set before training. More epochs allow the model to see the data more times, which can improve performance but also risks overfitting. Common strategies include:
- Early stopping: monitor validation loss and stop when it stops improving.
- Learning rate schedules: reduce the learning rate after certain epochs to fine-tune.
- Fixed epochs: set a number based on prior experience or computational budget.
There is no universal rule; it depends on dataset size, model complexity, and task. A small dataset may need many epochs (e.g., 50-100), while a large dataset might only need 1-5 epochs because each epoch already provides many updates.
Common Misconceptions and Pitfalls
One common mistake is confusing steps with epochs when reading logs. For example, a log line 'Epoch 5, Step 1000' means you are in the 5th epoch, and within that epoch you have processed 1000 batches. Another pitfall is setting the number of steps instead of epochs in some frameworks (like TensorFlow's steps_per_epoch argument) without realizing it changes the total data seen.
Also, when using data augmentation or shuffling, the composition of batches changes each epoch, so the model sees slightly different variations of the same data, which can help generalization.
Comparison with Other Training Paradigms
In full-batch gradient descent (rarely used for large datasets), one step equals one epoch because the entire dataset is one batch. In online learning (stochastic gradient descent with batch size 1), each step processes one sample, so steps per epoch equals the dataset size. Mini-batch sits in between, balancing computational efficiency and gradient stability.
Transfer learning often uses fewer epochs because the model is already pretrained; fine-tuning typically uses 2-10 epochs. In contrast, training from scratch on a small dataset may require dozens of epochs.
Frequently Asked Questions
How many steps are in one epoch?
It is the number of batches, calculated as the dataset size divided by the batch size, rounded up. For example, 1,000 samples with batch size 100 gives 10 steps per epoch.
What is the difference between a step and an update?
In standard training, they are the same: each step performs one weight update. However, with gradient accumulation, multiple steps (forward/backward passes) can occur before a single weight update, so the terms become distinct.
Does more epochs always mean better accuracy?
No. More epochs can lead to overfitting, where the model memorizes the training data and performs poorly on unseen data. Validation metrics often plateau or decline after a certain point.
How do I choose the batch size?
Batch size affects training speed and stability. Larger batches use memory more efficiently but may require a lower learning rate. Common sizes are 32, 64, or 128, but you should tune based on your hardware and model.
What is gradient accumulation?
It is a technique to simulate a larger batch size by accumulating gradients over several small batches before updating weights. This allows training with larger effective batch sizes without exceeding memory limits.