batch_method
Opened this issue · 7 comments
New batch method is ignoring additional Lora's included in a [choose] block when iterating through the batch count. The Lora from the first batch gets applied to all, despite a changing prompt (you can tell it's not even loading because the command line log only shows the loading of the first Lora). When I choose "legacy" for batch_method it chooses a new Lora for each generation as expected.
Hi @porternw,
Thank you for bringing this to my attention. I have released a possible fix in Unprompted v9.13.1.
Should you have a need to debug further, please be aware that the batch_method
setting was renamed to batch_count_method
earlier today, and the legacy
mode was renamed to safe
.
Thanks for working on this! Still not functioning correctly, though. Interestingly, while the first Lora gets applied to all generations, the second in the batch shows a second random Lora in the prompt (though obviously applies the first Lora), while the rest of the prompts in the batch show the first Lora instead of random ones. The "safe" mode works as expected.
`
22:09:59-200810 ERROR Error occurred while trying to deactivate extra networksTraceback (most recent call last):
File "/home/nporter/SD/automatic/extensions/_unprompted/scripts/unprompted.py", line 691, in process_batch
extra_networks.deactivate(p, p.extra_network_data)
AttributeError: 'StableDiffusionProcessingTxt2Img' object has no attribute 'extra_network_data'
22:09:59-204471 ERROR Running script process batch: /home/nporter/SD/automatic/extensions/_unprompted/scripts/unprompted.py: KeyError
╭─────────────────────────────────────────────────────────────────── Traceback (most recent call last) ───────────────────────────────────────────────────────────────────╮
│ /home/nporter/SD/automatic/modules/scripts.py:430 in process_batch │
│ │
│ 429 │ │ │ │ args = p.per_script_args.get(script.title(), p.script_args[script.args_f │
│ ❱ 430 │ │ │ │ script.process_batch(p, *args, **kwargs) │
│ 431 │ │ │ │ s.append(f'{script.title()}:{round(time.time()-t0, 2)}s') │
│ │
│ /home/nporter/SD/automatic/extensions/_unprompted/scripts/unprompted.py:732 in process_batch │
│ │
│ 731 │ │ │ │ │
│ ❱ 732 │ │ │ │ Unprompted.shortcode_user_vars["prompts"][batch_size_index] = prompt_res │
│ 733 │ │ │ │ Unprompted.shortcode_user_vars["negative_prompts"][batch_size_index] = n │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
KeyError: 'prompts'
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:05<00:00, 8.67it/s]
`
Thanks @porternw, I haven't had a chance yet to investigate further but I'll re-open the issue so I don't forget.
Hi @porternw,
I examined the behavior of batch_count with loras more closely but was not able to reproduce the issue you described.
Here is the prompt I tested at a batch_count of 3:
digital painting of an emerald dragon[choose]<lora:add_detail:1>|<lora:add_sharpness:1>|<lora:epi_noiseoffset2:1>|<lora:FilmVelvia2:1>|<lora:hd_helper_v1:1>|<lora:LowRA:1>|<lora:more_details:1>[/choose]
I can see in the "Lora hashes" section of the generation info that a different network was applied to each image.
There are no error messages in my console, either.
Some general diagnostic questions if you don't mind:
- Is your prompt formatted the same way as my example above?
- Is your WebUI up-to-date?
- What other extensions are you using?
Thanks.
I think I've found the problem. I'm running the SD.next fork of a1111...which I didn't even think about initially when reporting this. Anyway, comparing the two repositories, it seems that vlad's version doesn't include the attribute "extra_network_data" which is causing the failure seen above. Removing that reference from the batch_process function in unprompted.py seems to resolve the issue (the error message goes away and the loras load normally), though I don't know if there are any consequences of that removal.
Edit: Nope I was wrong, got excited and forgot to change the config back to "Standard".
SD.next, up-to-date
Prompt: portrait photo of a famous person, [choose] <lora:lora1:1.0>| <lora:lora2:1.0>[/choose]
Enabled extensions-builtin: ['sd-extension-system-info', 'LDSR', 'stable-diffusion-webui-rembg', 'sd-webui-agent-scheduler',
'clip-interrogator-ext', 'Lora', 'ScuNET', 'SwinIR', 'stable-diffusion-webui-images-browser']
Enabled extensions: ['CloneCleaner', '_unprompted', 'adetailer', 'canvas-zoom', 'sd-webui-ar']
Here's my log.
`
Loading weights: /home/nporter/SD/automatic/models/Lora/lora1.ckpt ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸━ 220.9/226.8 MB 0:00:00
Calculating model hash: /home/nporter/SD/automatic/models/Lora/lora1.ckpt ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 226.8/226.8 MB 0:00:00
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:09<00:00, 5.39it/s]
17:46:15-209657 ERROR Running script process batch: /home/nporter/SD/automatic/extensions/_unprompted/scripts/unprompted.py: AttributeError
╭─────────────────────────────────────────────────────────────────── Traceback (most recent call last) ───────────────────────────────────────────────────────────────────╮
│ /home/nporter/SD/automatic/extensions/_unprompted/scripts/unprompted.py:739 in process_batch │
│ │
│ 738 │ │ │ │ │ │ Unprompted.log.debug("Attempting to deactivate extra networks... │
│ ❱ 739 │ │ │ │ │ │ extra_networks.deactivate(p, p.extra_network_data) │
│ 740 │ │ │ │ │ │ #extra_networks.deactivate(p) │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
AttributeError: 'StableDiffusionProcessingTxt2Img' object has no attribute 'extra_network_data'
During handling of the above exception, another exception occurred:
╭─────────────────────────────────────────────────────────────────── Traceback (most recent call last) ───────────────────────────────────────────────────────────────────╮
│ /home/nporter/SD/automatic/modules/scripts.py:451 in process_batch │
│ │
│ 450 │ │ │ │ args = p.per_script_args.get(script.title(), p.script_args[script.args_f │
│ ❱ 451 │ │ │ │ script.process_batch(p, *args, **kwargs) │
│ 452 │ │ │ │ s.append(f'{script.title()}:{round(time.time()-t0, 2)}s') │
│ │
│ /home/nporter/SD/automatic/extensions/_unprompted/scripts/unprompted.py:742 in process_batch │
│ │
│ 741 │ │ │ │ │ except Exception as e: │
│ ❱ 742 │ │ │ │ │ │ self.log.exception("Exception while deactiating extra networks") │
│ 743 │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
AttributeError: 'Scripts' object has no attribute 'log'
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:06<00:00, 7.40it/s]
`
Thanks, @porternw.
It sounds like this issue relates to SD.Next specifically, and judging from the error log, you're on the right track with the extra_network_data
variable.
Removing the reference on line 739 may prevent loras from behaving correctly in a batch process, but it should circumvent the error message. I would try disabling it like this:
if "extra_network_data" in p: extra_networks.deactivate(p, p.extra_network_data)
Can you confirm that this at least prevents the crash?
There's another section of code later on--line 793--which is responsible for updating lora networks after processing each prompt in a batch run. It uses the extra_networks.py
module in A1111.
Ultimately, both references to extra_network_data
will likely need to be replaced with the equivalent object name in SD.Next. I will dig into their codebase if I find the chance, but WebUI forks are not officially supported by Unprompted as they become increasingly distinct over time.
Still errors with changing that line.
12:33:37-380792 ERROR Running script process batch: /home/nporter/SD/automatic/extensions/_unprompted/scripts/unprompted.py: AttributeError
╭─────────────────────────────────────────────────────────────────── Traceback (most recent call last) ───────────────────────────────────────────────────────────────────╮
│ /home/nporter/SD/automatic/extensions/_unprompted/scripts/unprompted.py:739 in process_batch │
│ │
│ 738 │ │ │ │ │ │ Unprompted.log.debug("Attempting to deactivate extra networks... │
│ ❱ 739 │ │ │ │ │ │ if "extra_network_data" in p: extra_networks.deactivate(p, p.ext │
│ 740 │ │ │ │ │ except Exception as e: │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
TypeError: argument of type 'StableDiffusionProcessingImg2Img' is not iterable
Thanks for looking into this!