“pytorch安装时与本地电脑NVIDIA 显卡驱动不匹配导致安装的pytorch无法使用”情况的解决教程
一、设定前置情况1、要求服务器参数●GPU: NVIDIA T4 16GB ×1●CPU8核●内存32G●磁盘≥100 GB SSD●NVIDIA驱动 ≥570.117CUDA 12.8 配套●CUDA/cuDNN容器内置 CUDA 12.8 cuDNN 9●Python: 3.12●推理框架: PyTorch 2.10.0 torchvision 0.25.02、本地电脑参数GPUNVIDIA GeForch GTX 1660TiCUDA Version: 11.6Driver Version: 511.23NVIDIA-SMI 511.23处理器Intel(R) Core(TM) i5-9400 CPU 2.90GHz 2.90 GHz机带RAM8.00 GB (7.84 GB 可用)系统类型64 位操作系统, 基于 x64 的处理器Windows规格版本Windows 11 家庭中文版 版本号23H2 操作系统版本22631.5624显存6G二、在本地电脑参数的基础上安装# CUDA 12.8 pip install torch2.10.0 torchvision0.25.0 torchaudio2.10.0 --index-url https://download.pytorch.org/whl/cu128安装成功后验证pytorch是否可用 import torch print(torch.__version__) 2.10.0cu128 print(torch.cuda.is_available()) E:\Users\Hasee\anaconda3\envs\pytorch\Lib\site-packages\torch\cuda\__init__.py:184: UserWarning: CUDA initialization: The NVIDIA driver on your system is too old (found version 11060). Please update your GPU driver by downloading and installing a new version from the URL: http://www.nvidia.com/Download/index.aspx Alternatively, go to: https://pytorch.org to install a PyTorch version that has been compiled with your version of the CUDA driver. (Triggered internally at C:\actions-runner\_work\pytorch\pytorch\pytorch\c10\cuda\CUDAFunctions.cpp:119.) return torch._C._cuda_getDeviceCount() 0 False由验证结果可以看到pytorch安装成功了但是不可用。原因如下问题根源驱动版本不匹配本地显卡驱动版本是511.23最高只支持到CUDA 11.6。PyTorch (cu128) 所需最低驱动570.65Windows 版两者之间存在巨大的版本差距所以 PyTorch 无法调用 GPU。解决方案更新驱动或更换 PyTorch 版本有两种方案可以选择方案一更新 NVIDIA 显卡驱动推荐这是最直接、最推荐的方法能继续使用 PyTorchCUDA 12.8。GTX 1660 Ti 完全能够通过更新驱动来使用PyTorch CUDA 12.8。报错核心原因就是驱动版本过低而不是显卡硬件本身不支持。为什么GTX 1660 Ti显卡支持GTX 1660 Ti 基于 NVIDIA 的Turing 架构其计算能力Compute Capability为7.5。关键在于从 CUDA 12.8 开始NVIDIA 和 PyTorch 都明确将Turing 架构计算能力 7.5作为最低支持门槛。这意味着你的显卡正好在官方支持列表之内。PyTorch 社区也确认在即将到来的 2.11 版本中CUDA 12.8 构建将继续支持 Turing (7.5)架构。操作步骤如下确认显卡型号在“设备管理器”的“显示适配器”中或在 NVIDIA 控制面板的“系统信息”里找到NVIDIA 显卡型号。如下图下载驱动访问 NVIDIA 官方驱动下载页面https://www.nvidia.com/Download/index.aspx手动选择你的显卡型号和操作系统下载最新版驱动。如下图安装驱动运行下载的安装程序。建议在安装选项中勾选“执行清洁安装”以避免旧文件冲突。安装完成后务必重启电脑。方案二降级 PyTorch 到与当前驱动兼容的版本如果你暂时不想或不能更新驱动可以选择安装一个支持你当前 CUDA 11.6 驱动的 PyTorch 版本。推荐版本torch1.13.0或torch2.0.0等支持 CUDA 11.6 或 11.7 的版本。安装命令卸载当前的 PyTorch 后使用以下命令安装兼容版本# 以 torch 1.13.0 cu116 为例 pip install torch1.13.0 torchvision0.14.0 torchaudio0.13.0 --index-url https://download.pytorch.org/whl/cu116注意请根据你实际需要的版本去 PyTorch 官网找到对应的cu116或cu117安装命令。三、验证无论选择哪种方案完成后都建议在 Python 中运行以下命令来验证 GPU 是否可用import torch print(torch.__version__) print(torch.cuda.is_available())如果输出True就说明 PyTorch 已经可以正常使用 GPU 了。本电脑更新驱动后验证结果如下(pytorch) C:\Users\Haseepython Python 3.12.14 | packaged by Anaconda, Inc. | (main, Aug 27 2026, 14:37:13) [MSC v.1942 64 bit (AMD64)] on win32 Type help, copyright, credits or license for more information. import torch print(torch.cuda.is_available()) True print(torch.__version__) 2.10.0cu128