搭建深度学习环境,需要安装:Nvidia显卡驱动、CUDA、cuDNN,三个组件。
一 安装驱动
安装驱动:
步骤详细:https://www.jianshu.com/p/c2212b89f7b6
条理清晰:https://blog.csdn.net/u012759136/article/details/53355781
解决Bug:https://blog.csdn.net/ysy950803/article/details/78507892
安装驱动分三步(事先下载好显卡驱动run文件):
- 卸载原有驱动;
- 禁用第三方显卡驱动nouveau,并关闭显示服务;
- 进入非图形终端安装驱动;
具体过程见链接教程,建议所有教程看一遍后再动手。
二 安装CUDA
安装CUDA:
https://www.jianshu.com/p/c2212b89f7b6
按照链接教程易安装。
三 安装cuDNN
安装cuDNN:基本上是按照官方教程
https://zhuanlan.zhihu.com/p/106708516
https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html#axzz4qYJp45J2
cuDNN的下载需要注册Nvidia账号,按照链接教程易安装。
注意:
不管是上面完整安装三个部分的教程,还算这里安装cuddn的教程,里面都有验证cudnn安装成功的步骤。本人实际安装过程中,两种验证方式都失败了,但是在pytorch中仍然能正常使用。网上教程,pytorch中验证cuda、cudnn是否安装成功、版本信息方式如下:
https://blog.csdn.net/bat67/article/details/84065261
https://blog.csdn.net/RufyHuang/article/details/106572460
https://blog.csdn.net/weixin_39916758/article/details/111512561
四 安装pytorch
https://pytorch.org/
pytorch分CPU、GPU版本,根据上面的链接可获得与cuda版本匹配的GPU版pytorch的下载链接,然后通过pip安装。
pip show torch
可查看下载的torch的信息,判断是不是GPU版本
五 问题
5.1 nvidia-smi错误
之前使用nvidia-smi命令能够成功显示显存的使用情况,但是最近就不行了。
由于ubuntu内核升级导致,开机时可选旧版内核。
https://blog.csdn.net/qq_39742013/article/details/87932189
上面这种解决方式,每次开机时要选择内核版本,很麻烦。下面这种方式更好。
https://www.jianshu.com/p/3cedce05a481
5.2
Found GPU0 TITAN V which requires CUDA_VERSION >= 9000 for optimal
performance and fast startup time
torch的选择还涉及和cuda版本匹配的问题,选择由哪个版本cuda编译的pytorch,官网torch下载选择中已经有这个选项了。
RuntimeError: CUDNN_STATUS_EXECUTION_FAILED
https://blog.csdn.net/qq_39938666/article/details/86611474
https://www.cnblogs.com/naive-LR/p/14256624.html
一个可行的组合:驱动460+cuda11.2+python3.7+torch(1.3.0+cu100)
下面这个链接是torch官网提供的链接,可以看看有哪些版本可选
https://download.pytorch.org/whl/torch_stable.html
pip install torch==1.8.0+cu111 -f https://download.pytorch.org/whl/torch_stable.html
根据上面网页选择,torch==1.8.0+cu111的版本和编译用的cuda版本。
5.3 torch加载模型
https://blog.csdn.net/qq_40250862/article/details/103628164
当存储和加载时使用的pytorch版本不同,可能发生“has no attribute XXX”的异常。一种方式是重装本地的torch,和存储时使用的版本一致;一种是这里的方法,直接修改torch源码。