Intel ARC oneAPI Stable Diffusionとsd-scriptsのWindowsネイティブ対応

Stable Diffusion Webui/Automatic1111のfork版 Vladmandic/automatic、通称SD.nextはWindowsネイティブ環境で動かす場合に初期化に相当の時間を必要としていました。最近そのような制約がなくなったので手順をメモします

はじめに

IntelはCUDAを使ったpythonモジュールのARC対応版をリリースしています。Linux版とWindows版では別々のモジュールが必要です。Window版モジュールは動作させて初めて使うときに動的コンパイルが発生するため待ち時間を必要とします。Linux用はAOT(事前コンパイル)形式の待ち時間が起きない形式なので、SD.nextを使う際は環境構築やOS切り替えの手間を考えてもWSLやLinuxで動かした方が快適でした

'23年9月にNuullllという方がIntel ARC対応WindowsPythonモジュールのAOT形式版を作成、公開したため、Windowsネイティブ環境でも待ち時間が少なくなりました。インストール手順も見直され簡単になりました

なお動作速度は低解像度ではWSL/Linux環境より割ほど遅いようです

またドライバ4885 や 4887では動かないことがあるため、それ以前のVer.ドライバを使用してください

 

だいたい下記の翻訳です

github.com

 

10/13のdev版からより簡単な手順になったので本当にメモだけ

Intel ARCドライバをインストールする

・Git for Windowsをインストールする

・Python3.10.xをインストールする

・適当なディレクトリにリポジトリをクローンして実行 

git clone https://github.com/vladmandic/automatic.git -b dev
cd automatic
.\webui.bat --use-ipex




sd-scriptsも試す

これだけでは何なので今回リリースされたWindows AOT対応版モジュールでsd-scriptsもWindowネイティブ対応になるか試してみました

モジュールはこちらです

github.com

・ドライバ、git、pythonをインストール

・適当なディレクトリにリポジトリをクローン


git clone https://github.com/kohya-ss/sd-scripts.git
cd sd-scripts
python -m venv venv
.\venv\Scripts\activate

・oneAPI用モジュールをインストール


pip install https://github.com/Nuullll/intel-extension-for-pytorch/releases/download/v2.0.110%2Bxpu-master%2Bdll-bundle/torch-2.0.0a0+gite9ebda2-cp310-cp310-win_amd64.whl
pip install https://github.com/Nuullll/intel-extension-for-pytorch/releases/download/v2.0.110%2Bxpu-master%2Bdll-bundle/torchvision-0.15.2a0+fa99a53-cp310-cp310-win_amd64.whl
pip install https://github.com/Nuullll/intel-extension-for-pytorch/releases/download/v2.0.110%2Bxpu-master%2Bdll-bundle/intel_extension_for_pytorch-2.0.110+gitc6ea20b-cp310-cp310-win_amd64.whl
pip install --upgrade -r requirements.txt

・accelerate設定


accelerate config
- This machine
- No distributed training
- NO
- yes
- NO
- all
- bf16

kohyaさんのカエルLoraを試しましたが動いてはいるようです。なお

・xformers,bitsandbytesはインストール不要で不可
・8bit系オプティマイザは使用不可
・--gradient_checkpointingを設定すると動作停止
・--persistent_data_loader_workersは設定可能

でした。いろいろ制約はありそう…

 

※以下数日前の設定です

インストール手順

こんな順番です

Intel ARCドライバをインストールする

・Git for Windowsをインストールする

・Python3.10.8をインストールする

・Miniconda for Windowsをインストールする

・SD.nextことvladmandic/automaticの動くpython環境を作り、インストールする

Intel ARCドライバをインストールする

 今動いてるドライバで大丈夫です

Git for Windowsをインストールする

 略

Python3.10.8をインストールする

 略。インストール時「PATHの拡張を有効にする」にチェックを入れて下さい

Miniconda for Windowsをインストールする

通常SD.nexはPythonのvenv形式Python環境を使いますが、Intel ARC Windowsネイティブ版ではanacond形式のPython環境を使うようです

SD.next用のPython環境を作る
minicondaコンソールを開く

Windowsメニューからminiconda プロンプト(PowrShellじゃない方)を選択し、開きます

>conda create -n sdnext python=3.10

sdnext用環境に切り替え、不足モジュールをインストールする

>conda activate sdnext

>conda install -c conda-forge libuv=1.39

IntelのサイトよりoneAPI用ランタイムをインストールする

>conda install -c intel dpcpp-cpp-rt mkl-dpcpp

SD.nextフォルダーを作る
git clone https://github.com/vladmandic/automatic.git
cd automatic
Windows用AOT対応モジュールをコピーする

automatic直下に有志の作成したAOT対応版pythonモジュールをコピーします

ここからダウンロードできます

ipex-windows-wheels - Google ドライブ

dir *.whl

2023/09/19  13:13       289,085,958 intel_extension_for_pytorch-2.0.110+git0f2597b-cp310-cp310-win_amd64.whl
2023/09/19  10:58       195,693,642 torch-2.0.0a0+gite9ebda2-cp310-cp310-win_amd64.whl
2023/09/19  10:58           767,270 torchvision-0.15.2a0+fa99a53-cp310-cp310-win_amd64.whl

 

SD.nextをlaunch.pyの直接呼出しにより起動します

先ほどコピーしたAOT版モジュールを使用するように環境変数を修正します

>set TORCH_COMMAND=intel_extension_for_pytorch-2.0.110+git0f2597b-cp310-cp310-win_amd64.whl torch-2.0.0a0+gite9ebda2-cp310-cp310-win_amd64.whl torchvision-0.15.2a0+fa99a53-cp310-cp310-win_amd64.whl
>python launch.py --use-ipex

 

次回からの起動手順

minicondaプロンプトを開く→sdnext仮想環境を有効にする→launch.py --use-ipexを直接起動する

バッチでまとめるとこんな感じ

call C:\Users\username\miniconda3\Scripts\activate.bat C:\Users\username\miniconda3
call activate sdnext
cd /D X:\dir\automatic
python launch.py --use-ipex --listen