简体   繁体   English

如何在pytorch中从gpu返回cpu?

[英]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. 我在pytorch中有一个文本分类器,我想使用GPU来提高运行速度。 I have used this part of code to check CUDA and use it: 我已经使用这部分代码来检查CUDA并使用它:

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). 现在,我想返回使用cpu(而不是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? 您能否指导我如何返回到cpu运行?

You can set the GPU device that you want to use using: 您可以使用以下命令设置要使用的GPU设备:

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

And in your case just you can return to CPU using: 就您而言,您可以使用以下命令返回到CPU:

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 . 根据该线程中的 @soumith,您的GT 425M似乎具有2.1的计算能力,不满足PyTorch所需的版本(至少3.0)。

Ergo, it is not possible for you to access some of the GPU-related functions. 因此,您无法访问某些与GPU相关的功能。

You can check the compute capability here 您可以在此处检查计算能力

More info here 更多信息在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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