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

FloatingPointError: Loss is infinite or NaN #73

Open
LvXiangzhu opened this issue Feb 26, 2024 · 1 comment
Open

FloatingPointError: Loss is infinite or NaN #73

LvXiangzhu opened this issue Feb 26, 2024 · 1 comment

Comments

@LvXiangzhu
Copy link

Thank you for your nice work!
However, I encountered some issues when I try to run it. I haven't been able to solve this error for a long time so I have to ask you for help.

When the procedure go into "TextEncoder" of "CustomCLIP" for the second time, it makes this error: "FloatingPointError: Loss is infinite or NaN!"

I debugged this error and found that the problem was in the TextEncoder's transformer network: Before the input enters the first LayerNorm, there is no NaN. But after LayerNorm, the output appears NaN.

I have searched the solutions of this error.
Someone says that it may be because float16 is not precise enough, causing overflow, and needs to be converted to float32. But your code is like this:

orig_type = x.dtype
ret = super().forward(x.type(torch.float32))
return ret.type(orig_type)

The input type has been converted to float32 before LayerNorm.

In addition, the input values are not large. They are all in the order of magnitude of about 1e-2.

So does anyone know why this error occurs?

@Lilzhuzixi
Copy link

halo friend! Did you work out this error? Can you give me some advice?

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

2 participants