错误原因:
代码使用了GPU加速的torch,但是我下载的是C++版本的torch。使用pip list发现包如下:

参考HIP网站:
https://pytorch.org/docs/stable/notes/hip.html
解决方案:
卸载torch和torchvision,然后使用pip install torch==1.7.0+cu110 torchvision==0.8.0+cu110 torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
安装即可。