Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request]: Use the same seed for batch generation #6

Closed
Woisek opened this issue Mar 2, 2023 · 26 comments
Closed

[Feature request]: Use the same seed for batch generation #6

Woisek opened this issue Mar 2, 2023 · 26 comments

Comments

@Woisek
Copy link

Woisek commented Mar 2, 2023

In the title. Whenever I want to refine a seed, I have to do only singe generations, because when using batch, the seed gets counted up.
This is a bit annoying. Could you make a checkbox that makes the seed always the same, even when useing batch generation, please?

Thanks for this great tool.

@Kahsolt Kahsolt closed this as completed in a05129a Mar 3, 2023
@Kahsolt
Copy link
Owner

Kahsolt commented Mar 3, 2023

You mean you wanna a batch sharing the same Seed but differs in Variation seed or Variation strength individually?
The newest commit now move it to AlwaysVisible, and you can use it with X/Y/Z plot extension to refine your seed ;)

@Woisek
Copy link
Author

Woisek commented Mar 3, 2023

Hmm, no, what I meant is using the same seed, yes, but once I adjusted the Momentums, the batch function should stay on the same seed (right now it always count 1 up) but still respect the options set in Sonar.
When I manually create images useing Sonar, the output is basicly the same but something always shifts a little bit to something different, dependeing on how the settings are. That's why we have Sonar, right? :)
In other words: That, what is done when manualy always clicking "Generate", but automated. :) If that makes any sense.

@Kahsolt
Copy link
Owner

Kahsolt commented Mar 3, 2023

Hmm well, webui's batching mechanism (controlled by Batch count and Batch size) is natively designed to do what you've noticed: keep all other settings the same in one "Generate" process, but sequentially increase Seed by +1 for each image individual, otherwise all outputs would be identical...

If you even let a batch sharing the same Seed (and Variation seed), then what should vary, to avoid all identical outputs? 🤔
You mean some kind of X/Y/Z plot on Sonar's settings like Momentum under this situation?
Kind of automatic parameter grid search?

@Woisek
Copy link
Author

Woisek commented Mar 3, 2023

Hmm ... I don't know how to desribe it more accurate.
My workflow is as follows:
I generate some images with the batch function. It get me several different images, becasue the seed is added +1 with every batch image.
If I find an image that I like and want to refine further, I freeze the seed and activate Sonar.
I single generate an image and look, where it gets me. I tweak Momentum (current) and Momentum (history), and again, single generate an image. If the changes go to my liking, I want to generate more images at once.
This is now the point.
I have to either
click on "Genrate" and wait till it finished,
click on "Genrate" and wait till it finished,
click on "Genrate" and wait till it finished,
click on "Genrate" and wait till it finished,
... -> annoying
or
I have an option to activate and it generates n images after I click once "Generate".

What I want to say is, the batch option can not be used, because auf this +1 addition to the seed, thus skew the refining.
But because I don't know of any other way, I thought maybe this can be controled via the Sonar extension.
Like, to have an option on/off and an input field to specify the amount of images generated. When clicking "Generate", Sonar then keeps "clicking" Generate for as much images are specified.

I hope it's now clearer. :)

@Kahsolt Kahsolt reopened this Mar 5, 2023
@Kahsolt
Copy link
Owner

Kahsolt commented Mar 5, 2023

Now I understand!
It is actually grid search on Sonar's momentum parameter, but I'd take some time to think about how could it be wisely implemented ;), Just wait for some days, it should be done next week soon.

@Woisek
Copy link
Author

Woisek commented Mar 5, 2023

Allright! Many thanks! I'm looking foreward to it.
And thanks again for this great extension.

Kahsolt added a commit that referenced this issue Mar 8, 2023
@Kahsolt
Copy link
Owner

Kahsolt commented Mar 8, 2023

sorry the last pr is a fix of #7 (
now I'm working with this #6 ((((

@Woisek
Copy link
Author

Woisek commented Mar 8, 2023

Bug fix over feature, totally fine. :)
Thanks again!

Kahsolt added a commit that referenced this issue Mar 8, 2023
@Kahsolt
Copy link
Owner

Kahsolt commented Mar 8, 2023

now you can make grid search easily~

@Woisek
Copy link
Author

Woisek commented Mar 8, 2023

now you can make grid search easily~

*JUHU* by Homer S.

@Woisek
Copy link
Author

Woisek commented Mar 8, 2023

Could you please do a quick explanation how "Grid search" is meant to be used, how it works?

@Kahsolt
Copy link
Owner

Kahsolt commented Mar 9, 2023

I thought it was clear sensible enough as the README.md updates... 🤔
Just click the checkbox Grid search, now your Momentum current/history with turn from a Slider to a Text.
Using syntax like 0.75:0.95:5 you'll create five images with parameter values [0.75, 0.8, 0.85, 0.9, 0.95] (e.g. for the Momentum current).
The defaults grid search parameter yields is a simple XY-plot over Momentum current and Momentum history, which has 25 images. For your reference to decide further parameter tuning.

How it works? Just generate one - take a step of parameter change - generate the next one, in a for loop...

Isn't it what you really need, or something I still didn't catch? 😢

@Woisek
Copy link
Author

Woisek commented Mar 9, 2023

I thought it was clear sensible enough as the README.md updates... 🤔

Well, you updated it 3 hours ago, I didn't saw it at the time I wrote it. :) But, I thought of something along those lines when seeing the example in the script (that is also working). But because my entered values didn't work and give error, I wasn't sure about it.

So, to be honest, no, it's not that what I originally meant, BUT this is just as great to have. There are only some bugs to squish.
When I enter the following:

Momentum current search list | Momentum history search list

0.9 | 0.8:0.9:2 -> Nothings happening
| 0.8:0.9:2 -> It generates 2 images but errors with: AssertionError: bad number of horizontal texts: 2; must be 1
0.90:0.95:5 | 0.8 -> Nothings happening
0.90:0.95:5 | -> It generates 5 images but errors with: AssertionError: bad number of horizontal texts: 1; must be 2

When entering nothing, what value is taken? The one the slider was on? It would be cool if we could set a single value there.
Besides that, I'm missing some infos, at least in the console. Like saying "Generating 5 images" and estimation time or something. And I'm missing the used values in the image meta (if that's even possible).

Thanks again for your work. :)

@Kahsolt
Copy link
Owner

Kahsolt commented Mar 9, 2023

Hello~

  1. now the syntax is extend to use one single value
  2. the AssertionError is recognized as a bug and been fixed
  3. there should be a console log saying >> grid search n_jobs: 5 when grid search is on and n_jobs>1, it not appears at your console? 🤔
  4. momentum and momentum_hist is added to PNG info

@Woisek
Copy link
Author

Woisek commented Mar 9, 2023

Thanks for this quick fix.
I'm checking #3 again and report.

@Kahsolt
Copy link
Owner

Kahsolt commented Mar 9, 2023

Thx for your appreciation~ 😄

@Woisek
Copy link
Author

Woisek commented Mar 9, 2023

OK, there is indeed this output you mentioned, but it gets almost invisible in this "clutter". That's probably why I missed it in the first place. :)
Maybe you could output a visible divider first, like "--------------------" or embedd it like "--==// grid search n_jobs: 5 //==--" or something like that.

There is still this error exsiting, don't know what happend. Here is a longer log before the error:

100%|██████████████████████████████████████████████████████████████████████████████████| 30/30 [00:06<00:00, 4.97it/s]
INFO:sd_dynamic_prompts.dynamic_prompting:Prompt matrix will create 1 images in a total of 1 batches.<00:12, 4.93it/s]
100%|██████████████████████████████████████████████████████████████████████████████████| 30/30 [00:06<00:00, 4.97it/s]
INFO:sd_dynamic_prompts.dynamic_prompting:Prompt matrix will create 1 images in a total of 1 batches.<00:06, 4.95it/s]
100%|██████████████████████████████████████████████████████████████████████████████████| 30/30 [00:05<00:00, 5.11it/s]
Error completing request█████████████████████████████████████████████████████████████| 300/300 [01:20<00:00, 5.50it/s]
Arguments: ('task(ieqngaxmzwmguyg)', 'detailed painting of a dark and stormy landscape with a river running through it. there are buildings and a castle on the foreground and the sky is filled with water. by greg rutkowski and thomas kinkade and artgerm and tom bagshaw and magali villeneuve. 8k resolution trending on artstation concept art digital illustration', '', [], 30, 0, False, False, 1, 1, 5, 679539664.0, -1.0, 0, 0, 0, False, 543, 768, False, 0.7, 2, 'Latent', 0, 0, 0, [], 12, False, False, 'LoRA', 'None', 1, 1, 'LoRA', 'None', 1, 1, 'LoRA', 'None', 1, 1, 'LoRA', 'None', 1, 1, 'LoRA', 'None', 1, 1, None, 'Refresh models', False, 'keyword prompt', 'random', 'None', 'textual inversion first', 'None', '0.7', 'None', False, '', 0, True, False, 1, False, False, False, 1.1, 1.5, 100, 0.7, False, False, True, False, False, 0, 'Gustavosta/MagicPrompt-Stable-Diffusion', '', False, True, False, 'none', 'None', 1, None, False, 'Scale to Fit (Inner Fit)', False, False, 64, 64, 64, 0, 1, False, False, 'none', 'None', 1, None, False, 'Scale to Fit (Inner Fit)', False, False, 64, 64, 64, 0, 1, False, 0.9, 5, '0.0001', False, 'None', '', 0.1, False, None, '', 'outputs', False, False, 'positive', 'comma', 0, False, False, '', 'Illustration', 'svg', True, True, False, 0.5, True, 16, True, 16, 1, '', 0, '', 0, '', True, False, False, False, 0, 'Not set', True, True, '', '', '', '', '', 1.3, 'Not set', 'Not set', 1.3, 'Not set', 1.3, 'Not set', 1.3, 1.3, 'Not set', 1.3, 'Not set', 1.3, 'Not set', 1.3, 'Not set', 1.3, 'Not set', 1.3, 'Not set', False, 'None', None, True, None, None, False, None, None, 50, False, 4.0, '', 10.0, 'Linear', 3, False, True, 30.0, True, False, False, 0, 0.0, 'Lanczos', 1, True, 0, 0, 0.0001, 0, 0, 512, 512, False, False, True, True, True, False, False, 1, False, False, 2.5, 4, 0, False, 0, 1, False, False, 'u2net', False, False, False, False, False, True, 'Euler a', 0.85, 0.75, '0.80:0.85:5', '0.75:0.73:2', 'zero', 'pos', 'linear', 0.2, 0.0, 0.75, None, 'Lanczos', 1, 0, 0) {}
Traceback (most recent call last):
File "I:\Super SD 2.0\stable-diffusion-webui\modules\call_queue.py", line 56, in f
res = list(func(*args, **kwargs))
File "I:\Super SD 2.0\stable-diffusion-webui\modules\call_queue.py", line 37, in f
res = func(*args, **kwargs)
File "I:\Super SD 2.0\stable-diffusion-webui\modules\txt2img.py", line 53, in txt2img
processed = modules.scripts.scripts_txt2img.run(p, *args)
File "I:\Super SD 2.0\stable-diffusion-webui\modules\scripts.py", line 376, in run
processed = script.run(p, *script_args)
File "I:\Super SD 2.0\stable-diffusion-webui\extensions\stable-diffusion-webui-sonar\scripts\sonar.py", line 780, in run
grid = images.draw_grid_annotations(
File "I:\Super SD 2.0\stable-diffusion-webui\modules\images.py", line 179, in draw_grid_annotations
assert rows == len(ver_texts), f'bad number of vertical texts: {len(ver_texts)}; must be {rows}'
AssertionError: bad number of vertical texts: 5; must be 4

I guess because of this error, the grid image will not be created ... ?

That aside, I'm so sorry to bother you again with a wish, but i like to finetune things. :)
You have setup the grid search with this sysntax: :: (BTW, is it possible to revert this like 0.95:0.85:5?).
This is great if I know and want a number of images. It would be great, if we also could enter (float) steps like:
:: -> 0.75:0:8:(+0.01) -> 0.75, 0.76, 0.77, 0.78, 0.79, 0.80
That would be like the incement steps used in the original xyz plot script.

And once again, many thanks for your great work, really appreciate it. 👍

@Kahsolt
Copy link
Owner

Kahsolt commented Mar 9, 2023

  1. Weirrrd, I followed your setting 0.80:0.85:5 and 0.75:0.73:2, then got the grid image without any error:

sonar_grid_search-0015-114514 0-(((masterpiece))), highres, ((boy)), child, cat ears, white hair, red eyes, yellow bell, red cloak, barefoot, angel,  flying , e

Could this error due to webui itself? My webui is the latest at master branch commit #0cc0ee1bcb4c24a8c9715f66cede06601bfc00c8, updated at 20 2 2023 19:45:54 +08:00.

  1. The reversed string 0.95:0.85:5 is also OK and will be expanded as you would expect: [0.95, 0.9, ...., 0.85].
  2. I'm adding float step right now

@Woisek
Copy link
Author

Woisek commented Mar 9, 2023

Where do I find the WebUI hash again ... ? :/
NM, found it. Yes, it's the latest like you have.

@Kahsolt
Copy link
Owner

Kahsolt commented Mar 9, 2023

oh no, this commit is buggy, wait for a while (((

@Kahsolt
Copy link
Owner

Kahsolt commented Mar 9, 2023

Should it be OK now, tested 0.75:0.95:0.1 and 0.6:0.5:-0.05 on my machine:

sonar_grid_search-0019-114514 0-(((masterpiece))), highres, ((boy)), child, cat ears, white hair, red eyes, yellow bell, red cloak, barefoot, angel,  flying , e

As for the AssertionError for the missing figure legend... I have no idea why....
You might have to remember that moment_cur varies top-down while moment_hist varies left-right :(

@Woisek
Copy link
Author

Woisek commented Mar 9, 2023

Hmm ... this is really weird ... Your example given works. I get 9 images. I get a 3x3 grid image, but no annotations, that's also in written in the console:

100%|██████████████████████████████████████████████████████████████████████████████████| 35/35 [00:07<00:00, 4.68it/s]
100%|██████████████████████████████████████████████████████████████████████████████████| 15/15 [00:35<00:00, 2.39s/it]
100%|██████████████████████████████████████████████████████████████████████████████████| 35/35 [00:07<00:00, 4.68it/s]
100%|██████████████████████████████████████████████████████████████████████████████████| 15/15 [00:27<00:00, 1.82s/it]
Traceback (most recent call last):███████████████████████████████████████████████████| 450/450 [06:54<00:00, 1.70s/it]
File "I:\Super SD 2.0\stable-diffusion-webui\extensions\stable-diffusion-webui-sonar\scripts\sonar.py", line 802, in run
grid = images.draw_grid_annotations(
File "I:\Super SD 2.0\stable-diffusion-webui\modules\images.py", line 178, in draw_grid_annotations
assert cols == len(hor_texts), f'bad number of horizontal texts: {len(hor_texts)}; must be {cols}'
AssertionError: bad number of horizontal texts: 3; must be 6

[Sonar] failed to draw_grid_annotations()
vertically top to down are momentums_cur: [0.75, 0.85, 0.95]
horizontally left to right are momentum_hists: [0.6, 0.5499999999999999, 0.49999999999999994]
Total progress: 100%|████████████████████████████████████████████████████████████████| 450/450 [07:08<00:00, 1.05it/s]

Also, if I input from your readme -> 0.95:0.75:-0.1 and enter 0.6:0.5:1 in "history", nothing happens. :(
Under the image box it reads: >> [Sonar] error parse_gs:, but this is not written in the console.

Sorry to tell you ... it's somewhat strange ... :/

@Kahsolt
Copy link
Owner

Kahsolt commented Mar 9, 2023

uhmmmm, I forget to handle like 0.6:0.5:1 when is exactly step=1

but step=1 is useless, should be simply 0.6 ((

@Kahsolt
Copy link
Owner

Kahsolt commented Mar 9, 2023

As for the annotations, I really do not know why your env fails to call images.draw_grid_annotations().
This is an inner API of webui and we should have the same stuff...
But mine works and yours broken... I have no way to debug on your environment, hence I added those extra info vertically top... for your reference :(

@Kahsolt
Copy link
Owner

Kahsolt commented Mar 9, 2023

As you see, the grid is actually 3x3, hence this AssertionError: bad number of horizontal texts: 3; must be 6 is insane, it must not be 6, it of course should be 3. Some thing went wrong but not sonar aware of :(

@Woisek
Copy link
Author

Woisek commented Mar 9, 2023

OK, I will observe this further and try to help you solve this. Mybe we find what's happening ... &)
Thanks a lot!

@Kahsolt Kahsolt closed this as completed Mar 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants