fast-stable-diffusion: Error when trying to use BLIP, Dreambooth, Hypernetwork and Embeddings. SD 2.1 - Automatic1111 Updated.
First i have this problem when trying to use BLIP for Captions in Automatic1111
0% 0/770 [00:01<?, ?it/s] Error completing request Arguments: ('/content/gdrive/MyDrive/Dataset', '/content/gdrive/MyDrive/DatasetFinal', 768, 768, 'ignore', False, False, True, False, 0.5, 0.2, True, 0.9, 0.15, 0.5, False) {} Traceback (most recent call last): File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/call_queue.py", line 45, in f res = list(func(*args, **kwargs)) File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/call_queue.py", line 28, in f res = func(*args, **kwargs) File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/textual_inversion/ui.py", line 19, in preprocess modules.textual_inversion.preprocess.preprocess(*args) File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/textual_inversion/preprocess.py", line 23, in preprocess preprocess_work(process_src, process_dst, process_width, process_height, preprocess_txt_action, process_flip, process_split, process_caption, process_caption_deepbooru, split_threshold, overlap_ratio, process_focal_crop, process_focal_crop_face_weight, process_focal_crop_entropy_weight, process_focal_crop_edges_weight, process_focal_crop_debug) File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/textual_inversion/preprocess.py", line 188, in preprocess_work save_pic(focal, index, params, existing_caption=existing_caption) File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/textual_inversion/preprocess.py", line 83, in save_pic save_pic_with_caption(image, index, params, existing_caption=existing_caption) File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/textual_inversion/preprocess.py", line 52, in save_pic_with_caption caption += shared.interrogator.generate_caption(image) File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/interrogate.py", line 133, in generate_caption caption = self.blip_model.generate(gpu_image, sample=False, num_beams=shared.opts.interrogate_clip_num_beams, min_length=shared.opts.interrogate_clip_min_length, max_length=shared.opts.interrogate_clip_max_length) File "/content/gdrive/MyDrive/sd/stablediffusion/src/blip/models/blip.py", line 156, in generate outputs = self.text_decoder.generate(input_ids=input_ids, File "/usr/local/lib/python3.8/dist-packages/torch/autograd/grad_mode.py", line 27, in decorate_context return func(*args, **kwargs) File "/usr/local/lib/python3.8/dist-packages/transformers/generation_utils.py", line 1268, in generate self._validate_model_kwargs(model_kwargs.copy()) File "/usr/local/lib/python3.8/dist-packages/transformers/generation_utils.py", line 964, in _validate_model_kwargs raise ValueError( ValueError: The followingmodel_kwargs are not used by the model: ['encoder_hidden_states', 'encoder_attention_mask'] (note: typos in the generate arguments will also show up in this list)
I have this error when i’m trying to run Dreambooth in Automatic1111 Webui.
First part of the error when I try to start a new entry with Dreambooth installed on SD. (But it starts normally, only this error appears) `Error loading script: api.py Traceback (most recent call last): File “/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/scripts.py”, line 184, in load_scripts module = script_loading.load_module(scriptfile.path) File “/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/script_loading.py”, line 13, in load_module exec(compiled, module.dict) File “/content/gdrive/MyDrive/sd/stable-diffusion-webui/extensions/sd_dreambooth_extension/scripts/api.py”, line 10, in <module> from extensions.sd_dreambooth_extension.dreambooth.sd_to_diff import extract_checkpoint File “/content/gdrive/MyDrive/sd/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/sd_to_diff.py”, line 36, in <module> from diffusers import ( ImportError: cannot import name ‘HeunDiscreteScheduler’ from ‘diffusers’ (/usr/local/lib/python3.8/dist-packages/diffusers/init.py)
Error loading script: main.py Traceback (most recent call last): File “/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/scripts.py”, line 184, in load_scripts module = script_loading.load_module(scriptfile.path) File “/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/script_loading.py”, line 13, in load_module exec(compiled, module.dict) File “/content/gdrive/MyDrive/sd/stable-diffusion-webui/extensions/sd_dreambooth_extension/scripts/main.py”, line 5, in <module> from extensions.sd_dreambooth_extension.dreambooth.diff_to_sd import compile_checkpoint File “/content/gdrive/MyDrive/sd/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/diff_to_sd.py”, line 214, in <module> def convert_text_enc_state_dict_v20(text_enc_dict: dict[str, torch.Tensor]): TypeError: ‘type’ object is not subscriptable
LatentDiffusion: Running in v-prediction mode DiffusionWrapper has 865.91 M params. Loading weights [6bccbcc6] from /content/gdrive/MyDrive/sd/stable-diffusion-webui/models/Stable-diffusion/model.ckpt Applying xformers cross attention optimization. Model loaded. Loaded a total of 0 textual inversion embeddings. Embeddings: `
Then when I go into the GUI, it doesn’t show the Dreambooth tab.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 4
- Comments: 99 (3 by maintainers)
@cerarslan I’m working on a fix
Hey mate, I am facing exactly this issue rn. If you find a solution please share here
@jvkap
EDIT: The following solved the ‘Dreambooth tab not showing in the web UI’ problem.
I solved the
HeunDiscreteSchedulererror by!pip install git+https://github.com/huggingface/diffusers. This should install a compatible version of Diffusers and fix the error.But if then throws a transformers error do
!pip install git+https://github.com/huggingface/transformers. This should install a compatible version of Transformers.Having done that you should be left with one last error message :
This seem to be a Python3.8 problem (i think doesn’t happen with Python 3.11). So open the file
"/content/gdrive/MyDrive/sd/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/diff_to_sd.py"and then delete the type hint from the parameter of the function so changedef convert_text_enc_state_dict_v20(text_enc_dict: dict[str, torch.Tensor]):todef convert_text_enc_state_dict_v20(text_enc_dict). Also changedef convert_text_enc_state_dict(text_enc_dict: dict[str, torch.Tensor])todef convert_text_enc_state_dict(text_enc_dict):. These two deletions are 100% safe.Save those two edited files, re-run everything and voila! You should finally get the Dreambooth tab.
PS. I’m using model 1.5 but this should work for 2.X
@TheLastBen I was able to fix Hypernetworks and Embedding using this fix.
https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/5523#issuecomment-1343041303
I've added self.logvar = self.logvar.to(self.device) in ddpm.py above line 903 before starting anything.However, when it goes to generate the example images, they turn black. The normal generation in txt2img is normal. In the automatic’s repo it says that:
If 2.0 or 2.1 is generating black images, enable full precision with --no-half or try using the --xformers optimization.
However, I do not know how to add this to the part only to the generation of previews of Hypernetworks and Embedding. You know and could help me?
Sure! Let me state this again though: this is a bodge, and not only it is a bodge but it is also probably not going to work with SD 2.x! A more order-agnostic process should be made instead of this mess.
First thing is I opened the .ckpt of a model i knew worked and from that I extracted the keys of the state_dict and wrote them in order on a .txt file. Then I changed the code for the converter such that, when a .safetensors model is loaded, the .txt too is opened. And instead of building a dictionary by just reading the .safetensors file and writing the tensors as they are read, I instead read the keys from the .txt in their own order and retrieve the relative tensor from the file.
Essentially, instead of doing this:
I do:
This is what I did, sorry if I don’t know this codebase therefore I don’t know how you’re doing the loading 😛. At any rate I suggest in doing this stuff in a way better manner- as said the conversion in my opinion should be agnostic to the order of the given dict (after all it’s a dictionary… its order shouldn’t matter!), otherwise it may create a mess for portability!
Ohh you uptaded your tweaks. Thank you for guidance. I will try today!
Sure, I’ll give it a shot tonight. (Makes me think its worth having a tiny Creative Commons dateset for training with specified captions to keep it standardized). I’ll update once I’ve tested it. I’ll update the Web UI / sd_dreambooth_extention and let you know.
I already use your tweaks 1 and 2 so I will try soon.
Nope, surprisingly, this one I don’t think is my fault. 😛
This is the eternal joy that is the “safe unpickle” module of SD-Webui. The goal is to make it so that arbitrary code can’t be executed when unpickling a model. The reality is that it just breaks stuff for no reason.
I’ve got around it in my code by creating a pair of methods that I call to set and unset the --disable-safe-unpickle command when I’m loading a module I specifically know is safe to run, like the YoloV5 library for image detection.
In this instance, I’d be hesitant to use this workaround, as we can’t be sure what ckpt the user is trying to load. As such, this would be one of those discretionary things where it’s up to the user to say “Yes, this is safe” and add the flag manually.
On a separate note - I’ve noticed an uptick in issues from people trying to run this stuff in your collab. I’m totally cool with you using the code - the more the merrier - but it might be a bit easier for both of us if we could talk directly. If you have any questions or issues updating from my nightmare commits, I can answer them, and if I accidentally add another typehint that’s not compatible with Python 3.8, you can let me know easier.
The link is in the “create an issue” section in my repo if you want to hop on and chat. I check in there pretty frequently.
Cool, thanks. I’ll add this upstream.
@markojak
Edit file
/content/gdrive/MyDrive/sd/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/finetune_utils.pyIn line 330
Change
def generate_images(self, prompt_data: list[PromptData]) -> [Image]:To
def generate_images(self, prompt_data):That will remove the TypeError.
Delete they typehint at 359 as well (->tuple…)
On Mon, Dec 19, 2022 at 9:41 PM mediocreatmybest @.***> wrote:
Oooohhh…
I wonder, is it the type hint that’s making it mad?
You could try editing line 214 to read
def convert_text_enc_state_dict_v20(text_enc_dict):Removing the hint. I bet that fixes it.
On Mon, Dec 19, 2022 at 9:02 PM mediocreatmybest @.***> wrote:
Hey all!
So, I think the issue here (at least from the first post) is that the latest transformers version has some check that throws an issue if it finds extra kwargs.
"/usr/local/lib/python3.8/dist-packages/transformers/generation_utils.py", line 964, in _validate_model_kwargs raise ValueError( ValueError: The followingmodel_kwargs are not used by the model: ['encoder_hidden_states', 'encoder_attention_mask'] (note: typos in the generate arguments will also show up in this list)I had that patched out using the “xattention.py” file in my repo, which is just sort of a generic catchall for monkey-patching various bugs I found along the way. But, I bumped my diffusers and transformers versions to match the official diffusers repo (as of ver 0.10.2), and didn’t have to monkey-patch this any more. So, I think the right answer is “check the diffusers and transfomers” versions.
If I missed some other issue in the discussion, throw me an error message and I’ll let you know if it’s anything else I hacked in to fix stuff.
@ekeric13 - “Launch” refers to launch.py from the auto1111 script. It’s just a wrapper for the run_command call, which I should probably just remove and add my own, as I’m already working to make less of the extension depend directly on Auto1111, just for compatibility and sanity’s sake. 😉
Dreambooth works for me but only after making the changes I suggested above.
Wait what? I didn’t know this even existed. You guys have adapted LoRA here?
@mediocreatmybest
Amazing! I’ll test it and get back if anything goes wrong. Thanks!