If you want to double check your implementation, you can use torch.autograd.gradcheck() with your function and double precision inputs. See the doc for more details.
But I will restate what I said above, a 1-bit difference at any stage (due to floating point non-associativity for example) will be increased by gradient descent and will lead to completely different final weights (even after a small number of iterations if you have a fairly deep net).