InvokeAI
インストール&アップデート(Linux)
https://invoke-ai.github.io/InvokeAI/installation/020_INSTALL_MANUAL/
- 初回インストール時は、install用のシェルを実行する
- インストール先は、HDDの容量が大きいところを選んだほうが無難
- アップデートの際は、invokeAIのインストールディレクトリに行って、リリース時のtagをチェックアウトしたほうがやりやすい
- nvidiaのdriverは特にこだわりがなければdebianのnonfreeのリポジトリを使ったほうが簡単
- CUDA : 11.2 インストール
- マニュアルにあるように、InvokeAI側で使用されるcudaは11.7
- tag一覧: https://github.com/invoke-ai/InvokeAI/tags
- pipのパッケージ一覧: https://pypi.org/project/InvokeAI/#history
$ git fetch origin $ git checkout -b v2.3.2.post1 refs/tags/v2.3.2.post1 // 以下・初回以外は不要で、公式ドキュメントを見るべし $ python -m venv .venv --prompt InvokeAI $ source .venv/bin/activate $ python -m pip install --upgrade pip $ pip install InvokeAI[xformers] --use-pep517 --extra-index-url https://download.pytorch.org/whl/cu117 // ここまででうまくいったら、各種invokeaiコマンドが使えるようになる $ deactivate && source .venv/bin/activate // INVOKEAI_ROOT は自分の決めたInvokeAIのホームディレクトリ $ cd $INVOKEAI_ROOT && invokeai --web
- インストール時になにかトラブルあれば Common problems# を見て対応
自分の場合足りない機械学習モデルがあったので、以下でTUI画面を開いて対応した。
$ configure_invokeai.py
v2.3.1.post1 アップデートメモ
- v2.3.1.post1
- v2.3.1ぐらいからcondaでのインストールは非推奨となっている
As of InvokeAI v2.3.0 installation using the conda package manager is no longer being supported. It will likely still work, but we are not testing this installation method.
v2.3.4rc1 アップデートメモ
- LoRaがサポートされた, diffuserとかをちゃんとアップデートするには以下
$ source .venv/bin/activate $ pip install --use-pep517 --upgrade InvokeAI==2.3.4rc1
手動で起動すると以下のプロンプトが出るのでエンターを押す
>> ALERT: >> The location of your previously-installed diffusers models needs to move from >> invokeai/models/diffusers to invokeai/models/hub due to a change introduced by >> diffusers version 0.14. InvokeAI will now move all models from the "diffusers" directory >> into "hub" and then remove the diffusers directory. This is a quick, safe, one-time >> operation. However if you have customized either of these directories and need to >> make adjustments, please press ctrl-C now to abort and relaunch InvokeAI when you are ready. >> Otherwise press <enter> to continue. ** This is a quick one-time operation. continue>
systemdで動かす(optional)
詳細は省くが、以下のようにすれば動くはず(なぜかログがちゃんと出力されない)
$ sudo cat /etc/systemd/system/invokeai.service [Unit] Description=InvokeAI After=network.target [Service] Type=simple WorkingDirectory=/opt/invokeAI/ ExecStartPre=/usr/bin/pkill -f "cpulimit -e Xorg" ; /usr/bin/cpulimit -e Xorg -l 60 ExecReload=/usr/bin/pkill -f "cpulimit -e Xorg" ; /usr/bin/cpulimit -e Xorg -l 60 ExecStart=/bin/bash -c 'cd /自分の決めたInvokeAIのホームディレクトリ/ && source .venv/bin/activate && invokeai --root="/<invokeaiのHOME>/invokeai" --web &>> /var/log/invokeai/invokeai.log' StandardOutput=file:/var/log/invokeai/invokeai.log StandardError=file:/var/log/invokeai/invokeai.log User=一般ユーザー Group=一般ユーザー # LoRaを使うとCPUをかなり使うので CPUWeight=60 CPUQuota=60% IOWeight=20 MemorySwapMax=0 [Install] WantedBy=multi-user.target
モデルの追加の仕方について
ここを読んでモデルを追加する
まず、huggingfaceから必要なモデルを <インストールディレクトリ>/invokeai/models/ldm/stable-diffusion-v1/以下に入れる
InvokeAIをインストールしているディレクトリに行き
$ conda activate invokeai (invokeai) $ python scripts/invoke.py // promptが変わるので、ほしいモデルに合わせて以下のようにコマンド実行(以下はstable-diffusion-v1の例) invoke> !import_model models/ldm/stable-diffusion-v1/arabian-nights-1.0.ckpt
- デフォルトで使用するモデルを変更したい場合は
$ vim <InvokeAIのディレクトリ>/configs/models.yaml モデル名: default: true <-- ここをtrueに設定
構造
https://github.com/invoke-ai/InvokeAI
これの中身の構造、特にStableDiffusionのバージョンは何なのか
- InvokeAI (v2.3.1.post2)
- stable-diffusionが含まれない?
- どうやらk-diffusionというdiffusion系のツールのラッパーを使っているらしい。
- pytorch
- torch>=1.13.1
依存関係
dependencies = [ ... "diffusers[torch]~=0.13", ... "huggingface-hub>=0.11.1", ... "k-diffusion", ... "pytorch-lightning==1.7.7", ... "torch>=1.13.1", "torch-fidelity", "torchvision>=0.14.1", "torchmetrics", "transformers~=4.25", ...
pipを見るとこんな感じ
- pytorchは https://github.com/pytorch/pytorch/tree/v1.13.1
- これとcuda11.7の組み合わせっぽい
pip list | grep torch clip-anytorch 2.5.0 pytorch-lightning 1.7.7 torch 1.13.1+cu117 torch-fidelity 0.3.0 torchdiffeq 0.2.3 torchmetrics 0.11.1 torchsde 0.2.5 torchvision 0.14.1+cu117
- k-diffusion
- https://github.com/crowsonkb/k-diffusion/blob/master/requirements.txt
- pytorchは最新のものをとってきそう、これは実行系とは別なのかな
- pytorch-large-model-support
- https://github.com/IBM/pytorch-large-model-support/tree/master/patches
- patchはv1.1.0〜v1.5.0までしか用意されていない
学習済みモデルについて
- .ckptと.safetensorで性質が異なるらしい
- .ckptは前からあるので、Pythonのデータをシリアライズしたものであることは知っているのだが
- .safetensorは知らない
- .safetensorについて、また変換については以下ページにまとめた