The optimizer already executed its step() method using the calculated gradients from the output.backward() call and thus manipulated the parameters.
all_losses stores these output tensors (losses) and tries to calculate the gradients again, which won’t work since the parameters were already updated.