Epoch
Also known as: training epoch
One complete pass of model training through every example in the training data; training often runs for several.
Draft - this entry has not been reviewed yet.
Formal
A unit of model training in which each example in the training data has been used once to update the model; the number of epochs is a hyperparameter set before training starts.
In plain English
Like one full run-through of a choir's concert programme; a few run-throughs polish it, but after fifty the singers can only sing it exactly as rehearsed.
In practice
A data analyst at a Danish shipping company trains a model to predict fuel use from past voyages; she checks the validation set after each epoch and stops at epoch six, when results stop improving although the training error keeps falling.
Why it matters
Too few epochs leave a model half-learned; too many make it learn its examples by heart, so picking the count is a direct trade-off between underfitting and overfitting.
Technical deep dive
With N training examples and batch size B, an epoch consists of ⌈N/B⌉ optimiser steps, or ⌊N/B⌋ when the last incomplete batch is dropped (drop_last=True in a PyTorch DataLoader). The data is normally reshuffled at the start of each epoch, so training samples without replacement within an epoch; this random reshuffling generally works better in practice than the with-replacement sampling assumed in much SGD theory. With on-the-fly data augmentation each epoch sees different random crops, flips or noise, so later epochs are not exact repeats. In distributed training each replica must see a disjoint shard per epoch, which is why samplers such as PyTorch's DistributedSampler need set_epoch() called each epoch, otherwise every epoch repeats the same order.
The epoch is a convenient unit for logging, checkpointing and validation, but it is not what the optimiser sees; learning-rate warmup and cosine or step decay are defined in steps, so changing the batch size silently changes how many steps an epoch-based schedule contains. Typical counts vary enormously: classic ImageNet ResNet-50 recipes use about 90 epochs, small tabular or vision data sets may use hundreds, and fine-tuning a pretrained language model usually uses only one to three epochs, since more tends to cause memorisation and loss of general ability.
Large-scale pretraining has largely abandoned multi-epoch training over the whole corpus. Most web data is seen once or less, while smaller high-quality sources are upsampled and repeated. Muennighoff et al. (2023) found that, for a fixed compute budget, up to about four epochs of repeated data yield almost the same loss as unique data, after which the value of repetition falls off quickly. Repetition also has privacy implications: sequences duplicated many times in training data are far more likely to be memorised and regurgitated verbatim (Carlini et al., 2022), which is one reason deduplication is a standard preprocessing step.
The number of epochs is usually chosen by early stopping on the validation set, but the loss curve does not always behave as the textbook U-shape suggests. Nakkiran et al. (2019) documented epoch-wise double descent, where test error rises and then falls again with further training in sufficiently large models, and Power et al. (2022) described "grokking", where small networks on algorithmic tasks generalise long after fitting their training set perfectly. Patience-based stopping is therefore a heuristic, and for expensive runs it pays to keep periodic checkpoints rather than only the best one.
What to learn first
Everything this builds on, foundations first.
- Training data
- →Epoch
Relationships
- Part of
- Model training
- Requires
- Training data
- Causes
- Overfitting
- Used with
- Hyperparameter
Sources & further reading
Reference works
Textbooks
Where this data comes from
This entry was drafted by an AI from the sources above and has not yet been checked by a person. Treat it as a starting point, and check anything important against the sources.
See the review queueSuggest a correction on GitHubThis term as JSON
Mentioned in
Check yourself
Loading…