RuntimeError: exp_vml_cpu not implemented for 'Long'

I want to define an activation function for my model. The activation function I want to use is the sigmoid function.

I define this activation function.

import torch
def sigmoid(z):
   return 1/(1+torch.exp(-z))
X = np.array([0])
t = torch.from_numpy(X)
sigmoid(t)

RuntimeError: exp_vml_cpu not implemented for ‘Long’

But when use X = np.array([0.]) I don’t get any error. Why that occurs?

torch.from_numpy keeps the dtype.
If you initialize the numpy array with 0, it will result in t being a LongTensor, while 0. yields a FloatTensor.
The method torch.exp is not implemented for LongTensors, which throws this error.

7 Likes