回心誌

日々是回心

TensorRTを試す

NVIDIA公式からSD-WebUI向けに。
GitHub - NVIDIA/Stable-Diffusion-WebUI-TensorRT: TensorRT Extension for Stable Diffusion Web UI

インストール

ExtensionsのIntall from URLのところに「https://github.com/NVIDIA/Stable-Diffusion-WebUI-TensorRT」を入れてインストールボタンぽち。

すんげー時間かかった。2~3分くらい。その間、なんの進捗も表示されないので不安になる。

インストールが終わったら、「Apply and restart UI」


すると、

これと同じのが4連発。

プロシ ー ジャエントリポイント?destroyTensorDescriptorEx@ops@YA?AW4cudnnStatus_t@@PEEAPEAPEAUcudnnTensorStruct@@@Z がダイナミック リンク ライブラリ D:\Program\stable-diffusion-webui\venv\Lib\site-packages\nvidia\cudnn\bin\cudnn_adv_train64_8.dll から見つかりませんでした。

Entry Point Not Found Error : StableDiffusion
TensorRTの拡張機能で爆速ガチャ生成|はかな鳥

うーん。venvでPythonの環境を切ってるからか?

venvの再構築でうまくいったというコメントもあり。
The procedure entry point could not be located in the DLL Library · Issue #143 · NVIDIA/Stable-Diffusion-WebUI-TensorRT · GitHub
Error loading script: trt.py, ModuleNotFoundError: No module named 'tensorrt_bindings' · Issue #27 · NVIDIA/Stable-Diffusion-WebUI-TensorRT · GitHub

From your base SD webui folder: (E:\Stable diffusion\SD\webui\ in your case).

  • In the extensions folder delete: stable-diffusion-webui-tensorrt folder if it exists
  • Delete the venv folder

Open a command prompt and navigate to the base SD webui folder

  • Run webui.bat - this should rebuild the virtual environment venv
  • When the WebUI appears close it and close the command prompt

Open a command prompt and navigate to the base SD webui folder

  • enter: venv\Scripts\activate.bat
  • the command line should now have (venv) shown at the beginning.
  • enter the following commands:
  • webui.bat
  • Install the TensorRT extension using the Install from URL option
  • Once installed, go to the Extensions >> Installed tab and Apply and Restart

まんまこの通りやってみたら、とりあえずうまく行きました。

ただ、venv消しちゃったのが大丈夫なのかはよくわからん。
他の拡張機能に影響してなきゃいいけど。

触ってみる

タグを開くと説明あり。

Set Up
Click on the "Generate Default Engines" button. This step can take 2-10 min depending on your GPU. You can generate engines for other combinations.
Go to Settings → User Interface → Quick Settings List, add sd_unet. Apply these settings, then reload the UI.
Back in the main UI, select the TRT model from the sd_unet dropdown menu at the top of the page.
You can now start generating images accelerated by TRT. If you need to create more Engines, go to the TensorRT tab.

適当に設定入力して、Export Engineぽち

あとは待つだけ。

5分くらいしたら「Exported Successfully」と出て完了。

Settings > User Interface > Quicksettings list に「sd_unet」を追加。
設定を適用してUIをリロード。


やってみると、実際かなり速くなってる。
使わない場合は14~16it/secだったところ、使うと20~24it/secに。

ただ、LoRAを使う場合はLoRA用にもengineの作成が必要で、しかも複数LoRA併用は無理っぽい。

あんまり実用しないかも。
コンセプト決めてLoRAも自作してから同じ画像を何枚も何枚も生成するならあり?