Skip to content

Commit d100f69

Browse files
committed
Fix inversion prompt broadcasting
1 parent 473f55c commit d100f69

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -730,10 +730,14 @@ def prepare_image_latents(self, image, batch_size, dtype, device, generator=None
730730

731731
init_latents = self.vae.config.scaling_factor * init_latents
732732

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-
)
733+
if batch_size > init_latents.shape[0]:
734+
if batch_size % init_latents.shape[0] == 0:
735+
additional_init_latents_per_image = batch_size // init_latents.shape[0]
736+
init_latents = torch.cat([init_latents] * additional_init_latents_per_image, dim=0)
737+
else:
738+
raise ValueError(
739+
f"Cannot duplicate `image` of batch size {init_latents.shape[0]} to {batch_size} text prompts."
740+
)
737741
else:
738742
init_latents = torch.cat([init_latents], dim=0)
739743

0 commit comments

Comments
 (0)