AUTOMATIC1111 / stable-diffusion-webui

Stable Diffusion web UI
GNU Affero General Public License v3.0
140.75k stars 26.63k forks source link

[Bug]: [1.9.0] Create Embedding FAILS #15505

Open pbl2017 opened 5 months ago

pbl2017 commented 5 months ago

Checklist

What happened?

Creation of new embedding failed.

Steps to reproduce the problem

  1. fresh 1.9.0 install -- first run --
  2. start webui
  3. navigate to "Train" tab
  4. navigate to "Create embedding" tab 4/ Enter Name, e.g. "00_CreateTest"
  5. Enter Initialization text,e.g. "00_CreateTest"
  6. Click "Create Embedding" (failure)

What should have happened?

embedding file should have been successfully created

What browsers do you use to access the UI ?

Mozilla Firefox

Sysinfo

sysinfo-2024-04-13-18-26.json

Console logs

[STARTUP]

################################################################
Install script for stable-diffusion + Web UI
Tested on Debian 11 (Bullseye), Fedora 34+ and openSUSE Leap 15.4 or newer.
################################################################

################################################################
Running on sd user
################################################################

################################################################
Repo already cloned, using it as install directory
################################################################

################################################################
Create and activate python venv
################################################################

################################################################
Launching launch.py...
################################################################
glibc version is 2.37
Check TCMalloc: libtcmalloc_minimal.so.4
libtcmalloc_minimal.so.4 is linked with libc.so,execute LD_PRELOAD=/lib64/libtcmalloc_minimal.so.4
Python 3.11.8 (main, Feb 28 2024, 00:00:00) [GCC 13.2.1 20231011 (Red Hat 13.2.1-4)]
Version: v1.9.0
Commit hash: adadb4e3c7382bf3e4f7519126cd6c70f4f8557b
Launching Web UI with arguments: 
no module 'xformers'. Processing without...
no module 'xformers'. Processing without...
No module 'xformers'. Proceeding without it.
Loading weights [6ce0161689] from /heim/sd/Automatic1111-1.9.0/stable-diffusion-webui/models/Stable-diffusion/v1-5-pruned-emaonly.safetensors
Running on local URL:  http://127.0.0.1:7861

To create a public link, set `share=True` in `launch()`.
Creating model from config: /heim/sd/Automatic1111-1.9.0/stable-diffusion-webui/configs/v1-inference.yaml
Applying attention optimization: Doggettx... done.
Model loaded in 1.8s (load weights from disk: 0.4s, create model: 0.3s, apply weights to model: 0.9s).
Startup time: 10.1s (prepare environment: 0.9s, import torch: 2.1s, import gradio: 0.4s, setup paths: 0.6s, other imports: 0.2s, load scripts: 0.2s, create ui: 0.3s, gradio launch: 5.2s).

[CREATE EMBEDDING]

*** Error verifying pickled file from /heim/sd/Automatic1111-1.9.0/stable-diffusion-webui/embeddings/00_CreateTest.pt
*** The file may be malicious, so the program is not going to read it.
*** You can skip this check with --disable-safe-unpickle commandline argument.
*** 
    Traceback (most recent call last):
      File "/heim/sd/Automatic1111-1.9.0/stable-diffusion-webui/modules/safe.py", line 137, in load_with_extra
        check_pt(filename, extra_handler)
      File "/heim/sd/Automatic1111-1.9.0/stable-diffusion-webui/modules/safe.py", line 84, in check_pt
        check_zip_filenames(filename, z.namelist())
      File "/heim/sd/Automatic1111-1.9.0/stable-diffusion-webui/modules/safe.py", line 76, in check_zip_filenames
        raise Exception(f"bad file inside {filename}: {name}")
    Exception: bad file inside /heim/sd/Automatic1111-1.9.0/stable-diffusion-webui/embeddings/00_CreateTest.pt: 00_CreateTest/byteorder

---
*** Error loading embedding 00_CreateTest.pt
    Traceback (most recent call last):
      File "/heim/sd/Automatic1111-1.9.0/stable-diffusion-webui/modules/textual_inversion/textual_inversion.py", line 203, in load_from_dir
        self.load_from_file(fullfn, fn)
      File "/heim/sd/Automatic1111-1.9.0/stable-diffusion-webui/modules/textual_inversion/textual_inversion.py", line 184, in load_from_file
        embedding = create_embedding_from_data(data, name, filename=filename, filepath=path)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/heim/sd/Automatic1111-1.9.0/stable-diffusion-webui/modules/textual_inversion/textual_inversion.py", line 284, in create_embedding_from_data
        if 'string_to_param' in data:  # textual inversion embeddings
           ^^^^^^^^^^^^^^^^^^^^^^^^^
    TypeError: argument of type 'NoneType' is not iterable

---

Additional information

Bug introduced in 1.8.0, reported twice by others; reports possibly incomplete and moved to /dev/null ?

pbl2017 commented 5 months ago

Previous reports: Creating new embedding.pt fails pickle check #15214 TypeError when creating new embedding in textual inversion module #15277

jasonoh commented 5 months ago

fwiw, i'm seeing this same error as well. mac 14.4.1, latest automatic.

VL4DST3R commented 5 months ago

Came here to report the same issue ever since 1.8. Why is this happening and why does it seem like nobody is acknowledging it?

pbl2017 commented 5 months ago

The issues persists in 1.9.3...

Tower13Studios commented 5 months ago

Issue still persists, was greeted by it's error messages after updating from 1.7 to 1.9.3

Tower13Studios commented 4 months ago

Here is a real workaround/Fix for those who have the bug and still want to publish embeddings to the public without the error embedded: User "Perfection" from CivitAI gets the credit for telling me how to fix this

I try to make this understandable for dummies, I am a dummie and I usually don't understand what people say here :-D

Your Issue is: You can't create a new embedding due to the error message

Why? Because the software writes code into your PT File that should not be there.. stay tuned we will fix this

I recommend 2 installations of Automatic1111 one basic one without extensions for creating embeddings and your regular one with all bells and whistles that make you happy It helps you store the corrupt embeddings in one place and move the fixed ones over to your actual A1111 installation for generating content. 2 Installations aren't necessary but it helps to explain what we are doing here.

Now what you want to do is add this code into the webui-user.bat (the one you use for creating embeddings) set COMMANDLINE_ARGS=--xformers --disable-safe-unpickle (This is not a fix, this just ignores the error and let's you train the model, it trains the model as a corrupted file)

Train your embedding and after the training you follow these steps exactly: rename your Embedding "Yourname.pt" to "Yourname.zip" (for the real dummies, you don't have to name it "yourname")

Now open the zipfile (don't unpack it) locate the folder ".data" (not Data) and the file "Byteorder" delete both of them

Rename your Embedding back to "Yourname.pt" Now the file is 100% clean and it runs on every system again.

This will work, it doesn't stop the error from reproducing, but those who publish embeddings can now post their work again without having to explain why their files are corrupted.

This also means, all that Automatic1111 needs to do is to disallow the .data folder and the bytorder to be written into the file or create a script that deletes those files from a finished embedding.

LingXuanYin commented 4 months ago

I try to fix this ,if you are in a hurry ,try edit modules/textual_inversion/textual_inversion.py line 64 and line 71 just like this image After do this ,restart webui and recreat embedding This could cause some performance issues but train and infer should be all correct now

VL4DST3R commented 4 months ago

This could cause some performance issues

Why is that?

LingXuanYin commented 4 months ago

This could cause some performance issues

Why is that?

This prevents pytorch from using new compression and serialization methods (after pytorch version 1.6), which do not change the model structure but may require writing more data during the loading and saving stages (please refer to the relevant update logs of pytorch for specific details, i never tested)

Sorry, my English is not good, so I am using translation software for conversation.

VL4DST3R commented 4 months ago

That sounds like a very small impact to performance if indeed that's all that is affected, I reckon hardly noticeable during training. Thank you for the explanation.