xsquared:

for imgs, labels in loader:


Are you running the code on page 214 Section 8.4.1? That block has been annotated as “We do not want gradients…”. That code is just for measuring accuracy, not training.
Use the training_loop function (pg 215) - that is the one for training. The github repo @ https://github.com/deep-learning-with-pytorch/dlwpt-code will help you out.