简体   繁体   中英

How to return back to cpu from gpu in pytorch?

I have a text classifier in pytorch and I want to use GPUs to increase running speed. I have used this part of code to check CUDA and use it:

if torch.cuda.device_count() > 1:
    print("Let's use", torch.cuda.device_count(), "GPUs!")
    my_rnn_model = nn.DataParallel(my_rnn_model)
if torch.cuda.is_available():
    my_rnn_model.cuda()

Now I want to return back to use cpu (instead of gpu). So I cleared this part of code. But it does'nt work and I receive this error:

RuntimeError: cuda runtime error (8) : invalid device function at /opt/conda/conda-bld/pytorch_1503963423183/work/torch/lib/THC/THCTensorCopy.cu:204

Would you please guide me how can I return back to cpu running?

You can set the GPU device that you want to use using:

device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')

And in your case just you can return to CPU using:

torch.device('cpu')

有一个.cpu()方法,与.cuda()等效,在早期版本中也可用。

It would seem like your GT 425M has the compute capability of 2.1 which does not met the PyTorch required version (at least 3.0) according to @soumith in this thread .

Ergo, it is not possible for you to access some of the GPU-related functions.

You can check the compute capability here

More info here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM