欢迎访问我的网站,希望内容对您有用,感兴趣的可以加入我们的社群。

pytorch-gpu源码编译

PyTorch 迷途小书童 5年前 (2020-11-20) 4583次浏览 0个评论

软硬件环境

  • ubuntu 18.04 64bit
  • NVidia GTX 1070Ti
  • anaconda with python 3.7
  • CUDA 10.1
  • cuDNN 7.6
  • pytorch 1.8

视频看这里

此处是 youtube 的播放链接,需要科学上网。喜欢我的视频,请记得订阅我的频道,打开旁边的小铃铛,点赞并分享,感谢您的支持。

python和gpu环境

这个就不多讲了,没装好的,可以参考下面的链接

编译步骤

安装基础依赖

  1. conda install numpy ninja pyyaml mkl mkl-include setuptools cmake cffi typing_extensions future six requests dataclasses

由于要使用 gpu,所以还需要安装 LAPACK 支持,根据 CUDA 版本安装对应的软件包

  1. # Add LAPACK support for the GPU if needed
  2. conda install -c pytorch magma-cuda101 # or [ magma-cuda101 | magma-cuda100 | magma-cuda92 ] depending on your cuda version

接下来就可以开始克隆代码了

  1. git clone --recursive https://github.com/pytorch/pytorch
  2. cd pytorch
  3. # if you are updating an existing checkout
  4. git submodule sync
  5. git submodule update --init --recursive

准备工作完成后,就可以开始编译了

  1. export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../"}
  2. python setup.py install

CMAKE_PREFIX_PATH 其实就是 anaconda 的安装目录,如我这里的/home/xugaoxiang/anaconda3

pytorch

编译的时候较长,耐心等待就好

测试

重新开一个 terminal 终端进行测试

  1. (base) xugaoxiang@1070Ti:~$ ipython
  2. Python 3.7.6 (default, Jan 8 2020, 19:59:22)
  3. Type 'copyright', 'credits' or 'license' for more information
  4. IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.
  5. In [1]: import torch
  6. In [2]: torch.__version__
  7. Out[2]: '1.8.0a0+46d846f'
  8. In [3]: torch.cuda.is_available()
  9. Out[3]: True
  10. In [4]:

说明 pytorch 已经安装到了 anaconda 的环境中,而且是 gpu 的版本,搞定!

小结

整个编译过程还是非常顺利的,之前我们编译过 opencvtensorflowcaffe,跟他们相比,pytorch 在依赖关系的处理上做的非常好,以子项目的形式纳入到自己的工程当中,整个编译过程没出现过报错,文档也是写的简单明了,难怪它的市占率会越来越高。

参考资料

喜欢 (0)

您必须 登录 才能发表评论!