4

阿里云交互式建模(DSW)的探索和踩坑 - 从零开始的程序员生活

 1 year ago
source link: https://www.cnblogs.com/lgjbky/p/17359237.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

阿里云交互式建模(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 的文档安装就好,没啥好说的.

一切都装好了,运行也没问题,点一下保存镜像不用时停止实例,虽然是白嫖来的但也省着点花,减少碳排放人人有责


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK