klimaleksus / stable-diffusion-webui-embedding-merge

Extension for AUTOMATIC1111/stable-diffusion-webui for creating and merging Textual Inversion embeddings at runtime from string literals.
The Unlicense
106 stars 10 forks source link

Strange behaviour with dynamic prompts #11

Closed miasik closed 4 months ago

miasik commented 5 months ago

A prompt: A girl next door <'__celeb-female__' + '__celeb-female__' + '__celeb-female__'> wearing casual clothes, outdoors, [by Luis Royo : RAW photo, film grain : 0.25] Batch count: 2 Batch size: 2 The text under the image (the seed is OK, it changes): A girl next door <'EM_1'> wearing casual clothes, outdoors, [by Luis Royo : RAW photo, film grain : 0.25] Negative prompt: sad, monotone, low quality, low resolution, [mutated | extra | missed | broken] fingers, text Steps: 30, Sampler: DPM++ 3M SDE Karras, CFG scale: 7, Seed: 3815115804, Size: 512x768, Model hash: 670934b0bd, Model: YACAM-SR-16286.fp16, RNG: CPU, EmbeddingMerge: "<'EM_1'>=<'Kathleen Robertson' + 'Zooey Deschanel' + 'Carla Gugino'>, <'EM_2'>=<'Kirsten Prout' + 'Gemma Ward' + 'Abigail Ratchford'>, <'EM_3'>=<'Miranda Kerr' + 'Anna Faris' + 'Paget Brewster'>, <'EM_4'>=<'Scout Taylor-Compton' + 'Briana Evigan' + 'Gwyneth Paltrow'>, <'EM_5'>=<'__celeb-female__' + '__celeb-female__' + '__celeb-female__'>", Eta: 0.5, Version: v1.7.0

door <'EM_1'> wearing is a key point. The number increases from image to image and the extension puts all combinations into all images.

aleksusklim commented 5 months ago

Are the results correct? Can you recreate other (beside the first) images by putting the correct combination into the prompt again?

Are generation infos for other images correct when examined separately from files? I.e. the third image puts <'EM_3'> into the prompt but erroneously lists all 1 and 2 inside its info?

Or it is the batch itself lists all? Or only the first image?

If the problem is listing of unrelated embeddings, I think it might be possible to simply not print those that weren't used in THIS iteration. Hmm, this can be done either by tracking actually used names, or by scanning the resulting prompts (which might have been already modified by other extensions).

It might or might not be related to the last caching fix.

P.S.

The number increases from image to image and the extension puts all combinations into all images.

So, image 2 lists both EM_3 and EM_1? Even between batches?

miasik commented 5 months ago

All the resulting images look correct.

All images from any batch contain all "dynamic" EM from the batch in their info, but use them correctly, so image №3 has EM_3 in its prompt. The example info above is from a 4 images batch and we see 4 normal "dynamic" EM and one strange EM_5 in the end

aleksusklim commented 5 months ago

My code is not checking specifically for batches, I just process everything in a generation (as Processing "p" instance), not trying to split prompts by actual images. Thus, I see all prompts together and can return the only one generation info!

Are you aware of any other extension that "should" put into the generation info something DIFFERENT when used with batch count or batch sizes? Different except for prompts and seeds, those are set in all_* properties of Processing object.

As the worst-case I would need to hook an image-saving function to strip unused embeddings, but this feels wrong. Maybe WebUI already have a function to control individual image infos?

miasik commented 5 months ago

Sure, the extension work correctly in batches. This behavior is only with dynamic prompt extension.

aleksusklim commented 5 months ago

Wildcard extension changes prompts and correctly saves them into the generation infos because multiple prompts are already supported. Is there any extension that changes something custom, and ought to put that into individual image infos in batches?

miasik commented 5 months ago

No, even more, I disabled almost all my extension to check and make the report.

aleksusklim commented 5 months ago

I mean, I need to know HOW to output the different image infos in a batch!

miasik commented 5 months ago

I mean, I need to know HOW to output the different image infos in a batch!

Sorry. What do I need to do?

aleksusklim commented 5 months ago

Apparently you are generally using more other extensions than I am. So I ask, whether you know any extension that also needs to emit DIFFERENT info in batches?

(It is fine if not; I'm still up to see how WebUI is handling the image info and when it gets separated to different images)

miasik commented 5 months ago

Apparently you are generally using more other extensions than I am. So I ask, whether you know any extension that also needs to emit DIFFERENT info in batches?

(It is fine if not; I'm still up to see how WebUI is handling the image info and when it gets separated to different images)

No, sorry. I was thinking but couldn't recall any extension this such behavior

aleksusklim commented 4 months ago

At first I wanted to hook infotext creation function before it emits stringified generation info, but I noticed it ignores Hires Prompt in batch mode (as if allowing only one hr_prompt while accepting multiple normal prompts). Then I found out that dynamic prompt extension itself is bugging with wildcards put in hires prompts! https://github.com/adieyal/sd-dynamic-prompts/issues/633

That's why I decided to hook infotext after it is already stringified – to parse it back to remove unused embeddings if any. But I don't collapse to none if nothing was found, so everything will be listed for batch grid itself.

Also, I've pushed basic SDXL support to sdxl branch, you may try it out too!