AI Hints
Home›Fine-Tuning LLMs Tutorial›How Training Works
Fine-Tuning LLMs · Lesson 24 of 120

Epochs, Batches, Steps

How training is organised.

⏱ 2 min read▶ Video at 39:11🎓 Free
Watch this lesson in the Fine-Tuning LLMs courseWatch on YouTube ↗Full Fine-Tuning LLMs course

Our training set has hundreds of examples. We don't show them to the model one at a time, and we don't show them only once. Three words describe how training is organised.

  • Hundreds of examples
  • Not one at a time
  • Not only once

Three words

A batch is a small group of examples, processed together. A step is one update of the weights, after one batch. And an epoch is one full pass through the whole training set. So the number of steps in one epoch is the number of examples, divided by the batch size.

keyvalue
Batcha group of examples
Stepone weight update
Epochone pass through all data
Steps per epochexamples ÷ batch size

Count the steps

Let's do the maths for our Riverside Books data. Five hundred and twenty seven examples. A batch size of eight. And three epochs. Math dot ceil rounds up, because the last batch can be smaller. Run it. Sixty six steps per epoch, and one hundred and ninety eight in total.

app.pypython
import math

examples = 527
batch_size = 8
epochs = 3

steps_per_epoch = math.ceil(examples / batch_size)
print("Steps per epoch:", steps_per_epoch)
print("Total steps:    ", steps_per_epoch * epochs)
Output
Steps per epoch: 66
Total steps:     198

How many epochs?

How many epochs should you train? For fine-tuning, usually one to three. The model already knows a lot, so it learns your task quickly. Too many epochs, and it starts memorising the examples, instead of learning the task. That's called overfitting, and we'll learn to spot it soon.

keyvalue
Fine-tuningusually 1 to 3 epochs
Why fewit already knows a lot
Too manymemorises examples
Calledoverfitting

Summary

Let's recap. A batch is a group of examples. A step is one update. An epoch is one full pass. And fine-tuning usually needs only one to three epochs. That completes the theory. Next, we start working with real data.

Key takeaways
  • Batch, step, epoch
  • steps = examples ÷ batch
  • 1 to 3 epochs
Next up: The datasets Library — loading training data