Win10系统下torch.cuda.is_available()返回为False的问题解决

Q: Win10系统下torch.cuda.is_available()返回为False

复制代码
(l2) D:\opt\l2>python

Python 3.10.12 | packaged by conda-forge | (main, Jun 23 2023, 22:34:57) [MSC v.1936 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> import torch

>>> torch.cuda.is_available()

False

A: 安装指定的torchGPU版本

经查网上资料,说默认用官网命令安装的最新版torch是不加载cuda加速的,而且版本不匹配,需要手动指定版本安装

第一步,卸载已安装的torch2.10版本

复制代码
pip3 uninstall torch torchvision torchaudio

Found existing installation: torch 2.1.0

Uninstalling torch-2.1.0:

  Would remove:

    c:\users\xxxxxx\.conda\envs\l2\lib\site-packages\functorch\*

    c:\users\xxxxxx\.conda\envs\l2\lib\site-packages\torch-2.1.0.dist-info\*

    c:\users\xxxxxx\.conda\envs\l2\lib\site-packages\torch\*

    c:\users\xxxxxx\.conda\envs\l2\lib\site-packages\torchgen\*

    c:\users\xxxxxx\.conda\envs\l2\scripts\convert-caffe2-to-onnx.exe

    c:\users\xxxxxx\.conda\envs\l2\scripts\convert-onnx-to-caffe2.exe

    c:\users\xxxxxx\.conda\envs\l2\scripts\torchrun.exe

Proceed (Y/n)? y

  Successfully uninstalled torch-2.1.0

Found existing installation: torchvision 0.16.0

Uninstalling torchvision-0.16.0:

  Would remove:

    c:\users\xxxxxx\.conda\envs\l2\lib\site-packages\torchvision-0.16.0.dist-info\*

    c:\users\xxxxxx\.conda\envs\l2\lib\site-packages\torchvision\*

Proceed (Y/n)? y

  Successfully uninstalled torchvision-0.16.0

Found existing installation: torchaudio 2.1.0

Uninstalling torchaudio-2.1.0:

  Would remove:

    c:\users\xxxxxx\.conda\envs\l2\lib\site-packages\torchaudio-2.1.0.dist-info\*

    c:\users\xxxxxx\.conda\envs\l2\lib\site-packages\torchaudio\*

Proceed (Y/n)? y

  Successfully uninstalled torchaudio-2.1.0

第二步,安装指定版本的2.0.1的GPU版本

复制代码
pip install torch==2.0.0+cu118 torchvision==0.15.1+cu118 torchaudio==2.0.1+cu118 -f https://download.pytorch.org/whl/torch_stable.html

也可以离线下载GPU版本,2.0.0,2.0.1, 2.1.0:

https://download.pytorch.org/whl/cu118/torch-2.0.0%2Bcu118-cp310-cp310-win_amd64.whl

https://download.pytorch.org/whl/cu118/torch-2.0.1%2Bcu118-cp310-cp310-win_amd64.whl

https://download.pytorch.org/whl/cu118/torch-2.1.0%2Bcu118-cp310-cp310-win_amd64.whl

复制代码
(l2) D:\opt\l2>python
Python 3.10.12 | packaged by conda-forge | (main, Jun 23 2023, 22:34:57) [MSC v.1936 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> import torch

>>> torch.cuda.is_available()

True

>>>
相关推荐
MidJourney中文版32 分钟前
深度报告:中老年AI陪伴机器人需求分析
人工智能·机器人
William.csj44 分钟前
Pytorch/CUDA——flash-attn 库编译的 gcc 版本问题
pytorch·cuda
王上上1 小时前
【论文阅读41】-LSTM-PINN预测人口
论文阅读·人工智能·lstm
智慧化智能化数字化方案1 小时前
69页全面预算管理体系的框架与落地【附全文阅读】
大数据·人工智能·全面预算管理·智慧财务·智慧预算
PyAIExplorer1 小时前
图像旋转:从原理到 OpenCV 实践
人工智能·opencv·计算机视觉
Wilber的技术分享1 小时前
【机器学习实战笔记 14】集成学习:XGBoost算法(一) 原理简介与快速应用
人工智能·笔记·算法·随机森林·机器学习·集成学习·xgboost
19891 小时前
【零基础学AI】第26讲:循环神经网络(RNN)与LSTM - 文本生成
人工智能·python·rnn·神经网络·机器学习·tensorflow·lstm
burg_xun2 小时前
【Vibe Coding 实战】我如何用 AI 把一张草图变成了能跑的应用
人工智能
酌沧2 小时前
AI做美观PPT:3步流程+工具测评+避坑指南
人工智能·powerpoint
狂师2 小时前
啥是AI Agent!2025年值得推荐入坑AI Agent的五大工具框架!(新手科普篇)
人工智能·后端·程序员