UbuntuでStable Diffusion WebUIを使用中、スリープから復帰すると生成できなくなる問題の対処

概要

ubuntuでStable Deiffusionを使っている最中、スリープ復帰するとエラーが出て生成できなくなる。PC再起動すれば解決するが面倒。原因はスリープによってGPUを見失うため。linuxにカーネルリロードのコマンドを送って解決。

環境

  • Ubuntu 22.10
  • Stable Diffusion WebUI Automatic1111使用
  • Nvidia Geforce 3070 8GB

現象

webui.shで起動、この時点では動作問題なし。
その後スリープ→復帰すると以下のエラーが出て生成ができなくなる。
Traceback (most recent call last):
  File "/home/hoge/stable-diffusion-webui/launch.py", line 380, in <module>
    prepare_environment()
  File "/home/hoge/stable-diffusion-webui/launch.py", line 287, in prepare_environment
    run_python("import torch; assert torch.cuda.is_available(), 'Torch is not able to use GPU; add --skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check'")
  File "/home/hoge/stable-diffusion-webui/launch.py", line 137, in run_python
    return run(f'"{python}" -c "{code}"', desc, errdesc)
  File "/home/hoge/stable-diffusion-webui/launch.py", line 113, in run
    raise RuntimeError(message)
RuntimeError: Error running command.
Command: "/home/hoge/stable-diffusion-webui/venv/bin/python3" -c "import torch; assert torch.cuda.is_available(), 'Torch is not able to use GPU; add --skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check'"
Error code: 1
stdout: <empty>
stderr: /home/hoge/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/cuda/__init__.py:88: UserWarning: CUDA initialization: CUDA unknown error - this may be due to an incorrectly set up environment, e.g. changing env variable CUDA_VISIBLE_DEVICES after program start. Setting the available devices to be zero. (Triggered internally at ../c10/cuda/CUDAFunctions.cpp:109.)
  return torch._C._cuda_getDeviceCount() > 0
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AssertionError: Torch is not able to use GPU; add --skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check

このエラーが出るようになると、Reload UIでもwebui.shの再起動でも同様のエラーがでて生成不可能になる。ただしPCを再起動すると治る。 

対処法

スリープによってGPUを見失うため発生。エラー自体はStable Diffusionに限らずCUDAを使うプログラム全般で発生する。
PCを再起動させずに治すには、カーネルモジュール(ドライバみたいなもん)をリロードする。
  1. すでに起動しているwebui.shを終了する
  2. 以下のコマンドを実行(参考:stackoverflow
    1. sudo rmmod nvidia_uvm
    2. sudo modprobe nvidia_uvm
    • 1行目でlinux用のnvidiaドライバをアンロード、2行目でドライバを依存関係考えていい感じにロードする。 
  3. webui.shを再度起動する
  4. webUI側でReload UI実行

0 件のコメント :

コメントを投稿