如何从GPU中pytorch返回到CPU?

问题描述 投票:2回答:3

我有一个pytorch文本分类,我想用GPU来提高运行速度。我用这部分代码检查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()

现在我要返回到使用CPU(而非GPU)。所以我清除这部分代码。但它一点儿也不工作,我收到此错误:

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

请你指导我如何返回到CPU运行?

python gpu cpu pytorch
3个回答
2
投票

您可以设置您想要使用使用GPU设备:

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

对你来说只是你可以返回到使用CPU:

torch.device('cpu')

1
投票

有一个.cpu()方法,相当于.cuda(),这是早期的版本了。


1
投票

它会根据这个thread @soumith看起来像你的GT 425M拥有2.1不符合所需的PyTorch版本(至少3.0)的计算能力。

人机工程学,这是不可能的,您可以访问一些GPU相关的功能。

您可以检查计算能力here

更多信息here

© www.soinside.com 2019 - 2024. All rights reserved.