Repository navigation
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 |
We recently found the torch_xla lowering of
torch.sigmoidis not numerically stable on GPU. One common use-case oftorch.sigmoidis 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))?