エラー概要
以前まで普通にStable Diffusion WebUIを使えていたのに、なぜかとある日以下のエラーになった。無事に解決できたので共有します。
To create a public link, set `share=True` in `launch()`.
Startup time: 14.1s (launcher: 0.7s, import torch: 5.8s, import gradio: 1.6s, setup paths: 2.0s, other imports: 3.3s, load scripts: 0.3s, create ui: 0.2s).
Creating model from config: /Users/xxx/xxxx/stable-diffusion-webui/repositories/stable-diffusion-stability-ai/configs/stable-diffusion/v2-inference-v.yaml
LatentDiffusion: Running in v-prediction mode
DiffusionWrapper has 865.91 M params.
Applying attention optimization: InvokeAI... done.
-[IOGPUMetalCommandBuffer validate]:200: failed assertion `commit command buffer with uncommitted encoder'
./webui.sh: line 254: 56657 Abort trap: 6 "${python_cmd}" "${LAUNCH_SCRIPT}" "$@"
webui-macos-env.sh
のCOMMANDLINE_ARGS
は以下で実施していました。
export COMMANDLINE_ARGS="--skip-torch-cuda-test --upcast-sampling --no-half-vae --no-half --use-cpu interrogate --lowvram"
Mac環境
機種ID:MacBookPro18,3
macOS:Monterey
チップ:Apple M1 Pro
メモリ:16GB
エラーの原因
エラーメッセージは、GPUのメモリが不足している、GPUのコマンドバッファが適切にコミットされていない、などの理由があると言っているっぽい。
PyTorchが使用するGPUメモリの最大量を制御することでメモリ不足によるエラーを回避することができるらしい。
MPS backend out of memory
というエラーが出た場合も同様の原因であるらしく、こちらも参考になりました。
MPS backend out of memory #9133
解決方法
PyTorchが使用するGPUメモリの最大量はPYTORCH_MPS_HIGH_WATERMARK_RATIO
で設定できます。1
に近いほどGPUメモリを使用します。デフォルトでは1
になっている。
ということで、webui-user.sh
に以下を追加したらエラーがなくなりました。
# PyTorch settings
export PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.7