Skip to content

Commit faa6cbc

Browse files
authored
Fix repeat of negative prompt (huggingface#4335)
fix repeat of negative prompt
1 parent 306a7bd commit faa6cbc

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/diffusers/pipelines/semantic_stable_diffusion/pipeline_semantic_stable_diffusion.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ def __call__(
442442
if do_classifier_free_guidance:
443443
uncond_tokens: List[str]
444444
if negative_prompt is None:
445-
uncond_tokens = [""]
445+
uncond_tokens = [""] * batch_size
446446
elif type(prompt) is not type(negative_prompt):
447447
raise TypeError(
448448
f"`negative_prompt` should be the same type to `prompt`, but got {type(negative_prompt)} !="
@@ -471,7 +471,7 @@ def __call__(
471471

472472
# duplicate unconditional embeddings for each generation per prompt, using mps friendly method
473473
seq_len = uncond_embeddings.shape[1]
474-
uncond_embeddings = uncond_embeddings.repeat(batch_size, num_images_per_prompt, 1)
474+
uncond_embeddings = uncond_embeddings.repeat(1, num_images_per_prompt, 1)
475475
uncond_embeddings = uncond_embeddings.view(batch_size * num_images_per_prompt, seq_len, -1)
476476

477477
# For classifier free guidance, we need to do two forward passes.

0 commit comments

Comments
 (0)