快速部署stable diffusion@Ubuntu

Stable Diffusion可以根据文本描述生成相关的图像,是当前最热门的文生图模型。

在Ubuntu下,可以选择快速安装,或者手动一步步安装。

快速安装

使用文档中的方法,先下载一个sh文件,然后执行这个文件,就自动安装依赖,自动启动服务了。

首先安装好需要的库

复制代码
# Debian-based:
sudo apt install wget git python3 python3-venv libgl1 libglib2.0-0
# Red Hat-based:
sudo dnf install wget git python3 gperftools-libs libglvnd-glx 
# openSUSE-based:
sudo zypper install wget git python3 libtcmalloc4 libglvnd
# Arch-based:
sudo pacman -S wget git python3

下载sh并执行:

复制代码
wget -q https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-webui/master/webui.sh
sh webui.sh 

如果github抽风导致git clone失败,可以进入webui.sh文件,修改其中的"{GIT}" clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git "{clone_dir}"

到 "{GIT}" clone --depth 2 https://github.com/AUTOMATIC1111/stable-diffusion-webui.git "{clone_dir}" ,可以提高成功率。

也可以手动去进行git clone指令。

后面按部就班一路安装成功即可。

也可以手动安装,手动安装可以较自由的选择torch版本等。

手动一步步安装

下载源代码

复制代码
git clone --depth 2 https://github.com/AUTOMATIC1111/stable-diffusion-webui.git

进入目录,使用conda安装pytorch等依赖

复制代码
cd stable-diffusion-webui
conda env update --file environment-wsl2.yaml --prune

安装好后激活环境

复制代码
conda activate automatic

下载模型

到huggingface网站下载模型,比如可以从gitee镜像下载:stable-diffusion-v1-5: Mirror of https://huggingface.co/runwayml/stable-diffusion-v1-5

可以从hf-mirrot.com这个镜像下载:https://hf-mirror.com/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.ckpt

下载这个文件:v1-5-pruned-emaonly.ckpt

将下载的文件改名成model.ckpt并放入指定目录:stable-diffusion-webui/models/Stable-diffusion/model.ckpt

比如

复制代码
mv v1-5-pruned-emaonly.ckpt ~/github/stable-diffusion-webui/models/Stable-diffusion/model.ckpt

启动服务

复制代码
python3 launch.py

如果是cpu环境,需要加上参数:

复制代码
python launch.py --skip-torch-cuda-test 1

调试

报错RuntimeError: Torch is not able to use GPU

raise RuntimeError( RuntimeError: Torch is not able to use GPU; add --skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check

加上参数执行:python launch.py --skip-torch-cuda-test 1

报错git clone Error code: 128

File "/home/linuxskywalk/github/stable-diffusion-webui/modules/launch_utils.py", line 115, in run

raise RuntimeError("\n".join(error_bits))

RuntimeError: Couldn't clone Stable Diffusion.

Command: "git" clone --config core.filemode=false "https://github.com/Stability-AI/stablediffusion.git" "/home/linuxskywalk/github/stable-diffusion-webui/repositories/stable-diffusion-stability-ai"

Error code: 128

是github repo下载出错,加上--depth 2 ,然后手工执行:

"git" clone --depth 2 --config core.filemode=false "https://github.com/Stability-AI/stablediffusion.git" "/home/linuxskywalk/github/stable-diffusion-webui/repositories/stable-diffusion-stability-ai"

如果还不行,就想其它办法,比如github不抽风的时候下载。

报错RuntimeError: Couldn't fetch Stable Diffusion XL.

run(f'"{git}" -C "{dir}" fetch --refetch --no-auto-gc', f"Fetching all contents for {name}", f"Couldn't fetch {name}", live=True)

File "/home/linuxskywalk/github/stable-diffusion-webui/modules/launch_utils.py", line 115, in run

raise RuntimeError("\n".join(error_bits))

RuntimeError: Couldn't fetch Stable Diffusion XL.

Command: "git" -C "/home/linuxskywalk/github/stable-diffusion-webui/repositories/generative-models" fetch --refetch --no-auto-gc

Error code: 129

使用conda install git试试

还是不行。原来generative-models不能用--depth 2 这个参数,因为用了之后可能拿不到repo branch

删除该目录,重新安装

git clone https://github.com/Stability-AI/generative-models.git

ok了

相关推荐
.30-06Springfield28 分钟前
人工智能概念之七:集成学习思想(Bagging、Boosting、Stacking)
人工智能·算法·机器学习·集成学习
说私域1 小时前
基于开源AI智能名片链动2+1模式S2B2C商城小程序的超级文化符号构建路径研究
人工智能·小程序·开源
永洪科技2 小时前
永洪科技荣获商业智能品牌影响力奖,全力打造”AI+决策”引擎
大数据·人工智能·科技·数据分析·数据可视化·bi
shangyingying_12 小时前
关于小波降噪、小波增强、小波去雾的原理区分
人工智能·深度学习·计算机视觉
书玮嘎3 小时前
【WIP】【VLA&VLM——InternVL系列】
人工智能·深度学习
猫头虎3 小时前
猫头虎 AI工具分享:一个网页抓取、结构化数据提取、网页爬取、浏览器自动化操作工具:Hyperbrowser MCP
运维·人工智能·gpt·开源·自动化·文心一言·ai编程
要努力啊啊啊3 小时前
YOLOv2 正负样本分配机制详解
人工智能·深度学习·yolo·计算机视觉·目标跟踪
CareyWYR3 小时前
大模型真的能做推荐系统吗?ARAG论文给了我一个颠覆性的答案
人工智能
特立独行的猫a3 小时前
百度AI文心大模型4.5系列开源模型评测,从安装部署到应用体验
人工智能·百度·开源·文心一言·文心一言4.5