Hi,
This is most likely due to your network. This function is quite widely used and tested so I think it is correct.
You can double check by using torch.autograd.gradcheck.gradcheck function wil double typed inputs to verify that the computed gradients are correct.