小小小幸运 发表于 2024-10-2 09:06:59

丹摩智算(damodel)部署stable diffusion实验

名词解释:
https://img-blog.csdnimg.cn/img_convert/f156d2f6f8540e199a3eac21e318154e.png
丹摩智算(damodel):是一款带有RTX4090,Tesla-P40等显卡的公有云服务器。
stable diffusion:是一个大模子,可支持文生图,图生图,文生视频等功能
一.实验目标

注册丹摩智算(damodel) 账户,创建带有显卡(Tesla-P40)的公有云服务器,体系为:ubuntu22.04_tensorflow2.1,通过ssh协议毗连到公有云服务器,在该服务器上安装stable diffusion,适配成功后,通过欣赏器访问stable diffusion后,实现文生图的功能
二.实验环境准备

1.公有云:丹摩智算(damodel)
2.体系:ubuntu22.04_tensorflow2.1
3.显卡:Tesla-P40 
4.ssh毗连工具:finalshell
5.stable diffusion:Stable Diffusion web UI
三.实验步骤

1.丹摩智算(damodel) 账户 注册
2.创建带显卡的公有云服务器。显卡:Tesla-P40  体系:ubuntu22.04_tensorflow2.1
3.ssh毗连工具finalshell下载安装
4.通过ssh协议毗连后,在ubuntu22.04_tensorflow2.1公有云上部署stable diffusion
5.Stable Diffusion web UI部署成功后,通过欣赏器访问
6.在Stable Diffusion web UI页面上,输入关键词,生成图片
四.实验过程

注意事项:
由于必要下载模子,模子50g巨细,以是磁盘肯定要在创建实例的时候一次性创建够用。比方:200g体系盘,300g数据盘。
1.丹摩智算(damodel) 账户 注册

 欣赏器登录地址:https://www.damodel.com/home
https://i-blog.csdnimg.cn/direct/212e4966ccb7418f913231e801462f7d.jpeg
注册成功后进入页面 
https://i-blog.csdnimg.cn/direct/e5bc9e6ed61a45c9b221e493a80bb1d1.jpeg
点击创建实例
https://i-blog.csdnimg.cn/direct/03defd8b75af4080af6ec0e6e1b3952c.png  
2.创建带显卡的公有云服务器。显卡:Tesla-P40  体系:ubuntu22.04_tensorflow2.1

 选择显卡型号,操作体系和默认支持框架,并选择使用优惠券和付费方式
https://i-blog.csdnimg.cn/direct/0757610760ee41e9aa091e80f2b4ac92.png
创建成功后 
https://i-blog.csdnimg.cn/direct/5d4bd411c9f74040a35e6c90670720b3.jpeg
3.ssh毗连工具finalshell下载安装

下载地址:FinalShell SSH工具,服务器管理,远程桌面加速软件,支持Windows,macOS,Linux,版本4.5.6,更新日期2024.8.27 - FinalShell官网
https://i-blog.csdnimg.cn/direct/ba10e2b5e12f4a429378957e9dd6b8e6.png
https://i-blog.csdnimg.cn/direct/7ca70ae621e647bb965f8826e5928e63.png
弹出来
https://i-blog.csdnimg.cn/direct/fdc154ac92924de7bf6f88bf87b12840.png
 https://i-blog.csdnimg.cn/direct/1bba7d057b8844808b440841915ceaea.png
https://i-blog.csdnimg.cn/direct/89cd24c525f14197a30456f88af8e035.png
安装成功后,https://i-blog.csdnimg.cn/direct/06f324b4619440c9ae7e956b18ec0854.png 丹摩DAMODEL|让AI开发更简朴!算力租赁上丹摩! 找到实例登录的用户名和密码(访问链接和密码分别复制获取)
https://i-blog.csdnimg.cn/direct/3a374c0c262c4770b3c65df037253511.png
输入实例 ip和用户名,密码https://i-blog.csdnimg.cn/direct/c5d4022ba4224f358cab52dfefa70965.png 
登录成功后
https://i-blog.csdnimg.cn/direct/2da40dcd1de54acd9cb87d4ade4d5ec9.png
4.Stable Diffusion web UI下载与部署

注意事项:由于github访问慢的原因,以是本文会用离线下载后上传安装Python组件的方式和修改github地址为gitee两种方式来办理。gitee库已放在文章中,过程vim 修改utils文件,请细致修改,耐心操作
地址:GitCode - 全球开发者的开源社区,开源代码托管平台

[*]安装依靠项:
# 更新库
sudo apt update
# 基于Debian的:
sudo apt install wget git python3 python3-venv libgl1 libglib2.0-0

 https://i-blog.csdnimg.cn/direct/e15c603ae39f4d7bb5facbb212472685.png
中心输入y 
https://i-blog.csdnimg.cn/direct/ed05f01d3d7a43188a069a991acdd963.png
   sudo apt install --no-install-recommends google-perftools
 https://i-blog.csdnimg.cn/direct/21100a08c8d2429096ef5e5dda264b7b.png

[*]转至盼望安装webui的目录,实行以下下令:
mkdir /opt/software
cd /opt/software
git clone https://gitcode.com/gh_mirrors/st/stable-diffusion-webui.git
https://i-blog.csdnimg.cn/direct/acf3bb1c65784a8a93782e897089bb80.png

或者在当地下载之后上传
https://i-blog.csdnimg.cn/direct/33271532b8f84275aa9eaa109b7d041b.png
创建用户,设置密码
root@crm1uavhri0c73fveip0-arhmb:/opt/software# useradd diffusion
root@crm1uavhri0c73fveip0-arhmb:/opt/software# passwd diffusion
输入密码:123456
https://i-blog.csdnimg.cn/direct/009cc0597f384a93b924473a854d8c36.png

[*]运行webui.sh。 bash webui.sh -f 
[*] https://i-blog.csdnimg.cn/direct/c7662157982e4f158cac8804975cd3da.png
[*]这里遇到一个问题,实行到上面下载步骤,有2G巨细的文件必要下载,但是网速只有200k,必要两个小时才气下载成功。必要耐心等待。
[*]查看webui-user.sh以获取选项。
https://i-blog.csdnimg.cn/direct/cc08b21a69ce4f70a490ba1eaac92cb8.png 创建目录:/opt/software/stable-diffusion-webui/
mkdir /opt/software/stable-diffusion-webui/
修改文件,去掉root登录限制
https://i-blog.csdnimg.cn/direct/539e5c09f2c64b1b8f2eace98d2309b8.png
sudo apt install python3-pip 手动下载whl文件后,上传到服务器,然后安装
下载地址:https://download.pytorch.org/whl/cu121/torch-2.1.2%2Bcu121-cp310-cp310-linux_x86
pip install torch-2.1.2+cu121-cp310-cp310-linux_x86_64.whl
 https://i-blog.csdnimg.cn/direct/b144abd57c504d57a16c5f450936acbd.png
下载clip并安装
下载地址:
https://github.com/openai/CLIP/archive/d50d76daa670286dd6cacf3bcd80b5e4823fc8e1.zip
用sheel工具上传
https://i-blog.csdnimg.cn/direct/829c4a83f88a44ac91ffb0d009d76a95.png
下载后安装:
python3-m pip install CLIP-d50d76daa670286dd6cacf3bcd80b5e4823fc8e1.zip --prefer-binary
’ 
安装bc计算工具
apt-get install bc https://i-blog.csdnimg.cn/direct/4ad4aa2d92994077a49e99b7df17afca.png
/opt/software/stable-diffusion-webui/venv/bin/python -m pip install /opt/package/CLIP-d50d76daa670286dd6cacf3bcd80b5e4823fc8e1.zip --prefer-binary
https://i-blog.csdnimg.cn/direct/57bf33c123814fbebf7291f0309d4fb5.png
下载安装openc_clip
地址:https://github.com/mlfoundations/open_clip/archive/bb6e834e9c70d9c27d0dc3ecedeebeaeb1ffad6b.zip
下载后上传 
安装:
/opt/software/stable-diffusion-webui/venv/bin/python -m pip install /opt/package/open_clip-bb6e834e9c70d9c27d0dc3ecedeebeaeb1ffad6b.zip --prefer-binary
https://i-blog.csdnimg.cn/direct/f579e70501fa45608abfa1cdf662ad60.png
python-m pip install open_clip_torch
python3-m pip install open_clip_torch
安装
修改文件/opt/software/stable-diffusion-webui/modules/launch_utils.py,
vim 找到198行,更换stable-diffusion-webui-assets.git的github地址为gitee 
https://i-blog.csdnimg.cn/direct/e7becf903f134d43bd95f521569c4150.png

mkdir -p /opt/software/stable-diffusion-webui/repositories
cd /opt/software/stable-diffusion-webui/repositories/
git clone https://gitee.com/akavir/stable-diffusion-webui-assets.git xsinbegin/stable-diffusion-stability-ai
修改stable-diffusion-stability-ai 地址为gitee.
https://i-blog.csdnimg.cn/direct/1007582c586c4f4c8a4d6bf8532807ec.png
修改stablediffusion地址为gitee
vim /opt/software/stable-diffusion-webui/modules/launch_utils.py
https://gitee.com/akavir/stablediffusion.git
https://i-blog.csdnimg.cn/direct/576ff985b6f34750968ffae8076959ed.png
修改generative-models: from https://github.com/Stability-AI/generative-models.git 
https://gitee.com/llf/Stability-AI-generative-models.git
https://i-blog.csdnimg.cn/direct/0bbad350d3204e7a9c949ec93959e08d.png
更改k-diffusion库
vim /opt/software/stable-diffusion-webui/modules/launch_utils.py

找到该行
https://i-blog.csdnimg.cn/direct/dc0f9a3245db4be9bb680d323ec59338.png
用下面的链接更换 
https://gitee.com/dinglinhe/k-diffusion.git
https://i-blog.csdnimg.cn/direct/144e59fb7d1040478853f4ce05c52fd2.png
更换blip
 地址为:
https://gitee.com/dinglinhe/BLIP.git
https://i-blog.csdnimg.cn/direct/11e31b9191214d968b779c1e0329f761.png
https://i-blog.csdnimg.cn/direct/62b5dcea142f4e16b36ca2d44a2bf4dc.png
安装xfromer
pip install xformers https://i-blog.csdnimg.cn/direct/a030a4b7b96a46f1b9faca72f8ce09f1.png
实行 部署脚本
bash /opt/software/stable-diffusion-webui/webui.sh -f https://i-blog.csdnimg.cn/direct/f419954e00234f0c87fe39c57a0c0f4a.png
注:本文未安装模子,在安装模子前必要扩展硬盘 
5.Stable Diffusion web UI部署成功后,通过欣赏器访问

http://127.0.0.1:7860
注:本文由于模子下载的缘故,暂未成功,后续补充
6.在Stable Diffusion web UI页面上,输入关键词,生成图片

必要等待模子下载成功后,继承实验
五.演示结果:

模子下载成功后演示
六.注意事项

1.丹摩智算(damodel)平台优惠券只有50元,创建成功实例后,由于是按时间进行算费,必要注意使用时效的问题
2.ERROR: This script must not be launched as root, aborting...
错误办理:

方法一. 运行 bash webui.sh如果是root用户,必要注释掉webui.sh中关于root权限的判定。
https://i-blog.csdnimg.cn/direct/831e8865a5c14db29c76a6b8720d26a5.png
创建用户
https://i-blog.csdnimg.cn/direct/ac04ee62bc39485badfdb80d70535710.png
方法二:或者:bash webui.sh -f 
 3.必须先实行sudo apt update 更新库,再安装依靠环境,否则会报错
https://i-blog.csdnimg.cn/direct/8ad6d2e93fb24752b16f3fcb7e58a0fb.png
4.ERROR: Cannot activate python venv, aborting...
5.
Cannot locate TCMalloc. Do you have tcmalloc or google-perftool installed on your system? (improves CPU memory usage)

 
七.附录

官网手册:
页: [1]
查看完整版本: 丹摩智算(damodel)部署stable diffusion实验