Thanks! I just realized what the problem was. Your answer was pretty helpful. Basically, during my first iteration, I don’t call .backward(), so the gradients are None, but I call backward() after the second iteration and on, that’s why it prints gradients, but can’t do torch.sum().