Skip to content

Commit 7ce3fa0

Browse files
authored
Fix TypeError when using prompt_embeds and negative_prompt (#2982)
* test: Added test case * fix: fixed type checking issue on _encode_prompt * fix: fixed copies consistency * fix: one copy was not sufficient
1 parent abd86d1 commit 7ce3fa0

20 files changed

+58
-19
lines changed

src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ def _encode_prompt(
369369
uncond_tokens: List[str]
370370
if negative_prompt is None:
371371
uncond_tokens = [""] * batch_size
372-
elif type(prompt) is not type(negative_prompt):
372+
elif prompt is not None and type(prompt) is not type(negative_prompt):
373373
raise TypeError(
374374
f"`negative_prompt` should be the same type to `prompt`, but got {type(negative_prompt)} !="
375375
f" {type(prompt)}."

src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def _encode_prompt(
378378
uncond_tokens: List[str]
379379
if negative_prompt is None:
380380
uncond_tokens = [""] * batch_size
381-
elif type(prompt) is not type(negative_prompt):
381+
elif prompt is not None and type(prompt) is not type(negative_prompt):
382382
raise TypeError(
383383
f"`negative_prompt` should be the same type to `prompt`, but got {type(negative_prompt)} !="
384384
f" {type(prompt)}."

src/diffusers/pipelines/stable_diffusion/pipeline_cycle_diffusion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ def _encode_prompt(
387387
uncond_tokens: List[str]
388388
if negative_prompt is None:
389389
uncond_tokens = [""] * batch_size
390-
elif type(prompt) is not type(negative_prompt):
390+
elif prompt is not None and type(prompt) is not type(negative_prompt):
391391
raise TypeError(
392392
f"`negative_prompt` should be the same type to `prompt`, but got {type(negative_prompt)} !="
393393
f" {type(prompt)}."

src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def _encode_prompt(
372372
uncond_tokens: List[str]
373373
if negative_prompt is None:
374374
uncond_tokens = [""] * batch_size
375-
elif type(prompt) is not type(negative_prompt):
375+
elif prompt is not None and type(prompt) is not type(negative_prompt):
376376
raise TypeError(
377377
f"`negative_prompt` should be the same type to `prompt`, but got {type(negative_prompt)} !="
378378
f" {type(prompt)}."

src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_attend_and_excite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def _encode_prompt(
384384
uncond_tokens: List[str]
385385
if negative_prompt is None:
386386
uncond_tokens = [""] * batch_size
387-
elif type(prompt) is not type(negative_prompt):
387+
elif prompt is not None and type(prompt) is not type(negative_prompt):
388388
raise TypeError(
389389
f"`negative_prompt` should be the same type to `prompt`, but got {type(negative_prompt)} !="
390390
f" {type(prompt)}."

src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_controlnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ def _encode_prompt(
427427
uncond_tokens: List[str]
428428
if negative_prompt is None:
429429
uncond_tokens = [""] * batch_size
430-
elif type(prompt) is not type(negative_prompt):
430+
elif prompt is not None and type(prompt) is not type(negative_prompt):
431431
raise TypeError(
432432
f"`negative_prompt` should be the same type to `prompt`, but got {type(negative_prompt)} !="
433433
f" {type(prompt)}."

src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def _encode_prompt(
256256
uncond_tokens: List[str]
257257
if negative_prompt is None:
258258
uncond_tokens = [""] * batch_size
259-
elif type(prompt) is not type(negative_prompt):
259+
elif prompt is not None and type(prompt) is not type(negative_prompt):
260260
raise TypeError(
261261
f"`negative_prompt` should be the same type to `prompt`, but got {type(negative_prompt)} !="
262262
f" {type(prompt)}."

src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def _encode_prompt(
385385
uncond_tokens: List[str]
386386
if negative_prompt is None:
387387
uncond_tokens = [""] * batch_size
388-
elif type(prompt) is not type(negative_prompt):
388+
elif prompt is not None and type(prompt) is not type(negative_prompt):
389389
raise TypeError(
390390
f"`negative_prompt` should be the same type to `prompt`, but got {type(negative_prompt)} !="
391391
f" {type(prompt)}."

src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ def _encode_prompt(
437437
uncond_tokens: List[str]
438438
if negative_prompt is None:
439439
uncond_tokens = [""] * batch_size
440-
elif type(prompt) is not type(negative_prompt):
440+
elif prompt is not None and type(prompt) is not type(negative_prompt):
441441
raise TypeError(
442442
f"`negative_prompt` should be the same type to `prompt`, but got {type(negative_prompt)} !="
443443
f" {type(prompt)}."

src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint_legacy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ def _encode_prompt(
376376
uncond_tokens: List[str]
377377
if negative_prompt is None:
378378
uncond_tokens = [""] * batch_size
379-
elif type(prompt) is not type(negative_prompt):
379+
elif prompt is not None and type(prompt) is not type(negative_prompt):
380380
raise TypeError(
381381
f"`negative_prompt` should be the same type to `prompt`, but got {type(negative_prompt)} !="
382382
f" {type(prompt)}."

0 commit comments

Comments
 (0)