Copy & Paste Engineer

Stable Diffusion WebUI を Dockerで使用する

Stable Diffusion WebUI を Dockerで使用する

簡単にローカル環境で Stable Diffusion WebUI を使用するメモ。

Docker が必要になります。

GitHub から対象をダウンロード

GitHub から対象を取得します。 Gitが入ってないのなら GitHub に飛んで対象のソースをダウンロードしてください。

git clone https://github.com/AbdBarho/stable-diffusion-webui-docker.git

構築

構築手順のとおりにやっていきます。

初回起動

まずはDockerをビルドします。

docker compose --profile download up --build

結構時間がかかるので待ちましょう。

以下のように exited with code 0 が出たら問題なくビルド完了になります。

webui-docker-download-1 exited with code 0

起動

WebUI を起動します。

docker compose --profile auto up --build

他にも以下のオプションがあります。

docker compose --profile [ui] up --build

これも初回はモデルのダウンロードなどで時間がかかります。

起動が完了したら http://localhost:7860/ にアクセスするとWebUI画面が出てきます。

停止

停止する場合は起動したターミナル上で Ctr+C で停止します。

NansException: A tensor with all NaNs was produced in Unet. エラーの対処

僕の環境では以下のようなエラーが発生しました。

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

調べたところ

このエラーを修正するためには以下の設定を行う必要があります。

Settings > StableDiffsion >「Upcast cross attention layer to float32」にチェック > ApplySettings で設定。

これでエラーが解消されて生成されるかと思います。

まとめ

これでローカル環境で簡単に使用ができます。 GPUが貧弱過ぎて辛い…(´;ω;`)

個人的にはローカルPCが汚れにくい、Docker版を推します。 PythonのバージョンアップなどもDocker側で対応してくれるので良いと思っています。