Python报错:AssertionError: Torch not compiled with CUDA enabled

Python项目运行的时候报错:

***其它报错信息***raise AssertionError("Torch not compiled with CUDA enabled")

AssertionError: Torch not compiled with CUDA enabled

这个提示就是应用想使用GPU进行计算,但是没有配置好支持CUDA的PyTorch版本,我们就按照pytorch,根据你的Python版本和CUDA版本,从PyTorch官网获取安装命令。PyTorch,

例如,对于CUDA 11.8,可以使用以下命令:

pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
 

运行以下代码验证PyTorch是否可以检测到GPU:

import torch

if torch.cuda.is_available():
    print("CUDA is available. PyTorch is using GPU.")
else:
    print("CUDA is not available. PyTorch is using CPU.")
 

你可能感兴趣的:(Python,python,深度学习,pytorch)