阿里雲交互式建模(DSW)的探索和踩坑

前言

自己的筆記本煉丹還是太喫力了些,風扇嘶吼有點心疼,看到阿里雲出了一些免費試用的資源,想着能白嫖一下高端顯卡跑一跑自制模型還挺有趣,於是有了下面的一些操作,其實沒啥難度的,大膽的按文檔來做基本就可以了.

在PAI-DSW中,可以爲存儲外掛OSS或NAS,注意,我看着oss好像也便宜於是就買了半年的,但是沒想到這裏不給掛載,說第一個掛載盤必須是NAS的,如果想真的白嫖那可能不想使用這些。每個容器自帶500GB的臨時存儲空間也是夠用的,但是請注意,該存儲空間是臨時的,所以如果關機或者容器運行出現問題,裏面的數據將會丟失。這也引出了一個問題,要選擇一個完整的鏡像,這樣就不用每次部署後都要重新配置
不過,也可以使用其他方法來解決這個問題。例如,可以保存運行中的鏡像,這樣可以保存鏡像中的文件等,下次啓動新的實例時就可以使用該鏡像。
另外溫馨提醒,官方雖然免費試用三個月,但是有計算時長限制,總共是5000CU_H。例如,我們選擇A10型號,每小時花費6.99CU_H大約可以玩29.8天。但是請注意,不用的話最好關機(一定要記得在關機前保存數據/鏡像),細水長流纔是白嫖的要義。這篇水文可以說是全網最全的了,希望能幫到你.

聚焦真正有價值的事,不要耗散了自己的激情和好奇心

白嫖交互式建模

鏡像選擇

選擇一個好用的鏡像特別重要,可以說是最重要的事了,不要用官方的鏡像,他們的不給保存,於是去hub.docker.com上找了些stable-diffusion-webui的鏡像,可以說前幾個給出的都不好用,測試下來,這些鏡像爲了減小體積都裁剪了重要的linux命令,對於使用交互式建模(DSW)可玩性不高,出了問題很不好定位,有幾個鏡像還默認使用的非root賬號啓動的就更難用了

# 這些鏡像都沒有定位工具,基礎命令缺失,很難使用
registry.docker.com/universonic/stable-diffusion-webui:latest
registry.docker.com/siutin/stable-diffusion-webui-docker:latest

# 阿里雲上的鏡像,但無法保存,很不好用
eas-registry-vpc.cn-hangzhou.cr.aliyuncs.com/pai-eas/stable-diffusion-webui:1.1

# 這個鏡像看着還行,命令不算完整,但夠用
registry.docker.com/kestr3l/stable-diffusion-webui:1.2.2

由於鏡像的選擇太重要了,想着打一個好用又完整的鏡像,於是把上面的鏡像都嘗試了,期間踩了很多坑,貿然更新裏面的cuda或者nvida驅動都會導致鏡像無法使用,最後使用了kestr3l的這個鏡像作爲基礎,打包了自己覺得重要的東西整合了一個新的鏡像,看了下鏡像倉庫裏大概17G大小,放了兩個常用大模型和關鍵的插件,也把訓練包打了進去.算是一個all in one

操作過程記錄

  • 找到下面這段代碼,給每個github地址前邊都加上ghproxy.com, 最好是設置下環境變量吧,參考下面的. 其實體驗下來,容器中下載github數據挺快的,不配置也沒關係,下載不動就多嘗試幾次.
# 原本的下載源,可以把秋葉大佬整合包裏的下載源複用到這裏,自己找風險很大
export GFPGAN_PACKAGE=git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379
export CLIP_PACKAGE=git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1
export OPENCLIP_PACKAGE=git+https://github.com/mlfoundations/open_clip.git@bb6e834e9c70d9c27d0dc3ecedeebeaeb1ffad6b
export STABLE_DIFFUSION_REPO=https://github.com/Stability-AI/stablediffusion.git
export TAMING_TRANSFORMERS_REPO=https://github.com/CompVis/taming-transformers.git
export K_DIFFUSION_REPO=https://github.com/crowsonkb/k-diffusion.git
export CODEFORMER_REPO=https://github.com/sczhou/CodeFormer.git
export BLIP_REPO=https://github.com/salesforce/BLIP.git
  • 補充的一些自己的操作
# source venv/bin/activate
python -m venv --system-site-packages --symlinks venv
sed -i 's/can_run_as_root=0/can_run_as_root=1/g' webui.sh
wget -c https://huggingface.co/naonovn/chilloutmix_NiPrunedFp32Fix/resolve/main/chilloutmix_NiPrunedFp32Fix.safetensors -O chilloutmix_NiPrunedFp32Fix.safetensors
cd stable-diffusion-webui/repositories/CodeFormer/weights/facelib/
wget -c http://pai-vision-data-hz.oss-cn-zhangjiakou.aliyuncs.com/EasyCV/datasets/try_on/detection_Resnet50_Final.pth && wget -c http://pai-vision-data-hz.oss-cn-zhangjiakou.aliyuncs.com/EasyCV/datasets/try_on/parsing_parsenet.pth
cd stable-diffusion-webui/embeddings && wget -c http://pai-vision-data-hz.oss-cn-zhangjiakou.aliyuncs.com/EasyCV/datasets/try_on/ng_deepnegative_v1_75t.pt
cd stable-diffusion-webui/models/Lora && wget -c https://huggingface.co/Kanbara/doll-likeness-series/resolve/main/koreanDollLikeness_v10.safetensors

  • 處理報錯
# 報錯
Could not load library libcudnn_cnn_infer.so.8. Error: libnvrtc.so: cannot open shared object file: No such file or directory
Aborted
# 解決
export LD_LIBRARY_PATH=/usr/local/lib/python3.10/dist-packages/nvidia/cudnn/lib/

# 保存鏡像報錯
failed to push image registry-vpc.cn-hangzhou.aliyuncs.com/aleimu123/stablediffusion-webui:v1, please try again later, failed to commit image, error: different regsitry for base images and commit image

dsw-registry-vpc.cn-hangzhou.cr.aliyuncs.com/cloud-dsw/eas-service:aigc-torch113-cu117-ubuntu22.04-v0.2.1_accelerated
# 經過工單詢問得知,阿里雲官方提供的鏡像(_accelerated)都不支持保存
  • 不要使用阿里雲的pip鏡像源,安裝GFPGAN有問題,換成清華源即可.
vim ~/.pip/pip.conf

[global] 
index-url = https://pypi.tuna.tsinghua.edu.cn/simple 
[install] 
trusted-host = pypi.tuna.tsinghua.edu.cn
  • 常用命令和操作
# 非root鏡像,用root啓動
docker run -ti --entrypoint /bin/bash -u root 41c15e30f4ff

# 補全常用命令行
vim /etc/apt/sources.list
apt-get install pciutils
apt-get install cron
apt-get install iputils-ping
apt-get install net-tools
apt install vim
apt-get install systemctl

# 啓動相關
cd stable-diffusion-webui && python -m venv --system-site-packages --symlinks venv
cd stable-diffusion-webui && sed -i 's/can_run_as_root=0/can_run_as_root=1/g' webui.sh 
./webui.sh 

# 安裝下ossutil的命令行,方便上傳東西到oss裏
apt-get install p7zip-full
curl https://gosspublic.alicdn.com/ossutil/install.sh | sudo bash
ossutil config

# 記得最後清理下緩存,避免保存的鏡像過大
apt-get clean
cd ~/.cache/pip && rm -rf *

必裝插件

git clone https://github.com/DominikDoom/a1111-sd-webui-tagcomplete.git
git clone https://github.com/pkuliyi2015/multidiffusion-upscaler-for-automatic1111.git
git clone https://github.com/fkunn1326/openpose-editor.git
git clone https://github.com/adieyal/sd-dynamic-prompts.git
git clone https://github.com/vladmandic/sd-extension-system-info.git
git clone https://github.com/Mikubill/sd-webui-controlnet.git
git clone https://github.com/continue-revolution/sd-webui-segment-anything.git
git clone https://github.com/hako-mikan/sd-webui-supermerger.git
git clone https://github.com/VinsonLaro/stable-diffusion-webui-chinese
git clone https://github.com/AlUlkesh/stable-diffusion-webui-images-browser.git
git clone https://github.com/sdbds/stable-diffusion-webui-wildcards.git

安裝訓練腳本

按照https://github.com/Akegarasu/lora-scripts 的文檔安裝就好,沒啥好說的.

最後

一切都裝好了,運行也沒問題,點一下保存鏡像不用時停止實例,雖然是白嫖來的但也省着點花,減少碳排放人人有責

常用連接

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章