Windows 部署 Stable Diffusion web UI

系统要求

环境要求

1. 安装 Python 3.10.6.
2. 安装 git.    # 自行百度安装

版本信息

Stable Diffusion: 1.8.0-RC  
python: 3.10.6  
torch: 2.1.2+cu121

配置 python 环境

打开 Anaconda Powershell Prompt

创建 python 环境

(base) PS C:\Users\wgs>conda create -p G:\stable-diffusion\stable-diffusion-webui\env python=3.10.6
Channels:
 - defaults
Platform: win-64
Collecting package metadata (repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: G:\stable-diffusion\stable-diffusion-webui\env

  added / updated specs:
    - python=3.10.6


The following NEW packages will be INSTALLED:

  bzip2              anaconda/pkgs/main/win-64::bzip2-1.0.8-h2bbff1b_5
  ca-certificates    anaconda/pkgs/main/win-64::ca-certificates-2024.3.11-haa95532_0
  libffi             anaconda/pkgs/main/win-64::libffi-3.4.4-hd77b12b_0
  openssl            anaconda/pkgs/main/win-64::openssl-1.1.1w-h2bbff1b_0
  pip                anaconda/pkgs/main/win-64::pip-23.3.1-py310haa95532_0
  python             anaconda/pkgs/main/win-64::python-3.10.6-hbb2ffb3_1
  setuptools         anaconda/pkgs/main/win-64::setuptools-68.2.2-py310haa95532_0
  sqlite             anaconda/pkgs/main/win-64::sqlite-3.41.2-h2bbff1b_0
  tk                 anaconda/pkgs/main/win-64::tk-8.6.12-h2bbff1b_0
  tzdata             anaconda/pkgs/main/noarch::tzdata-2024a-h04d1e81_0
  vc                 anaconda/pkgs/main/win-64::vc-14.2-h21ff451_1
  vs2015_runtime     anaconda/pkgs/main/win-64::vs2015_runtime-14.27.29016-h5e58377_2
  wheel              anaconda/pkgs/main/win-64::wheel-0.41.2-py310haa95532_0
  xz                 anaconda/pkgs/main/win-64::xz-5.4.6-h8cc25b3_0
  zlib               anaconda/pkgs/main/win-64::zlib-1.2.13-h8cc25b3_0


Proceed ([y]/n)? y


Downloading and Extracting Packages:

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate G:\stable-diffusion\stable-diffusion-webui\env
#
# To deactivate an active environment, use
#
#     $ conda deactivate

激活 python 环境

(base) PS C:\Users\wgs> conda activate G:\stable-diffusion\stable-diffusion-webui\env
(G:\stable-diffusion\stable-diffusion-webui\env) PS C:\Users\wgs>

安装 Stable Diffusion

下载 Stable Diffusion

(G:\stable-diffusion\stable-diffusion-webui\env) PS C:\Users\wgs> cd G:\stable-diffusion\stable-diffusion-webui
(G:\stable-diffusion\stable-diffusion-webui\env) PS G:\stable-diffusion\stable-diffusion-webui> git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
Cloning into 'stable-diffusion-webui'...
remote: Enumerating objects: 32750, done.
remote: Counting objects: 100% (137/137), done.
remote: Compressing objects: 100% (96/96), done.
Receiving objects: 100% (32750/32750), 34.46 MiB | 4.34 MiB/s, done.613

Resolving deltas: 100% (22884/22884), done.

修改 webui-user.bat 使用新 venv 路径

@echo off

set PYTHON=G:\stable-diffusion\stable-diffusion-webui\env\python.exe
set GIT=
set VENV_DIR=
set COMMANDLINE_ARGS=--no-half  --no-half-vae --api --port 7860

call webui.bat

初始化 Stable Diffusion 环境

执行 stable-diffusion-webui 目录下的 webui-user.bat 文件
Creating venv in directory G:\stable-diffusion\stable-diffusion-webui\env using python "G:\stable-diffusion\stable-diffusion-webui\env\python.exe"
venv "G:\stable-diffusion\stable-diffusion-webui\env\Scripts\Python.exe"
Python 3.10.6 | packaged by conda-forge | (main, Oct 24 2022, 16:02:16) [MSC v.1916 64 bit (AMD64)]
Version: v1.8.0
Commit hash: bef51aed032c0aaa5cfd80445bc4cf0d85b408b5
Installing torch and torchvision
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple, https://download.pytorch.org/whl/cu121
Collecting torch==2.1.2
  Downloading https://download.pytorch.org/whl/cu121/torch-2.1.2%2Bcu121-cp310-cp310-win_amd64.whl (2473.9 MB)
     ---------------------------------------- 2.5/2.5 GB 1.4 MB/s eta 0:00:00
Collecting torchvision==0.16.2
  Downloading https://download.pytorch.org/whl/cu121/torchvision-0.16.2%2Bcu121-cp310-cp310-win_amd64.whl (5.6 MB)
     ---------------------------------------- 5.6/5.6 MB 5.1 MB/s eta 0:00:00
Collecting filelock (from torch==2.1.2)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/8b/69/acdf492db27dea7be5c63053230130e0574fd8a376de3555d5f8bbc3d3ad/filelock-3.13.3-py3-none-any.whl (11 kB)
Collecting typing-extensions (from torch==2.1.2)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/f9/de/dc04a3ea60b22624b51c703a84bbe0184abcd1d0b9bc8074b5d6b7ab90bb/typing_extensions-4.10.0-py3-none-any.whl (33 kB)
Collecting sympy (from torch==2.1.2)
  Downloading https://download.pytorch.org/whl/sympy-1.12-py3-none-any.whl (5.7 MB)
     ---------------------------------------- 5.7/5.7 MB 8.0 MB/s eta 0:00:00
Collecting networkx (from torch==2.1.2)
  Downloading https://download.pytorch.org/whl/networkx-3.2.1-py3-none-any.whl (1.6 MB)
     ---------------------------------------- 1.6/1.6 MB 6.6 MB/s eta 0:00:00
Collecting jinja2 (from torch==2.1.2)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/30/6d/6de6be2d02603ab56e72997708809e8a5b0fbfee080735109b40a3564843/Jinja2-3.1.3-py3-none-any.whl (133 kB)
     ---------------------------------------- 133.2/133.2 kB 7.7 MB/s eta 0:00:00
Collecting fsspec (from torch==2.1.2)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/93/6d/66d48b03460768f523da62a57a7e14e5e95fdf339d79e996ce3cecda2cdb/fsspec-2024.3.1-py3-none-any.whl (171 kB)
     ---------------------------------------- 172.0/172.0 kB 10.1 MB/s eta 0:00:00
Collecting numpy (from torchvision==0.16.2)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/19/77/538f202862b9183f54108557bfda67e17603fc560c384559e769321c9d92/numpy-1.26.4-cp310-cp310-win_amd64.whl (15.8 MB)
     ---------------------------------------- 15.8/15.8 MB 6.4 MB/s eta 0:00:00
Collecting requests (from torchvision==0.16.2)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/70/8e/0e2d847013cb52cd35b38c009bb167a1a26b2ce6cd6965bf26b47bc0bf44/requests-2.31.0-py3-none-any.whl (62 kB)
     ---------------------------------------- 62.6/62.6 kB 3.3 MB/s eta 0:00:00
Collecting pillow!=8.3.*,>=5.3.0 (from torchvision==0.16.2)
  Downloading https://download.pytorch.org/whl/pillow-10.2.0-cp310-cp310-win_amd64.whl (2.6 MB)
     ---------------------------------------- 2.6/2.6 MB 9.3 MB/s eta 0:00:00
Collecting MarkupSafe>=2.0 (from jinja2->torch==2.1.2)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/69/48/acbf292615c65f0604a0c6fc402ce6d8c991276e16c80c46a8f758fbd30c/MarkupSafe-2.1.5-cp310-cp310-win_amd64.whl (17 kB)
Collecting charset-normalizer<4,>=2 (from requests->torchvision==0.16.2)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a2/a0/4af29e22cb5942488cf45630cbdd7cefd908768e69bdd90280842e4e8529/charset_normalizer-3.3.2-cp310-cp310-win_amd64.whl (100 kB)
     ---------------------------------------- 100.3/100.3 kB 2.9 MB/s eta 0:00:00
Collecting idna<4,>=2.5 (from requests->torchvision==0.16.2)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c2/e7/a82b05cf63a603df6e68d59ae6a68bf5064484a0718ea5033660af4b54a9/idna-3.6-py3-none-any.whl (61 kB)
     ---------------------------------------- 61.6/61.6 kB 3.2 MB/s eta 0:00:00
Collecting urllib3<3,>=1.21.1 (from requests->torchvision==0.16.2)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a2/73/a68704750a7679d0b6d3ad7aa8d4da8e14e151ae82e6fee774e6e0d05ec8/urllib3-2.2.1-py3-none-any.whl (121 kB)
     ---------------------------------------- 121.1/121.1 kB 1.4 MB/s eta 0:00:00
Collecting certifi>=2017.4.17 (from requests->torchvision==0.16.2)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ba/06/a07f096c664aeb9f01624f858c3add0a4e913d6c96257acb4fce61e7de14/certifi-2024.2.2-py3-none-any.whl (163 kB)
     ---------------------------------------- 163.8/163.8 kB 2.4 MB/s eta 0:00:00
Collecting mpmath>=0.19 (from sympy->torch==2.1.2)
  Downloading https://download.pytorch.org/whl/mpmath-1.3.0-py3-none-any.whl (536 kB)
     ---------------------------------------- 536.2/536.2 kB 4.2 MB/s eta 0:00:00
Installing collected packages: mpmath, urllib3, typing-extensions, sympy, pillow, numpy, networkx, MarkupSafe, idna, fsspec, filelock, charset-normalizer, certifi, requests, jinja2, torch, torchvision
Successfully installed MarkupSafe-2.1.5 certifi-2024.2.2 charset-normalizer-3.3.2 filelock-3.13.3 fsspec-2024.3.1 idna-3.6 jinja2-3.1.3 mpmath-1.3.0 networkx-3.2.1 numpy-1.26.4 pillow-10.2.0 requests-2.31.0 sympy-1.12 torch-2.1.2+cu121 torchvision-0.16.2+cu121 typing-extensions-4.10.0 urllib3-2.2.1
Installing clip
。。。
Cloning assets into G:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\repositories\stable-diffusion-webui-assets...
Cloning into 'G:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\repositories\stable-diffusion-webui-assets'...
remote: Enumerating objects: 20, done.
remote: Counting objects: 100% (20/20), done.
remote: Compressing objects: 100% (18/18), done.
remote: Total 20 (delta 0), reused 20 (delta 0), pack-reused 0
Receiving objects: 100% (20/20), 132.70 KiB | 2.50 MiB/s, done.
Cloning Stable Diffusion into G:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\repositories\stable-diffusion-stability-ai...
Cloning into 'G:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\repositories\stable-diffusion-stability-ai'...
remote: Enumerating objects: 580, done.
remote: Counting objects: 100% (357/357), done.
remote: Compressing objects: 100% (126/126), done.
remote: Total 580 (delta 260), reused 231 (delta 231), pack-reused 223Receiving objects:  93% (540/580), 71.95 MiB | 4.5Receiving objects:  95% (551/580), 71.95 MiB | 4.51 MiB/s
Receiving objects: 100% (580/580), 73.44 MiB | 4.61 MiB/s, done.
Resolving deltas: 100% (279/279), done.
Cloning Stable Diffusion XL into G:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\repositories\generative-models...
Cloning into 'G:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\repositories\generative-models'...
remote: Enumerating objects: 941, done.
remote: Total 941 (delta 0), reused 0 (delta 0), pack-reused 941
Receiving objects:  90% (847/941), 43.07 MiB | 4.48 MiB/s
Receiving objects: 100% (941/941), 43.85 MiB | 4.67 MiB/s, done.
Resolving deltas: 100% (489/489), done.
Cloning K-diffusion into G:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\repositories\k-diffusion...
Cloning into 'G:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\repositories\k-diffusion'...
remote: Enumerating objects: 1340, done.
remote: Counting objects: 100% (622/622), done.
remote: Compressing objects: 100% (86/86), done.
remote: Total 1340 (delta 576), reused 547 (delta 536), pack-reused 718
Receiving objects: 100% (1340/1340), 242.04 KiB | 6.05 MiB/s, done.
Resolving deltas: 100% (939/939), done.
Cloning BLIP into G:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\repositories\BLIP...
Cloning into 'G:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\repositories\BLIP'...
remote: Enumerating objects: 277, done.
remote: Counting objects: 100% (165/165), done.
remote: Compressing objects: 100% (30/30), done.
remote: Total 277 (delta 137), reused 136 (delta 135), pack-reused 112
Receiving objects: 100% (277/277), 7.03 MiB | 8.14 MiB/s, done.
Resolving deltas: 100% (152/152), done.
Installing requirements
Launching Web UI with arguments:
no module 'xformers'. Processing without...
no module 'xformers'. Processing without...
No module 'xformers'. Proceeding without it.
Downloading: "https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors" to G:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\models\Stable-diffusion\v1-5-pruned-emaonly.safetensors
Calculating sha256 for G:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\models\Stable-diffusion\v1-5-pruned-emaonly.safetensors: Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
Startup time: 957.5s (prepare environment: 6.7s, import torch: 9.5s, import gradio: 2.4s, setup paths: 2.3s, initialize shared: 0.8s, other imports: 1.5s, list SD models: 926.6s, load scripts: 3.0s, create ui: 0.7s, gradio launch: 3.9s).
6ce0161689b3853acaa03779ec93eafe75a02f4ced659bee03f50797806fa2fa
Loading weights [6ce0161689] from G:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\models\Stable-diffusion\v1-5-pruned-emaonly.safetensors
Creating model from config: G:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\configs\v1-inference.yaml
vocab.json: 100%|███████████████████████████████████████████████████████████████████| 961k/961k [00:00<00:00, 1.44MB/s]
merges.txt: 100%|███████████████████████████████████████████████████████████████████| 525k/525k [00:00<00:00, 1.93MB/s]
special_tokens_map.json: 100%|████████████████████████████████████████████████████████████████| 389/389 [00:00<?, ?B/s]
tokenizer_config.json: 100%|██████████████████████████████████████████████████████████████████| 905/905 [00:00<?, ?B/s]
config.json: 100%|████████████████████████████████████████████████████████████████| 4.52k/4.52k [00:00<00:00, 7.06MB/s]
Applying attention optimization: Doggettx... done.
Model loaded in 39.3s (calculate hash: 13.6s, load weights from disk: 0.4s, create model: 20.6s, apply weights to model: 2.6s, apply half(): 0.1s, load textual inversion embeddings: 0.3s, calculate empty prompt: 1.5s).

查看插件信息

http://127.0.0.1:7860

安装 xformers

安装xformers 之前需要关闭 stable diffusion。xformers 版本信息要和 PyTorch 版本对应。

确认 xformers 版本信息

 

安装 xformers

G:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\venv\Scripts\python.exe -m pip install  xformers==v0.0.23.post1 
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting xformers==v0.0.23.post1
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/76/cd/267bd111a346007084919704eacb047e4c51d75e4b1f92cc98e80d7728e6/xformers-0.0.23.post1-cp310-cp310-win_amd64.whl (201.1 MB)
     ---------------------------------------- 201.1/201.1 MB 3.8 MB/s eta 0:00:00
Requirement already satisfied: numpy in g:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\venv\lib\site-packages (from xformers==v0.0.23.post1) (1.26.2)
Requirement already satisfied: torch==2.1.2 in g:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\venv\lib\site-packages (from xformers==v0.0.23.post1) (2.1.2+cu121)
Requirement already satisfied: jinja2 in g:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\venv\lib\site-packages (from torch==2.1.2->xformers==v0.0.23.post1) (3.1.3)
Requirement already satisfied: sympy in g:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\venv\lib\site-packages (from torch==2.1.2->xformers==v0.0.23.post1) (1.12)
Requirement already satisfied: filelock in g:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\venv\lib\site-packages (from torch==2.1.2->xformers==v0.0.23.post1) (3.13.3)
Requirement already satisfied: typing-extensions in g:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\venv\lib\site-packages (from torch==2.1.2->xformers==v0.0.23.post1) (4.10.0)
Requirement already satisfied: networkx in g:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\venv\lib\site-packages (from torch==2.1.2->xformers==v0.0.23.post1) (3.2.1)
Requirement already satisfied: fsspec in g:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\venv\lib\site-packages (from torch==2.1.2->xformers==v0.0.23.post1) (2024.3.1)
Requirement already satisfied: MarkupSafe>=2.0 in g:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\venv\lib\site-packages (from jinja2->torch==2.1.2->xformers==v0.0.23.post1) (2.1.5)
Requirement already satisfied: mpmath>=0.19 in g:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\venv\lib\site-packages (from sympy->torch==2.1.2->xformers==v0.0.23.post1) (1.3.0)
Installing collected packages: xformers
Successfully installed xformers-0.0.23.post1

设置 COMMANDLINE_ARGS

编辑 stable-diffusion-webui 目录下的 webui-user.bat 文件。
@echo off

set PYTHON=G:\stable-diffusion\stable-diffusion-webui\env\python.exe
set GIT=
set VENV_DIR=

set COMMANDLINE_ARGS=--no-half --xformers --no-half-vae --api --port 7860

call webui.bat

运行 Stable Diffusion

执行 stable-diffusion-webui 目录下的 webui-user.bat 文件
venv "G:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\venv\Scripts\Python.exe"
Python 3.10.6 | packaged by conda-forge | (main, Oct 24 2022, 16:02:16) [MSC v.1916 64 bit (AMD64)]
Version: v1.8.0
Commit hash: bef51aed032c0aaa5cfd80445bc4cf0d85b408b5
Launching Web UI with arguments: --no-half --xformers --no-half-vae --api --port 7860
Loading weights [6ce0161689] from G:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\models\Stable-diffusion\v1-5-pruned-emaonly.safetensors
Creating model from config: G:\stable-diffusion\stable-diffusion-webui\stable-diffusion-webui\configs\v1-inference.yaml
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
Startup time: 27.6s (prepare environment: 6.1s, import torch: 9.6s, import gradio: 2.2s, setup paths: 2.4s, initialize shared: 0.8s, other imports: 1.4s, load scripts: 2.5s, create ui: 0.7s, gradio launch: 1.4s, add APIs: 0.4s).
Applying attention optimization: xformers... done.
Model loaded in 6.1s (load weights from disk: 0.2s, create model: 1.0s, apply weights to model: 3.7s, apply float(): 0.1s, move model to device: 0.3s, load textual inversion embeddings: 0.2s, calculate empty prompt: 0.5s).

登录 dashboard

http://127.0.0.1:7860

Stable Diffusion 测试

参考文档

安装说明:https://github.com/AUTOMATIC1111/stable-diffusion-webui?tab=readme-ov-file#/automatic-installation-on-windows

xformers:https://github.com/facebookresearch/xformers

参数说明:https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Command-Line-Arguments-and-Settings

posted @ 2024-04-02 08:53  小吉猫  阅读(223)  评论(0编辑  收藏  举报