Skip to content

Commit 9d50f7e

Browse files
sayakpaulyiyixuxuDN6
authored
[Core] is_cosxl_edit arg in SDXL ip2p. (#7650)
* is_cosxl_edit arg in SDXL ip2p. * Empty-Commit Co-authored-by: Yiyi Xu <[email protected]> * doc * remove redundant logic. * reflect drhuv's comments. --------- Co-authored-by: Yiyi Xu <[email protected]> Co-authored-by: Dhruv Nair <[email protected]>
1 parent fda1531 commit 9d50f7e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Diff for: src/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_instruct_pix2pix.py

+7
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ class StableDiffusionXLInstructPix2PixPipeline(
169169
Whether to use the [invisible_watermark library](https://github.com/ShieldMnt/invisible-watermark/) to
170170
watermark output images. If not defined, it will default to True if the package is installed, otherwise no
171171
watermarker will be used.
172+
is_cosxl_edit (`bool`, *optional*):
173+
When set the image latents are scaled.
172174
"""
173175

174176
model_cpu_offload_seq = "text_encoder->text_encoder_2->unet->vae"
@@ -185,6 +187,7 @@ def __init__(
185187
scheduler: KarrasDiffusionSchedulers,
186188
force_zeros_for_empty_prompt: bool = True,
187189
add_watermarker: Optional[bool] = None,
190+
is_cosxl_edit: Optional[bool] = False,
188191
):
189192
super().__init__()
190193

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

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

@@ -551,6 +555,9 @@ def prepare_image_latents(
551555
if image_latents.dtype != self.vae.dtype:
552556
image_latents = image_latents.to(dtype=self.vae.dtype)
553557

558+
if self.is_cosxl_edit:
559+
image_latents = image_latents * self.vae.config.scaling_factor
560+
554561
return image_latents
555562

556563
# Copied from diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl.StableDiffusionXLPipeline._get_add_time_ids

0 commit comments

Comments
 (0)