在安装pytorch的时候,如果服务器上有GPU,不能直接使用pip install pytorch==x.x
或conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 -c pytorch
,在这种情况下默认安装的是CPU版本的pytorch,因此如果使用GPU运行会出现CUDA版本不匹配的问题,即CUDA error: no kernel image is available for execution on the device。
按照官网的安装命令,如果需要安装GPU版本的pytorch,可以使用conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=11.0 -c pytorch
指定cudatoolkit的版本安装。
另,官网中给出了不同版本的pytorch对应的torchvision、torch audio和CUDA版本,十分实用。