in loss function(Loss(input, target)), the target.requires_grad must be False.
if you wanna calculate the grad for target, maybe simply use
loss = (predict-target)**2/predict.size(0)

it can’t take advantage of backend, but I think it won’t cost much time either.
I think maybe mse_loss should be  availiable in torch.nn.functional.