AssertionError: Torch not compiled with CUDA enabled解決方案

在執行pytorch代碼的時候,突然看到報錯

AssertionError: Torch not compiled with CUDA enabled

這說明了

1. 你pytoch确实安装了

2. 你安装的是cpu版本

作为验证,你可以在python编辑器输入下列代码

AssertionError: Torch not compiled with CUDA enabled解決方案_第1张图片

 解决方案

首先,你需要卸载pytorch,如下图。

conda uninstall pytorch

 否则,它可能只是更新不同的cpu版本,如下列截图。

AssertionError: Torch not compiled with CUDA enabled解決方案_第2张图片

 然后,再安装pytoch版本。注意,请确认自己电脑对应的cuda版本。如下图,对应的11,3

conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch

安装截图如下,可以看到,安装的都是cu版本了。

AssertionError: Torch not compiled with CUDA enabled解決方案_第3张图片

 最后,作为验证。

 Job Done.

你可能感兴趣的:(深度学习,编程工具,pytorch,深度学习,人工智能)