Skip to content

Commit 135c390

Browse files
committed
Clean changes to other pipelines
1 parent c0e5413 commit 135c390

File tree

2 files changed

+15
-25
lines changed

2 files changed

+15
-25
lines changed

src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_diffedit.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,6 @@ def prepare_latents(self, batch_size, num_channels_latents, height, width, dtype
771771
latents = latents * self.scheduler.init_noise_sigma
772772
return latents
773773

774-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_pix2pix_zero.StableDiffusionPix2PixZeroPipeline.prepare_image_latents
775774
def prepare_image_latents(self, image, batch_size, dtype, device, generator=None):
776775
if not isinstance(image, (torch.Tensor, PIL.Image.Image, list)):
777776
raise ValueError(

src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
from ...utils import (
3737
PIL_INTERPOLATION,
3838
BaseOutput,
39-
deprecate,
4039
is_accelerate_available,
4140
is_accelerate_version,
4241
logging,
@@ -722,31 +721,23 @@ def prepare_image_latents(self, image, batch_size, dtype, device, generator=None
722721
)
723722

724723
if isinstance(generator, list):
725-
latents = [self.vae.encode(image[i : i + 1]).latent_dist.sample(generator[i]) for i in range(batch_size)]
726-
latents = torch.cat(latents, dim=0)
724+
init_latents = [
725+
self.vae.encode(image[i : i + 1]).latent_dist.sample(generator[i]) for i in range(batch_size)
726+
]
727+
init_latents = torch.cat(init_latents, dim=0)
727728
else:
728-
latents = self.vae.encode(image).latent_dist.sample(generator)
729-
730-
latents = self.vae.config.scaling_factor * latents
731-
732-
if batch_size != latents.shape[0]:
733-
if batch_size % latents.shape[0] == 0:
734-
# expand image_latents for batch_size
735-
deprecation_message = (
736-
f"You have passed {batch_size} text prompts (`prompt`), but only {latents.shape[0]} initial"
737-
" images (`image`). Initial images are now duplicating to match the number of text prompts. Note"
738-
" that this behavior is deprecated and will be removed in a version 1.0.0. Please make sure to update"
739-
" your script to pass as many initial images as text prompts to suppress this warning."
740-
)
741-
deprecate("len(prompt) != len(image)", "1.0.0", deprecation_message, standard_warn=False)
742-
additional_latents_per_image = batch_size // latents.shape[0]
743-
latents = torch.cat([latents] * additional_latents_per_image, dim=0)
744-
else:
745-
raise ValueError(
746-
f"Cannot duplicate `image` of batch size {latents.shape[0]} to {batch_size} text prompts."
747-
)
729+
init_latents = self.vae.encode(image).latent_dist.sample(generator)
730+
731+
init_latents = self.vae.config.scaling_factor * init_latents
732+
733+
if batch_size > init_latents.shape[0] and batch_size % init_latents.shape[0] != 0:
734+
raise ValueError(
735+
f"Cannot duplicate `image` of batch size {init_latents.shape[0]} to {batch_size} text prompts."
736+
)
748737
else:
749-
latents = torch.cat([latents], dim=0)
738+
init_latents = torch.cat([init_latents], dim=0)
739+
740+
latents = init_latents
750741

751742
return latents
752743

0 commit comments

Comments
 (0)