Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: 'text_encoder_lora_state_dict' from 'diffusers.loaders' #1397

Closed
1 task done
Anime4000 opened this issue Nov 30, 2023 · 28 comments
Closed
1 task done

[Bug]: 'text_encoder_lora_state_dict' from 'diffusers.loaders' #1397

Anime4000 opened this issue Nov 30, 2023 · 28 comments

Comments

@Anime4000
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues and checked the recent builds/commits of both this extension and the webui

What happened?

during fresh install, pip using latest diffusers 0.24 as per requirements.txt: [+] diffusers version 0.24.0 installed.

Steps to reproduce the problem

pip install diffusers>=0.23.1 (it will install 0.24.0)
if don't, do diffusers==0.24.0

Commit and libraries

Starting at Initializing Dreambooth and ending several lines below at [+] bitsandbytes version 0.35.4 installed..

Command Line Arguments

--listen --xformers --no-half-vae --opt-sdp-no-mem-attention

Console logs

Initializing dreambooth training...
Traceback (most recent call last):
  File "E:\stable-diffusion-webui\extensions\sd_dreambooth_extension\dreambooth\ui_functions.py", line 732, in start_training
    from dreambooth.train_dreambooth import main  # noqa
  File "E:\stable-diffusion-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:\stable-diffusion-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:\stable-diffusion-webui\extensions\sd_dreambooth_extension\dreambooth\ui_functions.py", line 734, in start_training
    from dreambooth.train_dreambooth import main  # noqa
  File "E:\stable-diffusion-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:\stable-diffusion-webui\venv\lib\site-packages\diffusers\loaders\__init__.py)
Duration: 00:00:00
Duration: 00:00:01

Additional information

to fix this temporary run this from venv:

pip install xformers==0.0.21
pip install diffusers==0.23.1

For upcoming changes of diffusers >= 0.24.0, perhaps not to use text_encoder_lora_state_dict on normal UNET

@0Core
Copy link

0Core commented Nov 30, 2023

It is still does not work. Installed versions xformers==0.0.21 and diffusers==0.23.1 lead to the same error: cannot import name 'text_encoder_lora_state_dict' from 'diffusers.loaders'

@0Core
Copy link

0Core commented Nov 30, 2023

I've tried on ubuntu, windows and mac, still no result

@0Core
Copy link

0Core commented Nov 30, 2023

pip list
absl-py 2.0.0
accelerate 0.24.1
annotated-types 0.6.0
anyio 3.7.1
bitsandbytes 0.35.4
cachetools 5.3.2
certifi 2023.11.17
charset-normalizer 3.3.2
cmake 3.26.4
dadaptation 3.2
decorator 4.4.2
diffusers 0.23.1
discord-webhook 1.3.0
exceptiongroup 1.2.0
fastapi 0.104.1
filelock 3.12.0
fsspec 2023.10.0
gitdb 4.0.11
GitPython 3.1.40
google-auth 2.23.4
google-auth-oauthlib 1.1.0
grpcio 1.59.3
huggingface-hub 0.19.4
idna 3.6
imageio 2.31.0
imageio-ffmpeg 0.4.8
importlib-metadata 6.8.0
Jinja2 3.1.2
lit 16.0.5.post0
Markdown 3.5.1
MarkupSafe 2.1.3
moviepy 1.0.3
mpmath 1.3.0
networkx 3.1
numpy 1.24.3
nvidia-cublas-cu11 11.10.3.66
nvidia-cublas-cu12 12.1.3.1
nvidia-cuda-cupti-cu11 11.7.101
nvidia-cuda-cupti-cu12 12.1.105
nvidia-cuda-nvrtc-cu11 11.7.99
nvidia-cuda-nvrtc-cu12 12.1.105
nvidia-cuda-runtime-cu11 11.7.99
nvidia-cuda-runtime-cu12 12.1.105
nvidia-cudnn-cu11 8.5.0.96
nvidia-cudnn-cu12 8.9.2.26
nvidia-cufft-cu11 10.9.0.58
nvidia-cufft-cu12 11.0.2.54
nvidia-curand-cu11 10.2.10.91
nvidia-curand-cu12 10.3.2.106
nvidia-cusolver-cu11 11.4.0.1
nvidia-cusolver-cu12 11.4.5.107
nvidia-cusparse-cu11 11.7.4.91
nvidia-cusparse-cu12 12.1.0.106
nvidia-nccl-cu11 2.14.3
nvidia-nccl-cu12 2.18.1
nvidia-nvjitlink-cu12 12.3.101
nvidia-nvtx-cu11 11.7.91
nvidia-nvtx-cu12 12.1.105
oauthlib 3.2.2
opencv-python 4.7.0.72
packaging 23.2
Pillow 9.5.0
pip 22.2.1
proglog 0.1.10
protobuf 4.23.4
psutil 5.9.6
pyasn1 0.5.1
pyasn1-modules 0.3.0
pydantic 2.5.2
pydantic_core 2.14.5
pytorch_optimizer 2.12.0
PyYAML 6.0.1
regex 2023.10.3
requests 2.31.0
requests-oauthlib 1.3.1
rsa 4.9
safetensors 0.4.1
setuptools 63.2.0
six 1.16.0
smmap 5.0.1
sniffio 1.3.0
starlette 0.27.0
sympy 1.12
tensorboard-data-server 0.7.2
tokenizers 0.15.0
tomesd 0.1.3
torch 2.0.1
tqdm 4.65.0
transformers 4.35.2
triton 2.0.0
typing_extensions 4.8.0
urllib3 2.1.0
wcwidth 0.2.12
Werkzeug 3.0.1
wheel 0.42.0
xformers 0.0.21
zipp 3.17.0

@0Core
Copy link

0Core commented Nov 30, 2023

###############################################################
Launching launch.py...
################################################################
Using TCMalloc: libtcmalloc_minimal.so.4
Python 3.10.6 (main, Nov 28 2023, 20:39:01) [GCC 11.4.0]
Version: v1.6.0-2-g4afaaf8a
Commit hash: 4afaaf8a020c1df457bcf7250cb1c7f609699fa7
Installing requirements
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: c548ede
Checking xformers...
Checking bitsandbytes...
Checking bitsandbytes (Linux)
Installing bitsandbytes
Error occurred:
Usage:
/home/borg/projects/stable-diffusion-webui/venv/bin/python3 -m pip install [options] [package-index-options] ...
/home/borg/projects/stable-diffusion-webui/venv/bin/python3 -m pip install [options] -r [package-index-options] ...
/home/borg/projects/stable-diffusion-webui/venv/bin/python3 -m pip install [options] [-e] ...
/home/borg/projects/stable-diffusion-webui/venv/bin/python3 -m pip install [options] [-e] ...
/home/borg/projects/stable-diffusion-webui/venv/bin/python3 -m pip install [options] <archive url/path> ...

no such option: --force-install

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 NOT installed.

#######################################################################################################

LIBRARY ISSUE DETECTED

#######################################################################################################

bitsandbytes not installed.

Dreambooth may not work properly.

TROUBLESHOOTING

1. Fully restart your project (not just the webpage)

2. Update your A1111 project and extensions

3. Dreambooth requirements should have installed automatically, but you can manually install them

by running the following commands from the A1111 project root:

cd venv/Scripts
activate
cd ../..
pip install -r ./extensions/sd_dreambooth_extension/requirements.txt
pip install --prefer-binary --force-reinstall https://github.com/jllllll/bitsandbytes-windows-webui/releases/download/wheels/bitsandbytes-0.41.1-py3-none-win_amd64.whl
#######################################################################################################
Launching Web UI with arguments:
no module 'xformers'. Processing without...
no module 'xformers'. Processing without...
No module 'xformers'. Proceeding without it.

@0Core
Copy link

0Core commented Nov 30, 2023

also i'm running ubuntu-22.04 but it recommends to install pip install --prefer-binary --force-reinstall https://github.com/jllllll/bitsandbytes-windows-webui/releases/download/wheels/bitsandbytes-0.41.1-py3-none-win_amd64.whl Windows binary

@jcpinillos
Copy link

I am also receiving this error. I tried the temporary fix as well that was posted in the original post but it did not fix my issue. I received the same error. I checked the versions being used and it lists the version posted as the temporary fix.

Console Log

Initializing dreambooth training...
Traceback (most recent call last):
  File "E:\stable-diffusion-webui\extensions\sd_dreambooth_extension\dreambooth\ui_functions.py", line 732, in start_training
    from dreambooth.train_dreambooth import main  # noqa
  File "E:\stable-diffusion-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:\stable-diffusion-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:\stable-diffusion-webui\extensions\sd_dreambooth_extension\dreambooth\ui_functions.py", line 734, in start_training
    from dreambooth.train_dreambooth import main  # noqa
  File "E:\stable-diffusion-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:\stable-diffusion-webui\venv\lib\site-packages\diffusers\loaders\__init__.py)

@jcpinillos
Copy link

############################################################### Launching launch.py... ################################################################ Using TCMalloc: libtcmalloc_minimal.so.4 Python 3.10.6 (main, Nov 28 2023, 20:39:01) [GCC 11.4.0] Version: v1.6.0-2-g4afaaf8a Commit hash: 4afaaf8a020c1df457bcf7250cb1c7f609699fa7 Installing requirements 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: c548ede Checking xformers... Checking bitsandbytes... Checking bitsandbytes (Linux) Installing bitsandbytes Error occurred: Usage: /home/borg/projects/stable-diffusion-webui/venv/bin/python3 -m pip install [options] [package-index-options] ... /home/borg/projects/stable-diffusion-webui/venv/bin/python3 -m pip install [options] -r [package-index-options] ... /home/borg/projects/stable-diffusion-webui/venv/bin/python3 -m pip install [options] [-e] ... /home/borg/projects/stable-diffusion-webui/venv/bin/python3 -m pip install [options] [-e] ... /home/borg/projects/stable-diffusion-webui/venv/bin/python3 -m pip install [options] <archive url/path> ...

no such option: --force-install

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 NOT installed.

#######################################################################################################

LIBRARY ISSUE DETECTED

#######################################################################################################

bitsandbytes not installed.

Dreambooth may not work properly.

TROUBLESHOOTING

1. Fully restart your project (not just the webpage)

2. Update your A1111 project and extensions

3. Dreambooth requirements should have installed automatically, but you can manually install them

by running the following commands from the A1111 project root:

cd venv/Scripts activate cd ../.. pip install -r ./extensions/sd_dreambooth_extension/requirements.txt pip install --prefer-binary --force-reinstall https://github.com/jllllll/bitsandbytes-windows-webui/releases/download/wheels/bitsandbytes-0.41.1-py3-none-win_amd64.whl ####################################################################################################### Launching Web UI with arguments: no module 'xformers'. Processing without... no module 'xformers'. Processing without... No module 'xformers'. Proceeding without it.

It seems that you don't have the argument to use xformers set. I am not saying it will fix your issues but it should at least get you past the No module xformers. Proceeding without it.

You can see how to do it at Command Line Arguments and Settings

@0Core
Copy link

0Core commented Nov 30, 2023

############################################################### Launching launch.py... ################################################################ Using TCMalloc: libtcmalloc_minimal.so.4 Python 3.10.6 (main, Nov 28 2023, 20:39:01) [GCC 11.4.0] Version: v1.6.0-2-g4afaaf8a Commit hash: 4afaaf8a020c1df457bcf7250cb1c7f609699fa7 Installing requirements 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: c548ede Checking xformers... Checking bitsandbytes... Checking bitsandbytes (Linux) Installing bitsandbytes Error occurred: Usage: /home/borg/projects/stable-diffusion-webui/venv/bin/python3 -m pip install [options] [package-index-options] ... /home/borg/projects/stable-diffusion-webui/venv/bin/python3 -m pip install [options] -r [package-index-options] ... /home/borg/projects/stable-diffusion-webui/venv/bin/python3 -m pip install [options] [-e] ... /home/borg/projects/stable-diffusion-webui/venv/bin/python3 -m pip install [options] [-e] ... /home/borg/projects/stable-diffusion-webui/venv/bin/python3 -m pip install [options] <archive url/path> ...
no such option: --force-install
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 NOT installed.
#######################################################################################################

LIBRARY ISSUE DETECTED

#######################################################################################################

bitsandbytes not installed.

Dreambooth may not work properly.

TROUBLESHOOTING

1. Fully restart your project (not just the webpage)

2. Update your A1111 project and extensions

3. Dreambooth requirements should have installed automatically, but you can manually install them

by running the following commands from the A1111 project root:

cd venv/Scripts activate cd ../.. pip install -r ./extensions/sd_dreambooth_extension/requirements.txt pip install --prefer-binary --force-reinstall https://github.com/jllllll/bitsandbytes-windows-webui/releases/download/wheels/bitsandbytes-0.41.1-py3-none-win_amd64.whl ####################################################################################################### Launching Web UI with arguments: no module 'xformers'. Processing without... no module 'xformers'. Processing without... No module 'xformers'. Proceeding without it.

It seems that you don't have the argument to use xformers set. I am not saying it will fix your issues but it should at least get you past the No module xformers. Proceeding without it.

You can see how to do it at Command Line Arguments and Settings

Thanks, will try it right now

@Nothend
Copy link

Nothend commented Dec 1, 2023

I got this error ,too , running this extension in the stable diffusion on Windows11

`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 version 0.0.20 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: --listen --port=8089 --enable-insecure-extension-access --xformers
bin E:\LPF\StableDiffusion\stable-diffusion-webui\venv\Lib\site-packages\bitsandbytes\libbitsandbytes_cuda118.dll
Civitai Helper: Get Custom Model Folder
Additional Network extension not installed, Only hijack built-in lora
LoCon Extension hijack built-in lora successfully
dirname: E:\LPF\StableDiffusion\stable-diffusion-webui\localizations
localizations: {'zh_CN': 'E:\LPF\StableDiffusion\stable-diffusion-webui\localizations\zh_CN.json'}
Loading weights [7eedcb7b04] from E:\LPF\StableDiffusion\stable-diffusion-webui\models\Stable-diffusion\CheckpointYesmix_v35.safetensors
Civitai Helper: Settings:
Civitai Helper: max_size_preview: True
Civitai Helper: skip_nsfw_preview: False
Civitai Helper: open_url_with_js: True
Civitai Helper: proxy:
Creating model from config: E:\LPF\StableDiffusion\stable-diffusion-webui\configs\v1-inference.yaml
Running on local URL: http://0.0.0.0:8089
Applying attention optimization: xformers... done.
Model loaded in 2.2s (load weights from disk: 0.5s, create model: 0.7s, apply weights to model: 0.8s, calculate empty prompt: 0.1s).

To create a public link, set share=True in launch().
Startup time: 31.4s (prepare environment: 17.7s, import torch: 3.7s, import gradio: 1.6s, setup paths: 0.6s, initialize shared: 0.3s, other imports: 0.3s, setup codeformer: 0.3s, load scripts: 1.8s, create ui: 0.9s, gradio launch: 4.2s).
Advanced elements visible: False
Initializing dreambooth training...
Traceback (most recent call last):
File "E:\LPF\StableDiffusion\stable-diffusion-webui\extensions\sd_dreambooth_extension\dreambooth\ui_functions.py", line 732, in start_training
from dreambooth.train_dreambooth import main # noqa
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\LPF\StableDiffusion\stable-diffusion-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:\LPF\StableDiffusion\stable-diffusion-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:\LPF\StableDiffusion\stable-diffusion-webui\extensions\sd_dreambooth_extension\dreambooth\ui_functions.py", line 734, in start_training
from dreambooth.train_dreambooth import main # noqa
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\LPF\StableDiffusion\stable-diffusion-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:\LPF\StableDiffusion\stable-diffusion-webui\venv\Lib\site-packages\diffusers\loaders_init_.py)`

@Anime4000
Copy link
Contributor Author

my method to solve this:

  1. delete venv
  2. Run WebGUI
  3. Close WebGUI + Console/Terminal
  4. Enter venv Console/Terminal
  5. Run pip
  6. Run WebGUI

I have verify this on fresh install and existing

The best thing is wait digitalhigh release new update

@Nothend
Copy link

Nothend commented Dec 1, 2023

my method to solve this:

  1. delete venv
  2. Run WebGUI
  3. Close WebGUI + Console/Terminal
  4. Enter venv Console/Terminal
  5. Run pip
  6. Run WebGUI

I have verify this on fresh install and existing

The best thing is wait digitalhigh release new update

Thanks a lot ,but it's still did not work .maybe waiting is the best thing ,as you say

@klubkelli
Copy link

I get a similiar error.

Initializing dreambooth
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)

@klubkelli
Copy link

Initializing Dreambooth
Dreambooth revision: c548ede
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 [1a189f0be6] from E:\sd.webui\webui\models\Stable-diffusion\v1-5-pruned.safetensors
Creating model from config: E:\sd.webui\webui\configs\v1-inference.yaml
Running on local URL: http://127.0.0.1:7860

@Anime4000
Copy link
Contributor Author

Anime4000 commented Dec 1, 2023

if pip install diffusers==0.23.1 didn't work, edit requirements.txt at Line 3,

Instead of >=, replace to ==

make sure [+] diffusers version 0.23.1 installed. is shown

@SSamDav
Copy link

SSamDav commented Dec 1, 2023

Hi I'm using this extension on Automatic 111 that is running on a container, so I can't change the version of the diffuser by hand. Can you fix the version to 0.23.1?

@jcpinillos
Copy link

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:

  1. 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.

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

    pip uninstall diffusers
  3. Install the Desired Version of diffusers: Install a specific version of diffusers by specifying the version number:

    pip install diffusers==0.23.1
  4. 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.

Like @Anime4000 said, make sure you see, [+] diffusers version 0.23.1 installed. when you run Automatic1111 webUI.

This worked for me.

@biollas
Copy link

biollas commented Dec 2, 2023

I no longer get the error having switched back to diffusers version 0.23.1. It doesn't appear to be doing any training either, however, even with the same settings as a previous version of sd_dreambooth that works great.

@ManuelW77
Copy link

I'm on Mac (Intel) and have installed diffusers 0.23.1, but get the same error.

@jcpinillos
Copy link

I'm on Mac (Intel) and have installed diffusers 0.23.1, but get the same error.

Can you please post the startup process from the terminal when you run Automatic1111?

@ManuelW77
Copy link

Yes, of course :)

`################################################################
Launching launch.py...
################################################################
Python 3.10.13 (main, Aug 24 2023, 12:59:26) [Clang 15.0.0 (clang-1500.0.40.1)]
Version: v1.6.0-2-g4afaaf8a
Commit hash: 4afaaf8a020c1df457bcf7250cb1c7f609699fa7
Installing requirements
Installing sd-webui-controlnet requirement: changing opencv-python version from 4.7.0.72 to 4.8.0
Checking roop requirements
Install insightface==0.7.3
Installing sd-webui-roop requirement: insightface==0.7.3
Install onnx==1.14.0
Installing sd-webui-roop requirement: onnx==1.14.0
Install onnxruntime==1.15.0
Installing sd-webui-roop requirement: onnxruntime==1.15.0
Install opencv-python==4.7.0.72
Installing sd-webui-roop requirement: opencv-python==4.7.0.72
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: c548ede
Checking xformers...
Checking bitsandbytes...
Checking bitsandbytes (Linux)
Installing bitsandbytes
Error occurred:
Usage:
/usr/local/opt/python@3.10/bin/python3.10 -m pip install [options] [package-index-options] ...
/usr/local/opt/python@3.10/bin/python3.10 -m pip install [options] -r [package-index-options] ...
/usr/local/opt/python@3.10/bin/python3.10 -m pip install [options] [-e] ...
/usr/local/opt/python@3.10/bin/python3.10 -m pip install [options] [-e] ...
/usr/local/opt/python@3.10/bin/python3.10 -m pip install [options] <archive url/path> ...

no such option: --force-install

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 installed.
[!] torchvision version 0.15.2 installed.
[+] accelerate version 0.21.0 installed.
[+] diffusers version 0.24.0 installed.
[+] transformers version 4.30.2 installed.
[!] bitsandbytes NOT installed.

#######################################################################################################

LIBRARY ISSUE DETECTED

#######################################################################################################

torch is below the required 2.0.1+cu118 version.

torchvision is below the required 0.15.2+cu118 version.

bitsandbytes not installed.

Dreambooth may not work properly.

TROUBLESHOOTING

1. Fully restart your project (not just the webpage)

2. Update your A1111 project and extensions

3. Dreambooth requirements should have installed automatically, but you can manually install them

by running the following commands from the A1111 project root:

cd venv/Scripts
activate
cd ../..
pip install -r ./extensions/sd_dreambooth_extension/requirements.txt
pip install --prefer-binary --force-reinstall https://github.com/jllllll/bitsandbytes-windows-webui/releases/download/wheels/bitsandbytes-0.41.1-py3-none-win_amd64.whl
#######################################################################################################
Launching Web UI with arguments: --skip-torch-cuda-test --no-half
no module 'xformers'. Processing without...
no module 'xformers'. Processing without...
No module 'xformers'. Proceeding without it.
Warning: caught exception 'Torch not compiled with CUDA enabled', memory monitor disabled
2023-12-02 20:16:43,961 - ControlNet - INFO - ControlNet v1.1.419
ControlNet preprocessor location: /Volumes/Workdisk/_tmp/AI-Models/stable-diffusion-webui/extensions/sd-webui-controlnet/annotator/downloads
2023-12-02 20:16:44,138 - ControlNet - INFO - ControlNet v1.1.419
sd-webui-prompt-all-in-one background API service started successfully.
2023-12-02 20:16:45,147 - roop - INFO - roop v0.0.2
2023-12-02 20:16:45,197 - roop - INFO - roop v0.0.2
Loading weights [dde3b17c05] from /Volumes/Workdisk/_tmp/AI-Models/stable-diffusion-webui/models/Stable-diffusion/aZovyaPhotoreal_v2.safetensors
Creating model from config: /Volumes/Workdisk/_tmp/AI-Models/stable-diffusion-webui/configs/v1-inference.yaml
Deforum ControlNet support: enabled
Running on local URL: http://127.0.0.1:7860
`

@jcpinillos
Copy link

Yes, of course :)

`################################################################
Launching launch.py...
################################################################
Python 3.10.13 (main, Aug 24 2023, 12:59:26) [Clang 15.0.0 (clang-1500.0.40.1)]
Version: v1.6.0-2-g4afaaf8a
Commit hash: 4afaaf8a020c1df457bcf7250cb1c7f609699fa7
Installing requirements
Installing sd-webui-controlnet requirement: changing opencv-python version from 4.7.0.72 to 4.8.0
Checking roop requirements
Install insightface==0.7.3
Installing sd-webui-roop requirement: insightface==0.7.3
Install onnx==1.14.0
Installing sd-webui-roop requirement: onnx==1.14.0
Install onnxruntime==1.15.0
Installing sd-webui-roop requirement: onnxruntime==1.15.0
Install opencv-python==4.7.0.72
Installing sd-webui-roop requirement: opencv-python==4.7.0.72
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: c548ede
Checking xformers...
Checking bitsandbytes...
Checking bitsandbytes (Linux)
Installing bitsandbytes
Error occurred:
Usage:
/usr/local/opt/python@3.10/bin/python3.10 -m pip install [options] [package-index-options] ...
/usr/local/opt/python@3.10/bin/python3.10 -m pip install [options] -r [package-index-options] ...
/usr/local/opt/python@3.10/bin/python3.10 -m pip install [options] [-e] ...
/usr/local/opt/python@3.10/bin/python3.10 -m pip install [options] [-e] ...
/usr/local/opt/python@3.10/bin/python3.10 -m pip install [options] <archive url/path> ...

no such option: --force-install

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 installed.
[!] torchvision version 0.15.2 installed.
[+] accelerate version 0.21.0 installed.
[+] diffusers version 0.24.0 installed.
[+] transformers version 4.30.2 installed.
[!] bitsandbytes NOT installed.

#######################################################################################################

LIBRARY ISSUE DETECTED

#######################################################################################################

torch is below the required 2.0.1+cu118 version.

torchvision is below the required 0.15.2+cu118 version.

bitsandbytes not installed.

Dreambooth may not work properly.

TROUBLESHOOTING

1. Fully restart your project (not just the webpage)

2. Update your A1111 project and extensions

3. Dreambooth requirements should have installed automatically, but you can manually install them

by running the following commands from the A1111 project root:

cd venv/Scripts
activate
cd ../..
pip install -r ./extensions/sd_dreambooth_extension/requirements.txt
pip install --prefer-binary --force-reinstall https://github.com/jllllll/bitsandbytes-windows-webui/releases/download/wheels/bitsandbytes-0.41.1-py3-none-win_amd64.whl
#######################################################################################################
Launching Web UI with arguments: --skip-torch-cuda-test --no-half
no module 'xformers'. Processing without...
no module 'xformers'. Processing without...
No module 'xformers'. Proceeding without it.
Warning: caught exception 'Torch not compiled with CUDA enabled', memory monitor disabled
2023-12-02 20:16:43,961 - ControlNet - INFO - ControlNet v1.1.419
ControlNet preprocessor location: /Volumes/Workdisk/_tmp/AI-Models/stable-diffusion-webui/extensions/sd-webui-controlnet/annotator/downloads
2023-12-02 20:16:44,138 - ControlNet - INFO - ControlNet v1.1.419
sd-webui-prompt-all-in-one background API service started successfully.
2023-12-02 20:16:45,147 - roop - INFO - roop v0.0.2
2023-12-02 20:16:45,197 - roop - INFO - roop v0.0.2
Loading weights [dde3b17c05] from /Volumes/Workdisk/_tmp/AI-Models/stable-diffusion-webui/models/Stable-diffusion/aZovyaPhotoreal_v2.safetensors
Creating model from config: /Volumes/Workdisk/_tmp/AI-Models/stable-diffusion-webui/configs/v1-inference.yaml
Deforum ControlNet support: enabled
Running on local URL: http://127.0.0.1:7860
`

Thanks. If you look at your console log, you can see that after the "Checking Dreambooth requirements..." line, you have a few more Dreambooth lines. After that last one you see this:

[!] xformers NOT installed.
[!] torch version 2.0.1 installed.
[!] torchvision version 0.15.2 installed.
[+] accelerate version 0.21.0 installed.
[+] diffusers version 0.24.0 installed.
[+] transformers version 4.30.2 installed.
[!] bitsandbytes NOT installed.

You can see that the environment that Automatic1111 is using is still using diffusers 0.24.0. I made a comment a few comments up about this. If Automatic1111 runs on a Mac the same as Windows, which I would believe it does, it creates a virtual environment when you run the startup script. So you have to change the version of diffusers in that environment.

@Nothend
Copy link

Nothend commented Dec 3, 2023

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:

  1. 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.

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

    pip uninstall diffusers
  3. Install the Desired Version of diffusers: Install a specific version of diffusers by specifying the version number:

    pip install diffusers==0.23.1
  4. 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.

Like @Anime4000 said, make sure you see, [+] diffusers version 0.23.1 installed. when you run Automatic1111 webUI.

This worked for me.

Thanks a lot , it works for me !!!! Windows11

@ManuelW77
Copy link

ManuelW77 commented Dec 3, 2023

There was something wrong with my venv folder. I deleted it and installed all requirements new in the venv.

But now I get a new diffuser error:

Initializing bucket counter!
Steps: 0%| | 0/2000 [00:00<?, ?it/s]Traceback (most recent call last):
File "/Volumes/Workdisk/_tmp/AI-Models/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/ui_functions.py", line 735, in start_training
result = main(class_gen_method=class_gen_method)
File "/Volumes/Workdisk/_tmp/AI-Models/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/train_dreambooth.py", line 1830, in main
return inner_loop()
File "/Volumes/Workdisk/_tmp/AI-Models/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/memory.py", line 126, in decorator
return function(batch_size, grad_size, prof, *args, **kwargs)
File "/Volumes/Workdisk/_tmp/AI-Models/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/train_dreambooth.py", line 1583, in inner_loop
model_pred = unet(noisy_latents, timesteps, encoder_hidden_states).sample
File "/Volumes/Workdisk/_tmp/AI-Models/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "/Volumes/Workdisk/_tmp/AI-Models/stable-diffusion-webui/venv/lib/python3.10/site-packages/accelerate/utils/operations.py", line 581, in forward
return model_forward(*args, **kwargs)
File "/Volumes/Workdisk/_tmp/AI-Models/stable-diffusion-webui/venv/lib/python3.10/site-packages/accelerate/utils/operations.py", line 569, in call
return convert_to_fp32(self.model_forward(*args, **kwargs))
File "/Volumes/Workdisk/_tmp/AI-Models/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/amp/autocast_mode.py", line 14, in decorate_autocast
return func(*args, **kwargs)
File "/Volumes/Workdisk/_tmp/AI-Models/stable-diffusion-webui/venv/lib/python3.10/site-packages/diffusers/models/unet_2d_condition.py", line 1066, in forward
sample, res_samples = downsample_block(
File "/Volumes/Workdisk/_tmp/AI-Models/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "/Volumes/Workdisk/_tmp/AI-Models/stable-diffusion-webui/venv/lib/python3.10/site-packages/diffusers/models/unet_2d_blocks.py", line 1150, in forward
hidden_states = attn(
File "/Volumes/Workdisk/_tmp/AI-Models/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "/Volumes/Workdisk/_tmp/AI-Models/stable-diffusion-webui/venv/lib/python3.10/site-packages/diffusers/models/transformer_2d.py", line 363, in forward
hidden_states = torch.utils.checkpoint.checkpoint(
File "/Volumes/Workdisk/_tmp/AI-Models/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/utils/checkpoint.py", line 251, in checkpoint
return _checkpoint_without_reentrant(
File "/Volumes/Workdisk/_tmp/AI-Models/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/utils/checkpoint.py", line 432, in _checkpoint_without_reentrant
output = function(*args, **kwargs)
File "/Volumes/Workdisk/_tmp/AI-Models/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "/Volumes/Workdisk/_tmp/AI-Models/stable-diffusion-webui/venv/lib/python3.10/site-packages/diffusers/models/attention.py", line 293, in forward
attn_output = self.attn2(
File "/Volumes/Workdisk/_tmp/AI-Models/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "/Volumes/Workdisk/_tmp/AI-Models/stable-diffusion-webui/venv/lib/python3.10/site-packages/diffusers/models/attention_processor.py", line 522, in forward
return self.processor(
File "/Volumes/Workdisk/_tmp/AI-Models/stable-diffusion-webui/venv/lib/python3.10/site-packages/diffusers/models/attention_processor.py", line 1231, in call
hidden_states = F.scaled_dot_product_attention(
RuntimeError: Expected query, key, and value to have the same dtype, but got query.dtype: c10::Half key.dtype: float and value.dtype: float instead.

@reverSilly
Copy link

I am using this extension on windows 11, and I recieved the same problem. Downgrading the module 'diffusers' from '0.24.0' to '0.23.1' seemed to work for me.

@eternalld
Copy link

eternalld commented Dec 7, 2023

@Anime4000 I also encountered this problem, showing "ImportError: cannot import name 'text_encoder_lora_state_dict' from 'diffusers.loaders'". I found this function in the official library of diffuser and found that it will be replaced in version 0.27.0, maybe This problem can be solved by temporarily copying the function into the file where it is introduced.

text_encoder_bug_diffusers

code:
https://github.com/huggingface/diffusers/blob/c2717317f03b12535cfd02b477ace61189e10e4b/src/diffusers/loaders/__init__.py#L7

@d8ahazard
Copy link
Owner

@Anime4000 I also encountered this problem, showing "ImportError: cannot import name 'text_encoder_lora_state_dict' from 'diffusers.loaders'". I found this function in the official library of diffuser and found that it will be replaced in version 0.27.0, maybe This problem can be solved by temporarily copying the function into the file where it is introduced.

text_encoder_bug_diffusers

code: https://github.com/huggingface/diffusers/blob/c2717317f03b12535cfd02b477ace61189e10e4b/src/diffusers/loaders/__init__.py#L7

Yep, that's exactly what they did in the official SDXL training script. Should now be fixed in main.

@husw725
Copy link

husw725 commented Dec 14, 2023

i move the function from loaders.__init__py to models.__init__py,and then it ran fine

@d8ahazard
Copy link
Owner

d8ahazard commented Dec 14, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests