Skip to content

Commit

Permalink
sd3 skip_layer_guidance fix from upstream for num images per prompt > 1
Browse files Browse the repository at this point in the history
  • Loading branch information
bghira committed Dec 2, 2024
1 parent c98d0f7 commit 8719e73
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion helpers/models/sd3/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,11 +999,14 @@ def __call__(
continue

# expand the latents if we are doing classifier free guidance
# added fix from: https://github.com/huggingface/diffusers/pull/10086/files
# to allow for num_images_per_prompt > 1
latent_model_input = (
torch.cat([latents] * 2)
if self.do_classifier_free_guidance and skip_guidance_layers is None
if self.do_classifier_free_guidance
else latents
)

# broadcast to batch dimension in a way that's compatible with ONNX/Core ML
timestep = t.expand(latent_model_input.shape[0])

Expand Down Expand Up @@ -1033,6 +1036,8 @@ def __call__(
else False
)
if skip_guidance_layers is not None and should_skip_layers:
timestep = t.expand(latents.shape[0])
latent_model_input = latents
noise_pred_skip_layers = self.transformer(
hidden_states=latent_model_input.to(
device=self.transformer.device,
Expand Down

0 comments on commit 8719e73

Please sign in to comment.