导航

Win11下安装 stable diffusion 记录

Posted on 2023-07-25 18:50  蝈蝈俊  阅读(1077)  评论(1编辑  收藏  举报

这次是Win11下安装,安装方法:

https://github.com/AUTOMATIC1111/stable-diffusion-webui

Automatic Installation on Windows

  • Install Python 3.10.6 (Newer version of Python does not support torch), checking "Add Python to PATH".
  • Install git.
  • Download the stable-diffusion-webui repository, for example by running git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git.
  • Run webui-user.bat from Windows Explorer as normal, non-administrator, user.

对于已有的更新,则是

git pull

参看:
https://www.runoob.com/git/git-pull.html

之前提到两个安装过程中会碰到的问题
本地部署stable-diffusion-webui出现的问题记录

其中安装 gfpgan 卡住, 可以通过 Clash for Window 如下配置

先打开Service Mode,然后再开启TUN Mode

Upcast cross attention layer to float32

我在使用 stable diffusion v2-1_768-ema-pruned 模型时,收到下面错误:
https://huggingface.co/stabilityai/stable-diffusion-2-1

modules.devices.NansException: A tensor with all NaNs was produced in Unet. This could be either because there's not enough precision to represent the picture, or because your video card does not support half type. Try setting the "Upcast cross attention layer to float32" option in Settings > Stable Diffusion or using the --no-half commandline argument to fix this. Use --disable-nan-check commandline argument to disable this check.

解决方案就如同上面说的:

尝试在“Settings”>“Stable Diffusion”中设置“Upcast cross attention layer to float32”选项。

或使用 --no-half 命令行参数来修复此问题。 使用 --disable-nan-check 命令行参数禁用此检查。

xFormers

xFormers是一个模块化和可编程的Transformer建模库,可以加速图像的生成。

这种优化仅适用于nvidia gpus,它加快了图像生成,并降低了vram的使用量。

编辑 webui-user.bat 文件.
增加 --xformers 即可

set COMMANDLINE_ARGS = --xformers

安装扩展权限

在安装扩展时,默认是没有权限的,

AssertionError: extension access disabed because of commandline flags

启动WebUI的时候添加一个参数 --enable-insecure-extension-access 就可以具备权限。

KeyError: 'dataset'

安装 sd-webui-depth-lib 扩展后,会出现错误:

ERROR: Exception in ASGI application
File "D:\stable-diffusion-webui\venv\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 408, in run_asgi
result = await app( # type: ignore[func-returns-value]
...
KeyError: 'dataset'

解决方法1:删除sd-webui-depth-lib 扩展

https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/12112
可以看到,删除这个扩展就可以了。

解决方法2:升级 gradio 版本

最新版本可以在https://github.com/gradio-app/gradio/releases 看到

注意,不能用

# 检查安装的版本
pip show gradio 

# 升级到最新版本
pip install --upgrade gradio 

# 用指定的版本替换或安装
pip install gradio==<version> 
pip install gradio==3.39.0

因为 stable diffusion 是按照 requirements 文件中设置的依赖,每次启动时调整的。

下面两个文件都要修改:

  • requirements.txt
  • requirements_versions.txt

把其中的 gradio 版本都修改成 3.39.0

如何打开win11防火墙某个端口

  • 打开「开始」菜单并输入「防火墙」。
  • 选择「Windows 防火墙」。
  • 在左侧菜单栏中选择「高级设置」。
  • 在「入站规则」或「出站规则」中选择「新建规则」。
  • 选择「端口」,然后选择「下一步」。
  • 在「协议和端口」选项中,选择「TCP」或「UDP」,然后输入您想要打开的端口号。
  • 选择「下一步」,并选择「允许连接」。
  • 为该规则提供一个名称和描述(可选),然后选择「完成」。

这样就可以在 Windows 11 中打开指定的端口了。

设置局域网其它机器可访问

修改 webui-user.sh 文件,增加--listen参数。

set COMMANDLINE_ARGS= --listen

如果不修改是无法访问的,显示的端口将不会是 0.0.0.0,而是 127.0.0.1

能其它机器访问时,应该显示如下:

Running on local URL:  http://0.0.0.0:7860