My model works when I use torch.sigmoid. I tried to make the sigmoid steeper by creating a new sigmoid function:
def sigmoid(x):
return 1 / (1 + torch.exp(-1e5*x))
But for some reason the gradient doesn't flow through it (I get NaN). Is there a problem in my function, or is there a way to simply change the PyTorch implementation to be steeper (as my function)?
Code example:
def sigmoid(x):
return 1 / (1 + torch.exp(-1e5*x))
a = torch.tensor(0.0, requires_grad=True)
b = torch.tensor(0.58, requires_grad=True)
c = sigmoid(a-b)
c.backward()
a.grad
>>> tensor(nan)