在學校Arc中部署lora training,一大問題就是依賴缺失和沖突??梢岳胢iniconda或者anaconda建立虛擬環(huán)境來解決。
安裝anaconda 或者 miniconda(官網(wǎng)上也有教程):
wget https://repo.anaconda.com/archive/Anaconda3-5.3.0-Linux-x86_64.sh
chmod +x Anaconda3-5.3.0-Linux-x86_64.sh
./Anaconda3-5.3.0-Linux-x86_64.sh
建立虛擬環(huán)境:
conda create -n Lora python=3.10
conda init bash #添加conda環(huán)境進入Bash configuration file
source /root/.bashrc #重新加載bash配置
conda activate lora # 加載虛擬環(huán)境
現(xiàn)在進入到虛擬環(huán)境中
首先解決cuda的配置,其中要配置合適的cuda版本以及對應版本的cuDNN
conda官方庫中的cuda包都不完全,無法激活nvcc命令,因此使用conda-forge庫中的cudatoolkit包,以及dev包來確保可以激活nvcc命令。這里以cuda11.7版本為例。
conda install cudatoolkit==11.7.0 -c conda-forge#
conda install cudatoolkit-dev==11.7.0 -c conda-forge#
接下來安裝cuDNN,依舊使用conda-forge庫中的cudnn,我選擇使用8.4.0.27版本的。查看庫中的版本可以使用:
conda config --add channels conda-forge #加入conda forge 源
conda search -c conda-forge <package_name>
例如:
conda search -c conda-forge cudatoolkit #尋找可以使用的cudatoolkit版本
conda search -c conda-forge cudnn #尋找可以使用的cudnn版本
之后安裝對應版本的tensorflow:
參考:https://docs.nvidia.com/deeplearning/frameworks/tensorflow-release-notes/rel-23-02.html#rel-23-02
可知我們需要的tensorflow的版本是2.8.0版本,tensorRT版本是8.2.5,由于8.2.5無法由python 3.10 編譯,選擇最相近版本8.4.2.4。
pip install tensorflow-gpu==2.8.0
pip install tensorflow==2.8.0
pip install nvidia-tensorrt==8.4.2.4
之后安裝pytorch:
conda install pytorch cudatoolkit=11.7 -c pytorch
或者,你可以使用pip的話:
pip install torch==1.13.1+cu117 -f https://download.pytorch.org/whl/cu117/torch_stable.html
以及安裝pytorchvision:同樣可以使用:
conda install pytorch torchvision cudatoolkit=11.7 -c pytorch
或者:
pip install torch torchvision -f https://download.pytorch.org/whl/cu117/torch_stable.html
安裝triton
pip install nvidia-pyindex
pip install triton
安裝trainer本體
下面參考:https://github.com/zwh20081/LoRA_onekey_deploy_script/blob/main/onekey_with_xformers_new.sh
之后可以安裝xformers來加速lora的訓練:
git clone https://github.com/facebookresearch/xformers/ #導入xformer文件
cd xformers
git submodule update --init --recursive
# 強制使用CUDA環(huán)境,不開啟可能會導致xformers未和CUDA一起編譯
export FORCE_CUDA="1"
# 進入https://developer.nvidia.com/cuda-gpus#compute
# 設置所用顯卡對應的Compute Capability,我的a-100是8.0,v-100是7.0
export TORCH_CUDA_ARCH_LIST=8.0
# PATH環(huán)境變量中追加cuda目錄,確保編譯時能識別鏡像預置的cuda11.7
export PATH=$PATH:/usr/local/cuda
# 確保gcc編譯時能夠識別cuda的頭文件cd(可能用不到)
pip install -r requirements.txt #安裝requirements.txt文本下需要的依賴
pip install -e . #在當前目錄下安裝xformer
這時你的xformer 應當安裝完畢。
之后安裝Lora訓練器:
cd .. #回到上層目錄
git clone https://github.com/derrian-distro/LoRA_Easy_Training_Scripts
cd LoRA_Easy_Training_Scripts
git submodule init #初始化git子模塊
git submodule update #升級子模塊
cd sd_scripts
pip install --upgrade -r requirements.txt #升級文本下的依賴
此時可能會更新:
但是tensorflow可能會錯誤的升級到2.10版本。因此根據(jù)你的cuda版本降級tensorflow。
我這里還是降級到2.8.0:
pip install tensorflow==2.8.0
之后
accelerate config
這時應當可以正常使用了。
configure 過程中可能有一些設置,推薦是:
- This machine
- No distributed training
- NO
- NO
- NO
- all
- fp16/bf16
使用:
修改ArgsList.py中的參數(shù)設置
之后再main.py的目錄中使用:文章來源:http://www.zghlxwxcb.cn/news/detail-490094.html
accelerate launch main.py
Enjoy文章來源地址http://www.zghlxwxcb.cn/news/detail-490094.html
到了這里,關(guān)于關(guān)于stable diffusion的lora訓練在linux遠程工作站的部署的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!