core Estimated learning time: 6 h

6.9 The training loop, datasets, dataloaders

You have a training script you reuse for every project.

Before:05. Classical Machine LearningUnlocks:07. Natural Language Processing11. The ECE Bridge — Signals, Edge & Embedded AI

The training loop is the instrument: datasets, dataloaders, epoch and validation phases, checkpointing, seeds. Building one good script and reusing it turns every future project into filling in blanks. It follows the PyTorch topic because the loop is PyTorch in motion. The silent failure it teaches you to see is data starvation — a slow dataloader leaves the GPU idle, and without measuring utilisation the training just seems mysteriously slow.

Work through these

  • Dataset and DataLoader, collate functions

    The two objects that stand between raw data and a batch, and the function that assembles individual examples into one. Custom assembly is needed more often than beginners expect.

  • Epoch loop, validation loop, metrics logging

    The structure of a training run: passes over the data, a held-out check after each, and a record of what happened. Having one reusable script is worth more than any individual project.

  • Checkpointing and resuming

    Saving progress periodically and being able to continue from it, which matters because long runs are interrupted. Resuming correctly includes the optimiser state, not only the weights.

  • Reproducibility: seeds, determinism, and its cost

    Seeds make a run repeatable, full determinism costs speed, and some operations are not deterministic at all. Deciding how much reproducibility you need is a real trade rather than an ideal.

Sign in to keep your progress.

Free resources

Links last checked 29 Aug 2026.

Stuck here?

Ask a mentor. A real person answers, and they can see exactly which topic you're on. Usually within a couple of working days.

Checking your session…

Topics shown in module order.