stable-diffusion-webui icon indicating copy to clipboard operation
stable-diffusion-webui copied to clipboard

[Bug]: Newly created embeddings considered malicious

Open msoucy opened this issue 2 years ago • 7 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues and checked the recent builds/commits

What happened?

Newly created embedding (or any other embedding for that matter) fails to load

Freshly created embedding is attached

Steps to reproduce the problem

  1. Go to Train > Create Embedding
  2. Create an embedding with any name and start data
  3. Check terminal window

What should have happened?

Embedding should be created and load (albeit empty)

Commit where the problem happens

737eb28faca8be2bb996ee0930ec77d1f7ebd939

What platforms do you use to access UI ?

Windows

What browsers do you use to access the UI ?

Mozilla Firefox

Command Line Arguments

--vae-path models/Stable-diffusion/newVAE.vae.pt --autolaunch

Additional information, context and logs

Freshly created embedding: testembed.zip

Log:

Error verifying pickled file from C:\Users\demos\Documents\workspace\stable-diffusion-webui\embeddings\testembed.pt:
Traceback (most recent call last):
  File "C:\Users\demos\Documents\workspace\stable-diffusion-webui\modules\safe.py", line 97, in load
    check_pt(filename)
  File "C:\Users\demos\Documents\workspace\stable-diffusion-webui\modules\safe.py", line 77, in check_pt
    check_zip_filenames(filename, z.namelist())
  File "C:\Users\demos\Documents\workspace\stable-diffusion-webui\modules\safe.py", line 69, in check_zip_filenames
    raise Exception(f"bad file inside {filename}: {name}")
Exception: bad file inside C:\Users\demos\Documents\workspace\stable-diffusion-webui\embeddings\testembed.pt: testembed/data.pkl


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.


Error loading emedding testembed.pt:
Traceback (most recent call last):
  File "C:\Users\demos\Documents\workspace\stable-diffusion-webui\modules\textual_inversion\textual_inversion.py", line 133, in load_textual_inversion_embeddings
    process_file(fullfn, fn)
  File "C:\Users\demos\Documents\workspace\stable-diffusion-webui\modules\textual_inversion\textual_inversion.py", line 103, in process_file
    if 'string_to_param' in data:
TypeError: argument of type 'NoneType' is not iterable

msoucy avatar Oct 28 '22 23:10 msoucy

The only thing I can think of that might be unusual about my setup is that I changed the pip install command in launch.py to the following:

pip install torch==1.13.0+cu116 torchvision==0.14.0+cu116 --extra-index-url https://download.pytorch.org/whl/cu116

(I was trying to squeeze more performance out of my 4090)

msoucy avatar Oct 28 '22 23:10 msoucy

Using torch 1.13.0+cu117, torchvision 0.14.0+cu117 for speedup and encountered the same problem. I think you can avoid your problem for now by reverting back to the original torch 1.12.1+cu113 and torchvision 0.13.1+cu113.

takanorix avatar Oct 29 '22 06:10 takanorix

Is there any configuration we can add to the UI loader to avoid this issue?

nachoal avatar Oct 29 '22 16:10 nachoal

I noticed the same issue after selecting "Create hypernetwork" and using the default values. Once I select "Train" -> "Train Hypernetwork", it fails loading the .pt it just created with error below. Can bypass that with --disable-safe-unpickle

This is running on Mac M1

file path: /stable-diffusion-webui-mps-master/stable-diffusion-webui/models/hypernetworks/hyper1.pt Error verifying pickled file from /stable-diffusion-webui-mps-master/stable-diffusion-webui/models/hypernetworks/hyper1.pt: Traceback (most recent call last): File "/stable-diffusion-webui-mps-master/stable-diffusion-webui/modules/safe.py", line 97, in load check_pt(filename) File "/stable-diffusion-webui-mps-master/stable-diffusion-webui/modules/safe.py", line 77, in check_pt check_zip_filenames(filename, z.namelist()) File "/stable-diffusion-webui-mps-master/stable-diffusion-webui/modules/safe.py", line 69, in check_zip_filenames raise Exception(f"bad file inside {filename}: {name}") Exception: bad file inside /stable-diffusion-webui-mps-master/stable-diffusion-webui/models/hypernetworks/hyper1.pt: hyper1/data.pkl

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.

kamalWam avatar Oct 29 '22 23:10 kamalWam

Same issue with torch 11.3+cu117 on Windows.

aliencaocao avatar Oct 30 '22 10:10 aliencaocao

Using torch 1.13.0+cu117, torchvision 0.14.0+cu117 for speedup and encountered the same problem. I think you can avoid your problem for now by reverting back to the original torch 1.12.1+cu113 and torchvision 0.13.1+cu113.

I wasted so much time today, because I somehow upgraded these packages without realizing an broke my dreambooth training... thanks!!

richardstrnad avatar Nov 02 '22 14:11 richardstrnad

I ended up modifying the startup script with --disable-safe-unpickle for now as: python webui.py --disable-safe-unpickle --precision full --no-half --use-cpu Interrogate GFPGAN CodeFormer $@

Of course I'm using a trusted model from my own build

nachoal avatar Nov 02 '22 16:11 nachoal

Can confirm happening to me too with official stable diffusion 1.5 model files

ye7iaserag avatar Nov 24 '22 03:11 ye7iaserag

Same, torch 1.13+cu117

Need to add --disable-safe-unpickle

OedoSoldier avatar Nov 30 '22 01:11 OedoSoldier

This is an actual issue with the safety checker. It assumes the internal structure of any checkpoint is 'archive/data.pkl', but any model saved directly with torch.save(model, 'filename.ckpt') will have the structure 'filename/data.pkl'. The only reason many checkpoints get 'archive' instead, is that pytorch-lightning does not save directly to a file, but uses an intermediate buffer.

Edit: Looked into it a bit further, this seems to be an issue with newer versions of pytorch. Checkpoints I created fairly recently still used 'archive/data.pkl'.

smirkingface avatar Dec 02 '22 00:12 smirkingface

This issue will be fixed with the following pull request: https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/5327

smirkingface avatar Dec 02 '22 10:12 smirkingface