简介:本文将指导您如何使用pip安装特定CUDA版本的PyTorch,以支持深度学习在NVIDIA显卡上的运行。
在安装特定CUDA版本的PyTorch之前,需要先确认您的系统环境和CUDA版本。首先,请确保您的操作系统是Windows或Linux,并且已经安装了NVIDIA显卡和相应的驱动程序。接下来,请根据您的CUDA版本选择对应的PyTorch版本。
对于CUDA版本为11.4的PyTorch,可以参考以下步骤进行安装:
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip config set install.use-mirrors true
pip config set pip.download.mirror https://pypi.tuna.tsinghua.edu.cn/simple
pip config set pip.trusted-host pypi.tuna.tsinghua.edu.cn
在上述命令中,将
pip install torch==1.9.0+cu114 torchvision==0.10.0+cu114 -f https://download.pytorch.org/whl/cu114/torch_stable.html
cu114
替换为您的CUDA版本号,例如cu113
或cu102
等。该命令将从PyTorch官网下载对应版本的PyTorch和torchvision,并安装到您的系统中。如果成功导入了PyTorch并显示了正确的版本号,则表示安装成功。
import torch
print(torch.__version__)