d8ahazard / sd_dreambooth_extension

Other
1.85k stars 281 forks source link

[Bug]: Exception training model: 'cannot import name 'text_encoder_lora_state_dict' from 'diffusers.loaders' #1398

Closed klubkelli closed 7 months ago

klubkelli commented 7 months ago

Is there an existing issue for this?

What happened?

Unable to use dreambooth. I get the following error.

Exception training model: 'cannot import name 'text_encoder_lora_state_dict' from 'diffusers.loaders' (E:\sd.webui\webui\venv\lib\site-packages\diffusers\loaders__init__.py)'.

Steps to reproduce the problem

  1. Go to dreambooth tab in Automatic111
  2. Create a lora (fill out all the items)
  3. Press train
  4. Get error

Commit and libraries

Initializing Dreambooth Dreambooth revision: c548ede6a3acb85d78650ff50ae583786b305f0e Checking xformers... Checking bitsandbytes... Checking bitsandbytes (Windows) Virtual environment path: E:\sd.webui\webui\venv Checking for E:\sd.webui\webui\venv\lib\site-packages\bitsandbytes\libbitsandbytes_cuda118.dll Checking Dreambooth requirements... [Dreambooth] accelerate v0.21.0 is already installed. [Dreambooth] dadaptation v3.1 is already installed. [Dreambooth] diffusers v0.23.1 is already installed. [Dreambooth] discord-webhook v1.3.0 is already installed. [Dreambooth] fastapi is already installed. [Dreambooth] gitpython v3.1.40 is not installed. Successfully installed gitpython-3.1.40

[Dreambooth] pytorch_optimizer v2.12.0 is already installed. [Dreambooth] Pillow is already installed. [Dreambooth] tqdm is already installed. [Dreambooth] tomesd v0.1.2 is already installed. [Dreambooth] transformers v4.30.2 is already installed. [Dreambooth] tensorboard v2.13.0 is already installed. [!] xformers NOT installed. [+] torch version 2.0.1+cu118 installed. [+] torchvision version 0.15.2+cu118 installed. [+] accelerate version 0.21.0 installed. [+] diffusers version 0.24.0 installed. [+] transformers version 4.30.2 installed. [+] bitsandbytes version 0.41.1 installed. Launching Web UI with arguments: bin E:\sd.webui\webui\venv\lib\site-packages\bitsandbytes\libbitsandbytes_cuda118.dll no module 'xformers'. Processing without... no module 'xformers'. Processing without... No module 'xformers'. Proceeding without it. Loading weights [582daed225] from E:\sd.webui\webui\models\Stable-diffusion\pirsusEpicRealism_v31Pruned.safetensors Creating model from config: E:\sd.webui\webui\configs\v1-inference.yaml Running on local URL: http://127.0.0.1:7860

To create a public link, set share=True in launch(). Startup time: 16.6s (prepare environment: 10.2s, import torch: 2.2s, import gradio: 0.7s, setup paths: 0.8s, initialize shared: 0.2s, other imports: 0.2s, load scripts: 1.1s, create ui: 0.7s, gradio launch: 0.3s). Applying attention optimization: Doggettx... done. Model loaded in 2.2s (load weights from disk: 0.5s, create model: 0.4s, apply weights to model: 1.1s, calculate empty prompt: 0.1s). Advanced elements visible: False Traceback (most recent call last): File "E:\sd.webui\webui\venv\lib\site-packages\gradio\routes.py", line 488, in run_predict output = await app.get_blocks().process_api( File "E:\sd.webui\webui\venv\lib\site-packages\gradio\blocks.py", line 1431, in process_api result = await self.call_function( File "E:\sd.webui\webui\venv\lib\site-packages\gradio\blocks.py", line 1103, in call_function prediction = await anyio.to_thread.run_sync( File "E:\sd.webui\webui\venv\lib\site-packages\anyio\to_thread.py", line 33, in run_sync return await get_asynclib().run_sync_in_worker_thread( File "E:\sd.webui\webui\venv\lib\site-packages\anyio_backends_asyncio.py", line 877, in run_sync_in_worker_thread return await future File "E:\sd.webui\webui\venv\lib\site-packages\anyio_backends_asyncio.py", line 807, in run result = context.run(func, args) File "E:\sd.webui\webui\venv\lib\site-packages\gradio\utils.py", line 707, in wrapper response = f(args, **kwargs) File "E:\sd.webui\webui\modules\ui_extra_networks.py", line 392, in pages_html return refresh() File "E:\sd.webui\webui\modules\ui_extra_networks.py", line 400, in refresh ui.pages_contents = [pg.create_html(ui.tabname) for pg in ui.stored_extra_pages] File "E:\sd.webui\webui\modules\ui_extra_networks.py", line 400, in ui.pages_contents = [pg.create_html(ui.tabname) for pg in ui.stored_extra_pages] File "E:\sd.webui\webui\modules\ui_extra_networks.py", line 162, in create_html self.items = {x["name"]: x for x in self.list_items()} File "E:\sd.webui\webui\modules\ui_extra_networks.py", line 162, in self.items = {x["name"]: x for x in self.list_items()} File "E:\sd.webui\webui\extensions-builtin\Lora\ui_extra_networks_lora.py", line 69, in list_items for index, name in enumerate(networks.available_networks): RuntimeError: dictionary changed size during iteration 100%|██████████████████████████████████████████████████████████████████████████████████| 20/20 [00:01<00:00, 10.05it/s] Total progress: 100%|██████████████████████████████████████████████████████████████████| 20/20 [00:01<00:00, 12.43it/s] Extracting config from E:\sd.webui\webui\extensions\sd_dreambooth_extension\dreambooth..\configs\v1-training-unfrozen.yaml Extracting checkpoint from E:\sd.webui\webui\models\Stable-diffusion\v1-5-pruned.safetensors E:\sd.webui\webui\venv\lib\site-packages\transformers\models\clip\feature_extraction_clip.py:28: FutureWarning: The class CLIPFeatureExtractor is deprecated and will be removed in version 5 of Transformers. Please use CLIPImageProcessor instead. warnings.warn( Duration: 00:00:45 Updating scheduler name to: DDIM Advanced elements visible: True Initializing dreambooth training... Traceback (most recent call last): File "E:\sd.webui\webui\extensions\sd_dreambooth_extension\dreambooth\ui_functions.py", line 732, in start_training from dreambooth.train_dreambooth import main # noqa File "E:\sd.webui\webui\extensions\sd_dreambooth_extension\dreambooth\train_dreambooth.py", line 32, in from diffusers.loaders import LoraLoaderMixin, text_encoder_lora_state_dict ImportError: cannot import name 'text_encoder_lora_state_dict' from 'diffusers.loaders' (E:\sd.webui\webui\venv\lib\site-packages\diffusers\loaders__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "E:\sd.webui\webui\extensions\sd_dreambooth_extension\dreambooth\ui_functions.py", line 734, in start_training from dreambooth.train_dreambooth import main # noqa File "E:\sd.webui\webui\extensions\sd_dreambooth_extension\dreambooth\train_dreambooth.py", line 32, in from diffusers.loaders import LoraLoaderMixin, text_encoder_lora_state_dict ImportError: cannot import name 'text_encoder_lora_state_dict' from 'diffusers.loaders' (E:\sd.webui\webui\venv\lib\site-packages\diffusers\loaders__init__.py) Duration: 00:00:00 Duration: 00:00:01

Command Line Arguments

No

Console logs

venv "E:\sd.webui\webui\venv\Scripts\Python.exe"
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug  1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]
Version: v1.6.1
Commit hash: 4afaaf8a020c1df457bcf7250cb1c7f609699fa7
Installing requirements
bin E:\sd.webui\webui\venv\lib\site-packages\bitsandbytes\libbitsandbytes_cuda118.dll
no module 'xformers'. Processing without...
no module 'xformers'. Processing without...
No module 'xformers'. Proceeding without it.
If submitting an issue on github, please provide the full startup log for debugging purposes.

Initializing Dreambooth
Dreambooth revision: c548ede6a3acb85d78650ff50ae583786b305f0e
Checking xformers...
Checking bitsandbytes...
Checking bitsandbytes (Windows)
Virtual environment path: E:\sd.webui\webui\venv
Checking for E:\sd.webui\webui\venv\lib\site-packages\bitsandbytes\libbitsandbytes_cuda118.dll
Checking Dreambooth requirements...
[Dreambooth] accelerate v0.21.0 is already installed.
[Dreambooth] dadaptation v3.1 is already installed.
[Dreambooth] diffusers v0.23.1 is already installed.
[Dreambooth] discord-webhook v1.3.0 is already installed.
[Dreambooth] fastapi is already installed.
[Dreambooth] gitpython v3.1.40 is not installed.
Successfully installed gitpython-3.1.40

[Dreambooth] pytorch_optimizer v2.12.0 is already installed.
[Dreambooth] Pillow is already installed.
[Dreambooth] tqdm is already installed.
[Dreambooth] tomesd v0.1.2 is already installed.
[Dreambooth] transformers v4.30.2 is already installed.
[Dreambooth] tensorboard v2.13.0 is already installed.
[!] xformers NOT installed.
[+] torch version 2.0.1+cu118 installed.
[+] torchvision version 0.15.2+cu118 installed.
[+] accelerate version 0.21.0 installed.
[+] diffusers version 0.24.0 installed.
[+] transformers version 4.30.2 installed.
[+] bitsandbytes version 0.41.1 installed.
Launching Web UI with arguments:
bin E:\sd.webui\webui\venv\lib\site-packages\bitsandbytes\libbitsandbytes_cuda118.dll
no module 'xformers'. Processing without...
no module 'xformers'. Processing without...
No module 'xformers'. Proceeding without it.
Loading weights [582daed225] from E:\sd.webui\webui\models\Stable-diffusion\pirsusEpicRealism_v31Pruned.safetensors
Creating model from config: E:\sd.webui\webui\configs\v1-inference.yaml
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
Startup time: 16.6s (prepare environment: 10.2s, import torch: 2.2s, import gradio: 0.7s, setup paths: 0.8s, initialize shared: 0.2s, other imports: 0.2s, load scripts: 1.1s, create ui: 0.7s, gradio launch: 0.3s).
Applying attention optimization: Doggettx... done.
Model loaded in 2.2s (load weights from disk: 0.5s, create model: 0.4s, apply weights to model: 1.1s, calculate empty prompt: 0.1s).
Advanced elements visible: False
Traceback (most recent call last):
  File "E:\sd.webui\webui\venv\lib\site-packages\gradio\routes.py", line 488, in run_predict
    output = await app.get_blocks().process_api(
  File "E:\sd.webui\webui\venv\lib\site-packages\gradio\blocks.py", line 1431, in process_api
    result = await self.call_function(
  File "E:\sd.webui\webui\venv\lib\site-packages\gradio\blocks.py", line 1103, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "E:\sd.webui\webui\venv\lib\site-packages\anyio\to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "E:\sd.webui\webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
  File "E:\sd.webui\webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 807, in run
    result = context.run(func, *args)
  File "E:\sd.webui\webui\venv\lib\site-packages\gradio\utils.py", line 707, in wrapper
    response = f(*args, **kwargs)
  File "E:\sd.webui\webui\modules\ui_extra_networks.py", line 392, in pages_html
    return refresh()
  File "E:\sd.webui\webui\modules\ui_extra_networks.py", line 400, in refresh
    ui.pages_contents = [pg.create_html(ui.tabname) for pg in ui.stored_extra_pages]
  File "E:\sd.webui\webui\modules\ui_extra_networks.py", line 400, in <listcomp>
    ui.pages_contents = [pg.create_html(ui.tabname) for pg in ui.stored_extra_pages]
  File "E:\sd.webui\webui\modules\ui_extra_networks.py", line 162, in create_html
    self.items = {x["name"]: x for x in self.list_items()}
  File "E:\sd.webui\webui\modules\ui_extra_networks.py", line 162, in <dictcomp>
    self.items = {x["name"]: x for x in self.list_items()}
  File "E:\sd.webui\webui\extensions-builtin\Lora\ui_extra_networks_lora.py", line 69, in list_items
    for index, name in enumerate(networks.available_networks):
RuntimeError: dictionary changed size during iteration
100%|██████████████████████████████████████████████████████████████████████████████████| 20/20 [00:01<00:00, 10.05it/s]
Total progress: 100%|██████████████████████████████████████████████████████████████████| 20/20 [00:01<00:00, 12.43it/s]
Extracting config from E:\sd.webui\webui\extensions\sd_dreambooth_extension\dreambooth\..\configs\v1-training-unfrozen.yaml
Extracting checkpoint from E:\sd.webui\webui\models\Stable-diffusion\v1-5-pruned.safetensors
E:\sd.webui\webui\venv\lib\site-packages\transformers\models\clip\feature_extraction_clip.py:28: FutureWarning: The class CLIPFeatureExtractor is deprecated and will be removed in version 5 of Transformers. Please use CLIPImageProcessor instead.
  warnings.warn(
Duration: 00:00:45
Updating scheduler name to: DDIM
Advanced elements visible: True
Initializing dreambooth training...
Traceback (most recent call last):
  File "E:\sd.webui\webui\extensions\sd_dreambooth_extension\dreambooth\ui_functions.py", line 732, in start_training
    from dreambooth.train_dreambooth import main  # noqa
  File "E:\sd.webui\webui\extensions\sd_dreambooth_extension\dreambooth\train_dreambooth.py", line 32, in <module>
    from diffusers.loaders import LoraLoaderMixin, text_encoder_lora_state_dict
ImportError: cannot import name 'text_encoder_lora_state_dict' from 'diffusers.loaders' (E:\sd.webui\webui\venv\lib\site-packages\diffusers\loaders\__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\sd.webui\webui\extensions\sd_dreambooth_extension\dreambooth\ui_functions.py", line 734, in start_training
    from dreambooth.train_dreambooth import main  # noqa
  File "E:\sd.webui\webui\extensions\sd_dreambooth_extension\dreambooth\train_dreambooth.py", line 32, in <module>
    from diffusers.loaders import LoraLoaderMixin, text_encoder_lora_state_dict
ImportError: cannot import name 'text_encoder_lora_state_dict' from 'diffusers.loaders' (E:\sd.webui\webui\venv\lib\site-packages\diffusers\loaders\__init__.py)
Duration: 00:00:00
Duration: 00:00:01

Additional information

No response

Rkfecc commented 7 months ago

Its my BUG :( Help please!


I fix it!


I am not sure how it is on other OS's but on Windows, if you are trying to use the fix from the OP post, make sure you are running the commands within the environment created by Automatic1111.

To change the version of diffusers in the environment set up by the batch file for Automatic1111, you can follow these steps:

Activate the Virtual Environment: First, navigate to the directory where Automatic1111 is located. Then, activate the virtual environment. You can do this by running:


venv\Scripts\activate


Replace venv with the actual name of your virtual environment directory if it's different.

Uninstall the Current Version of diffusers: Run the following command:


pip uninstall diffusers


Install the Desired Version of diffusers: Install a specific version of diffusers by specifying the version number:


pip install diffusers==0.23.1


Verify the Installation: Check if the correct version is installed:


pip show diffusers


This will install the specified version of diffusers in the virtual environment used by Automatic1111. You can follow the same steps from step 2 for xformers if you need to.

Make sure you see, [+] diffusers version 0.23.1 installed. when you run Automatic1111 webUI.


Need to edit the file: C:\Users\User\Desktop\STABLEDIFFUSION\sd.webui\webui\requirements_versions.txt

And

Need to edit the file: C:\Users\User\Desktop\STABLEDIFFUSION\sd.webui\webui\extensions\sd_dreambooth_extension\requirements.txt

Need to change or add "diffusers==0.23.1"

d8ahazard commented 7 months ago

Fixed in latest revision.