Search⌘ K
AI Features

Training Methods

Explore how to implement training methods in a PyTorch class by updating mini-batch handling and the training loop. Understand setting random seeds for reproducibility and managing training and validation loaders as class attributes. This lesson helps you build a flexible and reliable training loop that tracks losses and epochs without returning values, preparing your model for saving and loading operations.

Updating mini-batch

The next method we need is to add corresponds to the helper function #2 in the chapter, Rethinking the Training Loop: the mini-batch loop. We need to modify it a bit before incorporating it in our StepByStep class.

Inside the previous function, both the data loader and the step function were arguments. However, this is not the case anymore since we have both of them as attributes: self.train_loader and self.train_step for training; self.val_loader and ...