AIrjen / OneButtonPrompt

One Button Prompt
GNU General Public License v3.0
745 stars 77 forks source link

Error with superprompt: AttributeError: 'NoneType' object has no attribute 'keys' #190

Open tusharbhutt opened 2 months ago

tusharbhutt commented 2 months ago

Hi,

I get an error whenever trying out the SuperPrompt plugin, see truncated data error data below. The error does not occur when the extension is off.

Here's an image of the settings used:

image

*** Error completing request

Traceback (most recent call last):
  File "C:\Applications\StableDiffusion\Automatic1111\modules\call_queue.py", line 57, in f
    res = list(func(*args, **kwargs))
  File "C:\Applications\StableDiffusion\Automatic1111\modules\call_queue.py", line 36, in f
    res = func(*args, **kwargs)
  File "C:\Applications\StableDiffusion\Automatic1111\modules\txt2img.py", line 106, in txt2img
    processed = modules.scripts.scripts_txt2img.run(p, *p.script_args)
  File "C:\Applications\StableDiffusion\Automatic1111\modules\scripts.py", line 773, in run
    processed = script.run(p, *script_args)
  File "C:\Applications\StableDiffusion\Automatic1111\extensions\OneButtonPrompt\scripts\onebuttonprompt.py", line 1347, in run
    base_prompt = build_dynamic_prompt(insanitylevel,subject,artist, imagetype, False, antistring, prefixprompt, suffixprompt,promptcompounderlevel, seperator,givensubject,smartsubject,giventypeofimage,imagemodechance,chosengender, chosensubjectsubtypeobject, chosensubjectsubtypehumanoid, chosensubjectsubtypeconcept,True,False,-1,givenoutfit, False, base_model, OBP_preset, promptenhancer)
  File "C:\Applications\StableDiffusion\Automatic1111\extensions\OneButtonPrompt\build_dynamic_prompt.py", line 3319, in build_dynamic_prompt
    superpromptresult = one_button_superprompt(insanitylevel=insanitylevel, prompt=subjectprompt, seed=seed, override_subject=givensubject, override_outfit=overrideoutfit, chosensubject=subjectchooser, gender=gender, restofprompt = startprompt + endprompt)
  File "C:\Applications\StableDiffusion\Automatic1111\extensions\OneButtonPrompt\build_dynamic_prompt.py", line 4759, in one_button_superprompt
    load_models()
  File "C:\Applications\StableDiffusion\Automatic1111\extensions\OneButtonPrompt\superprompter\superprompter.py", line 25, in load_models
    model = T5ForConditionalGeneration.from_pretrained(modelDir, torch_dtype=torch.float16)
  File "C:\Applications\StableDiffusion\Automatic1111\venv\lib\site-packages\transformers\modeling_utils.py", line 2657, in from_pretrained
    loaded_state_dict_keys = list(state_dict.keys())
AttributeError: 'NoneType' object has no attribute 'keys'
Grogutech commented 2 months ago

Same here

AIrjen commented 2 months ago

Hi! It might mean that you are missing some requirements.

Check out the documentation here: https://github.com/AIrjen/OneButtonPrompt/blob/main/user_guides/superprompt.md

Basically, go to the OneButtonPrompt\superprompter\ directory and execute the following command:

$ pip install -r requirements.txt

It needs at least the following pieces installed:

transformers einops accelerate sentencepiece

It will download the model on first use, it will download into: \OneButtonPrompt\superprompter\model_files

You can remove that _modelfiles directory to trigger a redownload of the actual model.

Hope that helps!

tusharbhutt commented 2 months ago

Hi! It might mean that you are missing some requirements.

Check out the documentation here: https://github.com/AIrjen/OneButtonPrompt/blob/main/user_guides/superprompt.md

I'll give that a try, but just curious as to why that's not done automatically?

UPDATE: All requirements are met, and I deleted the model folder to let the model get downloaded. I also updated to version 817f2919 and restarted from scratch (i.e., I did not just reload the UI, I killed the process and restarted it). The issue remains:

Traceback (most recent call last):
  File "C:\Applications\StableDiffusion\Automatic1111\modules\call_queue.py", line 57, in f
    res = list(func(*args, **kwargs))
  File "C:\Applications\StableDiffusion\Automatic1111\modules\call_queue.py", line 36, in f
    res = func(*args, **kwargs)
  File "C:\Applications\StableDiffusion\Automatic1111\modules\txt2img.py", line 106, in txt2img
    processed = modules.scripts.scripts_txt2img.run(p, *p.script_args)
  File "C:\Applications\StableDiffusion\Automatic1111\modules\scripts.py", line 773, in run
    processed = script.run(p, *script_args)
  File "C:\Applications\StableDiffusion\Automatic1111\extensions\OneButtonPrompt\scripts\onebuttonprompt.py", line 1347, in run
    base_prompt = build_dynamic_prompt(insanitylevel,subject,artist, imagetype, False, antistring, prefixprompt, suffixprompt,promptcompounderlevel, seperator,givensubject,smartsubject,giventypeofimage,imagemodechance,chosengender, chosensubjectsubtypeobject, chosensubjectsubtypehumanoid, chosensubjectsubtypeconcept,True,False,-1,givenoutfit, False, base_model, OBP_preset, promptenhancer)
  File "C:\Applications\StableDiffusion\Automatic1111\extensions\OneButtonPrompt\build_dynamic_prompt.py", line 3319, in build_dynamic_prompt
    superpromptresult = one_button_superprompt(insanitylevel=insanitylevel, prompt=subjectprompt, seed=seed, override_subject=givensubject, override_outfit=overrideoutfit, chosensubject=subjectchooser, gender=gender, restofprompt = startprompt + endprompt)
  File "C:\Applications\StableDiffusion\Automatic1111\extensions\OneButtonPrompt\build_dynamic_prompt.py", line 4759, in one_button_superprompt
    load_models()
  File "C:\Applications\StableDiffusion\Automatic1111\extensions\OneButtonPrompt\superprompter\superprompter.py", line 25, in load_models
    model = T5ForConditionalGeneration.from_pretrained(modelDir, torch_dtype=torch.float16)
  File "C:\Applications\StableDiffusion\Automatic1111\venv\lib\site-packages\transformers\modeling_utils.py", line 2657, in from_pretrained
    loaded_state_dict_keys = list(state_dict.keys())
AttributeError: 'NoneType' object has no attribute 'keys'

AIrjen commented 2 months ago

Hi! Thanks for the anwer.

I'll give that a try, but just curious as to why that's not done automatically?

I have no idea how :D

As for your issue, I have no clue. It fails in venv\lib\site-packages\transformers\modeling_utils.py which is part of the transformers that is part of the requirements for the installation. I had this problem at the start, when sentencepiece was not installed correctly.

Not sure how else to help here.

AndreRatzenberger commented 4 weeks ago

I probably have some insights, since I get the same error... OP missed that the error starts way earlier

Please note that existing prompt and negative prompt fields are (no longer) used
Starting generating the prompt
only generated these artists:by Robert Vonnoh, Hendrick Avercamp
*** Error verifying pickled file from /workspace/stable-diffusion-webui/extensions/OneButtonPrompt/superprompter/./model_files/pytorch_model.bin
*** 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 "/workspace/stable-diffusion-webui/modules/safe.py", line 137, in load_with_extra
        check_pt(filename, extra_handler)
      File "/workspace/stable-diffusion-webui/modules/safe.py", line 84, in check_pt
        check_zip_filenames(filename, z.namelist())
      File "/workspace/stable-diffusion-webui/modules/safe.py", line 76, in check_zip_filenames
        raise Exception(f"bad file inside {filename}: {name}")
    Exception: bad file inside /workspace/stable-diffusion-webui/extensions/OneButtonPrompt/superprompter/./model_files/pytorch_model.bin: pytorch_model/byteorder

so it's because the model is in non-safe format. unfortunately I use a preconfigured and hosted instance of a1111, so any ideas how I can work around that?

EDIT:

Replace the model.bin with the model.safetensors of this repo https://huggingface.co/roborovski/superprompt-v1

image

seems to work!

AIrjen commented 4 weeks ago

Thanks, will look into making using of the safetensor file soon!