toshiaki1729 / dataset-tag-editor-standalone

WebUI to edit dataset captions for txt2img models
MIT License
129 stars 13 forks source link

ONNX error(EP Error) when using wd-v1-4-moat-tagger-v2 as Interrogators #47

Closed KwaiBird closed 2 months ago

KwaiBird commented 2 months ago

Describe the bug When I tried to use wd-v1-4-moat-tagger-v2 as Interrogators, error messages which is put in Additional context section were shown on Command Prompt. I'm not sure installed CUDA and cuDNN are correct version or not because I can generate image on the WebUI without error.

wd-v1-4-moat-tagger-v2をInterrogatorsとして使おうとしたのですが、コマンドプロンプトにエラーメッセージが表示されました。(下のAdditional contextに置いてあります) 一応WebUI上で画像の生成はできているので、CUDAと cuDNNのバージョンが間違っているかわかりません。

To Reproduce Steps to reproduce the behavior:

  1. select only wd-v1-4-moat-tagger-v2 as Interrogators
  2. set Dataset directory and press "Load"
  3. error

Expected behavior using wd-v1-4-moat-tagger-v2 without error

Environment (please complete the following information):

Additional context

[tag-editor] Total 148 files under the directory including not image files. [tag-editor] Preprocess images... [tag-editor] Preprocess completed 0%| | 0/1 [00:00<?, ?it/s]2024-06-17 09:46:44.6148411 [E:onnxruntime:Default, provider_bridge_ort.cc:1744 onnxruntime::TryGetProviderInfo_CUDA] C:\a_work\1\s\onnxruntime\core\session\provider_bridge_ort.cc:1426 onnxruntime::ProviderLibrary::Get [ONNXRuntimeError] : 1 : FAIL : LoadLibrary failed with error 126 "" when trying to load "C:\Stable Diffusion\sd.webui\system\python\lib\site-packages\onnxruntime\capi\onnxruntime_providers_cuda.dll"

EP Error EP Error C:\a_work\1\s\onnxruntime\python\onnxruntime_pybind_state.cc:866 onnxruntime::python::CreateExecutionProviderInstance CUDA_PATH is set but CUDA wasnt able to be loaded. Please install the correct version of CUDA andcuDNN as mentioned in the GPU requirements page (https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html#requirements), make sure they're in the PATH, and that your GPU is supported. when using ['CUDAExecutionProvider', 'DmlExecutionProvider', 'CPUExecutionProvider'] Falling back to ['CUDAExecutionProvider', 'CPUExecutionProvider'] and retrying.


2024-06-17 09:46:44.7613518 [E:onnxruntime:Default, provider_bridge_ort.cc:1744 onnxruntime::TryGetProviderInfo_CUDA] C:\a_work\1\s\onnxruntime\core\session\provider_bridge_ort.cc:1426 onnxruntime::ProviderLibrary::Get [ONNXRuntimeError] : 1 : FAIL : LoadLibrary failed with error 126 "" when trying to load "C:\Stable Diffusion\sd.webui\system\python\lib\site-packages\onnxruntime\capi\onnxruntime_providers_cuda.dll"

0%| | 0/1 [00:02<?, ?it/s] Traceback (most recent call last): File "C:\Stable Diffusion\sd.webui\system\python\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py", line 419, in init self._create_inference_session(providers, provider_options, disabled_optimizers) File "C:\Stable Diffusion\sd.webui\system\python\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py", line 483, in _create_inference_session sess.initialize_session(providers, provider_options, disabled_optimizers) RuntimeError: C:\a_work\1\s\onnxruntime\python\onnxruntime_pybind_state.cc:866 onnxruntime::python::CreateExecutionProviderInstance CUDA_PATH is set but CUDA wasnt able to be loaded. Please install the correct version of CUDA andcuDNN as mentioned in the GPU requirements page (https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html#requirements), make sure they're in the PATH, and that your GPU is supported.

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "C:\Stable Diffusion\sd.webui\system\python\lib\site-packages\gradio\routes.py", line 488, in run_predict output = await app.get_blocks().process_api( File "C:\Stable Diffusion\sd.webui\system\python\lib\site-packages\gradio\blocks.py", line 1431, in process_api result = await self.call_function( File "C:\Stable Diffusion\sd.webui\system\python\lib\site-packages\gradio\blocks.py", line 1103, in call_function prediction = await anyio.to_thread.run_sync( File "C:\Stable Diffusion\sd.webui\system\python\lib\site-packages\anyio\to_thread.py", line 33, in run_sync return await get_asynclib().run_sync_in_worker_thread( File "C:\Stable Diffusion\sd.webui\system\python\lib\site-packages\anyio_backends_asyncio.py", line 877, in run_sync_in_worker_thread return await future File "C:\Stable Diffusion\sd.webui\system\python\lib\site-packages\anyio_backends_asyncio.py", line 807, in run result = context.run(func, args) File "C:\Stable Diffusion\sd.webui\system\python\lib\site-packages\gradio\utils.py", line 707, in wrapper response = f(args, **kwargs) File "C:\Stable Diffusion\sd.webui\webui\extensions\stable-diffusion-webui-dataset-tag-editor\scripts\tag_editor_ui\block_load_dataset.py", line 158, in load_files_from_dir dte_instance.load_dataset( File "C:\Stable Diffusion\sd.webui\webui\extensions\stable-diffusion-webui-dataset-tag-editor\scripts\dataset_tag_editor\dte_logic.py", line 783, in load_dataset tg.start() File "C:\Stable Diffusion\sd.webui\webui\extensions\stable-diffusion-webui-dataset-tag-editor\scripts\dataset_tag_editor\taggers_builtin.py", line 115, in start self.tagger_inst.load() File "C:\Stable Diffusion\sd.webui\webui\extensions\stable-diffusion-webui-dataset-tag-editor\scripts\dataset_tag_editor\interrogators\waifu_diffusion_tagger.py", line 82, in load self.model = ort.InferenceSession(path_model, providers=providers) File "C:\Stable Diffusion\sd.webui\system\python\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py", line 432, in init raise fallback_error from e File "C:\Stable Diffusion\sd.webui\system\python\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py", line 427, in init self._create_inference_session(self._fallback_providers, None) File "C:\Stable Diffusion\sd.webui\system\python\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py", line 483, in _create_inference_session sess.initialize_session(providers, provider_options, disabled_optimizers) RuntimeError: C:\a_work\1\s\onnxruntime\python\onnxruntime_pybind_state.cc:866 onnxruntime::python::CreateExecutionProviderInstance CUDA_PATH is set but CUDA wasnt able to be loaded. Please install the correct version of CUDA andcuDNN as mentioned in the GPU requirements page (https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html#requirements), make sure they're in the PATH, and that your GPU is supported.

toshiaki1729 commented 2 months ago

ご報告ありがとうございます。 スタンドアロン版の不具合として報告いただいていますが、ログを見る限りAutomatic1111版SD webUI用の拡張機能でしょうか? 私の環境では再現しませんでしたが、SD webUI版は他の拡張機能との競合もあるため、スタンドアロン版をお試しいただくと良いかもしれません。 ちなみに、A1111用版は画面下部のこちら↓ ss_version_sdwebui スタンドアロン版はこちら↓ ss_verion_standalone からバージョン情報を確認頂けます。

KwaiBird commented 2 months ago

すみません。報告する場所を間違えました。 スタンドアロン版のバージョンはv0.2.3 python: 3.10.11  •  torch: 2.0.0+cpu  •  gradio: 4.28.3  •  commit: [b58fdf09]  となっています。

スタンドアロン版でもおなじようなエラーが出たため、

pip uninstall onnx
pip uninstall onnxruntime
pip uninstall onnxruntime-gpu
pip uninstall onnxruntime-directml ←以前のAMD GPUで使用
pip uninstall olive
C:\Stable_Diffusion\dataset-tag-editor-standalone>venv\Scripts\activate
(venv) C:\Stable_Diffusion\dataset-tag-editor-standalone>pip install -r requirements.txt
(venv) C:\Stable_Diffusion\dataset-tag-editor-standalone>pip install onnx-pytorch
(venv) C:\Stable_Diffusion\dataset-tag-editor-standalone>pip install onnxruntime-gpu

としました。 その後、ブラウザアプリを起動し、インテロゲーターにwd-v1-4-moat-tagger-v2を設定しLoadしたところ、スタンドアロン版とwebUI版両方でタグ付け自体は正常に行われるようになった様です。

スタンドアロン版はこれと別の不具合がありました。 以下のメッセージが表示されました。またアプリ上で読み込んだ画像のサムネイルが表示されない状態でした。インテロゲーターにDeepDanbooruを設定してもサムネイルが表示されません。 サムネイルに関してはトピックの内容とすこし話が違ってくるので、新たにissue建てたほうがいいでしょうか?

wd-v1-4-moat-tagger-v2の場合

Auto-tuned CPU process count = 4 Total 363 files under the directory including not image files. Loading and checking images... Total 121 valid images Preprocessing images... Interrogating images... 0%| | 0/1 [00:00<?, ?it/s]C:\Stable_Diffusion\dataset-tag-editor-standalone\venv\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py:69: UserWarning: Specified provider 'CUDAExecutionProvider' is not in available provider names.Available providers: 'AzureExecutionProvider, CPUExecutionProvider' warnings.warn( C:\Stable_Diffusion\dataset-tag-editor-standalone\venv\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py:69: UserWarning: Specified provider 'DmlExecutionProvider' is not in available provider names.Available providers: 'AzureExecutionProvider, CPUExecutionProvider' warnings.warn( wd-v1-4-moat-tagger-v2: 100%|████████████████████████████████████████████████████████| 121/121 [01:10<00:00, 1.71it/s] 100%|████████████████████████████████████████████████████████████████████████████████████| 1/1 [01:12<00:00, 72.45s/it] Loading Completed: 121 images found

DeepDanbooruの場合

Auto-tuned CPU process count = 4 Total 363 files under the directory including not image files. Loading and checking images... Total 121 valid images Preprocessing images... Interrogating images... 0%| | 0/1 [00:00<?, ?it/s]C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\torch\amp\autocast_mode.py:204: UserWarning: User provided device_type of 'cuda', but CUDA is not available. Disabling warnings.warn('User provided device_type of \'cuda\', but CUDA is not available. Disabling') DeepDanbooru: 100%|██████████████████████████████████████████████████████████████████| 121/121 [00:09<00:00, 13.34it/s] 100%|████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:10<00:00, 10.62s/it] Loading Completed: 121 images found

toshiaki1729 commented 2 months ago

サムネイルについてはこれかもしれませんね トラブルシューティング > ギャラリーに画像が表示されず、コンソールにエラーが表示されない

gradioの仕様で、いつからかホワイトリスト(またはpythonを実行しているフォルダ)に入ってない場所の画像を読み込まなくなったようです。

toshiaki1729 commented 2 months ago

torch: 2.0.0+cpu 'CUDAExecutionProvider' is not in available provider names.Available providers: 'AzureExecutionProvider, CPUExecutionProvider'

また、PyTorchとonnxがGPUでなくCPUで動作していると思われます。 意図した動作でない場合は下記を試していただけますか?

  1. 一旦venvを削除する
  2. PyTorchについて、 トラブルシューティング>PyTorch が CUDA を使っていない を参考にインストールする
    • PyTorchをvenv内のみにインストールする場合、install.batを先に実行してください
  3. onnxは手動でインストールせず、起動後に1度 WD Taggerのいずれかを走らせる(タグ付け直前に自動で pip installされると思います)
KwaiBird commented 2 months ago

ありがとうございます。read meの確認が足りず申し訳ありません。

サムネイルについてはこれかもしれませんね トラブルシューティング > ギャラリーに画像が表示されず、コンソールにエラーが表示されない

gradioの仕様で、いつからかホワイトリスト(またはpythonを実行しているフォルダ)に入ってない場所の画像を読み込まなくなったようです。 上記のリンク通り設定後、Reload UIをしてもサムネイルが表示されなかったので、アプリを落としてからlaunch_user.batを実行したところ正常にサムネイルが表示されるようになりました。

また、PyTorchとonnxがGPUでなくCPUで動作していると思われます。 意図した動作でない場合は下記を試していただけますか?

1. 一旦venvを削除する

2. PyTorchについて、 [トラブルシューティング>PyTorch が CUDA を使っていない](https://github.com/toshiaki1729/dataset-tag-editor-standalone/blob/main/README-JP.md#pytorch-%E3%81%8C-cuda-%E3%82%92%E4%BD%BF%E3%81%A3%E3%81%A6%E3%81%84%E3%81%AA%E3%81%84) を参考にインストールする

   * PyTorchをvenv内のみにインストールする場合、`install.bat`を先に実行してください

3. onnxは手動でインストールせず、起動後に1度 WD Taggerのいずれかを走らせる(タグ付け直前に自動で `pip install`されると思います)

1をし、2のリンク先の「他のスクリプトと共有するために PyTorch をシステムにインストールする場合」の手順をvenvの削除以外実行しました。 pip3 install -U torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 pip3 install -U torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. torch-directml 0.2.0.dev230426 requires torch==2.0.0, but you have torch 2.3.1+cu118 which is incompatible. torch-directml 0.2.0.dev230426 requires torchvision==0.15.1, but you have torchvision 0.18.1+cu118 which is incompatible

というエラーが出た以外は正常にインストールできているようです。 その後、アプリを起動したところ、

PyTorch device: cuda Custom taggers loaded: ['aesthetic shadow', 'cafeai aesthetic classifier', 'Improved Aesthetic Predictor', 'wd aesthetic classifier'] Settings has been read from config.json C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\gradio\components\dropdown.py:179: UserWarning: The value passed into gr.Dropdown() is not in the list of choices. Please update the list of choices to include: or set allow_custom_value=True. warnings.warn( Running on local URL: http://127.0.0.1:7861

To create a public link, set share=True in launch().

と表示されたため、3をwd-v1-4-moat-tagger-v2・wd-vit-tagger-v3それぞれで実行しましたがpip installは行われていないようでした。

wd-v1-4-moat-tagger-v2

Auto-tuned CPU process count = 1 Total 81 files under the directory including not image files. Loading and checking images... Total 27 valid images Preprocessing images... Interrogating images... 0%| | 0/1 [00:00<?, ?it/s]C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py:69: UserWarning: Specified provider 'DmlExecutionProvider' is not in available provider names.Available providers: 'TensorrtExecutionProvider, CUDAExecutionProvider, CPUExecutionProvider' warnings.warn( wd-v1-4-moat-tagger-v2: 100%|██████████████████████████████████████████████████████████| 27/27 [00:27<00:00, 1.02s/it] 100%|████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:29<00:00, 29.30s/it] Loading Completed: 27 images found

wd-vit-tagger-v3

Auto-tuned CPU process count = 1 Total 81 files under the directory including not image files. Loading and checking images... Total 27 valid images Preprocessing images... Interrogating images... config.json: 100%|████████████████████████████████████████████████████████████████████████████| 684/684 [00:00<?, ?B/s] C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\huggingface_hub\file_download.py:148: UserWarning: huggingface_hub cache-system uses symlinks by default to efficiently store duplicated files but your machine does not support them in C:\Users\user.cache\huggingface\hub\models--SmilingWolf--wd-vit-tagger-v3. Caching files will still work but in a degraded version that might require more space on your disk. This warning can be disabled by setting the HF_HUB_DISABLE_SYMLINKS_WARNING environment variable. For more details, see https://huggingface.co/docs/huggingface_hub/how-to-cache#limitations. To support symlinks on Windows, you either need to activate Developer Mode or to run Python as an administrator. In order to see activate developer mode, see this article: https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development warnings.warn(message) model.safetensors: 100%|████████████████████████████████████████████████████████████| 378M/378M [00:06<00:00, 57.1MB/s] selected_tags.csv: 100%|████████████████████████████████████████████████████████████| 308k/308k [00:00<00:00, 2.14MB/s] selected_tags.csv: 100%|████████████████████████████████████████████████████████████| 308k/308k [00:00<00:00, 2.14MB/s]C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\timm\models\vision_transformer.py:91: UserWarning: 1Torch was not compiled with flash attention. (Triggered internally at ..\aten\src\ATen\native\transformers\cuda\sdp_utils.cpp:455.) x = F.scaled_dot_product_attention( wd-vit-tagger-v3: 100%|████████████████████████████████████████████████████████████████| 27/27 [00:00<00:00, 35.22it/s] 86%|████████████████████████████████████████████████████████████████████████ | 6/7 [00:00<00:00, 7.84it/s] 100%|████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:10<00:00, 10.21s/it] Loading Completed: 27 images found

toshiaki1729 commented 2 months ago

確認ありがとうございます。 1.02s/it は流石に4070Tiの速度ではないように見えますね…… CPU版のonnxruntimeだけインストールしたところ同様のメッセージが再現したので、おそらくシステムにCPU版のonnxruntimeが既にインストールされており、それが参照されているのだと思います。

ストレージ節約の為、pytorch等既にインストールされたライブラリは参照する設定になっているのですが、現行のコードではonnxruntimeをGPUで動かせるかどうかまで確認していないため、自動でインストールされなかったようです。 この仕様はユーザーフレンドリーで無いので、何らかの形で修正するかもしれません。

すぐに直したい場合は、バッチファイル等があるディレクトリで、

venv/scripts/activate
pip uninstall -y onnxruntime
pip install onnxruntime-gpu

することで直るはずです…… (ただhttps://github.com/toshiaki1729/dataset-tag-editor-standalone/issues/47#issuecomment-2172759007 で似た状況ではありましたが)

KwaiBird commented 2 months ago

返答ありがとうございます。こちらのコマンドを実行してみましたが、以前と同様のエラーが出ました。一方で、wd-convnext-tagger-v3を使った場合は、エラーの表示はありませんでした。 一部onnxruntimeのGPU駆動に非対応のインテロゲータがあるという感じでしょうか。 ひとまず、表題の問題とサムネイルの件は解決しました。ありがとうございます。

Auto-tuned CPU process count = 7 Total 267 files under the directory including not image files. Loading and checking images... Total 267 valid images Preprocessing images... Interrogating images... wd-convnext-tagger-v3: 100%|█████████████████████████████████████████████████████████| 267/267 [00:05<00:00, 46.31it/s] 99%|████████████████████████████████████████████████████████████████████████████████▊ | 66/67 [00:05<00:00, 11.45it/s] 100%|████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:08<00:00, 8.03s/it] Loading Completed: 267 images found

toshiaki1729 commented 2 months ago

ありがとうございます。

wd-convnext-tagger-v3など、v3のモデルはtimmという別のライブラリを使っており、並列処理に対応させています。 ただ特定のモデルだけGPU非対応ということは無いので、onnxruntime-gpuのインストールに何らかの問題があるとは思われます……

toshiaki1729 commented 2 months ago

因みにですが、

UserWarning: Specified provider 'DmlExecutionProvider' is not in available provider names.Available providers: 'TensorrtExecutionProvider, CUDAExecutionProvider, CPUExecutionProvider'

この部分は少し手の込んだことをしない限りどうしても表示されるので、気にしないでいただけると幸いです。 ただ、CUDAでやれば速度が流石に5it/sとかになるはずでしたので……

versionはまだ上げていませんが、直近のコミットで、ONNXを実行しているのがCPUかGPUかだけは分かるようにしました。

KwaiBird commented 2 months ago

ありがとうございます。 git pullして実行してみたところ、wd-v1-4-moat-tagger-v2でもGPU上で動いているようだと確認できました。

Auto-tuned CPU process count = 1 Total 3 files under the directory including not image files. Loading and checking images... Total 3 valid images Preprocessing images... Interrogating images... 0%| | 0/1 [00:00<?, ?it/s]Running ONNX on GPU C:\Stable_Diffusion\dataset-tag-editor-standalone\venv\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py:69: UserWarning: Specified provider 'DmlExecutionProvider' is not in available provider names.Available providers: 'TensorrtExecutionProvider, CUDAExecutionProvider, CPUExecutionProvider' warnings.warn( wd-v1-4-moat-tagger-v2: 100%|████████████████████████████████████████████████████████████| 3/3 [00:14<00:00, 4.89s/it] 100%|████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:17<00:00, 17.45s/it] Loading Completed: 3 images found