X86架构CPU下Ubuntu系统环境源码编译pytorch-gpu-2.0.1版本

本文操作步骤与 aarch64架构CPU下Ubuntu系统环境源码编译pytorch-gpu-2.0.1版本大致相同,只是CPU架构不同而已,因此这里只记录不同的地方。

 

重点:

一个个人心得,那就是要编译pytorch源码最好是选择docker环境,因为这种环境下配置比较纯净,一定要避免那种自己使用多年的Linux系统,那种使用多年的老系统中各种配置都比较混乱,如果这么使用往往导致最好编译pytorch源码的失败。

一定要使用docker镜像环境进行pytorch源码编译!!!

一定要使用docker镜像环境进行pytorch源码编译!!!

一定要使用docker镜像环境进行pytorch源码编译!!!

 

---------------------------------------------------------------------------------------

 

 

编译的系统环境:

docker镜像这里的选择为:(可选docker镜像列表:https://gitlab.com/nvidia/container-images/cuda/blob/master/doc/supported-tags.md)

命令:(参考:如何拉取指定CPU架构并且指定ubuntu版本并且指定cuda和cudnn版本的docker镜像

docker pull  --platform=linux/x86_64   nvidia/cuda:12.1.1-devel-ubuntu22.04

 

 

 

源码下载方法建议使用代理(跳墙):

参考:git clone 如何通过proxy进行远程代码仓库拷贝下载

(至于怎么找proxy站点这个实在无法言说)

 

 

anaconda环境下编译,安装相关依赖:

conda install cmake ninja
# Run this command from the PyTorch directory after cloning the source code using the “Get the PyTorch Source“ section below
pip install -r requirements.txt

 

 

 

 

 (性能加速组件,可选择性安装)(对应的版本是否存在需要参考:https://anaconda.org/pytorch/repo

conda install mkl mkl-include
# CUDA only: Add LAPACK support for the GPU if needed
conda install -c pytorch magma-cuda121  # or the magma-cuda* that matches your CUDA version from https://anaconda.org/pytorch/repo

# (optional) If using torch.compile with inductor/triton, install the matching version of triton
# Run from the pytorch directory after cloning
make triton

 

 

 

 

 

 

编译:

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

 

 

 

 

打包:

pip wheel .

 

 

===============================================

 

 

 

 

执行完打包命令后在源码目录下找到编译后的文件:

 

 

 

安装:

 

 

 

 

 

运行报错:

ImportError: /root/anaconda3/lib/./libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /root/anaconda3/lib/python3.11/site-packages/torch/lib/libtorch_python.so)

 

 

 

查看当前环境下使用的libstdc++.so文件的具体情况:

 

 

 

 

 

查询系统中是否有版本GLIBCXX_3.4.30libstdc++.so文件

find / -name libstdc++.so.6

 

 

 

 

查询其他位置的版本是否支持:

strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6| grep GLIBCXX_3.4.30

 

 

 

 

修改当前环境下的libstdc++.so.6的指向:

rm /root/anaconda3/lib/./libstdc++.so.6

ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.30 /root/anaconda3/lib/./libstdc++.so.6

 

 

 

再次运行pytorch:

 

成功执行。

 

 

 

-------------------------------------------------------------------

 

 

需要注意的是在运行docker容器时应该确认下容器环境内是否可以使用GPU:

 

posted on 2023-07-31 12:30  Angry_Panda  阅读(142)  评论(0编辑  收藏  举报

导航