I would recommend you check the 60min blitz and in particular the section on neural nets there that will explain it better than I could https://pytorch.org/tutorials/beginner/deep_learning_60min_blitz.html 163