作者:茴忆是抹不掉的伤 | 来源:互联网 | 2023-08-11 10:09
在執行pytorch代碼的時候,突然看到報錯AssertionError:TorchnotcompiledwithCUDAenabled這說明了1.你pytoch确
在執行pytorch代碼的時候,突然看到報錯
AssertionError: Torch not compiled with CUDA enabled
這說明了
1. 你pytoch确实安装了
2. 你安装的是cpu版本
作为验证,你可以在python编辑器输入下列代码
解决方案
首先,安装Nvidia toolkit
sudo apt install nvidia-cuda-toolkit
然后,你需要卸载pytorch,如下图。
conda uninstall pytorch
否则,它可能只是更新不同的cpu版本,如下列截图。
然后,再安装pytoch版本。注意,请确认自己电脑对应的cuda版本。如下图,对应的11,3.
conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
注意,如果执行下列指令仍安装的是cpu版本,建议参考
Previous PyTorch Versions | PyTorch三An open source machine learning framework that accelerates the path from research prototyping to production deployment.
最后,作为验证。
Job Done.