🤖

Ubuntu 24.04 LTSでWan2.2 インストール時、flash_attnのインストールでエラーとなった

に公開

Wan2.2 インストール時、flash_attnのインストールでエラーとなった

0. エラーになるところまで。

環境

  • Ubuntu 24.04 LTS
  • cuda 12.8
  • proxmoxのLXC コンテナ
  • GPUは、RTX-3090
  • ollamaインストール済みで動作しているので、cudaのインストール状態は問題ない

0.1 ソースの取得

git clone https://github.com/Wan-Video/Wan2.2.git

0.2 venvの作成

python3.12 -m venv venv312_wan22
. venv312_wan22/bin/activate

0.3 cuda系の環境変数

(venv312_wan22) ryuuri@ct103:~/WAN/wan2.2$ cat cuda_env12
export CUDA_HOME=/usr/local/cuda-12.8
export PATH=$CUDA_HOME/bin:$PATH
(venv312_wan22) ryuuri@ct103:~/WAN/wan2.2$ . cuda_env12

pip install

(venv312_wan22) ryuuri@ct103:~/WAN/wan2.2$ cd Wan2.2
(venv312_wan22) ryuuri@ct103:~/WAN/wan2.2/Wan2.2$ pip install -r requirements.txt

ここで、attn_flashのインストール時にエラーとなりました。

1. まず、torchをcuda12.8にする (https://pytorch.org/get-started/locally/ を参照)

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128

2. flash_attn を requirements.txtから削除して、pip install -r requirements.txt を実行する

3. 以下のように、flash_attnをインストールする

(参照: https://github.com/Dao-AILab/flash-attention/issues/246)

pip install psutil # also required by flash-attn
pip install flash-attn --no-build-isolation # to be able to find the previous two packages

モデルのインストール

pip install "huggingface_hub[cli]"
huggingface-cli download Wan-AI/Wan2.2-TI2V-5B --local-dir ./Wan2.2-TI2V-5B

推論

  • PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True を設定しないとGPUメモリのフラグメンテーションが発生して、GPUメモリが足りなくなります。
  • 設定しても、24GBギリギリな感じでした
export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True
date; python generate.py --task ti2v-5B --size 1280*704 --ckpt_dir ../Wan2.2-TI2V-5B --offload_model True --convert_model_dtype --t5_cpu --prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage"; date;
date; python generate.py --task ti2v-5B --size 1280*704 --ckpt_dir ../Wan2.2-TI2V-5B --offload_model True --convert_model_dtype --t5_cpu --prompt "擬人化された2匹の猫が、快適なボクシング用具と鮮やかなグローブを身に着けて、スポットライトに照らされたステージ上で激しく戦っている。"; date;
  • 大体、20分ちょいくらいかかります。
  • 英語と日本語のプロンプトで、品質にそれほど差は感じませんでした。(まあ、1回ずつしか出してないので、なんとも言えないのですが)

Discussion