运行代码报错:
raise AssertionError(“Torch not compiled with CUDA enabled”)
AssertionError: Torch not compiled with CUDA enabled
**解决方法:**下载对应gpu版本的torch即可
在官网上查找对应版本:https://pytorch.org/get-started/previous-versions/

运行指令进行下载:

pip install torch==1.13.0+cu117 torchvision==0.14.0+cu117 torchaudio==0.13.0 --extra-index-url https://download.pytorch.org/whl/
cu117 -i https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main

控制台输入下面语句,查看cuda是否可用:

`import torch
print(torch.cuda.is_available())`

在这里插入图片描述
至此,成功解决报错。

更多推荐