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
else:
out[i] = (c * x[i]) / (1 + torch.mul(b * p, torch.pow(x[i], p)))

out = out.view(input_size, input_size, input_size, input_size)
return out

Hi,

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
{"ft_lang_label":"__label__en","ft_lang_prob":0.7110044,"math_prob":0.98732704,"size":731,"snap":"2019-43-2019-47","text_gpt3_token_len":228,"char_repetition_ratio":0.12517194,"word_repetition_ratio":0.0,"special_character_ratio":0.3392613,"punctuation_ratio":0.19075145,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99172986,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-10-22T22:01:09Z\",\"WARC-Record-ID\":\"<urn:uuid:2cff8433-548f-4fc7-9150-fc2443144b82>\",\"Content-Length\":\"12971\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:d7f74828-ad77-442e-b4dc-a670712846db>\",\"WARC-Concurrent-To\":\"<urn:uuid:53b41388-2a2d-4078-bce6-00a29a0cb651>\",\"WARC-IP-Address\":\"159.203.172.63\",\"WARC-Target-URI\":\"https://discuss.pytorch.org/t/segmentation-fault-when-using-the-custom-activation-function/57695\",\"WARC-Payload-Digest\":\"sha1:SLGOGI2UP2UPQWFMMWEPKCHRZIQLXVN2\",\"WARC-Block-Digest\":\"sha1:OTOBRNBJVXFRBQVILGQOPVJAG2FU2AO6\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-43/CC-MAIN-2019-43_segments_1570987824701.89_warc_CC-MAIN-20191022205851-20191022233351-00053.warc.gz\"}"}