Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] is_cosxl_edit arg in SDXL ip2p. #7650

Merged
merged 9 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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/loaders/single_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def from_single_file(cls, pretrained_model_link_or_path, **kwargs):
local_files_only = kwargs.pop("local_files_only", False)
revision = kwargs.pop("revision", None)
torch_dtype = kwargs.pop("torch_dtype", None)
is_cosxl_edit = kwargs.pop("is_cosxl_edit", None)
sayakpaul marked this conversation as resolved.
Show resolved Hide resolved

class_name = cls.__name__

Expand Down Expand Up @@ -309,7 +310,7 @@ def from_single_file(cls, pretrained_model_link_or_path, **kwargs):
init_kwargs.update(components)

additional_components = set_additional_components(
class_name, original_config, checkpoint=checkpoint, model_type=model_type
class_name, original_config, checkpoint=checkpoint, model_type=model_type, is_cosxl_edit=is_cosxl_edit
sayakpaul marked this conversation as resolved.
Show resolved Hide resolved
)
if additional_components:
init_kwargs.update(additional_components)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ class StableDiffusionXLInstructPix2PixPipeline(
Whether to use the [invisible_watermark library](https://github.com/ShieldMnt/invisible-watermark/) to
watermark output images. If not defined, it will default to True if the package is installed, otherwise no
watermarker will be used.
is_cosxl_edit (`bool`, *optional*):
When set the image latents are scaled.
"""

model_cpu_offload_seq = "text_encoder->text_encoder_2->unet->vae"
Expand All @@ -185,6 +187,7 @@ def __init__(
scheduler: KarrasDiffusionSchedulers,
force_zeros_for_empty_prompt: bool = True,
add_watermarker: Optional[bool] = None,
is_cosxl_edit: Optional[bool] = False,
):
super().__init__()

Expand All @@ -201,6 +204,7 @@ def __init__(
self.vae_scale_factor = 2 ** (len(self.vae.config.block_out_channels) - 1)
self.image_processor = VaeImageProcessor(vae_scale_factor=self.vae_scale_factor)
self.default_sample_size = self.unet.config.sample_size
self.is_cosxl_edit = is_cosxl_edit

add_watermarker = add_watermarker if add_watermarker is not None else is_invisible_watermark_available()

Expand Down Expand Up @@ -551,6 +555,9 @@ def prepare_image_latents(
if image_latents.dtype != self.vae.dtype:
image_latents = image_latents.to(dtype=self.vae.dtype)

if self.is_cosxl_edit:
image_latents = image_latents * self.vae.config.scaling_factor

return image_latents

# Copied from diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl.StableDiffusionXLPipeline._get_add_time_ids
Expand Down
Loading