# RuntimeError: cuda runtime error (3)

I hope to add a ResNet in the transform.compose utility. And then apply the dataLoader to create batches for training. When the ResNet and images are both on CPU, it works. But when the ResNet and images are both on GPU, there is a cuda problem:

File “”, line 4, in
transforms.Lambda(lambda x: FM(resnet, x))])
File “”, line 23, in FM
input_imgs = Variable(imgs.cuda(),volatile=True)
File “/project/focus/hong/anaconda3/lib/python3.5/site-packages/torch/_utils.py”, line 65, in cuda
return new_type(self.size()).copy(self, async)
RuntimeError: cuda runtime error (3) initialization error at /py/conda-bld/pytorch_1490983232023/work/torch/lib/THC/generic/THCStorage.c:55

What’s wrong with .cuda()?

``````data_transforms = transforms.Compose([transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
transforms.Lambda(lambda x: FM(resnet, x))])

def FM(model, img):
[d,h,w] = img.size()

if w > h:
w_new, h_new, s_new = int((w - h)/2), 0, h // NGSIZE
else:
w_new, h_new, s_new = 0, int((h - w)/2), w // NGSIZE

imgs = torch.Tensor(NGSIZE**2,d,s_new,s_new)

# crop the center part of the image
i = 0
for nh in range(NGSIZE):
for nw in range(NGSIZE):
Hsta = h_new + nh * s_new
Wsta = w_new + nw * s_new
Hend = h_new + nh * s_new + s_new
Wend = w_new + nw * s_new + s_new
imgs[i,:,:,:] = img[:,Hsta:Hend,Wsta:Wend]
i += 1

if use_gpu:
input_imgs = Variable(imgs.cuda())
else:
input_imgs = Variable(imgs)

# forward
outputs = model.forward(input_imgs).squeeze()

return outputs.cpu().data.view(3,3,512)

If you want to use CUDA, you have to use the `forkserver` or `spawn` start methods.
DataLoader with anything greater than `0` workers uses multiprocessing.
{"ft_lang_label":"__label__en","ft_lang_prob":0.5160493,"math_prob":0.9749071,"size":1765,"snap":"2022-40-2023-06","text_gpt3_token_len":559,"char_repetition_ratio":0.10902896,"word_repetition_ratio":0.069565214,"special_character_ratio":0.3427762,"punctuation_ratio":0.26329115,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9700629,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-01-27T15:22:04Z\",\"WARC-Record-ID\":\"<urn:uuid:6e15c556-5d2c-46e4-a923-1a9736b9d309>\",\"Content-Length\":\"17083\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:66aeb1a0-4dec-46ad-a800-2c6d4f1e6956>\",\"WARC-Concurrent-To\":\"<urn:uuid:e5cbb189-98c8-4fb5-a051-821df19de58b>\",\"WARC-IP-Address\":\"159.203.145.104\",\"WARC-Target-URI\":\"https://discuss.pytorch.org/t/runtimeerror-cuda-runtime-error-3/3478\",\"WARC-Payload-Digest\":\"sha1:MKBQEDPRH4KAWJTSYY2SC5BZ2K5CY6DO\",\"WARC-Block-Digest\":\"sha1:UYWLYIBGDYGNZLVW2LOPY2SGL7S5ZSBK\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-06/CC-MAIN-2023-06_segments_1674764494986.94_warc_CC-MAIN-20230127132641-20230127162641-00056.warc.gz\"}"}