Stable Diffusion Web UIをCPUだけ実行し、APIを利用するまで

# 概要
AIで画像を生成するStable Diffusion＋CPUをローカルで簡単に動かせるような手順＋APIでの要求方法と整形方法についても合わせて紹介する。

Stable Diffusionの有償サービスとしての提供等もあり、そちらも簡単に利用できるが、今回は無償で利用できるローカル版のものにフォーカスする。

使用ターゲットとしては、以下を想定している。
- GPUなんて高価なマシンを用意できない。
- 通常マシンでちょっとだけ試したい。
- 時間が掛かってもある程度問題ないユースケース用。
- 
キレイなお姉様の画像をいつでも簡単に出力したい。


# ベースライン(環境前提)
以下の環境にて、インストールしたVMが用意された状態にて、実施する。

## 物理環境
- マシン : MacBook Pro 13-inch(2020)
- CPU : Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
- MEM : 16GB
- OS : macOS Sonoma 14.5
- 仮想化ソフトウェア : VMware Fusion
## 仮想化環境
- ゲストOS : Ubuntu 24.04.1 (Desktop/amd64)
- CPUコア数 : 2
- MEM : 6GB
- DISK : 50GB
- Language : English
- Installed : openssh-server, htop, vim, curl, caca-utils
## インストール対象
本項目は、以下のインストール手順により、インストールされる想定の主なパッケージや資材等の一覧になります。
- Python : 3.11 (Torch 2.1.2等含む)
- StableDiffusion WebUI : 1.10.0
- yayoi_mix : v25-fp16

# 注意点
インストール時に発生した問題点等を記載する。

- Python 3.11必要のため、Python 3.11を追加インストール必須
  - 現在のUbuntu 24.04.1は、『Python 3.12』が標準となっており、標準のリポジトリでは、変更や追加はできない。(Stable Diffusion WebUI ver.1.10に必要なtorchのバージョンが2.1.2だが、Python 3.12にインストールできるのは、2.2.0以降のバージョンで、Stable Diffusion WebUIのインストールや起動が行えない。)
- 『Stable diffusion model failed to load』エラーへの対応
    このエラーの場合、複数の原因が考えられるので、一つずつ確認してみてほしい。
  - メモリ不足の可能性
    - 割当メモリ量を増やす。
  - 『--no-half』オプション不足
    - 『webui-user.sh』の『COMMANDLINE_ARGS』に『--no-half』を記載する。
  - モデルの保存パスが誤っている。
    - 『./models/Stable-diffusion』ではなく、『stable-diffusion-webui/models/Stable-diffusion』にモデルをダウンロードすること。
  - モデルの形式(拡張子)が誤っている。
    - 『\*.ckpt』か、『\*.safetensors』の形式(拡張子)のファイルを読み込ませる。
  - 『v1-5-pruned-emaonly.safetensors』のダウンロード失敗
    - 起動後、何回かダウンロードを試行するが、ダウンロード先のリンクがうまく機能していないようで、こちらのファイルは現在参照できなくなっている。そのため、別途モデルをダウンロードする必要があります。(今回の手順では対応済み)




## エラーメッセージ例
<details><summary>『--no-half』オプション不足のエラーメッセージ例</summary>
```
    Stable diffusion model failed to load
Exception in thread Thread-2 (load_model):
Traceback (most recent call last):
  File "/usr/lib/python3.11/threading.py", line 1045, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.11/threading.py", line 982, in run
    self._target(*self._args, **self._kwargs)
  File "/home/nttdata/WORK/stable-diffusion-webui-1.10.0/stable-diffusion-webui/modules/initialize.py", line 154, in load_model
    devices.first_time_calculation()
  File "/home/nttdata/WORK/stable-diffusion-webui-1.10.0/stable-diffusion-webui/modules/devices.py", line 277, in first_time_calculation
    linear(x)
  File "/home/nttdata/WORK/venv_py3.11/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nttdata/WORK/venv_py3.11/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nttdata/WORK/stable-diffusion-webui-1.10.0/stable-diffusion-webui/extensions-builtin/Lora/networks.py", line 584, in network_Linear_forward
    return originals.Linear_forward(self, input)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nttdata/WORK/venv_py3.11/lib/python3.11/site-packages/torch/nn/modules/linear.py", line 114, in forward
    return F.linear(input, self.weight, self.bias)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: "addmm_impl_cpu_" not implemented for 'Half'
```
</details>


# インストールコマンド
Stable Diffusion WebUI(AUTOMATIC1111版)のインストール手順となります。基本的には、インタラクティブな入力を求められることがないように引数を調整しております。

```shell
## 事前パッケージインストール
sudo apt install -y git screen

## Install Python 3.11 on Ubuntu 24.04
sudo add-apt-repository -y ppa:deadsnakes/ppa
sudo apt update -y
sudo apt install -y python3.11 python3.11-venv

cd #別ディレクトリが良ければ、ここで指定してください。
mkdir WORK
cd WORK

python3.11 -m venv venv_py3.11
source venv_py3.11/bin/activate

## Download Stable Diffusion WebUI(AUTOMATIC1111版)
wget https://github.com/AUTOMATIC1111/stable-diffusion-webui/archive/refs/tags/v1.10.0.tar.gz -O stablediffusion_webui_v1.10.0.tar.gz
tar zxf stablediffusion_webui_v1.10.0.tar.gz

cd stable-diffusion-webui-1.10.0/
cp -p webui-user.sh webui-user.sh_original
echo 'export COMMANDLINE_ARGS="--skip-torch-cuda-test --upcast-sampling --no-half-vae --use-cpu interrogate  --precision full --no-half"' >> webui-user.sh
echo 'export python_cmd="python3.11"' >> webui-user.sh
diff webui-user.sh_original webui-user.sh

## Stable Diffusion WebUI起動(初回起動)
./webui.sh
##  timeout 900 ./webui.sh # (参考)15分で自動終了。
# 『Running on local URL:  http://127.0.0.1:7860』と表示されれば、Stable Diffusion Web UIの起動完了(初回起動は、10分程度を要した。よりスペックの悪いマシンやネットワーク環境(3GB程度ダウンロードが発生)が悪いともっと時間が掛かるかと思います。)。
# 起動完了後、『stable-diffusion-webui』のディレクトリで生成される。『Ctrl+c』を押下し、停止し、後続のモデルをダウンロードする。

wget "https://huggingface.co/Kotajiro/yayoi_mix/resolve/main/yayoi_mix_v25-fp16.safetensors?download=true" -O stable-diffusion-webui/models/Stable-diffusion/yayoi_mix_v25-fp16.safetensors # 2.2GB程度のダウンロード発生
```

## インストールコマンドの実行結果
<details><summary>インストールコマンドの実行結果(開く/閉じる)</summary>

```shell
Welcome to Ubuntu 24.04.1 LTS (GNU/Linux 6.8.0-41-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/pro

Expanded Security Maintenance for Applications is not enabled.

1 update can be applied immediately.
To see these additional updates run: apt list --upgradable

Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status

Last login: Sun Sep  1 20:56:26 2024 from 192.168.1.222
nttdata@UD2404:~$ ## 事前パッケージインストール
nttdata@UD2404:~$ sudo apt install -y git screen
[sudo] password for nttdata:
Sorry, try again.
[sudo] password for nttdata:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  git-man liberror-perl libutempter0
Suggested packages:
  git-daemon-run | git-daemon-sysvinit git-doc git-email git-gui gitk gitweb
  git-cvs git-mediawiki git-svn byobu | screenie | iselect
The following NEW packages will be installed:
  git git-man liberror-perl libutempter0 screen
0 upgraded, 5 newly installed, 0 to remove and 3 not upgraded.
Need to get 5469 kB of archives.
After this operation, 25.6 MB of additional disk space will be used.
Get:1 http://jp.archive.ubuntu.com/ubuntu noble/main amd64 liberror-perl all 0.17029-2 [25.6 kB]
Get:2 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 git-man all 1:2.43.0-1ubuntu7.1 [1100 kB]
Get:3 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 git amd64 1:2.43.0-1ubuntu7.1 [3679 kB]
Get:4 http://jp.archive.ubuntu.com/ubuntu noble/main amd64 libutempter0 amd64 1.2.1-3build1 [9606 B]
Get:5 http://jp.archive.ubuntu.com/ubuntu noble/main amd64 screen amd64 4.9.1-1build1 [655 kB]
Fetched 5469 kB in 4s (1539 kB/s)
Selecting previously unselected package liberror-perl.
(Reading database ... 153073 files and directories currently installed.)
Preparing to unpack .../liberror-perl_0.17029-2_all.deb ...
Unpacking liberror-perl (0.17029-2) ...
Selecting previously unselected package git-man.
Preparing to unpack .../git-man_1%3a2.43.0-1ubuntu7.1_all.deb ...
Unpacking git-man (1:2.43.0-1ubuntu7.1) ...
Selecting previously unselected package git.
Preparing to unpack .../git_1%3a2.43.0-1ubuntu7.1_amd64.deb ...
Unpacking git (1:2.43.0-1ubuntu7.1) ...
Selecting previously unselected package libutempter0:amd64.
Preparing to unpack .../libutempter0_1.2.1-3build1_amd64.deb ...
Unpacking libutempter0:amd64 (1.2.1-3build1) ...
Selecting previously unselected package screen.
Preparing to unpack .../screen_4.9.1-1build1_amd64.deb ...
Unpacking screen (4.9.1-1build1) ...
Setting up liberror-perl (0.17029-2) ...
Setting up libutempter0:amd64 (1.2.1-3build1) ...
Setting up git-man (1:2.43.0-1ubuntu7.1) ...
Setting up screen (4.9.1-1build1) ...
Setting up git (1:2.43.0-1ubuntu7.1) ...
Processing triggers for install-info (7.1-3build2) ...
Processing triggers for libc-bin (2.39-0ubuntu8.3) ...
Processing triggers for man-db (2.12.0-4build2) ...
Processing triggers for debianutils (5.17build1) ...
nttdata@UD2404:~$ # Install Python 3.11 on Ubuntu 24.04
nttdata@UD2404:~$ sudo add-apt-repository -y ppa:deadsnakes/ppa
Repository: 'Types: deb
URIs: https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu/
Suites: noble
Components: main
'
Description:
This PPA contains more recent Python versions packaged for Ubuntu.

Disclaimer: there's no guarantee of timely updates in case of security problems or other issues. If you want to use them in a security-or-otherwise-critical environment (say, on a production server), you do so at your own risk.

Update Note
===========
Please use this repository instead of ppa:fkrull/deadsnakes.

Reporting Issues
================

Issues can be reported in the master issue tracker at:
https://github.com/deadsnakes/issues/issues

Supported Ubuntu and Python Versions
====================================

- Ubuntu 20.04 (focal) Python3.5 - Python3.7, Python3.9 - Python3.13
- Ubuntu 22.04 (jammy) Python3.7 - Python3.9, Python3.11 - Python3.13
- Ubuntu 24.04 (noble) Python3.7 - Python3.11, Python3.13
- Note: Python2.7 (focal, jammy), Python 3.8 (focal), Python 3.10 (jammy), Python3.12 (noble) are not provided by deadsnakes as upstream ubuntu provides those packages.

Why some packages aren't built:
- Note: for focal, older python versions require libssl<1.1 so they are not currently built
- Note: for jammy and noble, older python versions requre libssl<3 so they are not currently built
- If you need these, reach out to asottile to set up a private ppa

The packages may also work on other versions of Ubuntu or Debian, but that is not tested or supported.

Packages
========

The packages provided here are loosely based on the debian upstream packages with some modifications to make them more usable as non-default pythons and on ubuntu.  As such, the packages follow debian's patterns and often do not include a full python distribution with just `apt install python#.#`.  Here is a list of packages that may be useful along with the default install:

- `python#.#-dev`: includes development headers for building C extensions
- `python#.#-venv`: provides the standard library `venv` module
- `python#.#-distutils`: provides the standard library `distutils` module
- `python#.#-lib2to3`: provides the `2to3-#.#` utility as well as the standard library `lib2to3` module
- `python#.#-gdbm`: provides the standard library `dbm.gnu` module
- `python#.#-tk`: provides the standard library `tkinter` module

Third-Party Python Modules
==========================

Python modules in the official Ubuntu repositories are packaged to work with the Python interpreters from the official repositories. Accordingly, they generally won't work with the Python interpreters from this PPA. As an exception, pure-Python modules for Python 3 will work, but any compiled extension modules won't.

To install 3rd-party Python modules, you should use the common Python packaging tools.  For an introduction into the Python packaging ecosystem and its tools, refer to the Python Packaging User Guide:
https://packaging.python.org/installing/

Sources
=======
The package sources are available at:
https://github.com/deadsnakes/

Nightly Builds
==============

For nightly builds, see ppa:deadsnakes/nightly https://launchpad.net/~deadsnakes/+archive/ubuntu/nightly
More info: https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa
Adding repository.
Hit:1 http://security.ubuntu.com/ubuntu noble-security InRelease
Hit:2 http://jp.archive.ubuntu.com/ubuntu noble InRelease
Get:3 http://jp.archive.ubuntu.com/ubuntu noble-updates InRelease [126 kB]
Get:4 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu noble InRelease [17.8 kB]
Hit:5 http://jp.archive.ubuntu.com/ubuntu noble-backports InRelease
Get:6 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu noble/main amd64 Packages [24.4 kB]
Get:7 http://jp.archive.ubuntu.com/ubuntu noble-updates/main amd64 Packages [469 kB]
Get:8 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu noble/main Translation-en [4952 B]
Get:9 http://jp.archive.ubuntu.com/ubuntu noble-updates/universe amd64 Packages [337 kB]
Fetched 979 kB in 4s (270 kB/s)
Reading package lists... Done
nttdata@UD2404:~$ sudo apt update -y
Hit:1 http://security.ubuntu.com/ubuntu noble-security InRelease
Hit:2 http://jp.archive.ubuntu.com/ubuntu noble InRelease
Hit:3 http://jp.archive.ubuntu.com/ubuntu noble-updates InRelease
Hit:4 http://jp.archive.ubuntu.com/ubuntu noble-backports InRelease
Hit:5 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu noble InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
3 packages can be upgraded. Run 'apt list --upgradable' to see them.
nttdata@UD2404:~$ sudo apt install -y python3.11 python3.11-venv
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libnsl2 libpython3.11-minimal libpython3.11-stdlib python3.11-distutils
  python3.11-lib2to3 python3.11-minimal
Suggested packages:
  binutils binfmt-support
The following NEW packages will be installed:
  libnsl2 libpython3.11-minimal libpython3.11-stdlib python3.11
  python3.11-distutils python3.11-lib2to3 python3.11-minimal python3.11-venv
0 upgraded, 8 newly installed, 0 to remove and 3 not upgraded.
Need to get 8749 kB of archives.
After this operation, 25.9 MB of additional disk space will be used.
Get:1 http://jp.archive.ubuntu.com/ubuntu noble/main amd64 libnsl2 amd64 1.3.0-3build3 [41.4 kB]
Get:2 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu noble/main amd64 libpython3.11-minimal amd64 3.11.9-1+noble3 [832 kB]
Get:3 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu noble/main amd64 python3.11-minimal amd64 3.11.9-1+noble3 [2163 kB]
Get:4 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu noble/main amd64 libpython3.11-stdlib amd64 3.11.9-1+noble3 [1879 kB]
Get:5 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu noble/main amd64 python3.11 amd64 3.11.9-1+noble3 [595 kB]
Get:6 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu noble/main amd64 python3.11-lib2to3 all 3.11.9-1+noble3 [82.5 kB]
Get:7 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu noble/main amd64 python3.11-distutils all 3.11.9-1+noble3 [138 kB]
Get:8 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu noble/main amd64 python3.11-venv amd64 3.11.9-1+noble3 [3018 kB]
Fetched 8749 kB in 14s (642 kB/s)
Selecting previously unselected package libpython3.11-minimal:amd64.
(Reading database ... 154225 files and directories currently installed.)
Preparing to unpack .../0-libpython3.11-minimal_3.11.9-1+noble3_amd64.deb ...
Unpacking libpython3.11-minimal:amd64 (3.11.9-1+noble3) ...
Selecting previously unselected package python3.11-minimal.
Preparing to unpack .../1-python3.11-minimal_3.11.9-1+noble3_amd64.deb ...
Unpacking python3.11-minimal (3.11.9-1+noble3) ...
Selecting previously unselected package libnsl2:amd64.
Preparing to unpack .../2-libnsl2_1.3.0-3build3_amd64.deb ...
Unpacking libnsl2:amd64 (1.3.0-3build3) ...
Selecting previously unselected package libpython3.11-stdlib:amd64.
Preparing to unpack .../3-libpython3.11-stdlib_3.11.9-1+noble3_amd64.deb ...
Unpacking libpython3.11-stdlib:amd64 (3.11.9-1+noble3) ...
Selecting previously unselected package python3.11.
Preparing to unpack .../4-python3.11_3.11.9-1+noble3_amd64.deb ...
Unpacking python3.11 (3.11.9-1+noble3) ...
Selecting previously unselected package python3.11-lib2to3.
Preparing to unpack .../5-python3.11-lib2to3_3.11.9-1+noble3_all.deb ...
Unpacking python3.11-lib2to3 (3.11.9-1+noble3) ...
Selecting previously unselected package python3.11-distutils.
Preparing to unpack .../6-python3.11-distutils_3.11.9-1+noble3_all.deb ...
Unpacking python3.11-distutils (3.11.9-1+noble3) ...
Selecting previously unselected package python3.11-venv.
Preparing to unpack .../7-python3.11-venv_3.11.9-1+noble3_amd64.deb ...
Unpacking python3.11-venv (3.11.9-1+noble3) ...
Setting up libnsl2:amd64 (1.3.0-3build3) ...
Setting up libpython3.11-minimal:amd64 (3.11.9-1+noble3) ...
Setting up python3.11-lib2to3 (3.11.9-1+noble3) ...
Setting up python3.11-minimal (3.11.9-1+noble3) ...
Setting up python3.11-distutils (3.11.9-1+noble3) ...
Setting up libpython3.11-stdlib:amd64 (3.11.9-1+noble3) ...
Setting up python3.11 (3.11.9-1+noble3) ...
Setting up python3.11-venv (3.11.9-1+noble3) ...
Processing triggers for gnome-menus (3.36.0-1.1ubuntu3) ...
Processing triggers for libc-bin (2.39-0ubuntu8.3) ...
Processing triggers for man-db (2.12.0-4build2) ...
Processing triggers for desktop-file-utils (0.27-2build1) ...
nttdata@UD2404:~$ cd #別ディレクトリが良ければ、ここで指定してください。
nttdata@UD2404:~$ mkdir WORK
nttdata@UD2404:~$ cd WORK
nttdata@UD2404:~/WORK$ python3.11 -m venv venv_py3.11
nttdata@UD2404:~/WORK$ source venv_py3.11/bin/activate
(venv_py3.11) nttdata@UD2404:~/WORK$ # Download Stable Diffusion WebUI(AUTOMATIC1111版)
(venv_py3.11) nttdata@UD2404:~/WORK$ wget https://github.com/AUTOMATIC1111/stable-diffusion-webui/archive/refs/tags/v1.10.0.tar.gz -O stablediffusion_webui_v1.10.0.tar.gz
--2024-09-01 21:35:45--  https://github.com/AUTOMATIC1111/stable-diffusion-webui/archive/refs/tags/v1.10.0.tar.gz
Resolving github.com (github.com)... 20.27.177.113
Connecting to github.com (github.com)|20.27.177.113|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/AUTOMATIC1111/stable-diffusion-webui/tar.gz/refs/tags/v1.10.0 [following]
--2024-09-01 21:35:46--  https://codeload.github.com/AUTOMATIC1111/stable-diffusion-webui/tar.gz/refs/tags/v1.10.0
Resolving codeload.github.com (codeload.github.com)... 20.27.177.114
Connecting to codeload.github.com (codeload.github.com)|20.27.177.114|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-gzip]
Saving to: ‘stablediffusion_webui_v1.10.0.tar.gz’

stablediffusion_web     [  <=>               ]   1.75M  5.15MB/s    in 0.3s

2024-09-01 21:35:46 (5.15 MB/s) - ‘stablediffusion_webui_v1.10.0.tar.gz’ saved [1840950]

(venv_py3.11) nttdata@UD2404:~/WORK$ tar zxf stablediffusion_webui_v1.10.0.tar.gz
(venv_py3.11) nttdata@UD2404:~/WORK$ cd stable-diffusion-webui-1.10.0/
(venv_py3.11) nttdata@UD2404:~/WORK/stable-diffusion-webui-1.10.0$ cp -p webui-user.sh webui-user.sh_original
(venv_py3.11) nttdata@UD2404:~/WORK/stable-diffusion-webui-1.10.0$ echo 'export COMMANDLINE_ARGS="--skip-torch-cuda-test --upcast-sampling --no-half-vae --use-cpu interrogate  --precision full --no-half"' >> webui-user.sh
(venv_py3.11) nttdata@UD2404:~/WORK/stable-diffusion-webui-1.10.0$ echo 'export python_cmd="python3.11"' >> webui-user.sh
(venv_py3.11) nttdata@UD2404:~/WORK/stable-diffusion-webui-1.10.0$ diff webui-user.sh_original webui-user.sh
48a49,50
> export COMMANDLINE_ARGS="--skip-torch-cuda-test --upcast-sampling --no-half-vae --use-cpu interrogate  --precision full --no-half"
> export python_cmd="python3.11"
(venv_py3.11) nttdata@UD2404:~/WORK/stable-diffusion-webui-1.10.0$ timeout 900 ./webui.sh

################################################################
Install script for stable-diffusion + Web UI
Tested on Debian 11 (Bullseye), Fedora 34+ and openSUSE Leap 15.4 or newer.
################################################################

################################################################
Running on nttdata user
################################################################

################################################################
Clone stable-diffusion-webui
################################################################
Cloning into 'stable-diffusion-webui'...
remote: Enumerating objects: 34506, done.
remote: Counting objects: 100% (116/116), done.
remote: Compressing objects: 100% (86/86), done.
remote: Total 34506 (delta 65), reused 56 (delta 28), pack-reused 34390 (from 1)
Receiving objects: 100% (34506/34506), 35.22 MiB | 4.77 MiB/s, done.
Resolving deltas: 100% (24134/24134), done.

################################################################
python venv already activate or run without venv: /home/nttdata/WORK/venv_py3.11
################################################################

################################################################
Launching launch.py...
################################################################
glibc version is 2.39
Cannot locate TCMalloc. Do you have tcmalloc or google-perftool installed on your system? (improves CPU memory usage)
Python 3.11.9 (main, Apr 27 2024, 21:16:11) [GCC 13.2.0]
Version: v1.10.1
Commit hash: 82a973c04367123ae98bd9abdf80d9eda9b910e2
Installing torch and torchvision
Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/cu121
Collecting torch==2.1.2
  Downloading https://download.pytorch.org/whl/cu121/torch-2.1.2%2Bcu121-cp311-cp311-linux_x86_64.whl (2200.7 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.2/2.2 GB 665.2 kB/s eta 0:00:00
Collecting torchvision==0.16.2
  Downloading https://download.pytorch.org/whl/cu121/torchvision-0.16.2%2Bcu121-cp311-cp311-linux_x86_64.whl (6.8 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.8/6.8 MB 8.7 MB/s eta 0:00:00
Collecting filelock (from torch==2.1.2)
  Downloading filelock-3.15.4-py3-none-any.whl.metadata (2.9 kB)
Collecting typing-extensions (from torch==2.1.2)
  Downloading typing_extensions-4.12.2-py3-none-any.whl.metadata (3.0 kB)
Collecting sympy (from torch==2.1.2)
  Downloading sympy-1.13.2-py3-none-any.whl.metadata (12 kB)
Collecting networkx (from torch==2.1.2)
  Downloading networkx-3.3-py3-none-any.whl.metadata (5.1 kB)
Collecting jinja2 (from torch==2.1.2)
  Downloading jinja2-3.1.4-py3-none-any.whl.metadata (2.6 kB)
Collecting fsspec (from torch==2.1.2)
  Downloading fsspec-2024.6.1-py3-none-any.whl.metadata (11 kB)
Collecting triton==2.1.0 (from torch==2.1.2)
  Downloading https://download.pytorch.org/whl/triton-2.1.0-0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (89.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 89.2/89.2 MB 10.5 MB/s eta 0:00:00
Collecting numpy (from torchvision==0.16.2)
  Downloading numpy-2.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (60 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 60.9/60.9 kB 3.4 MB/s eta 0:00:00
Collecting requests (from torchvision==0.16.2)
  Downloading requests-2.32.3-py3-none-any.whl.metadata (4.6 kB)
Collecting pillow!=8.3.*,>=5.3.0 (from torchvision==0.16.2)
  Downloading pillow-10.4.0-cp311-cp311-manylinux_2_28_x86_64.whl.metadata (9.2 kB)
Collecting MarkupSafe>=2.0 (from jinja2->torch==2.1.2)
  Downloading https://download.pytorch.org/whl/MarkupSafe-2.1.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (28 kB)
Collecting charset-normalizer<4,>=2 (from requests->torchvision==0.16.2)
  Downloading charset_normalizer-3.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (33 kB)
Collecting idna<4,>=2.5 (from requests->torchvision==0.16.2)
  Downloading idna-3.8-py3-none-any.whl.metadata (9.9 kB)
Collecting urllib3<3,>=1.21.1 (from requests->torchvision==0.16.2)
  Downloading urllib3-2.2.2-py3-none-any.whl.metadata (6.4 kB)
Collecting certifi>=2017.4.17 (from requests->torchvision==0.16.2)
  Downloading certifi-2024.8.30-py3-none-any.whl.metadata (2.2 kB)
Collecting mpmath<1.4,>=1.1.0 (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 26.5 MB/s eta 0:00:00
Downloading pillow-10.4.0-cp311-cp311-manylinux_2_28_x86_64.whl (4.5 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.5/4.5 MB 9.1 MB/s eta 0:00:00
Downloading filelock-3.15.4-py3-none-any.whl (16 kB)
Downloading fsspec-2024.6.1-py3-none-any.whl (177 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 177.6/177.6 kB 27.1 MB/s eta 0:00:00
Downloading jinja2-3.1.4-py3-none-any.whl (133 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 133.3/133.3 kB 11.6 MB/s eta 0:00:00
Downloading networkx-3.3-py3-none-any.whl (1.7 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.7/1.7 MB 11.8 MB/s eta 0:00:00
Downloading numpy-2.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (16.3 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 16.3/16.3 MB 8.4 MB/s eta 0:00:00
Downloading requests-2.32.3-py3-none-any.whl (64 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 64.9/64.9 kB 6.5 MB/s eta 0:00:00
Downloading sympy-1.13.2-py3-none-any.whl (6.2 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.2/6.2 MB 9.7 MB/s eta 0:00:00
Downloading typing_extensions-4.12.2-py3-none-any.whl (37 kB)
Downloading certifi-2024.8.30-py3-none-any.whl (167 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 167.3/167.3 kB 15.3 MB/s eta 0:00:00
Downloading charset_normalizer-3.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (140 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 140.3/140.3 kB 7.7 MB/s eta 0:00:00
Downloading idna-3.8-py3-none-any.whl (66 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 66.9/66.9 kB 5.3 MB/s eta 0:00:00
Downloading urllib3-2.2.2-py3-none-any.whl (121 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 121.4/121.4 kB 8.7 MB/s eta 0:00:00
Installing collected packages: mpmath, urllib3, typing-extensions, sympy, pillow, numpy, networkx, MarkupSafe, idna, fsspec, filelock, charset-normalizer, certifi, triton, requests, jinja2, torch, torchvision
Successfully installed MarkupSafe-2.1.5 certifi-2024.8.30 charset-normalizer-3.3.2 filelock-3.15.4 fsspec-2024.6.1 idna-3.8 jinja2-3.1.4 mpmath-1.3.0 networkx-3.3 numpy-2.1.0 pillow-10.4.0 requests-2.32.3 sympy-1.13.2 torch-2.1.2+cu121 torchvision-0.16.2+cu121 triton-2.1.0 typing-extensions-4.12.2 urllib3-2.2.2

[notice] A new release of pip is available: 24.0 -> 24.2
[notice] To update, run: pip install --upgrade pip
Installing clip
Installing open_clip
Cloning assets into /home/nttdata/WORK/stable-diffusion-webui-1.10.0/stable-diffusion-webui/repositories/stable-diffusion-webui-assets...
Cloning into '/home/nttdata/WORK/stable-diffusion-webui-1.10.0/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 (from 0)
Receiving objects: 100% (20/20), 132.70 KiB | 1021.00 KiB/s, done.
Cloning Stable Diffusion into /home/nttdata/WORK/stable-diffusion-webui-1.10.0/stable-diffusion-webui/repositories/stable-diffusion-stability-ai...
Cloning into '/home/nttdata/WORK/stable-diffusion-webui-1.10.0/stable-diffusion-webui/repositories/stable-diffusion-stability-ai'...
remote: Enumerating objects: 580, done.
remote: Total 580 (delta 0), reused 0 (delta 0), pack-reused 580 (from 1)
Receiving objects: 100% (580/580), 73.44 MiB | 4.43 MiB/s, done.
Resolving deltas: 100% (282/282), done.
Cloning Stable Diffusion XL into /home/nttdata/WORK/stable-diffusion-webui-1.10.0/stable-diffusion-webui/repositories/generative-models...
Cloning into '/home/nttdata/WORK/stable-diffusion-webui-1.10.0/stable-diffusion-webui/repositories/generative-models'...
remote: Enumerating objects: 1064, done.
remote: Counting objects: 100% (123/123), done.
remote: Compressing objects: 100% (75/75), done.
remote: Total 1064 (delta 55), reused 94 (delta 47), pack-reused 941 (from 1)
Receiving objects: 100% (1064/1064), 53.61 MiB | 4.49 MiB/s, done.
Resolving deltas: 100% (544/544), done.
Cloning K-diffusion into /home/nttdata/WORK/stable-diffusion-webui-1.10.0/stable-diffusion-webui/repositories/k-diffusion...
Cloning into '/home/nttdata/WORK/stable-diffusion-webui-1.10.0/stable-diffusion-webui/repositories/k-diffusion'...
remote: Enumerating objects: 1345, done.
remote: Counting objects: 100% (1345/1345), done.
remote: Compressing objects: 100% (443/443), done.
remote: Total 1345 (delta 947), reused 1249 (delta 895), pack-reused 0 (from 0)
Receiving objects: 100% (1345/1345), 232.84 KiB | 4.48 MiB/s, done.
Resolving deltas: 100% (947/947), done.
Cloning BLIP into /home/nttdata/WORK/stable-diffusion-webui-1.10.0/stable-diffusion-webui/repositories/BLIP...
Cloning into '/home/nttdata/WORK/stable-diffusion-webui-1.10.0/stable-diffusion-webui/repositories/BLIP'...
remote: Enumerating objects: 277, done.
remote: Counting objects: 100% (183/183), done.
remote: Compressing objects: 100% (46/46), done.
remote: Total 277 (delta 145), reused 137 (delta 137), pack-reused 94 (from 1)
Receiving objects: 100% (277/277), 7.04 MiB | 3.21 MiB/s, done.
Resolving deltas: 100% (152/152), done.
Installing requirements
Launching Web UI with arguments: --skip-torch-cuda-test --upcast-sampling --no-half-vae --use-cpu interrogate --precision full --no-half
no module 'xformers'. Processing without...
no module 'xformers'. Processing without...
No module 'xformers'. Proceeding without it.
Warning: caught exception 'Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from http://www.nvidia.com/Download/index.aspx', memory monitor disabled
Downloading: "https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors" to /home/nttdata/WORK/stable-diffusion-webui-1.10.0/stable-diffusion-webui/models/Stable-diffusion/v1-5-pruned-emaonly.safetensors

loading stable diffusion model: FileNotFoundError
Traceback (most recent call last):
  File "/usr/lib/python3.11/threading.py", line 1002, in _bootstrap
    self._bootstrap_inner()
  File "/usr/lib/python3.11/threading.py", line 1045, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.11/threading.py", line 982, in run
    self._target(*self._args, **self._kwargs)
  File "/home/nttdata/WORK/stable-diffusion-webui-1.10.0/stable-diffusion-webui/modules/initialize.py", line 149, in load_model
    shared.sd_model  # noqa: B018
  File "/home/nttdata/WORK/stable-diffusion-webui-1.10.0/stable-diffusion-webui/modules/shared_items.py", line 175, in sd_model
    return modules.sd_models.model_data.get_sd_model()
  File "/home/nttdata/WORK/stable-diffusion-webui-1.10.0/stable-diffusion-webui/modules/sd_models.py", line 693, in get_sd_model
    load_model()
  File "/home/nttdata/WORK/stable-diffusion-webui-1.10.0/stable-diffusion-webui/modules/sd_models.py", line 788, in load_model
    checkpoint_info = checkpoint_info or select_checkpoint()
                                         ^^^^^^^^^^^^^^^^^^^
  File "/home/nttdata/WORK/stable-diffusion-webui-1.10.0/stable-diffusion-webui/modules/sd_models.py", line 234, in select_checkpoint
    raise FileNotFoundError(error_message)
FileNotFoundError: No checkpoints found. When searching for checkpoints, looked at:
 - file /home/nttdata/WORK/stable-diffusion-webui-1.10.0/stable-diffusion-webui/model.ckpt
 - directory /home/nttdata/WORK/stable-diffusion-webui-1.10.0/stable-diffusion-webui/models/Stable-diffusionCan't run without a checkpoint. Find and place a .ckpt or .safetensors file into any of those locations.


Stable diffusion model failed to load
Applying attention optimization: InvokeAI... done.
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
Startup time: 606.3s (prepare environment: 587.5s, import torch: 8.9s, import gradio: 1.4s, setup paths: 1.9s, initialize shared: 0.4s, other imports: 1.6s, list SD models: 0.6s, load scripts: 2.2s, create ui: 1.3s, gradio launch: 0.3s).
(venv_py3.11) nttdata@UD2404:~/WORK/stable-diffusion-webui-1.10.0$ wget "https://huggingface.co/Kotajiro/yayoi_mix/resolve/main/yayoi_mix_v25-fp16.safetensors?download=true" -O stable-diffusion-webui/models/Stable-diffusion/yayoi_mix_v25-fp16.safetensors # 2.2GB程度のダウンロード発生
--2024-09-01 22:02:10--  https://huggingface.co/Kotajiro/yayoi_mix/resolve/main/yayoi_mix_v25-fp16.safetensors?download=true
Resolving huggingface.co (huggingface.co)... 3.164.110.114, 3.164.110.128, 3.164.110.3, ...
Connecting to huggingface.co (huggingface.co)|3.164.110.114|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://cdn-lfs.huggingface.co/repos/2c/9a/2c9af21bb1767617fadf7e05b3570e1a14a3de1b66f24e29434ad034dd5b10f0/ca28aa4a449d07a23b15e239312cee95188c3ab4dd0808af7b8131bba48c506e?response-content-disposition=attachment%3B+filename*%3DUTF-8%27%27yayoi_mix_v25-fp16.safetensors%3B+filename%3D%22yayoi_mix_v25-fp16.safetensors%22%3B&Expires=1725454931&Policy=eyJTdGF0ZW1lbnQiOlt7IkNvbmRpdGlvbiI6eyJEYXRlTGVzc1RoYW4iOnsiQVdTOkVwb2NoVGltZSI6MTcyNTQ1NDkzMX19LCJSZXNvdXJjZSI6Imh0dHBzOi8vY2RuLWxmcy5odWdnaW5nZmFjZS5jby9yZXBvcy8yYy85YS8yYzlhZjIxYmIxNzY3NjE3ZmFkZjdlMDViMzU3MGUxYTE0YTNkZTFiNjZmMjRlMjk0MzRhZDAzNGRkNWIxMGYwL2NhMjhhYTRhNDQ5ZDA3YTIzYjE1ZTIzOTMxMmNlZTk1MTg4YzNhYjRkZDA4MDhhZjdiODEzMWJiYTQ4YzUwNmU%7EcmVzcG9uc2UtY29udGVudC1kaXNwb3NpdGlvbj0qIn1dfQ__&Signature=n3RQu0oJs93HET97w7ONLFj9%7EePqOA505cXHp5GEVY-i0poG7JyLSE2Pmr590Xo-FAbLpgSx7NP3GKl%7EJGB4V-kvjKDpf4%7Edb3moFKt76IFev6ok5TVFgR2Yp71uDA6EMQmJIt5aud74lWo4P1b8TWL6BXBt8Fga6OBfcKfgkR7eBgsdcgX8nHMA7E4VX5o8An8oOLUMfwltzoQoptV6vnNwGxjKM1vhD8GgbYvy3mzdtSowA1l2joybY3fej0szDjHG4vS-z37P473Oo3KLvFf36G2YQBBPnYL3DXnb990RM0gkKuGFYzvZ3ECb7CEMW9lp8RG7lr0WX27GWM35eA__&Key-Pair-Id=K3ESJI6DHPFC7 [following]
--2024-09-01 22:02:11--  https://cdn-lfs.huggingface.co/repos/2c/9a/2c9af21bb1767617fadf7e05b3570e1a14a3de1b66f24e29434ad034dd5b10f0/ca28aa4a449d07a23b15e239312cee95188c3ab4dd0808af7b8131bba48c506e?response-content-disposition=attachment%3B+filename*%3DUTF-8%27%27yayoi_mix_v25-fp16.safetensors%3B+filename%3D%22yayoi_mix_v25-fp16.safetensors%22%3B&Expires=1725454931&Policy=eyJTdGF0ZW1lbnQiOlt7IkNvbmRpdGlvbiI6eyJEYXRlTGVzc1RoYW4iOnsiQVdTOkVwb2NoVGltZSI6MTcyNTQ1NDkzMX19LCJSZXNvdXJjZSI6Imh0dHBzOi8vY2RuLWxmcy5odWdnaW5nZmFjZS5jby9yZXBvcy8yYy85YS8yYzlhZjIxYmIxNzY3NjE3ZmFkZjdlMDViMzU3MGUxYTE0YTNkZTFiNjZmMjRlMjk0MzRhZDAzNGRkNWIxMGYwL2NhMjhhYTRhNDQ5ZDA3YTIzYjE1ZTIzOTMxMmNlZTk1MTg4YzNhYjRkZDA4MDhhZjdiODEzMWJiYTQ4YzUwNmU%7EcmVzcG9uc2UtY29udGVudC1kaXNwb3NpdGlvbj0qIn1dfQ__&Signature=n3RQu0oJs93HET97w7ONLFj9%7EePqOA505cXHp5GEVY-i0poG7JyLSE2Pmr590Xo-FAbLpgSx7NP3GKl%7EJGB4V-kvjKDpf4%7Edb3moFKt76IFev6ok5TVFgR2Yp71uDA6EMQmJIt5aud74lWo4P1b8TWL6BXBt8Fga6OBfcKfgkR7eBgsdcgX8nHMA7E4VX5o8An8oOLUMfwltzoQoptV6vnNwGxjKM1vhD8GgbYvy3mzdtSowA1l2joybY3fej0szDjHG4vS-z37P473Oo3KLvFf36G2YQBBPnYL3DXnb990RM0gkKuGFYzvZ3ECb7CEMW9lp8RG7lr0WX27GWM35eA__&Key-Pair-Id=K3ESJI6DHPFC7
Resolving cdn-lfs.huggingface.co (cdn-lfs.huggingface.co)... 13.33.174.80, 13.33.174.84, 13.33.174.55, ...
Connecting to cdn-lfs.huggingface.co (cdn-lfs.huggingface.co)|13.33.174.80|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2132626066 (2.0G) [binary/octet-stream]
Saving to: ‘stable-diffusion-webui/models/Stable-diffusion/yayoi_mix_v25-fp16.safetensors’

stable-diffusion-we 100%[===================>]   1.99G  14.8MB/s    in 2m 27s

2024-09-01 22:04:37 (13.9 MB/s) - ‘stable-diffusion-webui/models/Stable-diffusion/yayoi_mix_v25-fp16.safetensors’ saved [2132626066/2132626066]

(venv_py3.11) nttdata@UD2404:~/WORK/stable-diffusion-webui-1.10.0$ ./webui.sh

################################################################
Install script for stable-diffusion + Web UI
Tested on Debian 11 (Bullseye), Fedora 34+ and openSUSE Leap 15.4 or newer.
################################################################

################################################################
Running on nttdata user
################################################################

################################################################
python venv already activate or run without venv: /home/nttdata/WORK/venv_py3.11
################################################################

################################################################
Launching launch.py...
################################################################
glibc version is 2.39
Cannot locate TCMalloc. Do you have tcmalloc or google-perftool installed on your system? (improves CPU memory usage)
Python 3.11.9 (main, Apr 27 2024, 21:16:11) [GCC 13.2.0]
Version: v1.10.1
Commit hash: 82a973c04367123ae98bd9abdf80d9eda9b910e2
Launching Web UI with arguments: --skip-torch-cuda-test --upcast-sampling --no-half-vae --use-cpu interrogate --precision full --no-half
no module 'xformers'. Processing without...
no module 'xformers'. Processing without...
No module 'xformers'. Proceeding without it.
Warning: caught exception 'Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from http://www.nvidia.com/Download/index.aspx', memory monitor disabled
Calculating sha256 for /home/nttdata/WORK/stable-diffusion-webui-1.10.0/stable-diffusion-webui/models/Stable-diffusion/yayoi_mix_v25-fp16.safetensors: Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
Startup time: 15.6s (prepare environment: 0.2s, import torch: 7.1s, import gradio: 1.8s, setup paths: 2.3s, initialize shared: 0.2s, other imports: 1.4s, load scripts: 0.9s, create ui: 1.2s, gradio launch: 0.3s).
ca28aa4a449d07a23b15e239312cee95188c3ab4dd0808af7b8131bba48c506e
Loading weights [ca28aa4a44] from /home/nttdata/WORK/stable-diffusion-webui-1.10.0/stable-diffusion-webui/models/Stable-diffusion/yayoi_mix_v25-fp16.safetensors
Creating model from config: /home/nttdata/WORK/stable-diffusion-webui-1.10.0/stable-diffusion-webui/configs/v1-inference.yaml
/home/nttdata/WORK/venv_py3.11/lib/python3.11/site-packages/huggingface_hub/file_download.py:1150: FutureWarning: `resume_download` is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use `force_download=True`.
  warnings.warn(
vocab.json: 100%|████████████████████████████| 961k/961k [00:00<00:00, 10.1MB/s]
merges.txt: 100%|████████████████████████████| 525k/525k [00:00<00:00, 1.19MB/s]
special_tokens_map.json: 100%|█████████████████| 389/389 [00:00<00:00, 2.60MB/s]
tokenizer_config.json: 100%|███████████████████| 905/905 [00:00<00:00, 1.16MB/s]
config.json: 100%|█████████████████████████| 4.52k/4.52k [00:00<00:00, 10.8MB/s]
Applying attention optimization: InvokeAI... done.
Model loaded in 81.8s (calculate hash: 8.0s, load weights from disk: 0.3s, create model: 4.1s, apply weights to model: 34.8s, apply float(): 30.6s, apply dtype to VAE: 0.7s, load weights from state dict: 0.8s, move model to device: 0.1s, hijack: 1.1s, load textual inversion embeddings: 0.4s, calculate empty prompt: 0.8s).
^CInterrupted with signal 2 in <frame at 0x785bb2f2e260, file '/usr/lib/python3.11/threading.py', line 331, code wait>
^C^C^C^C^C(venv_py3.11) nttdata@UD2404:~/WORK/stable-diffusion-webui-1.10.0$ ^C
(venv_py3.11) nttdata@UD2404:~/WORK/stable-diffusion-webui-1.10.0$ exit
logout
Connection to 192.168.1.37 closed.
```
</details>




# 起動コマンド
以下のコマンドで、Stable Diffusion WebUIを起動することができます。

```shell
## screen起動
screen -S sd

## Stable Diffusion WebUI起動
cd
cd WORK
source venv_py3.11/bin/activate
cd stable-diffusion-webui-1.10.0/
./webui.sh
# 『Running on local URL:  http://127.0.0.1:7860』と表示されれば、Stable Diffusion Web UIの起動完了。

## screenで起動しているので、ターミナルウインドウを閉じても続行されます。screenを抜けるには、『Ctrl+a d (デタッチ)』で抜けるか、screenを『Ctrl+c』＋『exit』で終了する。
```

## 起動コマンドの実行結果
<details><summary>起動コマンドの実行結果(開く/閉じる)</summary>

```shell
Last login: Sun Sep  1 22:49:51 2024 from 192.168.1.222
nttdata@UD2404:~$ ## screen起動
nttdata@UD2404:~$ screen -S sd
nttdata@UD2404:~$ ## Stable Diffusion WebUI起動
nttdata@UD2404:~$ cd
nttdata@UD2404:~$ cd WORK
nttdata@UD2404:~/WORK$ source venv_py3.11/bin/activate
(venv_py3.11) nttdata@UD2404:~/WORK$ cd stable-diffusion-webui-1.10.0/
(venv_py3.11) nttdata@UD2404:~/WORK/stable-diffusion-webui-1.10.0$ ./webui.sh

################################################################
Install script for stable-diffusion + Web UI
Tested on Debian 11 (Bullseye), Fedora 34+ and openSUSE Leap 15.4 or newer.
################################################################

################################################################
Running on nttdata user
################################################################

################################################################
python venv already activate or run without venv: /home/nttdata/WORK/venv_py3.11
################################################################

################################################################
Launching launch.py...
################################################################
glibc version is 2.39
Cannot locate TCMalloc. Do you have tcmalloc or google-perftool installed on your system? (improves CPU memory usage)
Python 3.11.9 (main, Apr 27 2024, 21:16:11) [GCC 13.2.0]
Version: v1.10.1
Commit hash: 82a973c04367123ae98bd9abdf80d9eda9b910e2
Launching Web UI with arguments: --skip-torch-cuda-test --upcast-sampling --no-half-vae --use-cpu interrogate --precision full --no-half
no module 'xformers'. Processing without...
no module 'xformers'. Processing without...
No module 'xformers'. Proceeding without it.
Warning: caught exception 'Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from http://www.nvidia.com/Download/index.aspx', memory monitor disabled
Loading weights [ca28aa4a44] from /home/nttdata/WORK/stable-diffusion-webui-1.10.0/stable-diffusion-webui/models/Stable-diffusion/yayoi_mix_v25-fp16.safetensors
Creating model from config: /home/nttdata/WORK/stable-diffusion-webui-1.10.0/stable-diffusion-webui/configs/v1-inference.yaml
Running on local URL:  http://127.0.0.1:7860
/home/nttdata/WORK/venv_py3.11/lib/python3.11/site-packages/huggingface_hub/file_download.py:1150: FutureWarning: `resume_download` is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use `force_download=True`.
  warnings.warn(

To create a public link, set `share=True` in `launch()`.
/home/nttdata/WORK/venv_py3.11/lib/python3.11/site-packages/huggingface_hub/file_download.py:1150: FutureWarning: `resume_download` is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use `force_download=True`.
  warnings.warn(
Startup time: 34.6s (prepare environment: 0.3s, import torch: 15.2s, import gradio: 3.6s, setup paths: 6.4s, initialize shared: 0.5s, other imports: 4.0s, load scripts: 1.1s, initialize extra networks: 0.2s, create ui: 2.5s, gradio launch: 0.7s).
Applying attention optimization: InvokeAI... done.
Model loaded in 32.7s (load weights from disk: 2.5s, create model: 2.8s, apply weights to model: 21.9s, apply float(): 4.9s, apply dtype to VAE: 0.1s, calculate empty prompt: 0.3s).
```

</details>

# Stable Diffusion WebUIの利用方法
## Stable Diffusion WebUIの接続方法
『Ubuntu 24.04.1(Desktop)』のFirefoxを起動し、『 http://localhost:7860 』へアクセスすると、以下のような画面が表示され、Stable Diffusionの利用が可能です。
※ デフォルト設定では、127.0.0.1でLISTENされており、別マシンからのアクセスはできません。

## 初期表示画面
![Stable Diffusion WebUIの初期画面](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3455334/db53d382-5be5-9eec-a609-a2da6aaec578.png "Stable Diffusion WebUIの初期画面")


## Stable Diffusionの実行結果
実行時間は、13分27秒でした。時間は掛かりますが、まだ現実的な時間内で完了していました。


![Stable Diffusion WebUIの実行結果画面](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3455334/10f3f0c1-8c09-f088-a156-5c0772435cfb.png "Stable Diffusion WebUIの実行結果画面")


# API利用方法
APIを利用するためには、Stable Diffusion WebUIのAPIに対して、リクエストJSONを送付して、返り値として、レスポンスJSONを取得して、そこに含まれているPNG画像を取り出す。その方法を以下にコマンドで記載する。

## Stable Diffusion WebUIのAPI取得用のコマンド
```shell
## 画像生成要求
cd
cd WORK
curl -XPOST -H "Content-Type: application/json" http://localhost:7860/sdapi/v1/txt2img -d '{"prompt":"Beautiful woman, Japanese actress, swimsuit, looking us and smiling, upper half of the body, incredibly detailed face, incredibly detailed beautiful eye, focus on face, masterpiece, high quality, best quality, highly detailed, insanely detailed, 4K", "negative":"3d, 3d render, painting, digital painting, watermark, sepia, black & white,NG_DeepNegative_V1_75T, EasyNegative,(worst quality:2), (low quality:2), (normal quality:2), lowres, normal quality, ((monochrome)), ((grayscale)),(ugly:1.33)","steps":"20"}' > response_sd.json

## 取得したJSONを整形し、PNGイメージファイルを生成。
cat response_sd.json | jq -r -e ".images[]" | base64 -d > response_sd.png

## 画面に表示
open response_sd.png # Ubuntu DesktopのGUI上のImage Viewerで表示される。
# img2txt response_sd.png # コマンドラインで画像を見れるツール。ですが、大分粗いので心の目で見てください。
```

# さいごに
GPUが搭載されていないCPUのみのマシンのみで、Stable Diffusionである程度きれいな画像を生成することができました。※ 無事にキレイな画像(
お姉様
)を出力できました。

利用用途によっては、CPUでも十分利用可能かと思います。

簡単に利用開始可能で、無償で利用できますので、PowerAutomateなどを活用して、色んなアプリケーションを作っていって頂けたらと思います。



# 参考文献
- yayoi_mix (今回利用しているモデル) : https://huggingface.co/Kotajiro/yayoi_mix/tree/main
- プロンプトのコピー元(コピペ可とのことでしたので利用させて頂きました🙇‍♂) : https://romptn.com/article/10844
- AUTOMATIC1111のStable Diffusionの配布サイト : https://github.com/AUTOMATIC1111/stable-diffusion-webui




<!-- https://soroban.highreso.jp/article/article-040#651d3601d90c7102d4621e0a-74f77511ad4d6459d0edd167 -->
<!-- https://highreso.jp/edgehub/stablediffusion/stablediffusioncpu.html -->