The PyTorch training loop repeats, for each batch: resetting the gradients, a forward pass to predict, computing the loss, backpropagation with backward(), and the optimizer update. It alternates with an evaluation phase in eval() mode without gradient computation.
Example
for x, y in loader:
optimiseur.zero_grad()
perte = critere(modele(x), y)
perte.backward()
optimiseur.step()