Currently, I am avoiding NaN by doing torch.sqrt(1e-5 + x.pow(2).sum(1)). However, when I check the output, it differs by about 0.001 which is quite big. Is there any way of doing this other than adding 1e-5 (anything smaller will still give NaN, e.g. 1e-6). Or is 0.001 actually fine? My result is not as desired though, still cannot find the culprit and I hope that I can remove this 0.001 discrepancy so that I can eliminate the possibility of this giving me bad result.