Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: Function 'SqrtBackward' returned nan values in its 0th output. #69

Open
niels-leif-bracher opened this issue May 18, 2021 · 3 comments

Comments

@niels-leif-bracher
Copy link

Hi,
i wanted to ask if its possible to add the epsilon under the sqrt in the norm function instead of adding it under the fraction because I think for my use case some sqrt are 0 and therefore the gradient returns nan.

def normalize_tensor(in_feat,eps=1e-10):
norm_factor = torch.sqrt(torch.sum(in_feat**2,dim=1,keepdim=True))
return in_feat/(norm_factor+eps)

@niels-leif-bracher
Copy link
Author

Somehow switching from vgg to alexnet solved this issue.

@MartinPernus
Copy link

MartinPernus commented Nov 4, 2021

Having the same problem using alexnet. Solved by adding epsilon under the sqrt.

@Sinjini15
Copy link

Hi @MartinPernus , do you mean you added an epsilon within the sqrt calculation? I am having the same error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants