3 回答

TA贡献1859条经验 获得超6个赞
你是如何安装pytorch的?听起来您在没有 CUDA 支持的情况下安装了 pytorch。https://pytorch.org/有关于如何安装支持 cuda 的 pytorch 的说明。
在这种情况下,我们有以下命令:
conda install pytorch torchvision cudatoolkit=10.1 -c pytorch
或具有最新 cudatoolkit 版本的命令。

TA贡献1773条经验 获得超3个赞
您不必通过 anaconda 安装它,您可以从他们的网站安装 cuda 。安装结束后打开一个新终端并检查您的 cuda 版本:
>>> nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Thu_Nov_18_09:52:33_Pacific_Standard_Time_2021
Cuda compilation tools, release 11.5, V11.5.119
Build cuda_11.5.r11.5/compiler.30672275_0
我的是 V11.5
之后,到这里选择你的操作系统和首选的包管理器(pip 或 anaconda),以及你安装的 cuda 版本,然后复制生成的安装命令,我得到:
pip3 install torch==1.10.1+cu113 torchvision==0.11.2+cu113 torchaudio===0.10.1+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html
请注意,对我来说,我安装了 python 3.10,但我的项目运行超过 3.9,所以要么使用虚拟环境,要么显式运行你想要的基本解释器的 pip(例如C:\Software\Python\Python39\python.exe -m pip install .....),否则你会遇到Could not find a version that satisfies the requirement torch错误
之后,打开 python 控制台并检查 cuda 可用性
>>> import torch
>>> torch.cuda.is_available()
True
添加回答
举报