From fb4638288b33f7aa47fd1f57ee60c15e3d24e038 Mon Sep 17 00:00:00 2001 From: AI-Casanova <54461896+AI-Casanova@users.noreply.github.com> Date: Fri, 8 Nov 2024 23:31:52 -0600 Subject: [PATCH] fix IndexError, change callback type --- modules/processing_callbacks.py | 2 +- modules/prompt_parser_diffusers.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/processing_callbacks.py b/modules/processing_callbacks.py index 59887c5c4..9e3c0cd31 100644 --- a/modules/processing_callbacks.py +++ b/modules/processing_callbacks.py @@ -73,7 +73,7 @@ def diffusers_callback(pipe, step: int = 0, timestep: int = 0, kwargs: dict = {} if 'negative_prompt_embeds' in kwargs: kwargs["negative_prompt_embeds"] = prompt_parser_diffusers.embedder("negative_prompt_embeds", step + 1) except Exception as e: - shared.log.debug(f"Callback: {e}") + debug_callback(f"Callback: {e}") if step == int(getattr(pipe, 'num_timesteps', 100) * p.cfg_end) and 'prompt_embeds' in kwargs and 'negative_prompt_embeds' in kwargs: if "PAG" in shared.sd_model.__class__.__name__: pipe._guidance_scale = 1.001 if pipe._guidance_scale > 1 else pipe._guidance_scale # pylint: disable=protected-access diff --git a/modules/prompt_parser_diffusers.py b/modules/prompt_parser_diffusers.py index eec6b0d32..907cc7208 100644 --- a/modules/prompt_parser_diffusers.py +++ b/modules/prompt_parser_diffusers.py @@ -172,11 +172,12 @@ class PromptEmbedder: for i in range(self.batchsize): if len(batch[i]) == 0: # if not using prompt-scheduling, this will be len(batch[i])==1 return None - else: - # causes error in callback + try: res.append(batch[i][step]) # and this requests element for specific step when called from callback - but self.scheduled_prompt==False so len(batch[i])==1 and step is list index out-of-bounds! - if step != 0: # For Callback - res.append(batch[i][step]) # Diffusers internally doubles batch dimension + except IndexError: + res.append(batch[i][0]) + if step != 0: # For Callback + res.append(res[-1]) # Diffusers internally doubles batch dimension return torch.cat(res)