adieyal / sd-dynamic-prompts

A custom script for AUTOMATIC1111/stable-diffusion-webui to implement a tiny template language for random prompt generation
MIT License
2.05k stars 263 forks source link

The Magic Prompt doesn't seem to work properly #62

Closed Harvester62 closed 1 year ago

Harvester62 commented 1 year ago

Describe the bug The Magic Prompt option, when activated, will put the additional prompt terms in the Negative field, therefore not adding them to the current input prompt.

Version used This Extension's version is v0.25.1

To Reproduce Steps to reproduce the behaviour, include the prompt you used if applicable:

  1. Activate Dynamic Prompts ticking the "Dynamic Prompts enabled" checkbox
  2. Activate the "Magic prompt" option witht the related checkbox
  3. Set the max Magic prompt lenght to 101, and Magic prompt creativity to 0.7
  4. type the prompt "Landscape of" in the Prompt field on top (positive)
  5. Press Generate

The image is generated but the additional prompts are displayed as Negative terms, therefore not having any effect on the generated image. Furthermore, the additional prompts seem to be unrelated to the input prompt.

Expected behaviour I would expect to have the additional prompt terms added to the positive prompt and not the negative one.

Additional context It seems a mismatch of the Magic prompt additional terms insertion place. Here follows a screenshot of the settings and issue immagine

adieyal commented 1 year ago

Could you please try v >= 0.26.0 - there is an option in advanced settings which disables negative prompts

Harvester62 commented 1 year ago

Thank you for your reply and suggestion. I've just updated the local copy of your repository and the current version is v0.27.1. I will use it for testing, if it's fine for you. I'm at work now and I will check your suggested solution as soon as I will be back at home, and let you know.

Harvester62 commented 1 year ago

I started SD Web UI and immediately unchecked the "Dynamic Prompts enabled" checkbox, nothing else was active in the DP interface. I then generated a batch of three images which were created but the console displays the following error messages:

Error running process_batch: C:\stable-diffusion-webui\extensions\sd-dynamic-prompts\scripts\dynamic_prompting.py Traceback (most recent call last): File "C:\stable-diffusion-webui\modules\scripts.py", line 309, in process_batch script.process_batch(p, *script_args, **kwargs) File "C:\stable-diffusion-webui\extensions\sd-dynamic-prompts\scripts\dynamic_prompting.py", line 247, in process_batch generator = self._negative_prompt_generator AttributeError: 'Script' object has no attribute '_negative_prompt_generator'

Being the Extension not enabled, as well as all its options, I wouldn't expect such messages related to Negative prompt.

These are the COMMAND_LINE_ARGS activated, for your information:

Launching Web UI with arguments: --xformers --opt-split-attention --disable-safe-unpickle --api --deepdanbooru --allow-code --administrator --medvram

I then activated the Dynamic Prompts as well as the "Disable negative prompt" option, and generated a new image. No error messages were displayed this time. So, I deactivated the "Disable negative prompt" option but left the main "Dynamic Prompts enabled" checkbox active, and a new image was generated without any error messages in the console. OK, last test now with "Dynamic Prompts enabled" checkbox active, "Magic prompt" active as well as "Disable negative prompt" option too, and a new image was generated without any error messages, and with the properly placed additional prompt terms appended to the input prompt (simply "Landscape").

So, there seems to be an issue when the "Dynamic Prompts enabled" checkbox is unchecked.

adieyal commented 1 year ago

Thanks for the detailed diagnosis. Could you please test 0.27.2, the bug should hopefully be fixed

Harvester62 commented 1 year ago

You're too fast! I was still testing. Very well, thank you, let me sync the repo and test again.

Harvester62 commented 1 year ago

Hmmm, sorry, nope. I did sync the repo, restarted everything, added the prompt "A Landscape", deactivated the "Dynamic Prompts enabled" checkbox, and the image was generated but got this error in the console:

(INFO) Result 0: A Landscape Error running process_batch: C:\stable-diffusion-webui\extensions\sd-dynamic-prompts\scripts\dynamic_prompting.py Traceback (most recent call last): File "C:\stable-diffusion-webui\modules\scripts.py", line 309, in process_batch script.process_batch(p, *script_args, **kwargs) File "C:\stable-diffusion-webui\extensions\sd-dynamic-prompts\scripts\dynamic_prompting.py", line 249, in process_batch

I then activated it and re-generated the image and got no errors, even without checking any other options. Strange.

adieyal commented 1 year ago

Is that the full error message?

Harvester62 commented 1 year ago

Yes, and it seems to happen only the very first time, then it no longer appears. But one thing I've just noticed is that the Magic Prompt no longer works, if used in conjunction with the "Disable negative prompt". If I disable the latter, the Magic prompt works but put the terms in the Negative, obviously. Also the "Don't generate images" doesn't seems to work, being an image generated anyway. Furthermore, wouldn't the additional terms be appended inside the Prompt text box, or only visible in the tags of the generated image?

Harvester62 commented 1 year ago

I've seen your commit. Now I sync and re-test and let you know.

adieyal commented 1 year ago

I just pushed 0.27.3 which should hopefully do the trick.

But one thing I've just noticed is that the Magic Prompt no longer works, if used in conjunction with the "Disable negative prompt".

Tested it now - should be working after this fix

Also the "Don't generate images" doesn't seems to work, being an image generated anyway.

I need to generate at least one image otherwise the webui complains - but if you set it to generate say 1000 prompts, it will write 1000 to a file and generate one image.

Furthermore, wouldn't the additional terms be appended inside the Prompt text box, or only visible in the tags of the generated image?

Could you elaborate on this? The prompt will be embedded in the image. You can check in the PNG info tab. Not sure what you mean by appending inside the Prompt text box.

Harvester62 commented 1 year ago

You just replied to my question, being the prompt embedded in the image and not appended inside the Prompt textbox. Thank you. Testing now, and thank you for your bug fixing!

adieyal commented 1 year ago

Thanks for taking the time to test

Harvester62 commented 1 year ago

Unfortunately, the Magic Prompt still doesn't work with or without the "Disable negative prompt" option. The "Don't generate images" option works and the file is saved inside the \output\txt2img-images folder. I mean that the Magic Prompt works with the "Don't generate images" option and the "Write prompts to file", but not without the latter. Nothing appears to be embedded in the generated image.

adieyal commented 1 year ago

I can't reproduce what you're seeing. These are my steps:

  1. Restart the webui
  2. Type A landscape in the text prompt
  3. Check Magic Prompt
  4. Click generate

This is my output

A landscape with a large galaxy in the sky, a fantasy digital painting by Greg Rutkowski and James Gurney, trending on Artstation, highly detailed Negative prompt: a hyperrealistic portrait of a cyberpunk man in cyberspace, by Guy Denning, Johannes Itten, Russ Mills, hacking effects, detailed lines, network, cybernetics, futurism, cybernetics, intricate detail, holographic, polished, chromatic, clear, (color blocking:1.1), acrylic on canvas, octane, concept art, abstract, red face, front view, artistic, 8k, cgsociety, trending on artstation

  1. I then check disable negative prompts
  2. Click generate

Here is my output

A landscape full of big red crystals and pulsar energy in an alien landscape, neon pink geometric light, a fantasy digital painting, HDR, concept art, octane render, unreal engine 5, trending on Artstation, high quality, highly detailed, 8K, soft lighting, anatomically correct, geometric, cinematic, high coherence

Finally

  1. I go to the image browser
  2. Click load
  3. Select my image
  4. And the prompt is in there

Am I doing something different to you?

Harvester62 commented 1 year ago

Let me reproduce exactly your above steps, and let you know.

Harvester62 commented 1 year ago

OK, first four steps, this is the result

A landscape Negative prompt: jossi of blackpink, wearing glasses, wearing a suit, tarot card, deep focus, d & d, fantasy, intricate, elegant, highly detailed, digital painting, artstation, concept art, matte, sharp focus, illustration, hearthstone, art by artgerm and greg rutkowski and alphonse mucha Steps: 20, Sampler: Euler a, CFG scale: 7, Seed: 3340343120, Size: 512x512, Model hash: 7460a6fa, Model: model

This is after steps 5 and 6

A landscape Steps: 20, Sampler: Euler a, CFG scale: 7, Seed: 5964667, Size: 512x512, Model hash: 7460a6fa, Model: model

After steps 7 to 10 the resulting tags are exactly as above reported.

FYI, I have all the officially listed Scripts and Extenstion activate in my installation because I need them to localize all of their interfaces in Italian language. Do you think there might be some conflicting Scripts or Extensions? Before it worked, so perhaps I am just worrying for nothing.

adieyal commented 1 year ago

There's always a chance that one script is interfering with another but I don't think that's what is causing this. The fact that the negative prompt is working but not the positive prompt is significant.

I'll look into this again in a few hours and let you know if I manage to find something.

Harvester62 commented 1 year ago

Let me know if you need me to do any testing, and I will be willing to help you.

adieyal commented 1 year ago

Would you be able to test this branch: https://github.com/adieyal/sd-dynamic-prompts/tree/bug/magic-prompt-not-working?

I have added some debug logging which will print out your settings. That will help me figure out why the positive prompt is not working for you.

Harvester62 commented 1 year ago

Sure, sorry I didn't read you message earlier, I will test your branch and let you know.

Harvester62 commented 1 year ago

OK, I hope I did it right. I pulled the latest changes as well as the new branch, then I Fetch and Rebase the local Main repo with the debugging branch and then I executed the same exact steps as above; first the 1 to 4, then I set the "Disable negative prompt" option and generated again. I got the same results without any new prompt terms appended or embedded. Here is a screenshot of the entire console from startup to end of step 6; in the Image Browser the two generated images don't show any additional tag apart from the original prompt "A landscape". Hope it helps and please let me know if a correctly set the new debugging branch.

dynaprom_debugging1

Harvester62 commented 1 year ago

Hi. Was the above information useful to narrow down the source of the issues? Let me know if I can provide any other useful information.

adieyal commented 1 year ago

hmmm - I've tried to recreate your exact situation but I can't. Do you have any other extensions running at the same time that might be swallowing up the prompt?

I have added additional debugging information to the test branch - could you please update your current version and try again. Then send me the output? I'm testing whether the positive prompts are generated at all

Harvester62 commented 1 year ago

Yes, I have ALL the Scripts and Extensions installed and activated for translation purposes, but I can deactivate all the Extensions but yours, and move away all the Scripts not officially included in the repository (I mean the one you sync or download from the repository) from the \scripts directory, and test again your Extension.

Harvester62 commented 1 year ago

Unfortunately, there is one Script that breaks the Gradio interface and prevent the generation of images. I will have to discover which one it is, but for now I will move away all the scripts and test your Extension.

Harvester62 commented 1 year ago

OK, I've the results of the tests and I can say that the issue should be caused by to one of the Extensions, not the Italian localization because it was activated in the third screenshot. Well, here follow screenshots of the entire console with three tests, every time restarting the webui, all without any additional Scripts apart from the nine supplied by default; the first and second test were executed with all the Extensions activated; the first test was with only the Magic Prompt option activated, while the second test was with Magic Promps and No negative prompt activated. The image generated in both first and second test had nothing added or embedded, and was only done with "a landscape" prompt text.

The third test was done with only Dynamic Prompts and Italian localization extensions activated, all the other were installed but deactivated. Magic Prompt and No negative prompt activated. The result was positive with the image generated and the additional terms added to the prompt, and nothing in the negative prompt, so it went fine, meaning the Dynamic Prompts is affected by one of the extensions, at least in my local installation. I might activate the other extensions one by one, restart the webui and test the generation, but it's a quite time consuming process and I would prefer to leave you the time to evaluate the collected data and screenshots herewith attached. Hope this helps to identify the source of the problem. Let me know if I can do anything else. The screenshots below are in the above described order.

magic_prompts_test_noscritps_allExtensions

magic_prompts_test_noscritps_allExtensions_nonegativeprompt

magic_prompts_test_noscritps_noExtensions_magic_and_nonegativeprompt

adieyal commented 1 year ago

Thanks for this - it is very helpful. From the screenshots you posted, it looks like Magic Prompt is always working. However, in the first two tests, stable-diffusion-webui-aesthetic-image-scorer breaks for some reason. If you look at the screenshot, you will see where it happens. Does everything work fine without Dynamic Prompts? I wonder whether it is caused by Dynamic Prompts in some way, or whether the issue is independent.

Screenshot from 2022-11-20 20-46-02

adieyal commented 1 year ago

I've installed aesthetic image scorer, but I can't reproduce the error. What settings do you have set for it? Maybe I'm not checking the right boxes.

Harvester62 commented 1 year ago

I discovered the source of the problem, after activating all the Extensions one by one and running Dynamic Prompts with the Magic Prompt and the No Negative Prompt options activated.

The Aesthetic Scorer is the source of another issue, that is when you restart the webui interface the VRAM memory get raised every time a little until its fully occupied; a VRAM memory leaking. In fact, deactivating this extension I get my VRAM at 1.4GB, at 1.9GB with the Krita Plugin activated, and no VRAM memory leaking. Interesting, I should let the developer know about this.

Now, back to our issue. I suspected that it was caused by one of the extensions that plays with the prompt, so I kept this one at the end of the tests, and I was right! The source of the problem is the extension named Unprompted. All the other extensions were activated one by one, then I restarted the Gradio interface from the Extensions tab, and left the activated extension on (to check for any possible interference). I am glad for the discovery. You Extension is working fine, at least the above two options; I also tested the "I feel lucky" and it works too.

adieyal commented 1 year ago

Glad we've figured it out. Unprompted and Dynamic Prompts are unlikely to play nicely together since there is a lot of overlap in their features. I definitely recommend only running one of them at a time.

I think we can close this issue now?

Harvester62 commented 1 year ago

Absolutely, yes! Thank you for your attention and great Extension, the generated images are very interesting and an inspiration for prompt engineering.