根據官方安裝指南選擇獲取安裝命令,例如:
conda install pytorch torchvision cudatoolkit=10.1 -c pytorch
使用國內鏡像,比如清華源鏡像,可以使用:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
但是pytorch需要另外的源,添加如下源:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch
注意:PyTorch 官網給的安裝命令需要去掉最後的 -c pytorch
,這樣才能享受清華源的高速。安裝的版本可能不正確,重新執行官網命令。
查看GPU信息
torch.cuda.is_available()
cuda是否可用;
torch.cuda.device_count()
返回gpu數量;
torch.cuda.get_device_name(0)
返回gpu名字,設備索引默認從0開始;
torch.cuda.current_device()
返回當前設備索引;