Pytorch, Machine Learning, Gradient Descent, Python, Hands On Tutorials.
optimizer.zero_grad() outputs = model(inputs) loss = loss_fn(outputs, labels) loss.backward() optimizer.step() print('epoch {}, loss {}'.format(epoch, loss.item())) Running this gives us text output that shows us the loss is decreasing, eventually down to a minimum, as expected: epoch 0, loss