Segmentation fault when using the custom activation function

I am trying to implement a custom activation function (the codes attached below). Before using the custom activation function, everything works well. However, as long as it is used, the server would throw the error:

Segmentation fault

The error always appears at the first epoch.

I am using

  1. Pytorch 1.1.0
  2. Cuda compilation tools, release 9.2, V9.2.148

the codes

def mg(x):

c = 1.33
b = 0.4
p = 6.88
input_size = x.shape
num = torch.numel(x) # the element number of the input tensor
x = x.view(num)

out = torch.zeros(len(x))

for i in range(len(x)):
    if x[i] < 0:
        out[i] = 0
        out[i] = (c * x[i]) / (1 + torch.mul(b * p, torch.pow(x[i], p)))

out = out.view(input_size[0], input_size[1], input_size[2], input_size[3])
return out


Could you give a full code that I can run to reproduce the issue please?

Hi AlbanD,

Thanks a lot for your reply. The issue has been solved by modifying the version of PyTorch. Thanks