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

The mathematical trick in self-attention, why it returns false for torch.allclose(xbow, xbow2)? #43

Open
Ryan-ZL-Lin opened this issue Feb 28, 2024 · 2 comments

Comments

@Ryan-ZL-Lin
Copy link

Hi
I noticed that the result of torch.allclose(xbow, xbow2), torch.allclose(xbow, xbow3) are all false when running the Collab example gpt-dev.ipynb in The mathematical trick in self-attention section. Here is what I got, has anyone encountered the same issue?
image

@0xArwa
Copy link

0xArwa commented Mar 24, 2024

@Ryan-ZL-Lin You can adjust the relative tolerance for less strict comparison. the default value is 1e-05 in PyTorch 2.2

This snippet will output True

torch.allclose(xbow, xbow2, rtol= 1e-04) # default 1e-05

@yyinsomnia
Copy link

我也详细排查了一下,发现太小的值,这里[1,5,1] 是 0.0020,会导致allclose判断为False
这个问题很有意思,我记得21年跑这个代码没有这个问题,现在出现了。我也运行了一下Andrej的原始notebook也是Fasle
说明大概率是python和torch的版本升级导致的?

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