antis0007 / sd-webui-multiple-hypernetworks

GNU General Public License v3.0
97 stars 12 forks source link

Hypernetwork strength index out of range #2

Closed Lumoria closed 1 year ago

Lumoria commented 1 year ago

When changing the strength of hypernetwork 1, all of the hypernetworks that come after 1 will need to have their strength changed to a different value or an index out of range error is given.

By the way thanks for fixing my other issue so fast!

antis0007 commented 1 year ago

Hello! No problem about the earlier issue, glad to help. I can't seem to replicate your issue on my own, so I'm a bit confused as to what could be causing this. If you could take some screenshots, copy the errors or detail how to replicate it I'd love to get on fixing this asap.

Lumoria commented 1 year ago

Here's the error: Error completing request Arguments: ('test prompt', '', 'None', 'None', 20, 0, True, False, 1, 1, 7, 2775983019.0, -1.0, 0, 0, 0, False, 512, 512, False, 0.7, 0, 0, 1, 'MJWD(77a9675b),\nMJNAI(088c8e83)\n', '0.0,\n0.0', 8, True, 16, 'Median cut', False, False, False, '', '', False, 4.0, '', 10.0, False, False, True, 30.0, True, False, False, 0, 0.0, 'Positive', 0, ', ', True, 32, 1, '', 0, '', True, False, False) {} Traceback (most recent call last): File "/home/lumori/stable-diffusion-webui-auto/modules/ui.py", line 185, in f res = list(func(*args, **kwargs)) File "/home/lumori/stable-diffusion-webui-auto/webui.py", line 57, in f res = func(*args, **kwargs) File "/home/lumori/stable-diffusion-webui-auto/modules/txt2img.py", line 46, in txt2img processed = modules.scripts.scripts_txt2img.run(p, *args) File "/home/lumori/stable-diffusion-webui-auto/modules/scripts.py", line 317, in run processed = script.run(p, *script_args) File "/home/lumori/stable-diffusion-webui-auto/scripts/multiple_hypernetworks.py", line 290, in run skip.append((new, shared.opts.hypernetwork_obj_list[old])) IndexError: list index out of range

edit: To reiterate, when a specific hypernet has its strength changed, all of the other hypernets that are applied after that one will have to have their strength changed to resolve the index out of range error.

antis0007 commented 1 year ago

I've made some updates today to fix the issues stemming from the latest version of the webui and looked into this. image Made some changes to the loading skip functionality since I believe that's where this issue came from. The image above is a stress test with 5 hypernetworks applied at:

0.8 , 0.8 , 0.2 , 0.2 , 0.3

Tested with 3 hypernetworks at the same time, and it seems to work. Even when applying at the same strength with the same hypernetwork multiple times, I don't have any issues.

Be sure to update to the latest version of the script, and hit Reset once you finish using the multiple hypernetworks feature. (May take a second to load, check for the "RESET!" in the console log to make sure its ready)

If the script works for you after the latest update, just mention me and I'll close the issue.

Lumoria commented 1 year ago

So for the first generation, say you use strengths 0.8 , 0.8 , 0.2 , 0.2 , 0.3

Then for the second generation, you change the third strength so they are now 0.8 , 0.8 , 0.6 , 0.2 , 0.3

You don't get an error when trying the second generation?

I've updated to the most recent script and am still getting the index out of range error.

antis0007 commented 1 year ago

@Lumoria Just tested this again, got no error. I'll continue experimenting to find the root cause, but please send an example with some of the default NAI hypernetworks and various weights that cause the error.

I JUST had an idea as to the cause, hypernetworks get stored in RAM between generations with this plugin, and they'll only stay there as long as they're needed. Each generation, it checks which hypernetworks are loaded currently that can be reused, and clears out the rest.

The problem with this is that memory can get cleared if python stays open for a very long time, or if you put your computer to sleep, etc... Not an expert on memory allocation things in python so I really don't know if you can predict this happening. Not sure how to avoid this issue but keep that in mind while testing this to not drive yourself crazy.

Lumoria commented 1 year ago

I've come back from a break and pulled the recent changes, this error doesn't occur for me anymore, thanks!