Dace:

for x,y in trainloader:
        optimizer.zero_grad()
        p = net(x)
        loss = loss_fn(p,torch.argmax(y,dim=1))
        optimizer.step()



It seems that there is no loss.backward() between the loss calculation and optimizer.step().
examples/main.py at master · pytorch/examples · GitHub 2 can be a reference.