最近搞了个谷歌云的Colab GCE虚拟机,迁移项目后发现torch各种报错,输出了一下版本才发现GCE的这个和原生Colab的Pytorch版本不一样。话不多说,已经帮你把包找好了,如果要配置原生Colab的Torch环境请直接用以下命令,其他Linux设备也一样适用。
如果要迁移到Win平台的话自己在这里找一下https://download.pytorch.org/whl/torch_stable.html 主要是链接最后面的平台不同,前面版本号都一样。
卸载原有的torch
!pip uninstall torch
!pip uninstall torchvision
!pip uninstall torchaudio
安装以下包
!pip install https://download.pytorch.org/whl/cu113/torch-1.12.1%2Bcu113-cp37-cp37m-linux_x86_64.whl
!pip install https://download.pytorch.org/whl/cu113/torchaudio-0.12.1%2Bcu113-cp37-cp37m-linux_x86_64.whl
!pip install https://download.pytorch.org/whl/cu113/torchvision-0.13.1%2Bcu113-cp37-cp37m-linux_x86_64.whl
安装完成后,重启代码执行程序,然后查看一下版本
import torch,torchaudio,torchvision
torch.__version__
1.12.1+cu113
torchaudio.__version__
0.12.1+cu113
torchvision.__version__
0.13.1+cu113
如果显示版本号和上面无误就说明配置好了
顺便一提,Colab CUDA版本如下,有需要自行安装就好。
NVIDIA-SMI 460.32.03 Driver Version: 460.32.03 CUDA Version: 11.2