Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/diffusers/models/controlnets/controlnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ def forward(
aug_emb = self.add_embedding(encoder_hidden_states)

elif self.config.addition_embed_type == "text_time":
if "text_embeds" not in added_cond_kwargs:
if added_cond_kwargs is None or "text_embeds" not in added_cond_kwargs:
raise ValueError(
f"{self.__class__} has the config param `addition_embed_type` set to 'text_time' which requires the keyword argument `text_embeds` to be passed in `added_cond_kwargs`"
)
Expand Down
2 changes: 1 addition & 1 deletion src/diffusers/models/controlnets/controlnet_union.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ def forward(
aug_emb = self.add_embedding(encoder_hidden_states)

elif self.config.addition_embed_type == "text_time":
if "text_embeds" not in added_cond_kwargs:
if added_cond_kwargs is None or "text_embeds" not in added_cond_kwargs:
raise ValueError(
f"{self.__class__} has the config param `addition_embed_type` set to 'text_time' which requires the keyword argument `text_embeds` to be passed in `added_cond_kwargs`"
)
Expand Down
2 changes: 1 addition & 1 deletion src/diffusers/models/controlnets/controlnet_xs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ def forward(
pass
elif self.config.addition_embed_type == "text_time":
# SDXL - style
if "text_embeds" not in added_cond_kwargs:
if added_cond_kwargs is None or "text_embeds" not in added_cond_kwargs:
raise ValueError(
f"{self.__class__} has the config param `addition_embed_type` set to 'text_time' which requires the keyword argument `text_embeds` to be passed in `added_cond_kwargs`"
)
Expand Down
2 changes: 1 addition & 1 deletion src/diffusers/models/unets/unet_2d_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ def get_aug_embed(
aug_emb = self.add_embedding(text_embs, image_embs)
elif self.config.addition_embed_type == "text_time":
# SDXL - style
if "text_embeds" not in added_cond_kwargs:
if added_cond_kwargs is None or "text_embeds" not in added_cond_kwargs:
raise ValueError(
f"{self.__class__} has the config param `addition_embed_type` set to 'text_time' which requires the keyword argument `text_embeds` to be passed in `added_cond_kwargs`"
)
Expand Down
2 changes: 1 addition & 1 deletion src/diffusers/models/unets/unet_motion_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1974,7 +1974,7 @@ def forward(
aug_emb = None

if self.config.addition_embed_type == "text_time":
if "text_embeds" not in added_cond_kwargs:
if added_cond_kwargs is None or "text_embeds" not in added_cond_kwargs:
raise ValueError(
f"{self.__class__} has the config param `addition_embed_type` set to 'text_time' which requires the keyword argument `text_embeds` to be passed in `added_cond_kwargs`"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ def __init__(
" checker. If you do not want to use the safety checker, you can pass `'safety_checker=None'` instead."
)

if unet is not None and getattr(unet.config, "addition_embed_type", None) == "text_time":
raise ValueError(
f"{self.__class__.__name__} does not support SDXL UNets (`addition_embed_type='text_time'`)."
" Use `StableDiffusionXLPipeline` instead."
)

is_unet_version_less_0_9_0 = (
unet is not None
and hasattr(unet.config, "_diffusers_version")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,12 @@ def __init__(
" checker. If you do not want to use the safety checker, you can pass `'safety_checker=None'` instead."
)

if unet is not None and getattr(unet.config, "addition_embed_type", None) == "text_time":
raise ValueError(
f"{self.__class__.__name__} does not support SDXL UNets (`addition_embed_type='text_time'`)."
" Use `StableDiffusionXLImg2ImgPipeline` instead."
)

is_unet_version_less_0_9_0 = (
unet is not None
and hasattr(unet.config, "_diffusers_version")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ def __init__(
" checker. If you do not want to use the safety checker, you can pass `'safety_checker=None'` instead."
)

if unet is not None and getattr(unet.config, "addition_embed_type", None) == "text_time":
raise ValueError(
f"{self.__class__.__name__} does not support SDXL UNets (`addition_embed_type='text_time'`)."
" Use `StableDiffusionXLInpaintPipeline` instead."
)

is_unet_version_less_0_9_0 = (
unet is not None
and hasattr(unet.config, "_diffusers_version")
Expand Down
11 changes: 11 additions & 0 deletions tests/models/unets/test_models_unet_2d_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import unittest
from collections import OrderedDict

import pytest
import torch
from huggingface_hub import snapshot_download
from parameterized import parameterized
Expand Down Expand Up @@ -580,6 +581,16 @@ def test_asymmetrical_unet(self):
# Check if input and output shapes are the same
assert output.shape == expected_shape, "Input and output shapes do not match"

def test_text_time_without_added_cond_kwargs(self):
init_dict = self.get_init_dict()
init_dict.update(
addition_embed_type="text_time", addition_time_embed_dim=8, projection_class_embeddings_input_dim=56
)
model = self.model_class(**init_dict).to(torch_device)

with pytest.raises(ValueError, match="text_embeds"):
model(**self.get_dummy_inputs())


class TestUNet2DConditionHubLoading(UNet2DConditionTesterConfig):
"""Hub checkpoint loading tests for UNet2DConditionModel."""
Expand Down
20 changes: 20 additions & 0 deletions tests/pipelines/stable_diffusion/test_stable_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,26 @@ def get_dummy_inputs(self):


class TestStableDiffusionPipeline(StableDiffusionPipelineTesterConfig, PipelineTesterMixin):
def test_rejects_sdxl_unet(self):
components = self.get_dummy_components()
components["unet"] = UNet2DConditionModel(
block_out_channels=(4, 8),
layers_per_block=1,
sample_size=32,
in_channels=4,
out_channels=4,
down_block_types=("DownBlock2D", "CrossAttnDownBlock2D"),
up_block_types=("CrossAttnUpBlock2D", "UpBlock2D"),
cross_attention_dim=8,
norm_num_groups=2,
addition_embed_type="text_time",
addition_time_embed_dim=8,
projection_class_embeddings_input_dim=56,
)

with pytest.raises(ValueError, match="does not support SDXL UNets"):
self.pipeline_class(**components)

def test_stable_diffusion_ddim(self):
# Run on CPU: the expected slice below is CPU-specific.
sd_pipe = self.get_pipeline()
Expand Down
19 changes: 19 additions & 0 deletions tests/pipelines/stable_diffusion/test_stable_diffusion_img2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,25 @@ def get_dummy_inputs(self):


class TestStableDiffusionImg2ImgPipeline(StableDiffusionImg2ImgPipelineTesterConfig, PipelineTesterMixin):
def test_rejects_sdxl_unet(self):
components = self.get_dummy_components()
components["unet"] = UNet2DConditionModel(
block_out_channels=(32, 64),
layers_per_block=2,
sample_size=32,
in_channels=4,
out_channels=4,
down_block_types=("DownBlock2D", "CrossAttnDownBlock2D"),
up_block_types=("CrossAttnUpBlock2D", "UpBlock2D"),
cross_attention_dim=32,
addition_embed_type="text_time",
addition_time_embed_dim=8,
projection_class_embeddings_input_dim=80,
)

with pytest.raises(ValueError, match="does not support SDXL UNets"):
self.pipeline_class(**components)

def test_stable_diffusion_img2img_default_case(self):
# Run on CPU: the expected slice below is CPU-specific.
sd_pipe = self.get_pipeline()
Expand Down
19 changes: 19 additions & 0 deletions tests/pipelines/stable_diffusion/test_stable_diffusion_inpaint.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,25 @@ def get_dummy_tensor_inputs(self, img_res=64):


class TestStableDiffusionInpaintPipeline(StableDiffusionInpaintPipelineTesterConfig, PipelineTesterMixin):
def test_rejects_sdxl_unet(self):
components = self.get_dummy_components()
components["unet"] = UNet2DConditionModel(
block_out_channels=(32, 64),
layers_per_block=2,
sample_size=32,
in_channels=9,
out_channels=4,
down_block_types=("DownBlock2D", "CrossAttnDownBlock2D"),
up_block_types=("CrossAttnUpBlock2D", "UpBlock2D"),
cross_attention_dim=32,
addition_embed_type="text_time",
addition_time_embed_dim=8,
projection_class_embeddings_input_dim=80,
)

with pytest.raises(ValueError, match="does not support SDXL UNets"):
self.pipeline_class(**components)

def test_stable_diffusion_inpaint(self):
# Run on CPU: the expected slice below is CPU-specific.
sd_pipe = self.get_pipeline()
Expand Down