Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/diffusers/pipelines/auto_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,8 @@ def from_pretrained(cls, pretrained_model_or_path, **kwargs):
if "enable_pag" in kwargs:
enable_pag = kwargs.pop("enable_pag")
if enable_pag:
orig_class_name = config["_class_name"].replace("Pipeline", "PAGPipeline")
to_replace = "InpaintPipeline" if "Inpaint" in config["_class_name"] else "Pipeline"
orig_class_name = config["_class_name"].replace(to_replace, "PAG" + to_replace)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we do this, the orig_class_name for StableDiffusionXLPipeline would be StableDiffusionXLPAGInpaintPipeline too - in this case will get the correct result regardless but logic is incorrect

the orig_class_name for StableDiffusionXLPipeline should be StableDiffusionXLPAGPipeline and then we map it to the corresponding to the inpainting class through _get_task_class(...) and get StableDiffusionXLPAGInpaintPipeline

we can maybe do something like

to_replace = "InpaintPipeline" if "Inpaint` in config["_class_name"] else "Pipeline"
orig_class_name = config["_class_name"].replace(to_replace, "PAG" + to_replace)

Nice code. I have appied it and verified that it works well


inpainting_cls = _get_task_class(AUTO_INPAINT_PIPELINES_MAPPING, orig_class_name)

Expand Down
14 changes: 11 additions & 3 deletions src/diffusers/pipelines/pag/pipeline_pag_sd_xl_inpaint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,14 @@ def denoising_value_valid(dnv):
generator,
self.do_classifier_free_guidance,
)
if self.do_perturbed_attention_guidance:
if self.do_classifier_free_guidance:
mask, _ = mask.chunk(2)
masked_image_latents, _ = masked_image_latents.chunk(2)
mask = self._prepare_perturbed_attention_guidance(mask, mask, self.do_classifier_free_guidance)
masked_image_latents = self._prepare_perturbed_attention_guidance(
masked_image_latents, masked_image_latents, self.do_classifier_free_guidance
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to handle batch size without modifying the prepare_mask_latents function.


# 8. Check that sizes of mask, masked image and latents match
if num_channels_unet == 9:
Expand Down Expand Up @@ -1659,10 +1667,10 @@ def denoising_value_valid(dnv):

if num_channels_unet == 4:
init_latents_proper = image_latents
if self.do_classifier_free_guidance:
init_mask, _ = mask.chunk(2)
if self.do_perturbed_attention_guidance:
init_mask, *_ = mask.chunk(3) if self.do_classifier_free_guidance else mask.chunk(2)
else:
init_mask = mask
init_mask, *_ = mask.chunk(2) if self.do_classifier_free_guidance else mask

if i < len(timesteps) - 1:
noise_timestep = timesteps[i + 1]
Expand Down