-
Notifications
You must be signed in to change notification settings - Fork 493
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
Improve numerical stability of torch.sigmoid #4311
Conversation
Ok it looks this issue exists on both cpu and gpu: |
I have a feeling that it might be because |
Yes, the x = torch.rand(1000000000,device=device)
xm.mark_step()
t0 = time.time()
for _ in range(100):
for _ in range(100):
y = torch.sigmoid(x)
xm.mark_step()
t1 = time.time()
print(t1-t0) I"m getting If we want to keep the |
I talked with Blake. Speed was the main reason we used |
Updated and thanks for the info. I just realize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
We recently found the torch_xla lowering of
torch.sigmoid
is not numerically stable on GPU. One common use-case oftorch.sigmoid
is to force the output value to be within [0,1].For example, the following code failed with nan loss because
x = -5.9604645e-08
.Are there any special reasons for torch_xla to use
sigmoid(x) = 0.5+0.5*tanh(0.5*x)
instead ofsigmoid(x) = 1 / (1 + exp(-x))
?