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

example.ipynb中进行训练测试loss为nan #32

Open
SilentMoebuta opened this issue Apr 20, 2023 · 1 comment
Open

example.ipynb中进行训练测试loss为nan #32

SilentMoebuta opened this issue Apr 20, 2023 · 1 comment

Comments

@SilentMoebuta
Copy link

前面代码不变

model(**batch).loss

改为

for i in range(10):
    output = model(**batch)
    loss = output.loss
    loss.backward()
    optimizer.step()
    lr_scheduler.step()
    optimizer.zero_grad()
    print(loss.detach().float())

输出

tensor(3.2207, device='cuda:0')
tensor(nan, device='cuda:0')
tensor(nan, device='cuda:0')
tensor(nan, device='cuda:0')
tensor(nan, device='cuda:0')
tensor(nan, device='cuda:0')
tensor(nan, device='cuda:0')
tensor(nan, device='cuda:0')
tensor(nan, device='cuda:0')
tensor(nan, device='cuda:0')

只有第1个step时loss正常计算,请问这是为啥?
lr设置1e-8

@iridescentee
Copy link

I have met the same problem. Did you find the solution?

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