d8ahazard / sd_dreambooth_extension

Other
1.86k stars 282 forks source link

[Bug]: AttributeError: 'AttnProcessor2_0' object has no attribute 'state_dict' when saving model #1363

Closed onebiozz closed 10 months ago

onebiozz commented 1 year ago

Is there an existing issue for this?

What happened?

Training a standard 768 model the training it self starts normally, during training it uses a suspiciously low amount of vram (around 7gb instead of the normal 10 or 11), when the model is canceled or completed the exception AttributeError: 'AttnProcessor2_0' object has no attribute 'state_dict' is raised

Steps to reproduce the problem

  1. train a new model
  2. cancel the model

Commit and libraries

Installing requirements bin H:\sd.webui\system\python\lib\site-packages\bitsandbytes\libbitsandbytes_cuda118.dll If submitting an issue on github, please provide the full startup log for debugging purposes.

Initializing Dreambooth Dreambooth revision: 1a1d1621086a4725fda1200256f319c845dc7a8a Successfully installed accelerate-0.23.0 fastapi-0.94.1 transformers-4.32.1

[+] xformers version 0.0.22 installed. [+] torch version 2.0.1+cu118 installed. [+] torchvision version 0.15.2+cu118 installed. [+] accelerate version 0.23.0 installed. [+] diffusers version 0.21.4 installed. [+] transformers version 4.32.1 installed. [+] bitsandbytes version 0.41.1 installed.

Command Line Arguments

--xformers

Console logs

Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug  1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]
Version: v1.6.0
Commit hash: 5ef669de080814067961f28357256e8fe27544f4
Installing requirements
bin H:\sd.webui\system\python\lib\site-packages\bitsandbytes\libbitsandbytes_cuda118.dll
If submitting an issue on github, please provide the full startup log for debugging purposes.

Initializing Dreambooth
Dreambooth revision: 1a1d1621086a4725fda1200256f319c845dc7a8a
Successfully installed accelerate-0.23.0 fastapi-0.94.1 transformers-4.32.1

[+] xformers version 0.0.22 installed.
[+] torch version 2.0.1+cu118 installed.
[+] torchvision version 0.15.2+cu118 installed.
[+] accelerate version 0.23.0 installed.
[+] diffusers version 0.21.4 installed.
[+] transformers version 4.32.1 installed.
[+] bitsandbytes version 0.41.1 installed.
Launching Web UI with arguments: --xformers
H:\sd.webui\webui\extensions\sd_dreambooth_extension\scripts\main.py:301: GradioDeprecationWarning: The `style` method is deprecated. Please set these arguments in the constructor instead.
  with gr.Row().style(equal_height=False):
Calculating sha256 for H:\sd.webui\webui\models\Stable-diffusion\XXXXXXXXX.safetensors: bin H:\sd.webui\system\python\lib\site-packages\bitsandbytes\libbitsandbytes_cuda118.dll
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
Startup time: 26.2s (prepare environment: 20.8s, import torch: 2.1s, import gradio: 0.6s, setup paths: 0.5s, initialize shared: 0.2s, other imports: 0.4s, load scripts: 0.9s, create ui: 0.4s, gradio launch: 0.2s).
37f48188925f12096d69da1051fa20d7c13796a91466c6f766f651fe121f52a2
Loading weights [37f4818892] from H:\sd.webui\webui\models\Stable-diffusion\XXXXXXXXX.safetensors
Creating model from config: H:\sd.webui\webui\models\Stable-diffusion\XXXXXXXXX.yaml
Applying attention optimization: xformers... done.
Model loaded in 13.2s (calculate hash: 9.1s, load weights from disk: 0.1s, create model: 0.2s, apply weights to model: 2.0s, apply half(): 0.8s, calculate empty prompt: 0.8s).
Initializing dreambooth training...
                                                                                                                       Init dataset!set:   0%|                                                                           | 0/5 [00:00<?, ?it/s]
Preparing Dataset (With Caching)
Bucket 0 (768, 768, 0) - Instance Images: 1096 | Class Images: 0 | Max Examples/batch: 1096
Bucket 1 (768, 768, 1) - Instance Images: 3721 | Class Images: 0 | Max Examples/batch: 3721
                                                                                                                       Saving cache!ed latents...: 100%|███████████████████████████████████████████████████| 4817/4817 [07:40<00:00, 10.36it/s]
Total Buckets 2 - Instance Images: 4817 | Class Images: 0 | Max Examples/batch: 4817

Total images / batch: 4817, total examples: 4817███████████████████████████████████| 4817/4817 [07:40<00:00, 10.36it/s]
                  Initializing bucket counter!
Loading pipeline components...: 100%|███████████████████████████████████████████████████| 5/5 [00:00<00:00, 105.25it/s]
Saving weights/samples...: : 0it [00:00, ?it/s]                                                                        Traceback (most recent call last):                                                                | 0/1 [00:00<?, ?it/s]
  File "H:\sd.webui\webui\extensions\sd_dreambooth_extension\dreambooth\ui_functions.py", line 730, in start_training
    result = main(class_gen_method=class_gen_method)
  File "H:\sd.webui\webui\extensions\sd_dreambooth_extension\dreambooth\train_dreambooth.py", line 1809, in main
    return inner_loop()
  File "H:\sd.webui\webui\extensions\sd_dreambooth_extension\dreambooth\memory.py", line 126, in decorator
    return function(batch_size, grad_size, prof, *args, **kwargs)
  File "H:\sd.webui\webui\extensions\sd_dreambooth_extension\dreambooth\train_dreambooth.py", line 1766, in inner_loop
    check_save(True)
  File "H:\sd.webui\webui\extensions\sd_dreambooth_extension\dreambooth\train_dreambooth.py", line 976, in check_save
    save_weights(
  File "H:\sd.webui\webui\extensions\sd_dreambooth_extension\dreambooth\train_dreambooth.py", line 1100, in save_weights
    unet_lora_layers_to_save = unet_attn_processors_state_dict(unet)
  File "H:\sd.webui\webui\extensions\sd_dreambooth_extension\dreambooth\utils\model_utils.py", line 242, in unet_attn_processors_state_dict
    for parameter_key, parameter in attn_processor.state_dict().items():
AttributeError: 'AttnProcessor2_0' object has no attribute 'state_dict'
Steps:   0%|                                | 42/963400 [00:47<303:38:44,  1.13s/it, loss=0.00705, lr=2.8e-7, vram=6.7]
Duration: 00:09:27
Duration: 00:09:27

Additional information

the latest SDwui was reinstalled from scratch in a new folder and the only modifications outside of the standard dreambooth extension install was using bitsandbytes-0.41.1-py3-none-win_amd64.whl from https://jllllll.github.io/bitsandbytes-windows-webui from requirements.txt to get around the CUDA errors as mentioned in #1360 resulting from the aparent incorrect version being installed by default for windows machines and also removing the safety checker as mentioned in #1352 I do not believe either of these would cause the issues i have been having I am on the latest nvidia studio driver (9/21/2023), i tried FP16. BF16, xformers or no xformers

DrozhzhinDen commented 1 year ago

same problem

adam-andrzejczak commented 1 year ago

+1

pasmat commented 1 year ago

same :(

1099271 commented 1 year ago

Same to me

HOHOHOLO commented 1 year ago

same

ninofiliu commented 1 year ago

same

looking at the stack trace it looks like a bug in the extension

using windows, not wsl, command line arguments: --xformers

RobertMtx commented 1 year ago

Same here. Can't use extension at all because of this error. Anyone have any clue what is causing it?

Edit: I just noticed "cancel the model" was being mentioned in steps to reproduce this error, but I get this error any time I try to train at all. It seems to happen when the model is being saved. I do not attempt to cancel.

madvas commented 12 months ago

same

SEnTInEL-RC commented 12 months ago

I have this same error. New installation of Webui, running on Lunix Mint. using standard v1.5 Pruned and have tried with various command line arguments, doesnt seem to make a difference. Tried different setting options. Cant get it to even start training.

Chris611 commented 12 months ago

I had this error. Went back a bunch of commits of this repo, to July I think, xformers 0.0.17, torch 2.0.0+cu117 and torchvision 0.15.1+cu117. Then it works.

I also had this error of issues/1358 Both solved by going back to July.

Edit: Also Linux Mint 21 (Ubuntu 22.04)

ninofiliu commented 12 months ago

@Chris611 I'm going to try this out, do you have a commit hash that works?

then I'm going to git bisect until I find the first commit that broke things, might save time to @d8ahazard to fix this

Chris611 commented 12 months ago

@ninofiliu b396af2

I was wrong about the library versions that I use: [+] xformers version 0.0.22 installed. [+] torch version 2.0.1+cu118 installed. [+] torchvision version 0.15.2+cu118 installed. [+] accelerate version 0.19.0 installed. [+] diffusers version 0.16.1 installed. [+] transformers version 4.29.2 installed. [+] bitsandbytes version 0.35.4 installed. Launching Web UI with arguments: --xformers

automatic1111 up to date with Master That is a working setup for me.

boundlessliving commented 12 months ago

While I am VERY encouraged that it's at least possible to get Dreambooth running again (out of business here for a week now), I'm not sure how I would get my setup to duplicate that environment. I've set up another independent installation of Automatic 1111 using Pinokio and only installed Dreambooth, and get the CUDA, bitsandbytes, and AttnProcessor errors like everyone else depending on what I'm doing.

This is how my libraries are currently listed. I just want to get an installation set up that i NEVER mess with once it's building models properly until I test new builds elsewhere.

[!] xformers version 0.0.20 installed. [+] torch version 2.0.1+cu118 installed. [+] torchvision version 0.15.2+cu118 installed. [+] accelerate version 0.23.0 installed. [+] diffusers version 0.21.4 installed. [+] transformers version 4.32.1 installed. [+] bitsandbytes version 0.41.1 installed. Launching Web UI with arguments: --api --xformers --disable-nan-check --no-half-vae --ckpt-dir E:\sd\stable-diffusion-webui\models\Stable-diffusion

Chris611 commented 12 months ago

Assuming Ubuntu 22.04 and you have a developers environment (git, python venv):

go to stable-diffusion-webui/extensions/sd_dreambooth_extension directory git checkout 6b45a92 go to stable-diffusion-webui directory source ./venv/bin/activate pip install -U xformers==0.0.22 deactivate Proceed as normal: ./webui.sh

Think that's it

boundlessliving commented 12 months ago

Hmm, well I probably should have said I'm Windows 11, but thank you so much for that. Looks like it might basically be the same up until ./webui.sh

boundlessliving commented 12 months ago

Well I did all that and the only thing that changed were my transformer versions and all errors remained. I appreciate the time you took though!

bgr commented 12 months ago

Try c2a5617c58, that's the first one I tried and the errors went away.

GIEYang commented 12 months ago

Is there a solution to the problem?

adam-andrzejczak commented 12 months ago

Try c2a5617, that's the first one I tried and the errors went away.

"'AttnProcessor2_0' object has no attribute 'state_dict' when saving model" still shows up when the model is supposed to be saved at the end of the training.

boundlessliving commented 12 months ago

It's been a week an a half now that I've not been able to create any models. I've done clean installs and tried every suggestion I've found over the past week, and I still juggle the CUDA errors, the bitsandbytes things, and this AttnProcessor2_0 thing.

The bitsandbytes thing causes the resulting model (when it DOES try to build one) to absolutely suck, and take a really long time to suck, and then it doesn't save the last iteration of the model with because of this error.

Surely the WORLD isn't out of the model building business, so what are my alternatives to get a working version of Dreambooth in ANY form until they get this all worked out.

It's clearly a bitch of a problem that seems to touch, at least in Windows 11, a lot of other things not even related to Dreambooth or Automatic 1111.

Would love to know how you're getting around this, if you are.

DrozhzhinDen commented 12 months ago

It's been a week an a half now that I've not been able to create any models. I've done clean installs and tried every suggestion I've found over the past week, and I still juggle the CUDA errors, the bitsandbytes things, and this AttnProcessor2_0 thing.

The bitsandbytes thing causes the resulting model (when it DOES try to build one) to absolutely suck, and take a really long time to suck, and then it doesn't save the last iteration of the model with because of this error.

Surely the WORLD isn't out of the model building business, so what are my alternatives to get a working version of Dreambooth in ANY form until they get this all worked out.

It's clearly a bitch of a problem that seems to touch, at least in Windows 11, a lot of other things not even related to Dreambooth or Automatic 1111.

Would love to know how you're getting around this, if you are.

I switched to Kohya_ss it and work great on it. It's a shame that this app no longer works and appears to be out of maintenance.

boundlessliving commented 12 months ago

I’ve used that to create Lora’s but I’d really like to create checkpoints. Is that how you’re using it? I thought about trying that, but I’m not sure how to adjust my settings to match what I do over in automatic 1111

DrozhzhinDen commented 11 months ago

I’ve used that to create Lora’s but I’d really like to create checkpoints. Is that how you’re using it? I thought about trying that, but I’m not sure how to adjust my settings to match what I do over in automatic 1111

All settings are very similar. You can transfer them to Kohya_ss.

sofianedjerbi commented 11 months ago

Is there any working hashes for both SD & Dreambooth on Linux ? Python 3.11 or 3.10?

boundlessliving commented 11 months ago

I’ve used that to create Lora’s but I’d really like to create checkpoints. Is that how you’re using it? I thought about trying that, but I’m not sure how to adjust my settings to match what I do over in automatic 1111

All settings are very similar. You can transfer them to Kohya_ss.

Well, I did my best to xfer the settings, but they don't line up exactly on the interfaces.

Still, when I run it, I get this:

CUDA SETUP: Loading binary C:\Users\bobdo\pinokio\api\Kohya\kohya_ss\venv\lib\site-packages\bitsandbytes\libbitsandbytes_cuda116.dll... use 8-bit AdamW optimizer | {} running training / 学習開始 num train images * repeats / 学習画像の数×繰り返し回数: 2000 num reg images / 正則化画像の数: 1555 num batches per epoch / 1epochのバッチ数: 500 num epochs / epoch数: 5 batch size per device / バッチサイズ: 8 total train batch size (with parallel & distributed & accumulation) / 総バッチサイズ(並列学習、勾配合計含む): 8 gradient ccumulation steps / 勾配を合計するステップ数 = 1 total optimization steps / 学習ステップ数: 2500 steps: 0%| | 0/2500 [00:00<?, ?it/s] epoch 1/5 A matching Triton is not available, some optimizations will not be enabled. Error caught was: No module named 'triton'

No idea where the Triton thing is coming from, but because of that, the training which would normally take about 20 minutes is over 24 hours.

Nope.

madvas commented 11 months ago

Try c2a5617, that's the first one I tried and the errors went away.

This worked for me. Although my trained model generates images that are rather dark and high contrast. Does anyone know why this might be? I'm new to dreambooth

ninofiliu commented 11 months ago

@madvas maybe something about the CFG scale? The higher it is, the more you force stable diffusion to recognize patterns from the prompt, so generated images have accentuated colors and contrasts

1690486410123717154

sweihub commented 11 months ago

Sample problem

Saving weights/samples...:   0%|          | 0/3 [00:00<?, ?itTraceback (most recent call last):
  File "/data/code/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/ui_functions.py", line 730, in start_training
    result = main(class_gen_method=class_gen_method)
  File "/data/code/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/train_dreambooth.py", line 1809, in main
    return inner_loop()
  File "/data/code/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/memory.py", line 126, in decorator
    return function(batch_size, grad_size, prof, *args, **kwargs)
  File "/data/code/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/train_dreambooth.py", line 1766, in inner_loop
    check_save(True)
  File "/data/code/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/train_dreambooth.py", line 976, in check_save
    save_weights(
  File "/data/code/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/train_dreambooth.py", line 1100, in save_weights
    unet_lora_layers_to_save = unet_attn_processors_state_dict(unet)
  File "/data/code/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/utils/model_utils.py", line 242, in unet_attn_processors_state_dict
    for parameter_key, parameter in attn_processor.state_dict().items():
AttributeError: 'AttnProcessor2_0' object has no attribute 'state_dict'
MoJIeAIGC commented 11 months ago

Total images / batch: 78, total examples: 78 Initializing bucket counter! WARNING:dreambooth.train_dreambooth:Loss is NaN, your model is dead. Cancelling training. Traceback (most recent call last): File "D:\novelai-webui-aki-v3\extensions\sd_dreambooth_extension\dreambooth\ui_functions.py", line 730, in start_training result = main(class_gen_method=class_gen_method) File "D:\novelai-webui-aki-v3\extensions\sd_dreambooth_extension\dreambooth\train_dreambooth.py", line 1809, in main return inner_loop() File "D:\novelai-webui-aki-v3\extensions\sd_dreambooth_extension\dreambooth\memory.py", line 126, in decorator return function(batch_size, grad_size, prof, *args, **kwargs) File "D:\novelai-webui-aki-v3\extensions\sd_dreambooth_extension\dreambooth\train_dreambooth.py", line 1766, in inner_loop check_save(True) File "D:\novelai-webui-aki-v3\extensions\sd_dreambooth_extension\dreambooth\train_dreambooth.py", line 976, in check_save save_weights( File "D:\novelai-webui-aki-v3\extensions\sd_dreambooth_extension\dreambooth\train_dreambooth.py", line 1100, in save_weights unet_lora_layers_to_save = unet_attn_processors_state_dict(unet) File "D:\novelai-webui-aki-v3\extensions\sd_dreambooth_extension\dreambooth\utils\model_utils.py", line 242, in unet_attn_processors_state_dict for parameter_key, parameter in attn_processor.state_dict().items(): AttributeError: 'AttnProcessor2_0' object has no attribute 'state_dict'

Same to me.

invalidaterestart commented 11 months ago

Same problem

boundlessliving commented 11 months ago

Well, ultimately my solution was to stop trying to get it to work with A1111 and moved to Kohya. After a few days of messing with settings to match those in my A1111 setup as closely as possible, I'm able to build my 1.5 models in 1/2 to 1/3 of the time using 20 images and 2000 reg images...about 12 minutes and I'm really happy with the results.

And to be clear, I'm talking about using Kohya to train the full checkpoints, not Lora's which is what I've always used for Loras. The safetensor files I'm creating are coming in at 2 gigs instead of 5 which is what my A1111 setup was giving me.

So it's all good. I'd still love for this to work inside A1111 though.

sertsessiz commented 11 months ago

+1

barisyk commented 11 months ago

+1

TonyKuroi commented 11 months ago

After a bunch of playing around, I managed to solve this problem tentatively for me.

In dreambooth/train_dreambooth.py, around line 1100, replace the line unet_lora_layers_to_save = unet_attn_processors_state_dict(unet)

With unet_lora_layers_to_save = accelerator.get_state_dict(unet, True)

Similarly, you will need to make the same replacement a few lines down, change them to the following text_encoder_one_lora_layers_to_save = accelerator.get_state_dict(text_encoder, True) text_encoder_two_lora_layers_to_save = accelerator.get_state_dict(text_encoder_two, True)

Should be self explanatory, just find the spot where the variables were set before, and replace the lines with this.

For now, this fixed the error for me with the default dreambooth training. I'm not making a pull request because I haven't done extensive testing, and there's bugs I know of that I want to investigate before I bother on a pull request. Also I really don't want to get too "famous" for programming haha I hate programming. I just started looking into AI stuff in the past couple weeks, so it took me several days and a lot of head pounding to get this - but I did it because it's something that I'm personally interested in using and I figured I might as well share with others.

Good luck, let me know if this works for anyone else

mrlespaul commented 11 months ago

So everyone hear me out. I got the same error and fixed.

1.Close the Stable Diffusion. 2.Go to the "...\stable-diffusion-webui\extensions\sd_dreambooth_extension" folder. 3.Type cmd to the folder line. command system will appear. 4.type; git checkout cf 0 8 6 c 5 3 6 b 1 4 1 f c 5 2 2 f f 1 1 f 6 c f f c 8 b 7 b 1 2 d a 0 4 b 9 (!!!!Delete all spaces after cf!!!!) This process fixes your commit ID. The ID I gave above (cf 0 8 6 c 5 3 6 b 1 4 1 f c 5 2 2 f f 1 1 f 6 c f f c 8 b 7 b 1 2 d a 0 4 b 9) is the ID one of the good ones. I found the ID on a discord server, but you can also follow the instructions on the video link below. I think newer versions of Dreambooth are working worse than old ones. So we change the commit ID in this way. It worked for me. And For more information, you can watch the video, link below. It doesn't explain every detail, but this video important for people who gets error on Dreambooth. https://www.youtube.com/watch?v=usgqmQ0Mq7g

elen07zz commented 11 months ago

Well, ultimately my solution was to stop trying to get it to work with A1111 and moved to Kohya. After a few days of messing with settings to match those in my A1111 setup as closely as possible, I'm able to build my 1.5 models in 1/2 to 1/3 of the time using 20 images and 2000 reg images...about 12 minutes and I'm really happy with the results.

And to be clear, I'm talking about using Kohya to train the full checkpoints, not Lora's which is what I've always used for Loras. The safetensor files I'm creating are coming in at 2 gigs instead of 5 which is what my A1111 setup was giving me.

So it's all good. I'd still love for this to work inside A1111 though.

Hi could you share your settings, i'm new with kohya and i want to train models, not loras.

EstherLee1995 commented 11 months ago

I have tried all the solution above, but apparently none of them work out!

553672759 commented 11 months ago

in save tab ,You can try checking the box Save Checkpoint to Subdirectory and Generate a .ckpt file when saving during training. im trying it.

leicex commented 11 months ago

After a bunch of playing around, I managed to solve this problem tentatively for me.

In dreambooth/train_dreambooth.py, around line 1100, replace the line unet_lora_layers_to_save = unet_attn_processors_state_dict(unet)

With unet_lora_layers_to_save = accelerator.get_state_dict(unet, True)

Similarly, you will need to make the same replacement a few lines down, change them to the following text_encoder_one_lora_layers_to_save = accelerator.get_state_dict(text_encoder, True) text_encoder_two_lora_layers_to_save = accelerator.get_state_dict(text_encoder_two, True)

Should be self explanatory, just find the spot where the variables were set before, and replace the lines with this.

For now, this fixed the error for me with the default dreambooth training. I'm not making a pull request because I haven't done extensive testing, and there's bugs I know of that I want to investigate before I bother on a pull request. Also I really don't want to get too "famous" for programming haha I hate programming. I just started looking into AI stuff in the past couple weeks, so it took me several days and a lot of head pounding to get this - but I did it because it's something that I'm personally interested in using and I figured I might as well share with others.

Good luck, let me know if this works for anyone else

When I modified it according to your method, the training started to appear Exception training model: ''ImageBuilder' object has no attribute 'accelerator''.

panyao commented 11 months ago

So everyone hear me out. I got the same error and fixed.

1.Close the Stable Diffusion. 2.Go to the "...\stable-diffusion-webui\extensions\sd_dreambooth_extension" folder. 3.Type cmd to the folder line. command system will appear. 4.type; git checkout cf 0 8 6 c 5 3 6 b 1 4 1 f c 5 2 2 f f 1 1 f 6 c f f c 8 b 7 b 1 2 d a 0 4 b 9 (!!!!Delete all spaces after cf!!!!) This process fixes your commit ID. The ID I gave above (cf 0 8 6 c 5 3 6 b 1 4 1 f c 5 2 2 f f 1 1 f 6 c f f c 8 b 7 b 1 2 d a 0 4 b 9) is the ID one of the good ones. I found the ID on a discord server, but you can also follow the instructions on the video link below. I think newer versions of Dreambooth are working worse than old ones. So we change the commit ID in this way. It worked for me. And For more information, you can watch the video, link below. It doesn't explain every detail, but this video important for people who gets error on Dreambooth. https://www.youtube.com/watch?v=usgqmQ0Mq7g

This works for me.

Apprentice-Modder commented 11 months ago

Wanted to leave a comment here to say that I've tried following @d8ahazard's potential fix, I'm currently getting this error after clicking "Train":

`Initializing dreambooth training... Traceback (most recent call last): File "F:\A1111\extensions\sd_dreambooth_extension\dreambooth\ui_functions.py", line 727, in start_training from dreambooth.train_dreambooth import main # noqa File "F:\A1111\extensions\sd_dreambooth_extension\dreambooth\train_dreambooth.py", line 34, in from diffusers.training_utils import unet_lora_state_dict ImportError: cannot import name 'unet_lora_state_dict' from 'diffusers.training_utils' (F:\A1111\venv\lib\site-packages\diffusers\training_utils.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "F:\A1111\extensions\sd_dreambooth_extension\dreambooth\ui_functions.py", line 729, in start_training from dreambooth.train_dreambooth import main # noqa File "F:\A1111\extensions\sd_dreambooth_extension\dreambooth\train_dreambooth.py", line 34, in from diffusers.training_utils import unet_lora_state_dict ImportError: cannot import name 'unet_lora_state_dict' from 'diffusers.training_utils' (F:\A1111\venv\lib\site-packages\diffusers\training_utils.py) Duration: 00:00:01 Duration: 00:00:02`

d8ahazard commented 11 months ago

Double-check your diffusers version, reinstall the one in requirements.txt. Still working on the install method. That unet_lora_state_dict method should definitely exist.

On Tue, Nov 7, 2023 at 4:13 PM Apprentice-Modder @.***> wrote:

Wanted to leave a comment here to say that I've tried following @d8ahazard https://github.com/d8ahazard's potential fix https://github.com/d8ahazard/sd_dreambooth_extension/commit/fbc0dea7e257a214c342f7376edb6fd7c5090a2a, I'm currently getting this error when right after clicking "Train":

`Initializing dreambooth training... Traceback (most recent call last): File "F:\A1111\extensions\sd_dreambooth_extension\dreambooth\ui_functions.py", line 727, in start_training from dreambooth.train_dreambooth import main # noqa File "F:\A1111\extensions\sd_dreambooth_extension\dreambooth\train_dreambooth.py", line 34, in from diffusers.training_utils import unet_lora_state_dict ImportError: cannot import name 'unet_lora_state_dict' from 'diffusers.training_utils' (F:\A1111\venv\lib\site-packages\diffusers\training_utils.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "F:\A1111\extensions\sd_dreambooth_extension\dreambooth\ui_functions.py", line 729, in start_training from dreambooth.train_dreambooth import main # noqa File "F:\A1111\extensions\sd_dreambooth_extension\dreambooth\train_dreambooth.py", line 34, in from diffusers.training_utils import unet_lora_state_dict ImportError: cannot import name 'unet_lora_state_dict' from 'diffusers.training_utils' (F:\A1111\venv\lib\site-packages\diffusers\training_utils.py) Duration: 00:00:01 Duration: 00:00:02`

— Reply to this email directly, view it on GitHub https://github.com/d8ahazard/sd_dreambooth_extension/issues/1363#issuecomment-1800274146, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMO4NHBGDOF5WE5523I7F3YDKXAPAVCNFSM6AAAAAA5Q3JC52VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMBQGI3TIMJUGY . You are receiving this because you were mentioned.Message ID: @.***>

swumagic commented 11 months ago

Bitsandbytes was not supported windows before, but my method can support windows.(yuhuang) 1 open folder J:\StableDiffusion\sdwebui,Click the address bar of the folder and enter CMD or WIN+R, CMD 。enter,cd /d J:\StableDiffusion\sdwebui 2 J:\StableDiffusion\sdwebui\py310\python.exe -m pip uninstall bitsandbytes

3 J:\StableDiffusion\sdwebui\py310\python.exe -m pip uninstall bitsandbytes-windows

4 J:\StableDiffusion\sdwebui\py310\python.exe -m pip install https://github.com/jllllll/bitsandbytes-windows-webui/releases/download/wheels/bitsandbytes-0.41.1-py3-none-win_amd64.whl

Replace your SD venv directory file(python.exe Folder) here(J:\StableDiffusion\sdwebui\py310)

swumagic commented 11 months ago

OR you are Linux distribution (Ubuntu, MacOS, etc.)system ,AND CUDA Version: 11.X.

Bitsandbytes can support ubuntu.(yuhuang) 1 open folder J:\StableDiffusion\sdwebui,Click the address bar of the folder and enter CMD or WIN+R, CMD 。enter,cd /d J:\StableDiffusion\sdwebui 2 J:\StableDiffusion\sdwebui\py310\python.exe -m pip uninstall bitsandbytes

3 J:\StableDiffusion\sdwebui\py310\python.exe -m pip uninstall bitsandbytes-windows

4 J:\StableDiffusion\sdwebui\py310\python.exe -m pip install https://github.com/TimDettmers/bitsandbytes/releases/download/0.41.0/bitsandbytes-0.41.0-py3-none-any.whl

Replace your SD venv directory file(python.exe Folder) here(J:\StableDiffusion\sdwebui\py310)

ZachHappel commented 10 months ago

As I encountered issues previously with using Dreambooth, I had added the following to webui-user.bat:

set COMMANDLINE_ARGS=--xformers --reinstall-xformers
set XFORMERS_PACKAGE=xformers==0.0.17

When I encountered this issue, I was able to resolve it by removing the flags that I had added to COMMANDLINE_ARGS and by also removing the package version specification that I had added to XFORMERS_PACKAGE. I am sure you could just removed the XFORMERS_PACKAGE environmental variable assignment it its entirety but I am going to leave it because it works, lol.

set COMMANDLINE_ARGS=
set XFORMERS_PACKAGE=

Essentially, my webui-user.bat exists now as it was when I cloned the repo.

catlog66 commented 10 months ago

So everyone hear me out. I got the same error and fixed.

1.Close the Stable Diffusion. 2.Go to the "...\stable-diffusion-webui\extensions\sd_dreambooth_extension" folder. 3.Type cmd to the folder line. command system will appear. 4.type; git checkout cf 0 8 6 c 5 3 6 b 1 4 1 f c 5 2 2 f f 1 1 f 6 c f f c 8 b 7 b 1 2 d a 0 4 b 9 (!!!!Delete all spaces after cf!!!!) This process fixes your commit ID. The ID I gave above (cf 0 8 6 c 5 3 6 b 1 4 1 f c 5 2 2 f f 1 1 f 6 c f f c 8 b 7 b 1 2 d a 0 4 b 9) is the ID one of the good ones. I found the ID on a discord server, but you can also follow the instructions on the video link below. I think newer versions of Dreambooth are working worse than old ones. So we change the commit ID in this way. It worked for me. And For more information, you can watch the video, link below. It doesn't explain every detail, but this video important for people who gets error on Dreambooth. https://www.youtube.com/watch?v=usgqmQ0Mq7g

This works for me, thank you so much

d8ahazard commented 10 months ago

Man, all these issues because of BitsandBytes.