我有一个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运行?