conda常用命令:
//创建的环境名为VGG python版本为3.8
conda create -n VGG python=3.8
//pytorch torchvision torchaudio cudatoolkit的安装
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.6 -c pytorch -c conda-forge
//卸载torch torchaudio torchvision命令
pip uninstall torch torchaudio torchvision
pip uninstall torch-geometric torch-scatter torch-sparse torch-cluster torch-spline-conv
//验证torch是否可用,CUDA是否可用
import torch
torch.cuda.is_available()
测试代码
import torch
print("torch_version:",torch.__version__)
print("cuda_version:",torch.version.cuda)
print("cudnn_version:",torch.backends.cudnn.version())
print("----------------------------------")
flag = torch.cuda.is_available() //检验cuda是否可用,true为可用
print(flag)
# 查看显卡个数
print("device_count:",torch.cuda.device_count())
ngpu= 1
# Decide which device we want to run on
device = torch.device("cuda:0" if (torch.cuda.is_available() and ngpu > 0) else "cpu")
print(device)
print("device_name:",torch.cuda.get_device_name(0))
print(torch.rand(3,3).cuda())
正确输出结果:
可以看到输出信息
torch版本1.12.1
cuda:11.6
cudnn:8302