解决torch.cuda.is_available()为False的问题

2022-09-28 10:06:30

解决torch.cuda.is_available为False

问题:在Anaconda环境下,电脑拥有GPU并且已经通过conda install安装了Pytorch、cudatoolkit,但是torch.cuda.is_available()始终返回False(找不到显卡)

原因:使用conda install安装的pytorch、torchvision均为CPU版本,无法使用GPU进行计算。

解决:访问镜像源 下载对应的GPU版本Pytorch、Torchvision
CPU版:
在这里插入图片描述
GPU版:
在这里插入图片描述
进入Anaconda的对应环境下,使用pip install 下载镜像路径名进行安装

完成后再次调用GPU

import torch
device= torch.device("cuda:0"if torch.cuda.is_available()else"cpu")# Assuming that we are on a CUDA machine, this should print a CUDA device:print(device)

成功返回gpu:0

  • 作者:Ostrich5yw
  • 原文链接:https://blog.csdn.net/qq_42606136/article/details/119572757
    更新时间:2022-09-28 10:06:30