Subscribe
AI
7 min read

What Is an Epoch? The Clocks Behind Every LLM Training Run

An explainer on how epochs, batch sizes, and steps function as different 'clocks' for measuring AI model training progress.

Diagram illustrating the relationship between epochs, batch size, and step counts in large language model training processes
Diagram illustrating the relationship between epochs, batch size, and step counts in large language model training processes

An epoch represents one full pass through a training dataset, but modern LLM pretraining rarely completes a single epoch due to vast data volumes and token-streamed inputs. Instead of fixed passes, these models prioritize consuming unique tokens to avoid memorization, making step and total token counts more relevant metrics for pretraining runs. Fine-tuning remains an exception, typically relying on multiple epochs to process smaller, specialized datasets effectively.

Training-run announcements quote numbers that almost nobody unpacks. A model "saw 15 trillion tokens." A config file lists a batch size of 4 million, a step count of 60,000. Loss curves get plotted against neither epochs nor examples but tokens. The vocabulary comes from three related clocks, and they measure different things: the epoch, the batch, and the step.

This explainer is about how those three clocks work, why frontier pretraining runs typically finish without completing a single epoch, and why fine-tuning lives in the opposite regime.

The three clocks

An epoch is one full pass through the training dataset. If a model reads every example exactly once, it has completed one epoch. Two epochs means the same data, reshuffled, is read twice.

A batch (usually a minibatch) is the set of examples whose gradients get averaged into one weight update. Instead of updating after every single example, which is noisy and slow, or after the entire dataset, which does not fit in memory, training splits the data into manageable chunks.

A step (or iteration) is one weight update: forward pass over a batch, backward pass, optimizer moves the weights.

They connect by simple arithmetic. Steps per epoch equals dataset size divided by batch size. Total data consumed equals steps multiplied by batch size. A 1.28-million-image dataset with batches of 256 images takes 5,000 steps per epoch. Train for 90 epochs and you get about 450,000 steps. That was the shape of a standard vision training run for years, and it is still roughly what the ResNet ImageNet recipe describes: 90 epochs, batch 256.

A dataset shown as a long band of tiles with a red bracket marking one batch inside a single pass

Why LLMs stopped counting in epochs

Language models changed the unit of the batch. LLM training batches are measured in tokens, not examples, and the numbers are large. GPT-3's 175B model used a batch of 3.2 million tokens, ramped up gradually from 32 thousand tokens at the start of training. The whole run consumed 300 billion tokens. Divide one by the other and the entire training of the largest GPT-3 model amounts to roughly 94,000 optimizer steps.

With batches that large, epochs stop being the natural clock. The GPT-3 paper's own appendix shows the consequence: over its 300-billion-token run, the model saw Wikipedia 3.4 times over but Common Crawl only 0.44 times. No source reached a clean pass, and the mix of sources, not any single epoch count, defined the curriculum.

Modern frontier runs push this further. Meta trained Llama 3 on over 15 trillion tokens, roughly seven times the 1.8 trillion used for Llama 2, and reported that model quality kept improving on a log-linear path far past the compute-optimal point of about 20 tokens per parameter that Chinchilla established for an 8B model (around 200 billion tokens). The 405B flagship consumed 15.6 trillion text tokens. Meta does not publish the size of the unique pool behind that stream, but if the pool is roughly that size, the run is about one pass through the data, no more.

Why train on fresh data instead of rereading? Because repetition loses value fast. A 2023 study by Muennighoff and colleagues, which ran experiments up to 900 billion training tokens, found that repeating a fixed dataset for up to about 4 epochs costs almost nothing compared with having an equal amount of unique data. Past that point the value of extra compute decays toward zero, and the model starts memorizing. So labs deduplicate aggressively and spend their compute on tokens the model has never seen. That is why "how many epochs did you train for?" is close to a category error for a frontier pretraining run. The honest answer is: less than one, and that is the point.

There is a second, quieter reason epochs faded: streams. When data arrives as shuffled token streams sampled from weighted sources, as in GPT-3's per-source sampling weights, the dataset has no fixed boundary to complete a pass over. The step counter keeps ticking; the epoch never ends.

Why batches cannot grow forever

If one big step approximates many small ones, why not make the batch the whole dataset? Because eventually the examples stop disagreeing. McCandlish and colleagues at OpenAI formalized this in 2018 with a measurable statistic they called the gradient noise scale: it compares the variance of individual gradients to the magnitude of their average. When individual gradients disagree wildly (high noise), averaging over a much larger batch genuinely improves the update direction, and big batches pay off. When they already agree, adding more examples to the batch costs compute and buys almost nothing. The batch size where returns halve is the "critical batch size," and their measurements showed it grows as training proceeds: late in training, when the model squeezes finer signals from data, larger batches become worthwhile.

Scaling the batch also forces you to scale the learning rate, a rule of thumb the ImageNet-in-an-hour paper states plainly: multiply the minibatch by k, multiply the learning rate by k. The authors trained ResNet-50 with batches up to 8,192 images at no accuracy loss, but needed a warmup phase at the start (large early steps with rapidly changing weights diverge) and observed training breaking down past a 64k batch. Every large-batch recipe in wide use today inherits those two constraints: linear scaling and a gentle ramp-up.

One practical workaround deserves a mention: gradient accumulation. Hardware cannot always fit a 3.2-million-token forward pass, so the framework runs several small minibatches, sums their gradients, and applies one update. The Alpaca fine-tuning code does exactly this: per-device batch 4, eight accumulation steps, four GPUs, which composes to the intended global batch of 128 examples. The clock that matters to the optimizer is the update step, not the micro-batch.

One very long band of tiles versus a stack of short repeated bands: a single vast pass versus repeated small passes

Fine-tuning lives in the other regime

Instruction tuning and LoRA runs look nothing like pretraining on the epoch clock. Stanford's Alpaca recipe, which defined the template for the open fine-tuning wave, trained for 3 epochs (5 for the 13B model) over 52,000 examples with a global batch of 128. A little arithmetic: 52,000 divided by 128 is about 406 steps per epoch, so the whole Alpaca run was roughly 1,200 optimizer steps, against GPT-3's 94,000 for pretraining.

Small datasets get re-read because there is no other option, and because the model benefits from repeated exposure up to a handful of passes. The failure mode is overfitting to the instruction set, which is why these runs keep the learning rate low (2e-5 for Alpaca's 7B run) and stop at single-digit epoch counts, and why practitioners watch validation loss rather than epoch numbers.

Reading a training config

Three numbers pin down any run: total tokens, batch size, and steps. They multiply out, so knowing any two gives you the third. When you see "60,000 steps, 4 million token batch," read it as 240 billion tokens consumed, and divide by the size of the pool to recover the epoch count. When a lab reports only "15 trillion tokens," as Meta did for Llama 3, the implied epochs depend entirely on how much unique data existed to be consumed, which is the number most announcements skip. The step count tells you how often the model updated. The token count tells you what it read. The epoch is the old clock, kept mostly for fine-tuning runs small enough to finish a lap.

Sources

Frequently asked questions

Why do LLMs rarely complete a full epoch during pretraining?

Frontier LLMs consume trillions of tokens from diverse sources, meaning the model sees specific subsets of data multiple times while other parts are seen zero or once. Since repetition loses value quickly, labs prioritize new, unique data over completing clean passes through any single source.

How many epochs was Meta Llama 3 trained for?

The text states that if Meta Llama 3's 15.6 trillion token pool consists largely of unique data, the run amounts to roughly one pass, or one epoch. However, the exact number depends on the size of the unique data pool, which is not publicly disclosed.

How many epochs did the Stanford Alpaca fine-tuning recipe use?

The Alpaca recipe trained for 3 epochs for standard models and up to 5 epochs for the 13B variant, utilizing a global batch of 128 examples over 52,000 total samples.

What is the difference between a step and an epoch in AI training?

A step is one weight update involving a forward and backward pass over a batch of data, whereas an epoch is one complete traversal of the entire dataset. Steps per epoch can be calculated by dividing the dataset size by the batch size.

AILLMEducation