【AnimateDiff】 OSError: Can't load tokenizer for '/AnimateDiff/models/StableDiffusion/feature_extractor/'. If you were trying to load it from 'https://huggingface.co/models', make sure you don't have a local directory with the same name. Otherwise, make sure '/AnimateDiff/models/StableDiffusion/feature_extractor/' is the correct path to a directory containing all relevant files for a CLIPTokenizer tokenizer.

2024/03/06
AnimateDiff のインストール中に発生したエラー。(AnimateDiff:https://github.com/guoyww/AnimateDiff )

■ 結論

$ git lfs clone https://huggingface.co/runwayml/stable-diffusion-v1-5 models/StableDiffusion/stable-diffusion-v1-5

■ 問題

app.pyを起動する。
$ python app.py
:
Running on local URL:  http://127.0.0.1:7860
:

ブラウザからStable Diffusion のモデルを選択するとエラーが起こる。
Pretrained model path メニュー

  File "/anaconda3/envs/animatediff/lib/python3.10/site-packages/gradio/utils.py", line 707, in wrapper
    response = f(*args, **kwargs)
  File "/AnimateDiff/app.py", line 83, in update_stable_diffusion
    self.tokenizer = CLIPTokenizer.from_pretrained(stable_diffusion_dropdown, subfolder="tokenizer")
  File "/anaconda3/envs/animatediff/lib/python3.10/site-packages/transformers/tokenization_utils_base.py", line 1785, in from_pretrained
    raise EnvironmentError(
OSError: Can't load tokenizer for '/AnimateDiff/models/StableDiffusion/feature_extractor/'. If you were trying to load it from 'https://huggingface.co/models', make sure you don't have a local directory with the same name. Otherwise, make sure '/AnimateDiff/models/StableDiffusion/feature_extractor/' is the correct path to a directory containing all relevant files for a CLIPTokenizer tokenizer.
エラー文。

公式githubの説明通りに作業をしていたんだけど、何回試してもこのエラーが出る。 逐次エラー対処していくと、やれ「unet/ がない」だ「vae/ がない」だの言い出す。でもcloneで全部持ってきてるんだよね。 
公式 Gradio Demoの画像を見ていると、モデルに「stable-diffusion-v1-5」を選択している。つまり選択肢に「feature_extractor/」が出てるのがすでにおかしいのではないか? 
AnimeteDiff 公式githubより


 どうも公式手順のここが間違ってる気がする。
git lfs install
git clone https://huggingface.co/runwayml/stable-diffusion-v1-5 models/StableDiffusion/
たぶんクローン先が`models/StableDiffusion/` じゃなくて `models/StableDiffusion/<任意の名称>` じゃないのかな。というかこのコマンド叩くと「すでにファイルがあるんですけど!」ってエラーが出るし変だとは思ってた。

せっかく lfs をインストールしたんだからついでに使っておく。
$ rm -rf models/StableDiffusion/*
$ git lfs clone https://huggingface.co/runwayml/stable-diffusion-v1-5 models/StableDiffusion/stable-diffusion-v1-5
これでモデル選択のドロップダウンに「stable-diffusion-v1-5」が表示された。
このまま選択してエラーが出なくなった。
Pretrained model path の内容が変わった

解決。

コメント