アップルが米大学と共同で発表したAI画像編集ツール「MGIE」をローカル環境で実行してみた

github.com

はじめに

「MGIE」(Guiding Instruction-based Image Editing via Multimodal Large Language Models)はアップルとカリフォルニア大学サンタバーバラ校(UCSB)が共同で開発したマルチモーダル大規模言語モデルを基にしたAI画像編集ツールです。

GitHub名は「ml-mgie」です。

Gradio実行環境を公開してくれている人がいたので、今回はそちらを使わせて頂き自宅のPCで実行してみました。
github.com
以前「Instruct-Pix2Pix」で似たようなことをしました。
touch-sp.hatenablog.com
MGIEのスクリプトを覗くと、内部で「Instruct-Pix2Pix」が使われていました。

「Instruct-Pix2Pix」にマルチモーダル大規模言語モデルを組み合わせたのがきっとMGIEの肝なんでしょう。

結果

「change the hair from brown to red」

左側の画像とプロンプトから右側の画像を作成しました。

PC環境

Ubuntu 22.04 on WSL2
Python 3.10
CUDA 11.8 (RTX 4090)

CUDA 11.8をインストールしている環境で「torch==12.0+cu113」を使いました。

問題なく動作しました。

環境構築

公式の環境構築を少しアレンジしています。

conda create -n mgie python=3.10 -y
conda activate mgie

pip install -U pip cmake cython==0.29.36 pydantic==1.10 numpy
pip install -U sentencepiece transformers diffusers tokenizers datasets accelerate evaluate git+https://github.com/openai/CLIP.git
pip install torch==1.12.0+cu113 torchvision==0.13.0+cu113 --extra-index-url https://download.pytorch.org/whl/cu113
pip install -U deepspeed

# git clone this repo
cd ml-mgie
git submodule update --init --recursive
cd LLaVA
pip install -e .
pip install torch==1.12.0+cu113 torchvision==0.13.0+cu113 --extra-index-url https://download.pytorch.org/whl/cu113
pip install -U ninja flash-attn==1.0.2
pip install -U gradio

cd ..
cp mgie_llava.py LLaVA/llava/model/llava.py
cp mgie_train.py LLaVA/llava/train/train.py

補足

1

以下のエラーは無視して問題なかったです。

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.
peft 0.3.0 requires torch>=1.13.0, but you have torch 1.12.0+cu113 which is incompatible.
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.
deepspeed 0.9.2 requires pydantic<2.0.0, but you have pydantic 2.6.1 which is incompatible.
llava 0.2.0 requires gradio==3.35.2, but you have gradio 4.17.0 which is incompatible.

2

Please make sure libcudnn_cnn_infer.so.8 is in your library path!

上記のエラーがでましたが以下のように対応して解決しました。(要再起動)

sudo ln -s /usr/lib/wsl/lib/libcuda.so.1 /usr/local/cuda/lib64/libcuda.so





このエントリーをはてなブックマークに追加