安装依赖

安装cuda

git clone git@github.com:FindHao/ml_scripts.git
cd ml_scripts
# t_cuda是想要的版本,t_cuda_path是cudatoolkit安装的位置
t_cuda=121 t_cuda_path=~/opt/cuda-12.1 ./install_cuda.sh

创建一个set12.1.sh的脚本,内容如下:

export PATH=~/opt/cuda-12.1/bin:$PATH
export LD_LIBRARY_PATH=~/opt/cuda-12.1/lib64:$LD_LIBRARY_PATH

安装miniconda

miniconda的官方页面下载对应的安装包,安装即可。

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh

安装过程中需要回答一些问题,比如安装路径,是否将conda加入到环境变量中等。安装完成后,需要重启终端,或者执行source ~/miniconda3/bin/activate,使得环境变量生效。 创建一个conda环境并激活。

conda create -n pytorch python=3.10
conda activate pytorch

编译安装pytorch,常用的包,以及TorchBench

可以直接使用脚本安装全部内容。

cd ml_scripts
work_path=$(pwd) ./compile_torch.sh

以下是单步执行的过程,如果使用脚本出现了错误,可以按照如下内容手动执行命令。

设置环境变量

export USE_NCCL=1

NCCL已经通过前面安装cuda的脚本安装完成。

安装依赖包

conda install -y magma-cuda121 cmake ninja mkl mkl-include libpng libjpeg-turbo graphviz -c pytorch
pip install numpy==1.23.5

参考 https://github.com/pytorch/benchmark/blob/main/requirements.txt 由于TorchBench使用了特定版本的numpy,必须在编译安装pytorch之前就安装该版本的numpy。

编译安装PyTorch

git clone --recursive [email protected]:pytorch/pytorch.git
cd pytorch
git submodule sync
git submodule update --init --recursive
pip install -r requirements.txt
make triton

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

我尝试在Ubuntu22.04上编译时,遇到了以下错误,

ImportError: /home/yhao24/anaconda3/envs/pt_compiled/bin/../lib/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /home/yhao24/p/p9/pytorch/torch/lib/libtorch_python.so)

使用strings /home/yhao24/anaconda3/envs/pt_compiled/bin/../lib/libstdc++.so.6 | grep GLIBCXX发现并没有找到GLIBCXX_3.4.30的信息。原因是conda里自带的gcc库过旧导致。那么在执行前面跟conda相关的命令时,可以使用另一个channel conda-forge

conda create -n pytorch python=3.10 -c conda-forge
conda install -y cmake ninja mkl mkl-include libpng  -c conda-forge

安装torchdata等包

# install torchdata
cd $work_path
git clone git@github.com:pytorch/data.git
cd data
git submodule update --init --recursive
pip uninstall -y  torchdata
python setup.py clean
python setup.py install

# install torchtext
# torchtext compilation may not detect the correct gcc and g++
export CC=`which gcc`
export CXX=`which g++`

cd $work_path
git clone git@github.com:pytorch/text.git
cd text
git submodule update --init --recursive
pip uninstall -y  torchtext
python setup.py clean
python setup.py install


# install torchvision
# FORCE_CUDA doesn't work
export FORCE_CUDA=TRUE
cd $work_path
git clone git@github.com:pytorch/vision.git
cd vision
git submodule update --init --recursive
pip uninstall -y torchvision
python setup.py clean
python setup.py install

# install torchaudio
cd $work_path
git clone git@github.com:pytorch/audio.git
cd audio
python setup.py install

cd $work_path
git clone git@github.com:pytorch/benchmark.git
pip install pyyaml
cd benchmark
python install.py

Reference

'GLIBCXX_3.4.30' not found for librosa in conda virtual environment (after trying out a lot of solutions)?


文章版权归 FindHao 所有丨本站默认采用CC-BY-NC-SA 4.0协议进行授权|
转载必须包含本声明,并以超链接形式注明作者 FindHao 和本文原始地址:
https://findhao.net/academic/2590.html

Comments