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

Scaled cosine similarity can cause NaNs #111

Open
bobcao3 opened this issue Aug 23, 2024 · 0 comments
Open

Scaled cosine similarity can cause NaNs #111

bobcao3 opened this issue Aug 23, 2024 · 0 comments

Comments

@bobcao3
Copy link

bobcao3 commented Aug 23, 2024

sqrt_scale = torch.sqrt(scale.to(dtype))

I know it's mentioned in the paper that this version of scaling directly parametrize scale instead of exponent, however an unintended side effects is that when the scale goes close to zero it can get into negatives due to some larger random gradient updates, which causes a NaN.

Fix is simple, in our adaptation for our in house models we changed it to torch.sqrt(torch.abs(scale) + eps). The eps is added for preserving gradients (so it never reaches zero). I guess a biased ReLU also probably works, along with other non linear functions.

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

1 participant