【踩坑笔记】从零开始部署安装Stable Diffusion 2 WebUI

【踩坑笔记】从零开始部署安装Stable Diffusion 2 WebUI

    正在检查是否收录...

一、材料准备

一台带GPU的电脑,系统Ubuntu20.2 Xshell和Xftp,用于连接云主机,传输文件

我用的是阿里云ECS,型号ecs.gn6i-c4g1.xlarge(4 vCPU 15 GiB 1 * NVIDIA T4)。推荐挂一个NAS盘方便保存文件。

二、安装步骤

(可选)安装显卡驱动
# T4显卡的驱动是460,在这找https://www.nvidia.com/Download/index.aspx apt-get install nvidia-driver-460 # 试试可不可以nvidia-smi检测显卡状态,如果可以显示则成功了 nvidia-smi 
安装Python虚拟环境
# 安装python环境 sudo apt install wget git python3 python3-venv 

如果git报错443,可以多试几次,或者在/etc/hosts文件最后加一行:
140.82.113.4 github.com
↑这个IP可以从这里找到

创建个非root用户
# --home 用户目录,我的NAS挂载在/mnt,所以用户目录就建在mnt下了 adduser --home /mnt/sd2 sd2 su sd2 cd /mnt/sd2 
正式安装webui,主要遵循官方[1]的方法
# 这里运行官方的自动化安装脚本webui.sh wget https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-webui/master/webui.sh bash webui.sh 

到这里其实已经结束了,但是如果主机是在国内,那么一般来说都会报错的,下面总结几种我遇到的错误解决方法:

ERROR: Can’t cd to /mnt/sd2/stable-diffusion-webui/, aborting…
原因:没有成功git clone
解决方式:重试几次一般就可以了,或者手动下载 https://github.com/AUTOMATIC1111/stable-diffusion-webui,然后放在stable-diffusion-webui文件夹下

重试的时候要运行bash webui.sh,切勿python3 launch.py,因为是使用虚拟环境的,比如我的python3路径是/mnt/sd2/stable-diffusion-webui/venv/bin/python3

Torch is not able to use GPU; add --skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check
原因:可能是驱动版本不对,也可能是你在docker里
解决:检查一下GPU驱动的版本对不对,在这里查找https://www.nvidia.com/Download/index.aspx
如果是docker,搜一下csdn一大片解决方式

RuntimeError: Couldn’t install torch. (或者无法install其他的pip库)
urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host=‘files.pythonhosted.org’, port=443): Read timed out.
原因:网络问题,pip安装torch超时失败
解决:使用清华pip源
1.编辑/stable-diffusion-webui/launch.py文件,找到这段代码:
run(f'"{python}" -m {torch_command}
整行改成:
run(f'"{python}" -m {torch_command} -i https://pypi.tuna.tsinghua.edu.cn/simple', "Installing torch and torchvision", "Couldn't install torch")
2.然后再找到这段代码:
return run(f'"{python}" -m pip {args}
整行改成:
return run(f'"{python}" -m pip {args} -i https://pypi.tuna.tsinghua.edu.cn/simple --prefer-binary{index_url_line}', desc=f"Installing {desc}", errdesc=f"Couldn't install {desc}")
3.然后重试,一般就好了。原理就是加了清华的pip镜像 -i https://pypi.tuna.tsinghua.edu.cn/simple

fatal: unable to access ‘https://github.com/sczhou/CodeFormer.git/’ (或者其他的库): GnuTLS recv error (-110): The TLS connection was non-properly terminated.
原因:还是github网络问题
解决:这个和git clone失败的解决方式一样,重试几次,或者改hosts

三、下载模型

下载模型的checkpoint:https://huggingface.co/stabilityai/stable-diffusion-2

官方给的示例有:
768-v-ema.ckpt 模型下载+yaml下载
512-base-ema.ckpt 模型下载+yaml下载

把.ckpt放到models/Stable-Diffusion/目录下(如果你下载的模型带有.yaml文件,那么也一起放进去,.yaml的文件命名需要和你的.ckpt前面一样) 启动后在右上角选择你的模型就可以了

四、启动

把参数带上,让远端可以访问。参数列表可以在/modules/shared.py里面找到

# 进到文件夹内,用虚拟环境的python运行 cd /stable-diffusion-webui venv/bin/python3 launch.py --port 9965 --listen --no-half --enable-insecure-extension-access 

第一次运行会下载一些模型,成功后会提示:

Launching Web UI with arguments: --port 9965 --listen --no-half --enable-insecure-extension-access No module 'xformers'. Proceeding without it. ... LatentDiffusion: Running in v-prediction mode DiffusionWrapper has 865.91 M params Loading weights [0b0d9f28] from ... Model loaded. Loaded a total of 0 textual inversion embeddings. Embeddings: Running on local URL: http://0.0.0.0:9965 # 这里是监听地址 

电脑访问http://云主机ip:9965就可以玩了~

五、其他

如果你像我一样是用云主机,为方便下一次运行,可以生成一个镜像,以后直接加载镜像就不需要重新安装了 以后重新进入记得切用户su 你的用户名 启动的完整参数看这里
usage: launch.py [-h] [--config CONFIG] [--ckpt CKPT] [--ckpt-dir CKPT_DIR] [--gfpgan-dir GFPGAN_DIR] [--gfpgan-model GFPGAN_MODEL] [--no-half] [--no-half-vae] [--no-progressbar-hiding] [--max-batch-count MAX_BATCH_COUNT] [--embeddings-dir EMBEDDINGS_DIR] [--hypernetwork-dir HYPERNETWORK_DIR] [--localizations-dir LOCALIZATIONS_DIR] [--allow-code] [--medvram] [--lowvram] [--lowram] [--always-batch-cond-uncond] [--unload-gfpgan] [--precision {full,autocast}] [--share] [--ngrok NGROK] [--ngrok-region NGROK_REGION] [--enable-insecure-extension-access] [--codeformer-models-path CODEFORMER_MODELS_PATH] [--gfpgan-models-path GFPGAN_MODELS_PATH] [--esrgan-models-path ESRGAN_MODELS_PATH] [--bsrgan-models-path BSRGAN_MODELS_PATH] [--realesrgan-models-path REALESRGAN_MODELS_PATH] [--clip-models-path CLIP_MODELS_PATH] [--xformers] [--force-enable-xformers] [--deepdanbooru] [--opt-split-attention] [--opt-split-attention-invokeai] [--opt-split-attention-v1] [--disable-opt-split-attention] [--use-cpu USE_CPU [USE_CPU ...]] [--listen] [--port PORT] [--show-negative-prompt] [--ui-config-file UI_CONFIG_FILE] [--hide-ui-dir-config] [--freeze-settings] [--ui-settings-file UI_SETTINGS_FILE] [--gradio-debug] [--gradio-auth GRADIO_AUTH] [--gradio-img2img-tool {color-sketch,editor}] [--gradio-inpaint-tool {sketch,color-sketch}] [--opt-channelslast] [--styles-file STYLES_FILE] [--autolaunch] [--theme THEME] [--use-textbox-seed] [--disable-console-progressbars] [--enable-console-prompts] [--vae-path VAE_PATH] [--disable-safe-unpickle] [--api] [--api-auth API_AUTH] [--nowebui] [--ui-debug-mode] [--device-id DEVICE_ID] [--administrator] [--cors-allow-origins CORS_ALLOW_ORIGINS] [--cors-allow-origins-regex CORS_ALLOW_ORIGINS_REGEX] [--tls-keyfile TLS_KEYFILE] [--tls-certfile TLS_CERTFILE] [--server-name SERVER_NAME] [--ldsr-models-path LDSR_MODELS_PATH] [--scunet-models-path SCUNET_MODELS_PATH] [--swinir-models-path SWINIR_MODELS_PATH] 

5.1 XFormer

如果不想用–no-half,可以安装XFormer

 # 先进入stable-diffusion-webui目录下 source ./venv/bin/activate cd repositories git clone https://github.com/facebookresearch/xformers.git cd xformers git submodule update --init --recursive ../../venv/bin/python3 -m pip install -r requirements.txt ../../venv/bin/python3 -m pip install -e . 

我经常卡在git submodule update --init --recursiv这一步,国内还是老老实实用–no-half吧。。

成功后,把启动参数改成–xformers

venv/bin/python3 launch.py --port 9965 --listen --enable-insecure-extension-access --xformers 

5.2 自定义脚本

可以安装一些实用的自定义脚本

# Tag输入智能提示,能在输入Tag时提供booru风格(如Danbooru)的TAG自动补全 git clone "https://github.com/DominikDoom/a1111-sd-webui-tagcomplete.git" extensions/tag-autocomplete # Prompt测试,这个插件可以根据用户输入的提示语句,自动生成相应数量的图像,以测试提示语句中每个单词的影响。 git clone "https://github.com/Extraltodeus/test_my_prompt.git" extensions/test-my-prompt 

codegitpythonwebwebuigandiffusiongithubgradiopromptclonecpuurlamlgpuapi虚拟环境clipdoc文件夹debugsharebashclidocker自定义shell自动化自动生成raplow-codeeditor自动补全prompt测试huggingface智能提示错误解决facebooknistappideai办公
  • 本文作者:李琛
  • 本文链接: https://wapzz.net/post-3916.html
  • 版权声明:本博客所有文章除特别声明外,均默认采用 CC BY-NC-SA 4.0 许可协议。
本站部分内容来源于网络转载,仅供学习交流使用。如涉及版权问题,请及时联系我们,我们将第一时间处理。
文章很赞!支持一下吧 还没有人为TA充电
为TA充电
还没有人为TA充电
0
  • 支付宝打赏
    支付宝扫一扫
  • 微信打赏
    微信扫一扫
感谢支持
文章很赞!支持一下吧
关于作者
2.3W+
5
0
1
WAP站长官方

AI的效能在网络安全方面受到限制,但在网络犯罪方面却是无限的

上一篇

「MagicAnimate」官网体验入口 AI动画图像生成软件app免费下载地址

下一篇
  • 复制图片
按住ctrl可打开默认菜单