


_lowercase       :      Optional[Any]	=	frozenset(
    [
        "prompt",
        "height",
        "width",
        "guidance_scale",
        "negative_prompt",
        "prompt_embeds",
        "negative_prompt_embeds",
        "cross_attention_kwargs",
    ]
)

_lowercase       :      str	=	frozenset(["prompt", "negative_prompt"])

_lowercase       :      Union[str, Any]	=	frozenset([])

_lowercase       :      Optional[int]	=	frozenset(["image"])

_lowercase       :      Dict	=	frozenset(
    [
        "image",
        "height",
        "width",
        "guidance_scale",
    ]
)

_lowercase       :      List[Any]	=	frozenset(["image"])

_lowercase       :      str	=	frozenset(
    [
        "prompt",
        "image",
        "height",
        "width",
        "guidance_scale",
        "negative_prompt",
        "prompt_embeds",
        "negative_prompt_embeds",
    ]
)

_lowercase       :      List[str]	=	frozenset(["prompt", "image", "negative_prompt"])

_lowercase       :      Optional[Any]	=	frozenset(
    [
        # Text guided image variation with an image mask
        "prompt",
        "image",
        "mask_image",
        "height",
        "width",
        "guidance_scale",
        "negative_prompt",
        "prompt_embeds",
        "negative_prompt_embeds",
    ]
)

_lowercase       :      Dict	=	frozenset(["prompt", "image", "mask_image", "negative_prompt"])

_lowercase       :      List[str]	=	frozenset(
    [
        # image variation with an image mask
        "image",
        "mask_image",
        "height",
        "width",
        "guidance_scale",
    ]
)

_lowercase       :      Tuple	=	frozenset(["image", "mask_image"])

_lowercase       :      Optional[int]	=	frozenset(
    [
        "example_image",
        "image",
        "mask_image",
        "height",
        "width",
        "guidance_scale",
    ]
)

_lowercase       :      List[str]	=	frozenset(["example_image", "image", "mask_image"])

_lowercase       :      str	=	frozenset(["class_labels"])

_lowercase       :      Optional[Any]	=	frozenset(["class_labels"])

_lowercase       :      List[Any]	=	frozenset(["batch_size"])

_lowercase       :      List[str]	=	frozenset([])

_lowercase       :      Union[str, Any]	=	frozenset(["batch_size"])

_lowercase       :      Optional[int]	=	frozenset([])

_lowercase       :      str	=	frozenset(
    [
        "prompt",
        "audio_length_in_s",
        "guidance_scale",
        "negative_prompt",
        "prompt_embeds",
        "negative_prompt_embeds",
        "cross_attention_kwargs",
    ]
)

_lowercase       :      int	=	frozenset(["prompt", "negative_prompt"])
_lowercase       :      Dict	=	frozenset(["input_tokens"])

_lowercase       :      str	=	frozenset(["input_tokens"])







import unittest
from typing import Tuple

import torch

from diffusers.utils import floats_tensor, randn_tensor, torch_all_close, torch_device
from diffusers.utils.testing_utils import require_torch






@require_torch
class       _UpperCamelCase    :

				"""simple docstring"""







				@property
				def      _UpperCAmelCase					(						self   )	->				Any:
					return self.get_dummy_input()

				@property
				def      _UpperCAmelCase					(						self   )	->				Union[str, Any]:
					if self.block_type == "down":
						return (4, 32, 16, 16)
					elif self.block_type == "mid":
						return (4, 32, 32, 32)
					elif self.block_type == "up":
						return (4, 32, 64, 64)

					raise ValueError(f'\'{self.block_type}\' is not a supported block_type. Set it to \'up\', \'mid\', or \'down\'.'   )

				def      _UpperCAmelCase					(						self				,   a__=True				,   a__=False				,   a__=False				,   a__=False				,   )	->				Optional[Any]:
					A								=				4
					A								=				32
					A								=				(32, 32)

					A								=				torch.manual_seed(0   )
					A								=				torch.device(a__   )
					A								=				(batch_size, num_channels) + sizes
					A								=				randn_tensor(a__				,   generator=a__				,   device=a__   )
					A								=				{"""hidden_states""": hidden_states}

					if include_temb:
						A								=				128
						A								=				randn_tensor((batch_size, temb_channels)				,   generator=a__				,   device=a__   )

					if include_res_hidden_states_tuple:
						A								=				torch.manual_seed(1   )
						A								=				(randn_tensor(a__				,   generator=a__				,   device=a__   ),)

					if include_encoder_hidden_states:
						A								=				floats_tensor((batch_size, 32, 32)   ).to(a__   )

					if include_skip_sample:
						A								=				randn_tensor(((batch_size, 3) + sizes)				,   generator=a__				,   device=a__   )

					return dummy_input

				def      _UpperCAmelCase					(						self   )	->				int:
					A								=				{
					    """in_channels""": 32,
					    """out_channels""": 32,
					    """temb_channels""": 128,
					}
					if self.block_type == "up":
						A								=				32

					if self.block_type == "mid":
						init_dict.pop("""out_channels"""   )

					A								=				self.dummy_input
					return init_dict, inputs_dict

				def      _UpperCAmelCase					(						self				,   a__   )	->				Optional[int]:
					A					,			A								=				self.prepare_init_args_and_inputs_for_common()
					A								=				self.block_class(**a__   )
					unet_block.to(a__   )
					unet_block.eval()

					with torch.no_grad():
						A								=				unet_block(**a__   )

					if isinstance(a__				,   a__   ):
						A								=				output[0]

					self.assertEqual(output.shape				,   self.output_shape   )

					A								=				output[0, -1, -3:, -3:]
					A								=				torch.tensor(a__   ).to(a__   )
					assert torch_all_close(output_slice.flatten()				,   a__				,   atol=5e-3   )

				@unittest.skipIf(torch_device == """mps"""				,   """Training is not supported in mps"""   )
				def      _UpperCAmelCase					(						self   )	->				str:
					A					,			A								=				self.prepare_init_args_and_inputs_for_common()
					A								=				self.block_class(**a__   )
					model.to(a__   )
					model.train()
					A								=				model(**a__   )

					if isinstance(a__				,   a__   ):
						A								=				output[0]

					A								=				torch.device(a__   )
					A								=				randn_tensor(output.shape				,   device=a__   )
					A								=				torch.nn.functional.mse_loss(a__				,   a__   )
					loss.backward()



