欢迎访问我的网站,希望内容对您有用,感兴趣的可以加入免费知识星球。

pytorch-gpu源码编译

PyTorch 迷途小书童 3年前 (2020-11-20) 3704次浏览 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环境

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

编译步骤

安装基础依赖

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

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

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

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

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

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

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

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

pytorch

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

测试

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

(base) xugaoxiang@1070Ti:~$ ipython
Python 3.7.6 (default, Jan  8 2020, 19:59:22)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import torch

In [2]: torch.__version__
Out[2]: '1.8.0a0+46d846f'

In [3]: torch.cuda.is_available()
Out[3]: True

In [4]:

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

小结

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

参考资料

喜欢 (0)

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