CUDA error while running .cuda() function

Hi all thanks for stopping by. I am a student trying to get familiar with the PyTorch and GPU computation for the purpose of self-learning.

I followed the official instructions from the PyTorch website to download all the torch package, and try to run the codes as included in this tutorial ipython notebook.

However, I am stuck on transferring the python codes into the version that uses by the cuda device.

I have checked my torch is Cuda available with the following code:

use_gpu = torch.cuda.is_available()
print('Using gpu: %s ' % use_gpu)

The run result returns “Using gpu: True”, which shows that I should be able to use the GPU that is installed in my laptop. However, when I try to run the other codes, such as:

inputs_try , labels_try = var_cgpu(inputs_try,use_gpu),var_cgpu(labels_try,use_gpu)

if use_gpu:
    model_vgg = model_vgg.cuda()

It returned with an error:

RuntimeError Traceback (most recent call last)
----> 1 inputs_try , labels_try = var_cgpu(inputs_try,use_gpu),var_cgpu(labels_try,use_gpu)
3 if use_gpu:
4 model_vgg = model_vgg.cuda()

~\dataflowr\Notebooks\ in var_cgpu(x, use_gpu)
45 def var_cgpu(x,use_gpu):
46 if use_gpu:
—> 47 return x.cuda()
48 else:
49 return x

~\AppData\Local\Continuum\anaconda3\envs\dataflowr\lib\site-packages\torch\ in _lazy_init()
161 "Cannot re-initialize CUDA in forked subprocess. " + msg)
162 _check_driver()
–> 163 torch._C._cuda_init()
164 _cudart = _load_cudart()
165 _cudart.cudaGetErrorName.restype = ctypes.c_char_p

RuntimeError: CUDA error: unknown error

You may click on this link to view the screen capture of this error

My System details are as follow:

  • Windows 10, 64-bit, x64
  • Python 3.7.1
  • PyTorch version 1.1.0 with Cuda enabled (Also torchvision == 0.3.0)
  • Cuda compilation tools, release 10.0, V10.0.130
  • NVIDIA Graphics Driver Version 430.86 (Graphics Card: GeForce GTX 1070 with Max-Q Design)
  • cuDNN v7.6.1 (June 24, 2019), for CUDA 10.0
  • It would be really really great if someone could give me an insight in how to solve this problem. I have tried many times of uninstalling the Pytorch, Cuda tools and the graphic drivers, but the problem still exists.

    Thanks in advance guys.