1,安装所需要的cuda和cudnn环境, 版本10.0
地址

2,编译安装caffe2
2.1安装系统依赖,根据官网

sudo apt-get update
sudo apt-get install -y --no-install-recommends build-essential cmake git libgoogle-glog-dev libgtest-dev 
sudo apt-get install -y --no-install-recommends liblmdb-dev libopencv-dev libopenmpi-dev protobuf-compiler 
sudo apt-get install -y --no-install-recommends libsnappy-dev libprotobuf-dev openmpi-bin openmpi-doc 
sudo apt-get install -y --no-install-recommends libiomp-dev libleveldb-dev python-dev python-pip

 # ubuntu 18.04
 sudo apt-get install -y --no-install-recommends libgflags-dev cmake                     

2.2安装python环境依赖

pip install --user future numpy protobuf typing hypothesis pyyaml

2.3,编译pytorch
执行完以上步骤,会产生一个build目录,现在开始编译pytorch

git clone https://github.com/pytorch/pytorch.git
cd pytorch
git checkout v1.4 # 1.4 版本
git submodule sync
git submodule update --init --recursive 
# python setup.py install # 安装
# cmake ..
# make install # 编译并安装caffe2
python setup.py bdist_wheel # 创建whl
dist/torch-1.4.0a0+72e1771-cp37-cp37m-linux_x86_64.whl # whl文件位置

2.4 安装和卸载

pip install torch-1.4.0a0+72e1771-cp37-cp37m-linux_x86_64.whl # 安装
pip uninstall torch # 卸载

3, 测试

(test) rose@z390-ud:~$ python
Python 3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 19:07:31) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.__version__
'1.3.0a0+0222ece'
>>> torch.cuda.is_available()
True
>>> from caffe2.python import core
>>> torch.version.cuda
'10.1'

到此,pytorch源码编译成功,且安装在test虚拟环境

3,相关文档
https://github.com/pytorch/pytorch/blob/master/CONTRIBUTING.md
https://cloud.tencent.com/developer/article/1625850

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐