Stable Diffusion は、ディープラーニング(深層学習)の Text-To-Image AIモデルです。
ブラウザ・インターフェイスの Stable Diffusion WebUI を使用して、テキスト プロンプトから画像を生成したり、テキスト プロンプトを使用して既存の画像を変更したりできます。
NVIDIA RTX Virtual Workstation は、NVIDIA RTXテクノロジーをサポートする仮想ワークステーションであり、ray tracing、AI-Denoising、Deep Learning Super Sampling(DLSS)などの高度な機能をクラウドベースの仮想環境に導入しています。最新世代の NVIDIA GPUをサポートすることで、可能な限り最高のパフォーマンスが得られるため、設計者とエンジニアは最高の作業をより迅速に作成できます。
ということで、NVIDIA RTX Virtual Workstation へ Stable Diffusion WebUI をインストールして、最新の画像生成モデル Stable Diffusion XL(SDXL) を使用して画像生成してみてみます。
今回使用する NVIDIA RTX Virtual Workstation は、Oracle Cloud Infrastructure (OCI) GPU インスタンスの、NVIDIA A10 Tensor Core GPU を搭載した VM.GPU.A10.1シェイプを使用します。
VM.GPU.A10.1シェイプは、15 個の OCPU、240 GB の CPU メモリ、24 Gbps のネットワーク帯域幅, 1 つの GPU と 24 GB の GPUメモリを備えています。
■ NVIDIA RTX Virtual Workstation インスタンス作成
Oracle Cloud Infrastructure (OCI) Web コンソールから作成します。
NVIDIA RTX Virtual Workstation はコンピュート・インスタンス作成画面で Marketplaceの中から選択して作成することができます。
1) 作成
Oracle Cloudの Webコンソールを使用して次のように、設定して作成
VM Image: NVIDIA RTX Virtual Workstation
Shape: VM.GPU.A10.1
boot volume size: 今回は256GB程度 ※絵画Modelのサイズが大きいので
・Market Place選択画面
Create compute instance画面にあるコンピュート・イメージを選択する項目で、Marketplace の中から NVIDIA RTX Virtual Workstationを選択して作成します。
・Create compute instance 全体画面
内容確認し、[Create]をクリックして作成
3) ログイン
Microsoft Remote Desktopで作成したインスタンスへ接続
■ NVIDIA ドライバー確認
PowerShellで nvidia-smi で GPU デバイスの状態を確認
PS C:\Windows\system32> nvidia-smi
Mon Oct 16 06:39:14 2023
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 536.25 Driver Version: 536.25 CUDA Version: 12.2 |
|-----------------------------------------+----------------------+----------------------+
| GPU Name TCC/WDDM | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+======================+======================|
| 0 NVIDIA A10 WDDM | 00000000:00:04.0 Off | 0 |
| 0% 28C P8 12W / 150W | 153MiB / 23028MiB | 2% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
+---------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=======================================================================================|
| 0 N/A N/A 836 C+G C:\Windows\System32\LogonUI.exe N/A |
| 0 N/A N/A 1196 C+G C:\Windows\System32\dwm.exe N/A |
| 0 N/A N/A 4792 C+G C:\Windows\explorer.exe N/A |
| 0 N/A N/A 6060 C+G C:\Windows\System32\dwm.exe N/A |
| 0 N/A N/A 6292 C+G ....Cortana_cw5n1h2txyewy\SearchUI.exe N/A |
| 0 N/A N/A 6996 C+G ...5n1h2txyewy\ShellExperienceHost.exe N/A |
+---------------------------------------------------------------------------------------+
■ Stable Diffusion web UI インストール
インストール方法は、GitHub の Stable Diffusion web UI を参考にインストールします。
・Automatic Installation on Windows
1. Install Python 3.10.6 (Newer version of Python does not support torch), checking "Add Python to PATH".
2. Install git.
3. Download the stable-diffusion-webui repository, for example by running git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
4. Run webui-user.bat from Windows Explorer as normal, non-administrator, user.
⚫︎ 1. Install Python 3.10.6
1) Python 3.10.6 をダウンロード
Webブラウザで Install Python 3.10.6 へ移動し、Windows installer (64-bit)をクリックしてダウンロード
今回ダウンロードされたファイルは次です
python-3.10.6-amd64.exe
2) インストール開始
ダウンロードしたファイルを右クリックして Administrator権限で実行
3) Install Python 3.10.6 (64-bit)画面
[Add Oython 3.10 to PATH]をクリックし、[Install Now]をクリック
4) Setup was successful画面
インストール完了
5) インストール確認
Powershell で 次のコマンドを実行し Python Versionを確認
PS C:\Windows\system32> python --version
Python 3.10.6
⚫︎ 2. Install git.
1) Git をダウンロード
Webブラウザで Git へ移動し、Click here to downloadをクリックしてダウンロード
今回ダウンロードされたファイルは次です
Git-2.42.0.2-32-bit.exe
2) インストール開始
ダウンロードしたファイルを右クリックして Administrator権限で実行
3) GNU General Public Licese 画面
問題なければ、Liceseに同意し、[Next]をクリック
4) Select Destination Location画面
インストール・ディレクトリを選択し、[Next]をクリック
この後すべてデフォルトで、[Next]をクリックしてインストールします。
5) Completing the Git Setup Wizard画面
[Finish]をクリックしインストール完了
6) インストール確認
Powershell で 次のコマンドを実行し Git Versionを確認
PS C:\Windows\system32> git -v
git version 2.42.0.windows.2
⚫︎ 3. Download the stable-diffusion-webui repository
1) インストール・ディレクトリ作成
今回、C:\StableDiffusion を PowerShellを使用して作成します。
PS C:\Windows\system32> mkdir C:\StableDiffusion
Directory: C:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 10/14/2023 4:36 AM StableDiffusion
2) stable-diffusion-webui repository ダウンロード
次のコマンドを使用して、Repository をダウンロード
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
・実行
PS C:\Windows\system32> cd C:\StableDiffusion\
PS C:\StableDiffusion> git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
Cloning into 'stable-diffusion-webui'...
remote: Enumerating objects: 27809, done.
remote: Counting objects: 100% (158/158), done.
remote: Compressing objects: 100% (84/84), done.
remote: Total 27809 (delta 97), reused 116 (delta 74), pack-reused 27651
Receiving objects: 100% (27809/27809), 32.47 MiB | 25.67 MiB/s, done.
Resolving deltas: 100% (19468/19468), done.
3) 確認
PS C:\StableDiffusion> ls
Directory: C:\StableDiffusion
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 10/15/2023 8:22 AM stable-diffusion-webui
PS C:\StableDiffusion> cd .\stable-diffusion-webui\
PS C:\StableDiffusion\stable-diffusion-webui> ls
Directory: C:\StableDiffusion\stable-diffusion-webui
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 10/15/2023 8:22 AM .github
d----- 10/15/2023 8:22 AM configs
d----- 10/15/2023 8:22 AM embeddings
d----- 10/15/2023 8:22 AM extensions
d----- 10/15/2023 8:22 AM extensions-builtin
d----- 10/15/2023 8:22 AM html
d----- 10/15/2023 8:22 AM javascript
d----- 10/15/2023 8:22 AM localizations
d----- 10/15/2023 8:22 AM models
d----- 10/15/2023 8:22 AM modules
d----- 10/15/2023 8:22 AM scripts
d----- 10/15/2023 8:22 AM test
d----- 10/15/2023 8:22 AM textual_inversion_templates
-a---- 10/15/2023 8:22 AM 51 .eslintignore
-a---- 10/15/2023 8:22 AM 3479 .eslintrc.js
-a---- 10/15/2023 8:22 AM 56 .git-blame-ignore-revs
-a---- 10/15/2023 8:22 AM 534 .gitignore
-a---- 10/15/2023 8:22 AM 122 .pylintrc
-a---- 10/15/2023 8:22 AM 33515 CHANGELOG.md
-a---- 10/15/2023 8:22 AM 250 CITATION.cff
-a---- 10/15/2023 8:22 AM 657 CODEOWNERS
-a---- 10/15/2023 8:22 AM 178 environment-wsl2.yaml
-a---- 10/15/2023 8:22 AM 1297 launch.py
-a---- 10/15/2023 8:22 AM 35240 LICENSE.txt
-a---- 10/15/2023 8:22 AM 196 package.json
-a---- 10/15/2023 8:22 AM 798 pyproject.toml
-a---- 10/15/2023 8:22 AM 11860 README.md
-a---- 10/15/2023 8:22 AM 52 requirements-test.txt
-a---- 10/15/2023 8:22 AM 360 requirements.txt
-a---- 10/15/2023 8:22 AM 541 requirements_versions.txt
-a---- 10/15/2023 8:22 AM 420577 screenshot.png
-a---- 10/15/2023 8:22 AM 4899 script.js
-a---- 10/15/2023 8:22 AM 21496 style.css
-a---- 10/15/2023 8:22 AM 687 webui-macos-env.sh
-a---- 10/15/2023 8:22 AM 92 webui-user.bat
-a---- 10/15/2023 8:22 AM 1380 webui-user.sh
-a---- 10/15/2023 8:22 AM 2223 webui.bat
-a---- 10/15/2023 8:22 AM 5471 webui.py
-a---- 10/15/2023 8:22 AM 8353 webui.sh
■ Stable Diffusion XL(SDXL) モデルのダウンロードと配置
Stable Diffusion web UIを起動する前に、絵画モデルをインストールしておきます。
今回 Stable Diffusion XL 画像生成モデルをインストールしてみてみます。
Stable Diffusion XL(SDXL) は、Stability AI社が開発した高画質な画像を生成してくれる最新のAI画像生成モデルです。
Stable Diffusion Web UI バージョンは、v1.5.0以降で対応しています。
⚫︎ SDXLの学習データ(モデルデータ)をダウンロード
1) ダウンロード
Stable Diffusion XL – SDXL 1.0 Modelのページから [Download SXL] をクリックして各種ダウンロードします。
・ Baseモデル: stable-diffusion-xl-base-1.0 から sd_xl_base_1.0.safetensors をダウンロード
・ Refinerモデル: stable-diffusion-xl-refiner-1.0 から sd_xl_refiner_1.0.safetensors をダウンロード
・ VAE: sdxl-vae から sdxl_vae.safetensors をダウンロード
2) インストール
取得したモデル、VAEを以下ディレクトリへ配置
・ モデル配置場所: "StableDiffusion\stable-diffusion-webui\models\Stable-diffusion"
・ VAE配置場所: "StableDiffusion\stable-diffusion-webui\models\VAE"
3) インストール確認
・モデル配置確認
PS C:> cd C:\StableDiffusion\stable-diffusion-webui\models\Stable-diffusion
PS C:\StableDiffusion\stable-diffusion-webui\models\Stable-diffusion> ls
Directory: C:\StableDiffusion\stable-diffusion-webui\models\Stable-diffusion
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 10/15/2023 8:22 AM 0 Put Stable Diffusion checkpoints here.txt
-a---- 10/15/2023 7:41 AM 6938078334 sd_xl_base_1.0_0.9vae.safetensors
-a---- 10/15/2023 7:42 AM 6075981930 sd_xl_refiner_1.0_0.9vae.safetensors
・VAE配置確認
PS C:> cd C:\StableDiffusion\stable-diffusion-webui\models\VAE
PS C:\StableDiffusion\stable-diffusion-webui\models\VAE> ls
Directory: C:\StableDiffusion\stable-diffusion-webui\models\VAE
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 10/15/2023 8:22 AM 0 Put VAE here.txt
-a---- 10/15/2023 2:13 PM 334641164 sdxl_vae.safetensors
■ Stable Diffusion WebUI 起動
⚫︎ Run webui-user.bat
webui-user.bat で Stable Diffusion web UIを起動
1) 実行
PS C:\StableDiffusion\stable-diffusion-webui> .\webui-user.bat
Creating venv in directory C:\StableDiffusion\stable-diffusion-webui\venv using python "C:\Users\opc\AppData\Local\Programs\Python\Python310\python.exe"
venv "C:\StableDiffusion\stable-diffusion-webui\venv\Scripts\Python.exe"
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug 1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]
Version: v1.6.0
Commit hash: 5ef669de080814067961f28357256e8fe27544f4
Installing torch and torchvision
Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/cu118
Collecting torch==2.0.1
Downloading https://download.pytorch.org/whl/cu118/torch-2.0.1%2Bcu118-cp310-cp310-win_amd64.whl (2619.1 MB)
---------------------------------------- 2.6/2.6 GB ? eta 0:00:00
Collecting torchvision==0.15.2
Downloading https://download.pytorch.org/whl/cu118/torchvision-0.15.2%2Bcu118-cp310-cp310-win_amd64.whl (4.9 MB)
---------------------------------------- 4.9/4.9 MB 105.0 MB/s eta 0:00:00
Collecting jinja2
Downloading https://download.pytorch.org/whl/Jinja2-3.1.2-py3-none-any.whl (133 kB)
---------------------------------------- 133.1/133.1 kB ? eta 0:00:00
Collecting networkx
Downloading networkx-3.1-py3-none-any.whl (2.1 MB)
---------------------------------------- 2.1/2.1 MB 66.5 MB/s eta 0:00:00
Collecting typing-extensions
Downloading typing_extensions-4.8.0-py3-none-any.whl (31 kB)
Collecting filelock
Downloading filelock-3.12.4-py3-none-any.whl (11 kB)
Collecting sympy
Downloading https://download.pytorch.org/whl/sympy-1.12-py3-none-any.whl (5.7 MB)
---------------------------------------- 5.7/5.7 MB 122.0 MB/s eta 0:00:00
Collecting numpy
Downloading numpy-1.26.1-cp310-cp310-win_amd64.whl (15.8 MB)
---------------------------------------- 15.8/15.8 MB 93.8 MB/s eta 0:00:00
Collecting pillow!=8.3.*,>=5.3.0
Downloading Pillow-10.1.0-cp310-cp310-win_amd64.whl (2.6 MB)
---------------------------------------- 2.6/2.6 MB 83.8 MB/s eta 0:00:00
Collecting requests
Downloading requests-2.31.0-py3-none-any.whl (62 kB)
---------------------------------------- 62.6/62.6 kB 3.3 MB/s eta 0:00:00
Collecting MarkupSafe>=2.0
Downloading MarkupSafe-2.1.3-cp310-cp310-win_amd64.whl (17 kB)
Collecting urllib3<3,>=1.21.1
Downloading urllib3-2.0.6-py3-none-any.whl (123 kB)
---------------------------------------- 123.8/123.8 kB 7.1 MB/s eta 0:00:00
Collecting idna<4,>=2.5
Downloading https://download.pytorch.org/whl/idna-3.4-py3-none-any.whl (61 kB)
---------------------------------------- 61.5/61.5 kB ? eta 0:00:00
Collecting charset-normalizer<4,>=2
Downloading charset_normalizer-3.3.0-cp310-cp310-win_amd64.whl (98 kB)
---------------------------------------- 98.2/98.2 kB ? eta 0:00:00
Collecting certifi>=2017.4.17
Downloading certifi-2023.7.22-py3-none-any.whl (158 kB)
---------------------------------------- 158.3/158.3 kB 9.3 MB/s eta 0:00:00
Collecting mpmath>=0.19
Downloading https://download.pytorch.org/whl/mpmath-1.3.0-py3-none-any.whl (536 kB)
---------------------------------------- 536.2/536.2 kB ? eta 0:00:00
Installing collected packages: mpmath, urllib3, typing-extensions, sympy, pillow, numpy, networkx, MarkupSafe, idna, filelock, charset-normalizer, certifi, requests, jinja2, torch, torchvision
Successfully installed MarkupSafe-2.1.3 certifi-2023.7.22 charset-normalizer-3.3.0 filelock-3.12.4 idna-3.4 jinja2-3.1.2 mpmath-1.3.0 networkx-3.1 numpy-1.26.1 pillow-10.1.0 requests-2.31.0 sympy-1.12 torch-2.0.1+cu118 torchvision-0.15.2+cu118 typing-extensions-4.8.0 urllib3-2.0.6
[notice] A new release of pip available: 22.2.1 -> 23.3
[notice] To update, run: C:\StableDiffusion\stable-diffusion-webui\venv\Scripts\python.exe -m pip install --upgrade pip
Installing clip
Installing open_clip
Cloning Stable Diffusion into C:\StableDiffusion\stable-diffusion-webui\repositories\stable-diffusion-stability-ai...
Cloning into 'C:\StableDiffusion\stable-diffusion-webui\repositories\stable-diffusion-stability-ai'...
remote: Enumerating objects: 577, done.
remote: Counting objects: 100% (307/307), done.
remote: Compressing objects: 100% (91/91), done.
Receiving objects: 100% (577/577), 73.43 MiB | 21.90 MiB/s, done.d 270
Resolving deltas: 100% (278/278), done.
Cloning Stable Diffusion XL into C:\StableDiffusion\stable-diffusion-webui\repositories\generative-models...
Cloning into 'C:\StableDiffusion\stable-diffusion-webui\repositories\generative-models'...
remote: Enumerating objects: 740, done.
remote: Counting objects: 100% (393/393), done.
remote: Compressing objects: 100% (157/157), done.
Receiving objects: 97% (718/740), 13.52 MiB | 25.20 MiB/sk-reused 347
Receiving objects: 100% (740/740), 22.31 MiB | 25.08 MiB/s, done.
Resolving deltas: 100% (378/378), done.
Cloning K-diffusion into C:\StableDiffusion\stable-diffusion-webui\repositories\k-diffusion...
Cloning into 'C:\StableDiffusion\stable-diffusion-webui\repositories\k-diffusion'...
remote: Enumerating objects: 1302, done.
remote: Counting objects: 100% (1302/1302), done.
remote: Compressing objects: 100% (412/412), done.
remote: Total 1302 (delta 913), reused 1239 (delta 883), pack-reused 0
Receiving objects: 100% (1302/1302), 232.58 KiB | 17.89 MiB/s, done.
Resolving deltas: 100% (913/913), done.
Cloning CodeFormer into C:\StableDiffusion\stable-diffusion-webui\repositories\CodeFormer...
Cloning into 'C:\StableDiffusion\stable-diffusion-webui\repositories\CodeFormer'...
remote: Enumerating objects: 594, done.
remote: Counting objects: 100% (245/245), done.
remote: Compressing objects: 100% (90/90), done.
Receiving objects: 100% (594/594), 17.30 MiB | 23.28 MiB/s, done.d 349
Resolving deltas: 100% (287/287), done.
Cloning BLIP into C:\StableDiffusion\stable-diffusion-webui\repositories\BLIP...
Cloning into 'C:\StableDiffusion\stable-diffusion-webui\repositories\BLIP'...
remote: Enumerating objects: 277, done.
Receiving objects: 2% (6/277)(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 | 26.19 MiB/s, done.
Resolving deltas: 100% (153/153), done.
Installing requirements for CodeFormer
Installing requirements
Launching Web UI with arguments:
no module 'xformers'. Processing without...
no module 'xformers'. Processing without...
No module 'xformers'. Proceeding without it.
Calculating sha256 for C:\StableDiffusion\stable-diffusion-webui\models\Stable-diffusion\sd_xl_base_1.0.safetensors: Running on local URL: http://127.0.0.1:7860
To create a public link, set `share=True` in `launch()`.
Startup time: 600.4s (prepare environment: 585.3s, import torch: 5.5s, import gradio: 2.0s, setup paths: 2.2s, initialize shared: 0.5s, other imports: 2.2s, setup codeformer: 0.3s, list SD models: 0.2s, load scripts: 1.3s, create ui: 0.4s, gradio launch: 0.2s).
31e35c80fc4829d14f90153f4c74cd59c90b779f6afe05a74cd6120b893f7e5b
Loading weights [31e35c80fc] from C:\StableDiffusion\stable-diffusion-webui\models\Stable-diffusion\sd_xl_base_1.0.safetensors
Creating model from config: C:\StableDiffusion\stable-diffusion-webui\repositories\generative-models\configs\inference\sd_xl_base.yaml
(…)it-large-patch14/resolve/main/vocab.json: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 961k/961k [00:00<00:00, 1.45MB/s]
(…)it-large-patch14/resolve/main/merges.txt: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 525k/525k [00:00<00:00, 1.10MB/s]
(…)h14/resolve/main/special_tokens_map.json: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 389/389 [00:00<?, ?B/s]
(…)tch14/resolve/main/tokenizer_config.json: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 905/905 [00:00<?, ?B/s]
(…)t-large-patch14/resolve/main/config.json: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 4.52k/4.52k [00:00<?, ?B/s]
Applying attention optimization: Doggettx... done.
Model loaded in 22.2s (calculate hash: 9.6s, load weights from disk: 1.0s, create model: 4.1s, apply weights to model: 4.1s, apply half(): 0.1s, move model to device: 0.2s, load textual inversion embeddings: 1.5s, calculate empty prompt: 1.6s).
2) Stable Diffusion web UI 動作確認
上記の webui-user.bat を実行すると
Webブラウザで http://127.0.0.1:7860/ へローカルアクセスされて table Diffusion web UI 画面が出力されます。
次の項目を設定して動作確認してみてみます。
・ Stable Diffusion checkpoint: モデルを選択
・ Prompt: Tokyo tower, mount Fuji, cherry blossoms
■ Model,LoRA の取得
Stable Diffusion で使用する絵画データ・モデルの取得は、Civitai が有名です。
Civitaiは, Stable Diffusion のモデルを共有するウェブサイトです。
ここからダウンロードできます。
ダウンロードしたModel,LoRAは次のディレクトリへ配置してリフレッシュ・ボタンもしくは再起動すると使用できます。
・ Model配置場所: "StableDiffusion\stable-diffusion-webui\models\Stable-diffusion"
・ LoRA配置場所: "StableDiffusion\stable-diffusion-webui\models\Lora"
■ 参考
・ Oracle: NVIDIA A10 Tensor Core GPUおよびNVIDIA RTX Virtual Workstationsにより、リアルタイムのAI推論とグラフィック集中型のワークロードを加速
・ NVIDIA A100 80GB Tensor Core GPUで大規模なモデル・トレーニングを加速
・ Oracle: Graphics rendering with NVIDIA A10 GPU shapes on OCI
・ Oracle: Deploy Stable Diffusion Automatic1111 on Oracle Cloud Infrastructure GPUs
・ GitHub: Stable Diffusion web UI
・ GitHub: lllyasviel/Fooocus: Focus on prompting and generating
・ NVIDIA: System Management Interface SMI
・ Stable Diffusion XL – SDXL 1.0 Model
・ SDXL 1.0 base model.
・ Civitai
・ LoRAの作り方。イラストを学習させてAIで生成する方法