muerrilla / stable-diffusion-NPW

Negative Prompt Weight: Extension for Stable Diffusion Web UI
The Unlicense
112 stars 10 forks source link

Error executing callback when switching models #13

Closed 413-xx closed 3 weeks ago

413-xx commented 3 weeks ago

So I’ve run into what may be a bit of an odd edge case..

I often switch between various SDXL and SD1.5 models, either as part of hires.fix or adetailer.

If I run the first pass with an SDXL model and the hires.fix pass with an SD1.5 model, NPW runs for the first pass but then errors out during the hires pass, giving the following on each step:

*** Error executing callback cfg_denoiser_callback for /content/gdrive/MyDrive/sd/stable-diffusion-webui/extensions/stable-diffusion-NPW/scripts/npw.py
    Traceback (most recent call last):
      File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/script_callbacks.py", line 333, in cfg_denoiser_callback
        c.callback(params)
      File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/extensions/stable-diffusion-NPW/scripts/npw.py", line 111, in denoiser_callback
        params.text_uncond = concat_and_lerp(empty_uncond, uncond, self.weight)
      File "/content/gdrive/MyDrive/sd/stable-
diffusion-webui/extensions/stable-diffusion-NPW/scripts/npw.py", line 88, in concat_and_lerp
        if empty.shape[0] != tensor.shape[0]:
    AttributeError: 'dict' object has no attribute 'shape'

For what it’s worth, I’m not using latent upscale (if that makes any difference) for hires.fix.

It gets a bit interesting looking at the behavior with adetailer. If I run batch count = 1 with an SDXL model for main generation then an SD1.5 model for adetailer inpainting. NPW runs on both the main SDXL pass and the adetailer SD1.5 pass. I was a bit surprised by this as I kind of expected it to throw the same error as hires.fix.

However, if I set a batch count > 1, the following happens:

The error it throws on the SDXL passes is:

 *** Error executing callback cfg_denoiser_callback for /content/gdrive/MyDrive/sd/stable-diffusion-webui/extensions/stable-diffusion-NPW/scripts/npw.py
    Traceback (most recent call last):
      File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/modules/script_callbacks.py", line 333, in cfg_denoiser_callback
        c.callback(params)
      File "/content/gdrive/MyDrive/sd/stable-diffusion-webui/extensions/stable-diffusion-NPW/scripts/npw.py", line 107, in denoiser_callback
        empty_uncond, empty_cross = empty_uncond['vector'], empty_uncond['crossattn']
    IndexError: too many indices for tensor of dimension 3

I assume it’s a different error because the hires.fix case is erroring out on the SD1.5 passes, while the adetailer case is erroring out on the SDXL passes.

What I don’t understand is why it runs fine with SDXL primary gen + SD1.5 adetailer for batch count = 1. It’s like NPW is resetting for the swap from SDXL to SD1.5 when adetailer starts, but not resetting for the swap back to SDXL?

Again I realize it’s probably an edge case but thought I would share in case there happens to be a simple fix. FWIW this extension has been extremely useful. Thanks!

muerrilla commented 3 weeks ago

Hey there. Thanks for the thorough report. I fixed the first issue (hires fix). I haven't used Adetailer and don't know how it works. So I'll have to look into it when I have some free time, but not making any promises!

Please update and let me know if the Adetailer issue still persist though. Cheers.

413-xx commented 3 weeks ago

Well that was quick! Just tested, the update appears to have resolved both issues (hires.fix and adetailer). Thanks!

muerrilla commented 3 weeks ago

Cool. No problem.