gpu sorobanでStableDiffusionWebUI上のDreamBoothを起動するまで。（依存問題解消。）

## 前提、参考サイト
①GPUSOROBAN系のStableDiffusionのインストール手順：https://soroban.highreso.jp/article/article-019#651d014631b283004a403802-1699527714969
Dreamboothのインストール：②https://xxroadxx.wpx.jp/%E3%80%90%E5%AE%8C%E5%85%A8%E3%82%AC%E3%82%A4%E3%83%89%E3%80%91webui1111%E3%81%A7dreambooth%E3%82%92%E7%B0%A1%E5%8D%98%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB%EF%BC%81%E5%AD%A6/
※GPUそろばん公式でDreamBoothの解説記事がありますが、WebUI版じゃない為、参考にしませんでした。

## DreamboothをWebUIのExtensionsタブ→Availableタブからインストールした後、下記のようなエラーが発生。

StableDiffusion自体は起動するがDreamBoothタブが表示されません。
困る方がいるかも知れないので検索のため全量コンソールアウトプット記載
~~~
ControlNet preprocessor location: /home/user/stable-diffusion-webui/extensions/sd-webui-controlnet/annotator/downloads
2025-01-10 12:30:09,257 - ControlNet - INFO - ControlNet v1.1.455
Exception importing api
Traceback (most recent call last):
  File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/utils/import_utils.py", line 920, in _get_module
    return importlib.import_module("." + module_name, self.__name__)
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/loaders/ip_adapter.py", line 36, in <module>
    from transformers import CLIPImageProcessor, CLIPVisionModelWithProjection, SiglipImageProcessor, SiglipVisionModel
ImportError: cannot import name 'SiglipImageProcessor' from 'transformers' (/home/user/.venv/base/lib/python3.10/site-packages/transformers/__init__.py)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/utils/import_utils.py", line 920, in _get_module
    return importlib.import_module("." + module_name, self.__name__)
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py", line 29, in <module>
    from ...loaders import (
  File "<frozen importlib._bootstrap>", line 1075, in _handle_fromlist
  File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/utils/import_utils.py", line 910, in __getattr__
    module = self._get_module(self._class_to_module[name])
  File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/utils/import_utils.py", line 922, in _get_module
    raise RuntimeError(
RuntimeError: Failed to import diffusers.loaders.ip_adapter because of the following error (look up to see its traceback):
cannot import name 'SiglipImageProcessor' from 'transformers' (/home/user/.venv/base/lib/python3.10/site-packages/transformers/__init__.py)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/user/stable-diffusion-webui/extensions/sd_dreambooth_extension/scripts/api.py", line 32, in <module>
    from dreambooth.ui_functions import create_model, generate_samples, \
  File "/home/user/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/ui_functions.py", line 28, in <module>
    from dreambooth.sd_to_diff import extract_checkpoint
  File "/home/user/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/sd_to_diff.py", line 24, in <module>
    from diffusers import StableDiffusionXLPipeline, StableDiffusionPipeline
  File "<frozen importlib._bootstrap>", line 1075, in _handle_fromlist
  File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/utils/import_utils.py", line 911, in __getattr__
    value = getattr(module, name)
  File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/utils/import_utils.py", line 911, in __getattr__
    value = getattr(module, name)
  File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/utils/import_utils.py", line 910, in __getattr__
    module = self._get_module(self._class_to_module[name])
  File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/utils/import_utils.py", line 922, in _get_module
    raise RuntimeError(
RuntimeError: Failed to import diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl because of the following error (look up to see its traceback):
Failed to import diffusers.loaders.ip_adapter because of the following error (look up to see its traceback):
cannot import name 'SiglipImageProcessor' from 'transformers' (/home/user/.venv/base/lib/python3.10/site-packages/transformers/__init__.py)
*** Error loading script: main.py
    Traceback (most recent call last):
      File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/utils/import_utils.py", line 920, in _get_module
        return importlib.import_module("." + module_name, self.__name__)
      File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
      File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/loaders/ip_adapter.py", line 36, in <module>
        from transformers import CLIPImageProcessor, CLIPVisionModelWithProjection, SiglipImageProcessor, SiglipVisionModel
    ImportError: cannot import name 'SiglipImageProcessor' from 'transformers' (/home/user/.venv/base/lib/python3.10/site-packages/transformers/__init__.py)

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last):
      File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/utils/import_utils.py", line 920, in _get_module
        return importlib.import_module("." + module_name, self.__name__)
      File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
      File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py", line 29, in <module>
        from ...loaders import (
      File "<frozen importlib._bootstrap>", line 1075, in _handle_fromlist
      File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/utils/import_utils.py", line 910, in __getattr__
        module = self._get_module(self._class_to_module[name])
      File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/utils/import_utils.py", line 922, in _get_module
        raise RuntimeError(
    RuntimeError: Failed to import diffusers.loaders.ip_adapter because of the following error (look up to see its traceback):
    cannot import name 'SiglipImageProcessor' from 'transformers' (/home/user/.venv/base/lib/python3.10/site-packages/transformers/__init__.py)

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last):
      File "/home/user/stable-diffusion-webui/modules/scripts.py", line 515, in load_scripts
        script_module = script_loading.load_module(scriptfile.path)
      File "/home/user/stable-diffusion-webui/modules/script_loading.py", line 13, in load_module
        module_spec.loader.exec_module(module)
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "/home/user/stable-diffusion-webui/extensions/sd_dreambooth_extension/scripts/main.py", line 20, in <module>
        from dreambooth.ui_functions import (
      File "/home/user/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/ui_functions.py", line 28, in <module>
        from dreambooth.sd_to_diff import extract_checkpoint
      File "/home/user/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/sd_to_diff.py", line 24, in <module>
        from diffusers import StableDiffusionXLPipeline, StableDiffusionPipeline
      File "<frozen importlib._bootstrap>", line 1075, in _handle_fromlist
      File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/utils/import_utils.py", line 911, in __getattr__
        value = getattr(module, name)
      File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/utils/import_utils.py", line 911, in __getattr__
        value = getattr(module, name)
      File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/utils/import_utils.py", line 910, in __getattr__
        module = self._get_module(self._class_to_module[name])
      File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/utils/import_utils.py", line 922, in _get_module
        raise RuntimeError(
    RuntimeError: Failed to import diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl because of the following error (look up to see its traceback):
    Failed to import diffusers.loaders.ip_adapter because of the following error (look up to see its traceback):
    cannot import name 'SiglipImageProcessor' from 'transformers' (/home/user/.venv/base/lib/python3.10/site-packages/transformers/__init__.py
~~~

## 原因
前提、参考サイト①の下記設定と競合していると思われる
user/stable-diffusion-webui/webui-user.sh
~~~
export TORCH_COMMAND="pip install torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 --index-url https://download.pytorch.org/whl/cu118 xformers==0.0.22.post7"
~~~
この設定はGPUSOROBANのグラフィックドライバーが古いため、最新だとエラーが出ます。それをTorch等ライブラリをダウングレードすることでなんとか動かしている設定。
今回は（多分）回避できましたが、この設定は今後深いことをやろうとするたびライブラリ依存に問題が出ると思いますので改善してほしいです。

## 試行①
下記更新。
user/stable-diffusion-webui/webui-user.sh
~~~
export COMMANDLINE_ARGS="--reinstall-xformers --reinstall-torch --autolaunch --xformers --skip-torch-cuda-test"
#export TORCH_COMMAND="pip install torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 --index-url https://download.pytorch.org/whl/cu118 xformers==0.0.22.post7"
~~~
Torchなどの最新化する設定です。GPUドライバが古いので怒られます。

## 試行②※多分解決
DreamBoothをダウングレード
~~~
   67  cd ~/stable-diffusion-webui/extensions;rm -rf sd_dreambooth_extension/;
   68  git clone https://github.com/d8ahazard/sd_dreambooth_extension.git -b 1.0.13
   69  cd ..
   70  bash webui.sh
~~~

下記のエラーになります。
~~~
ControlNet preprocessor location: /home/user/stable-diffusion-webui/extensions/sd-webui-controlnet/annotator/downloads
2025-01-10 12:39:06,608 - ControlNet - INFO - ControlNet v1.1.455
Loading weights [1a17bcd93d] from /home/user/stable-diffusion-webui/models/Stable-diffusion/beautifulRealistic_v7.safetensors
Creating model from config: /home/user/stable-diffusion-webui/configs/v1-inference.yaml
/home/user/.venv/base/lib/python3.10/site-packages/huggingface_hub/file_download.py:795: FutureWarning: `resume_download` is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use `force_download=True`.
  warnings.warn(
Model loaded in 0.9s (create model: 0.2s, apply weights to model: 0.3s, calculate empty prompt: 0.3s).
Exception importing api
Traceback (most recent call last):
  File "/home/user/stable-diffusion-webui/extensions/sd_dreambooth_extension/scripts/api.py", line 27, in <module>
    from dreambooth.dataclasses.db_config import from_file, DreamboothConfig
  File "/home/user/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/dataclasses/db_config.py", line 10, in <module>
    from dreambooth.utils.image_utils import get_scheduler_names  # noqa
  File "/home/user/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/utils/image_utils.py", line 11, in <module>
    from diffusers.schedulers import KarrasDiffusionSchedulers
  File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/__init__.py", line 3, in <module>
    from .configuration_utils import ConfigMixin
  File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/configuration_utils.py", line 34, in <module>
    from .utils import DIFFUSERS_CACHE, HUGGINGFACE_CO_RESOLVE_ENDPOINT, DummyObject, deprecate, logging
  File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/utils/__init__.py", line 37, in <module>
    from .dynamic_modules_utils import get_class_from_dynamic_module
  File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/utils/dynamic_modules_utils.py", line 29, in <module>
    from huggingface_hub import HfFolder, cached_download, hf_hub_download, model_info
ImportError: cannot import name 'cached_download' from 'huggingface_hub' (/home/user/.venv/base/lib/python3.10/site-packages/huggingface_hub/__init__.py)
*** Error loading script: main.py
    Traceback (most recent call last):
      File "/home/user/stable-diffusion-webui/modules/scripts.py", line 515, in load_scripts
        script_module = script_loading.load_module(scriptfile.path)
      File "/home/user/stable-diffusion-webui/modules/script_loading.py", line 13, in load_module
        module_spec.loader.exec_module(module)
      File "<frozen importlib._bootstrap_external>", line 883, in exec_module
      File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
      File "/home/user/stable-diffusion-webui/extensions/sd_dreambooth_extension/scripts/main.py", line 7, in <module>
        from dreambooth.dataclasses.db_config import (
      File "/home/user/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/dataclasses/db_config.py", line 10, in <module>
        from dreambooth.utils.image_utils import get_scheduler_names  # noqa
      File "/home/user/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/utils/image_utils.py", line 11, in <module>
        from diffusers.schedulers import KarrasDiffusionSchedulers
      File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/__init__.py", line 3, in <module>
        from .configuration_utils import ConfigMixin
      File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/configuration_utils.py", line 34, in <module>
        from .utils import DIFFUSERS_CACHE, HUGGINGFACE_CO_RESOLVE_ENDPOINT, DummyObject, deprecate, logging
      File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/utils/__init__.py", line 37, in <module>
        from .dynamic_modules_utils import get_class_from_dynamic_module
      File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/utils/dynamic_modules_utils.py", line 29, in <module>
        from huggingface_hub import HfFolder, cached_download, hf_hub_download, model_info
    ImportError: cannot import name 'cached_download' from 'huggingface_hub' (/home/user/.venv/base/lib/python3.10/site-packages/huggingface_hub/__init__.py)

---
Applying attention optimization: xformers... done.
2025-01-10 12:39:07,950 - ControlNet - INFO - ControlNet UI callback registered.
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
*** Error executing callback app_started_callback for /home/user/stable-diffusion-webui/extensions/sd_dreambooth_extension/scripts/api.py
    Traceback (most recent call last):
      File "/home/user/stable-diffusion-webui/modules/script_callbacks.py", line 256, in app_started_callback
        c.callback(demo, app)
      File "/home/user/stable-diffusion-webui/extensions/sd_dreambooth_extension/scripts/api.py", line 524, in dreambooth_api
        model_cfg: DreamboothConfig = Body(description="The config to save"),
    NameError: name 'DreamboothConfig' is not defined

---
Startup time: 24.2s (prepare environment: 17.4s, import torch: 1.7s, import gradio: 0.6s, setup paths: 1.7s, other imports: 0.2s, load scripts: 2.0s, create ui: 0.3s, gradio launch: 0.2s).
*** Failed reading extension data from Git repository (sd_dreambooth_extension)
    Traceback (most recent call last):
      File "/home/user/stable-diffusion-webui/modules/extensions.py", line 168, in do_read_info_from_repo
        if repo.active_branch:
      File "/home/user/.venv/base/lib/python3.10/site-packages/git/repo/base.py", line 896, in active_branch
        return self.head.reference
      File "/home/user/.venv/base/lib/python3.10/site-packages/git/refs/symbolic.py", line 309, in _get_reference
        raise TypeError("%s is a detached symbolic reference as it points to %r" % (self, sha))
    TypeError: HEAD is a detached symbolic reference as it points to 'e85c8c5f96485949d128b070069180347442cc78'
~~~

下記がおそらく原因
>File "/home/user/.venv/base/lib/python3.10/site-packages/diffusers/utils/dynamic_modules_utils.py", line 29, in <module>
        from huggingface_hub import HfFolder, cached_download, hf_hub_download, model_info
    ImportError: cannot import name 'cached_download' from 'huggingface_hub' (/home/user/.venv/base/lib/python3.10/site-packages/huggingface_hub/__init__.py)

「, cached_download」を消せばとりあえず動くようになりました。
なにの影響があるかまでは評価してないので、うまく動かないかもしれません。

※別ソフトですが参考にしたのは下記のIssue
https://github.com/easydiffusion/easydiffusion/issues/1851

ちなみに、似た感じで最新版（執筆時）でもインポート消せば一応起動することが確認できました。
最新版だとSiglipImageProcessor,SiglipVisionModelをどこかのライブラリから消しました。
影響あるかどうかはわかりませんが、最新のほうが情報多いのでおすすめです。

## ひとこと
2時間ぐらいハマりました。悲しいです
今回は（多分）回避できましたが、この設定は今後深いことをやろうとするたびライブラリ依存に問題が出ると思いますので改善してほしいです。