Closed13

Stable Diffusion web UIのセットアップメモ

ピン留めされたアイテム
fumiofumio

メモ:

  • 数をこなす場合は512x512で良さそう。解像度を上げた場合に要する時間に見合わないイメージ。
    • その場合は、引き延ばしやアップスケールを別途用いるべき。
  • VAEを試す
  • RTX4090なのでAD世代向けの最適化を試したい
fumiofumio

ひとまず導入するモデルは OedoSoldier/aniflatmix とする。(試したいワークフローで使用していたため)

webui\models\Stable-diffusion にDLした aniflatmixV2.safetensorsを配置。
(VAEがある場合は、 webui\models\VAE へ配置必要)

fumiofumio

sd.webui\update.bat を実行。
ログは下記。batの中を確認したが、普通にresetしてpullしてるだけの模様。

Updating 48a15821..5ab7f213
Fast-forward
 .github/ISSUE_TEMPLATE/bug_report.yml              |   29 +-
 .github/workflows/run_tests.yaml                   |    2 +-
 .gitignore                                         |    3 +-
 CHANGELOG.md                                       |   62 +
 README.md                                          |   32 +-
 configs/instruct-pix2pix.yaml                      |   98 ++
 .../v1-inpainting-inference.yaml                   |   36 +-
 environment-wsl2.yaml                              |   10 +-
 extensions-builtin/LDSR/scripts/ldsr_model.py      |   20 +-
 extensions-builtin/Lora/extra_networks_lora.py     |    8 +-
 extensions-builtin/Lora/lora.py                    |  228 ++-
 extensions-builtin/Lora/scripts/lora_script.py     |   28 +-
 extensions-builtin/Lora/ui_extra_networks_lora.py  |   15 +-
 extensions-builtin/ScuNET/scripts/scunet_model.py  |   83 +-
 .../javascript/prompt-bracket-checker.js           |  128 +-
 html/extra-networks-card.html                      |    6 +-
 html/licenses.html                                 |  245 ++++
 javascript/aspectRatioOverlay.js                   |   49 +-
 javascript/contextMenus.js                         |   10 +-
 javascript/edit-attention.js                       |   40 +-
 javascript/extensions.js                           |   48 +-
 javascript/extraNetworks.js                        |  118 +-
 javascript/generationParams.js                     |    6 +-
 javascript/hints.js                                |   30 +-
 javascript/imageviewer.js                          |   97 +-
 javascript/imageviewerGamepad.js                   |   36 +
 javascript/notification.js                         |    2 +-
 javascript/progressbar.js                          |   73 +-
 javascript/ui.js                                   |  148 +-
 launch.py                                          |  154 ++-
 models/karlo/ViT-L-14_stats.th                     |  Bin 0 -> 7079 bytes
 modules/api/api.py                                 |  225 ++-
 modules/api/models.py                              |   32 +-
 modules/call_queue.py                              |    1 +
 modules/cmd_args.py                                |  104 ++
 modules/codeformer_model.py                        |    4 +-
 modules/config_states.py                           |  200 +++
 modules/deepbooru_model.py                         |    4 +-
 modules/devices.py                                 |  112 +-
 modules/esrgan_model_arch.py                       |    1 +
 modules/extensions.py                              |   82 +-
 modules/extra_networks_hypernet.py                 |    8 +-
 modules/extras.py                                  |   67 +-
 modules/generation_parameters_copypaste.py         |  239 +++-
 modules/gfpgan_model.py                            |    5 +-
 modules/hashes.py                                  |    8 +-
 modules/hypernetworks/hypernetwork.py              |   20 +-
 modules/images.py                                  |   94 +-
 modules/img2img.py                                 |   47 +-
 modules/interrogate.py                             |    6 +-
 modules/lowvram.py                                 |   10 +-
 modules/mac_specific.py                            |   59 +
 modules/memmon.py                                  |   12 +-
 modules/modelloader.py                             |   13 +-
 modules/models/diffusion/ddpm_edit.py              | 1459 ++++++++++++++++++++
 modules/models/diffusion/uni_pc/__init__.py        |    1 +
 modules/models/diffusion/uni_pc/sampler.py         |  100 ++
 modules/models/diffusion/uni_pc/uni_pc.py          |  857 ++++++++++++
 modules/ngrok.py                                   |   12 +
 modules/paths.py                                   |    7 +-
 modules/paths_internal.py                          |   23 +
 modules/postprocessing.py                          |    9 +-
 modules/processing.py                              |  163 ++-
 modules/progress.py                                |   18 +
 modules/realesrgan_model.py                        |   16 +-
 modules/safe.py                                    |    9 +-
 modules/script_callbacks.py                        |   51 +-
 modules/script_loading.py                          |   10 +-
 modules/scripts.py                                 |  114 +-
 modules/scripts_auto_postprocessing.py             |   42 +
 modules/scripts_postprocessing.py                  |   13 +-
 modules/sd_disable_initialization.py               |   17 +-
 modules/sd_hijack.py                               |   70 +-
 modules/sd_hijack_inpainting.py                    |   10 +-
 modules/sd_hijack_ip2p.py                          |   13 +
 modules/sd_hijack_optimizations.py                 |  229 ++-
 modules/sd_hijack_unet.py                          |   49 +
 modules/sd_hijack_utils.py                         |   28 +
 modules/sd_models.py                               |  312 +++--
 modules/sd_models_config.py                        |  119 ++
 modules/sd_samplers.py                             |  519 +------
 modules/sd_samplers_common.py                      |   72 +
 modules/sd_samplers_compvis.py                     |  220 +++
 modules/sd_samplers_kdiffusion.py                  |  386 ++++++
 modules/sd_vae.py                                  |    5 +-
 modules/sd_vae_approx.py                           |    5 +-
 modules/shared.py                                  |  247 ++--
 modules/shared_items.py                            |   23 +
 modules/styles.py                                  |   12 +-
 modules/sub_quadratic_attention.py                 |    4 +-
 modules/textual_inversion/dataset.py               |   58 +-
 modules/textual_inversion/preprocess.py            |   19 +-
 modules/textual_inversion/textual_inversion.py     |   36 +-
 modules/timer.py                                   |   38 +
 modules/txt2img.py                                 |    6 +-
 modules/ui.py                                      |  376 +++--
 modules/ui_common.py                               |   27 +-
 modules/ui_components.py                           |   52 +-
 modules/ui_extensions.py                           |  354 ++++-
 modules/ui_extra_networks.py                       |  168 ++-
 modules/ui_extra_networks_checkpoints.py           |   31 +
 modules/ui_extra_networks_hypernets.py             |   13 +-
 modules/ui_extra_networks_textual_inversion.py     |   14 +-
 modules/ui_postprocessing.py                       |    8 +-
 modules/upscaler.py                                |    5 +-
 requirements.txt                                   |    7 +-
 requirements_versions.txt                          |   15 +-
 script.js                                          |    8 +-
 scripts/custom_code.py                             |   63 +-
 scripts/img2imgalt.py                              |   34 +-
 scripts/loopback.py                                |  100 +-
 scripts/outpainting_mk_2.py                        |    2 +-
 scripts/poor_mans_outpainting.py                   |    2 +-
 scripts/postprocessing_upscale.py                  |   69 +-
 scripts/prompt_matrix.py                           |   47 +-
 scripts/xy_grid.py                                 |  498 -------
 scripts/xyz_grid.py                                |  715 ++++++++++
 style.css                                          |  871 ++++++------
 test/basic_features/extras_test.py                 |    8 +-
 test/basic_features/img2img_test.py                |    8 +-
 test/basic_features/txt2img_test.py                |    2 +
 test/server_poll.py                                |    6 +-
 webui-macos-env.sh                                 |    4 +-
 webui-user.sh                                      |    3 +
 webui.py                                           |  184 ++-
 webui.sh                                           |   24 +-
 126 files changed, 9340 insertions(+), 2976 deletions(-)
 create mode 100644 CHANGELOG.md
 create mode 100644 configs/instruct-pix2pix.yaml
 rename v2-inference-v.yaml => configs/v1-inpainting-inference.yaml (61%)
 create mode 100644 javascript/imageviewerGamepad.js
 create mode 100644 models/karlo/ViT-L-14_stats.th
 create mode 100644 modules/cmd_args.py
 create mode 100644 modules/config_states.py
 create mode 100644 modules/mac_specific.py
 create mode 100644 modules/models/diffusion/ddpm_edit.py
 create mode 100644 modules/models/diffusion/uni_pc/__init__.py
 create mode 100644 modules/models/diffusion/uni_pc/sampler.py
 create mode 100644 modules/models/diffusion/uni_pc/uni_pc.py
 create mode 100644 modules/paths_internal.py
 create mode 100644 modules/scripts_auto_postprocessing.py
 create mode 100644 modules/sd_hijack_ip2p.py
 create mode 100644 modules/sd_hijack_utils.py
 create mode 100644 modules/sd_models_config.py
 create mode 100644 modules/sd_samplers_common.py
 create mode 100644 modules/sd_samplers_compvis.py
 create mode 100644 modules/sd_samplers_kdiffusion.py
 create mode 100644 modules/shared_items.py
 create mode 100644 modules/timer.py
 create mode 100644 modules/ui_extra_networks_checkpoints.py
 delete mode 100644 scripts/xy_grid.py
 create mode 100644 scripts/xyz_grid.py
続行するには何かキーを押してください . . .
fumiofumio

update.bat実行後に、再度 run.batを実行。
ログは下記。

Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug  1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]
Commit hash: 5ab7f213bec2f816f9c5644becb32eb72c8ffb89
Fetching updates for Stable Diffusion...
Checking out commit for Stable Diffusion with hash: cf1d67a6fd5ea1aa600c4df58e5b47da45f6bdbf...
Installing requirements
Launching Web UI with arguments:
The cache for model files in Transformers v4.22.0 has been updated. Migrating your old cache. This is a one-time only operation. You can interrupt this and resume the migration later on by calling `transformers.utils.move_cache()`.
Moving 5 files to the new cache system
  0%|                                                                                            | 0/5 [00:00<?, ?it/s]G:\AI\StableDiffusionWebUI\sd.webui\system\python\lib\site-packages\huggingface_hub\file_download.py:133: UserWarning: `huggingface_hub` cache-system uses symlinks by default to efficiently store duplicated files but your machine does not support them in G:\AI\StableDiffusionWebUI\sd.webui\system\transformers-cache. Caching files will still work but in a degraded version that might require more space on your disk. This warning can be disabled by setting the `HF_HUB_DISABLE_SYMLINKS_WARNING` environment variable. For more details, see https://huggingface.co/docs/huggingface_hub/how-to-cache#limitations.
To support symlinks on Windows, you either need to activate Developer Mode or to run Python as an administrator. In order to see activate developer mode, see this article: https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development
  warnings.warn(message)
100%|████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:00<00:00,  5.29it/s]
No module 'xformers'. Proceeding without it.
==============================================================================
You are running torch 1.13.1+cu117.
The program is tested to work with torch 2.0.0.
To reinstall the desired version, run with commandline flag --reinstall-torch.
Beware that this will cause a lot of large files to be downloaded, as well as
there are reports of issues with training tab on the latest version.

Use --skip-version-check commandline argument to disable this check.
==============================================================================
Loading weights [b0d25db787] from G:\AI\StableDiffusionWebUI\sd.webui\webui\models\Stable-diffusion\aniflatmixV2.safetensors
Creating model from config: G:\AI\StableDiffusionWebUI\sd.webui\webui\configs\v1-inference.yaml
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
Applying cross attention optimization (Doggettx).
Textual inversion embeddings loaded(0):
Model loaded in 3.7s (load weights from disk: 0.2s, create model: 0.4s, apply weights to model: 0.8s, apply half(): 0.6s, move model to device: 0.5s, load textual inversion embeddings: 1.1s).
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
Startup time: 10.7s (import torch: 2.2s, import gradio: 1.0s, import ldm: 0.6s, other imports: 1.1s, load scripts: 0.8s, load SD checkpoint: 4.0s, create ui: 0.7s, gradio launch: 0.1s).
fumiofumio

ChatGPTで個人的に好きな風景のイメージのプロンプトを出力させて、txt2imgで出力をトライ。

ChatGPTへは下記で投げて、

Stable Diffusionで、アジアのきれいな砂浜を出力するためのプロンプトを考えてください。
下記が、詳細な出力する画像のイメージです。
- タイのPhiphi島のような、木々の緑色と、空と海の青色、砂浜の白色が映える画像。
- ところどころにアクセントとなる、ビビットな色の植物がある。
- 海から海岸線をみた構図。

英語に変換させ、

Generate an image of a beautiful Asian beach with Stable Diffusion. The image should showcase the greenery of trees, the blue colors of the sky and sea, and the white sands that are prominent in beaches like Phiphi Island in Thailand. Additionally, there should be accent plants of vivid colors placed throughout the image. The composition should be from the perspective of looking at the coastline from the sea.

Sampling method のみ、Model 推奨の DPM++ 2M Karras に変更し、
1920 x 1080 で出力。30秒ほどで下記が得られた。

fumiofumio

アップデート後の run.bat の下記コメントに気づいたので、

==============================================================================
You are running torch 1.13.1+cu117.
The program is tested to work with torch 2.0.0.
To reinstall the desired version, run with commandline flag --reinstall-torch.
Beware that this will cause a lot of large files to be downloaded, as well as
there are reports of issues with training tab on the latest version.

Use --skip-version-check commandline argument to disable this check.
==============================================================================

webui\webui-user.bat 内の COMMANDLINE_ARGS"--reinstall-torch" を付けて、run.batを再度実行。
※ 実行後は、COMMANDLINE_ARGS の右辺を空に戻しておく。

Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug  1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]
Commit hash: 5ab7f213bec2f816f9c5644becb32eb72c8ffb89
Installing torch and torchvision
Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/cu118
Collecting torch==2.0.0
  Downloading https://download.pytorch.org/whl/cu118/torch-2.0.0%2Bcu118-cp310-cp310-win_amd64.whl (2611.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.6/2.6 GB 1.1 MB/s eta 0:00:00
Collecting torchvision==0.15.1
  Downloading https://download.pytorch.org/whl/cu118/torchvision-0.15.1%2Bcu118-cp310-cp310-win_amd64.whl (4.9 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.9/4.9 MB 10.5 MB/s eta 0:00:00
Requirement already satisfied: filelock in g:\ai\stablediffusionwebui\sd.webui\system\python\lib\site-packages (from torch==2.0.0) (3.12.0)
Requirement already satisfied: typing-extensions in g:\ai\stablediffusionwebui\sd.webui\system\python\lib\site-packages (from torch==2.0.0) (4.5.0)
Collecting sympy (from torch==2.0.0)
  Downloading https://download.pytorch.org/whl/sympy-1.11.1-py3-none-any.whl (6.5 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.5/6.5 MB 21.8 MB/s eta 0:00:00
Requirement already satisfied: networkx in g:\ai\stablediffusionwebui\sd.webui\system\python\lib\site-packages (from torch==2.0.0) (3.1)
Requirement already satisfied: jinja2 in g:\ai\stablediffusionwebui\sd.webui\system\python\lib\site-packages (from torch==2.0.0) (3.1.2)
Requirement already satisfied: numpy in g:\ai\stablediffusionwebui\sd.webui\system\python\lib\site-packages (from torchvision==0.15.1) (1.23.5)
Requirement already satisfied: requests in g:\ai\stablediffusionwebui\sd.webui\system\python\lib\site-packages (from torchvision==0.15.1) (2.25.1)
Requirement already satisfied: pillow!=8.3.*,>=5.3.0 in g:\ai\stablediffusionwebui\sd.webui\system\python\lib\site-packages (from torchvision==0.15.1) (9.4.0)
Requirement already satisfied: MarkupSafe>=2.0 in g:\ai\stablediffusionwebui\sd.webui\system\python\lib\site-packages (from jinja2->torch==2.0.0) (2.1.2)
Requirement already satisfied: chardet<5,>=3.0.2 in g:\ai\stablediffusionwebui\sd.webui\system\python\lib\site-packages (from requests->torchvision==0.15.1) (4.0.0)
Requirement already satisfied: idna<3,>=2.5 in g:\ai\stablediffusionwebui\sd.webui\system\python\lib\site-packages (from requests->torchvision==0.15.1) (2.10)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in g:\ai\stablediffusionwebui\sd.webui\system\python\lib\site-packages (from requests->torchvision==0.15.1) (1.26.15)
Requirement already satisfied: certifi>=2017.4.17 in g:\ai\stablediffusionwebui\sd.webui\system\python\lib\site-packages (from requests->torchvision==0.15.1) (2022.12.7)
Collecting mpmath>=0.19 (from sympy->torch==2.0.0)
  Downloading mpmath-1.3.0-py3-none-any.whl (536 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 536.2/536.2 kB 8.5 MB/s eta 0:00:00
Installing collected packages: mpmath, sympy, torch, torchvision
  Attempting uninstall: torch
    Found existing installation: torch 1.13.1+cu117
    Uninstalling torch-1.13.1+cu117:
      Successfully uninstalled torch-1.13.1+cu117
  Attempting uninstall: torchvision
    Found existing installation: torchvision 0.14.1+cu117
    Uninstalling torchvision-0.14.1+cu117:
      Successfully uninstalled torchvision-0.14.1+cu117
Successfully installed mpmath-1.3.0 sympy-1.11.1 torch-2.0.0+cu118 torchvision-0.15.1+cu118
Installing requirements
Launching Web UI with arguments: --reinstall-torch
No module 'xformers'. Proceeding without it.
Loading weights [b0d25db787] from G:\AI\StableDiffusionWebUI\sd.webui\webui\models\Stable-diffusion\aniflatmixV2.safetensors
Creating model from config: G:\AI\StableDiffusionWebUI\sd.webui\webui\configs\v1-inference.yaml
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
Applying cross attention optimization (Doggettx).
Textual inversion embeddings loaded(0):
Model loaded in 3.8s (load weights from disk: 0.2s, create model: 0.5s, apply weights to model: 0.6s, apply half(): 0.7s, move model to device: 0.5s, load textual inversion embeddings: 1.4s).
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
Startup time: 9.4s (import torch: 1.3s, import gradio: 1.0s, import ldm: 0.4s, other imports: 1.0s, load scripts: 0.8s, load SD checkpoint: 4.1s, create ui: 0.6s, gradio launch: 0.1s).
fumiofumio

上記のreinstall-torch後に、512x512で human でtxt2imgを試したが、 1.76sまで速度向上。
えぐい。

このスクラップは6日前にクローズされました