ubuntu18.04源码编译pytorch

上篇文章win10安装pytorch只是安装好了库,但是并不能追踪到pytorch源代码。windows平台下的源码编译太过麻烦,linux系统笔者是安装在虚拟机中,并不能调用宿主机的CUDA和CUDNN,但是还是编译一下CPU版的pytorch。

一、安装anaconda

使用清华镜像下载Anaconda3-2019.10-Linux-x86_64.sh,之后在下载目录运行,根据提示安装,默认会初始化一个base的虚拟环境。

bash Anaconda3-2019.10-Linux-x86_64.sh

这里顺便学习一下conda相关命令

conda create -n pytorch    #创建名为pytorch的虚拟环境
conda activate pytorch    #激活pytorch虚拟环境
conda deactivate    #从当前虚拟环境中退出
conda info -e    #显示所有当前的虚拟环境
conda list    #显示当前虚拟环境的安装包
conda remove --name pytorch --all    #删除pytorch虚拟环境
conda install numpy    #安装numpy

为了更快的利用conda下载软件,考虑更改conda的下载源,在home目录下新建隐藏文件.condarc,在.condarc中填写

channels:
  - defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

二、安装pytorch

首先安装依赖

conda install numpy ninja pyyaml mkl mkl-include setuptools cmake cffi

 下载代码,并更新仓库,这里更新的很慢,我用了之前在公司更新好的版本

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

在setup.py中设置USE_CUDA=0

export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../"}
python setup.py clean
python setup.py install
发布了36 篇原创文章 · 获赞 6 · 访问量 6992

猜你喜欢

转载自blog.csdn.net/zhuikefeng/article/details/104654810
今日推荐