
import unittest

from diffusers.models.unet_ad_blocks import *  # noqa F403
from diffusers.utils import torch_device

from .test_unet_blocks_common import UNetBlockTesterMixin





class 							A__		(	__SCREAMING_SNAKE_CASE  ,   unittest.TestCase):
      _UpperCAmelCase				:    Any           =			DownBlockaD  # noqa F405
      _UpperCAmelCase				:    List[str]           =			"""down"""
      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	Any							=      [-0.0_232, -0.9_869, 0.8_054, -0.0_637, -0.1_688, -1.4_264, 0.4_470, -1.3_394, 0.0_904]
       super().test_output(__magic_name__      )





class 							A__		(	__SCREAMING_SNAKE_CASE  ,   unittest.TestCase):
      _UpperCAmelCase				:    Union[str, Any]           =			ResnetDownsampleBlockaD  # noqa F405
      _UpperCAmelCase				:    Union[str, Any]           =			"""down"""
      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	Dict							=      [0.0_710, 0.2_410, -0.7_320, -1.0_757, -1.1_343, 0.3_540, -0.0_133, -0.2_576, 0.0_948]
       super().test_output(__magic_name__      )





class 							A__		(	__SCREAMING_SNAKE_CASE  ,   unittest.TestCase):
      _UpperCAmelCase				:    List[str]           =			AttnDownBlockaD  # noqa F405
      _UpperCAmelCase				:    Union[str, Any]           =			"""down"""
      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	Tuple							=      [0.0_636, 0.8_964, -0.6_234, -1.0_131, 0.0_844, 0.4_935, 0.3_437, 0.0_911, -0.2_957]
       super().test_output(__magic_name__      )





class 							A__		(	__SCREAMING_SNAKE_CASE  ,   unittest.TestCase):
      _UpperCAmelCase				:    Optional[int]           =			CrossAttnDownBlockaD  # noqa F405
      _UpperCAmelCase				:    List[str]           =			"""down"""
      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase			,    lowerCamelCase		:	Dict							=      super().prepare_init_args_and_inputs_for_common()
       lowerCamelCase		:	int							=      3_2
       return init_dict, inputs_dict






      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	List[str]							=      [0.2_238, -0.7_396, -0.2_255, -0.3_829, 0.1_925, 1.1_665, 0.0_603, -0.7_295, 0.1_983]
       super().test_output(__magic_name__      )





class 							A__		(	__SCREAMING_SNAKE_CASE  ,   unittest.TestCase):
      _UpperCAmelCase				:    List[Any]           =			SimpleCrossAttnDownBlockaD  # noqa F405
      _UpperCAmelCase				:    Any           =			"""down"""
      @property
      def 						UpperCamelCase__							(      self      ):
       return super().get_dummy_input(include_encoder_hidden_states=__magic_name__      )
      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase			,    lowerCamelCase		:	List[str]							=      super().prepare_init_args_and_inputs_for_common()
       lowerCamelCase		:	int							=      3_2
       return init_dict, inputs_dict






      @unittest.skipIf(torch_device == """mps"""    ,  """MPS result is not consistent"""      )
      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	Union[str, Any]							=      [0.7_921, -0.0_992, -0.1_962, -0.7_695, -0.4_242, 0.7_804, 0.4_737, 0.2_765, 0.3_338]
       super().test_output(__magic_name__      )





class 							A__		(	__SCREAMING_SNAKE_CASE  ,   unittest.TestCase):
      _UpperCAmelCase				:    List[Any]           =			SkipDownBlockaD  # noqa F405
      _UpperCAmelCase				:    int           =			"""down"""
      @property
      def 						UpperCamelCase__							(      self      ):
       return super().get_dummy_input(include_skip_sample=__magic_name__      )






      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	Dict							=      [-0.0_845, -0.2_087, -0.2_465, 0.0_971, 0.1_900, -0.0_484, 0.2_664, 0.4_179, 0.5_069]
       super().test_output(__magic_name__      )





class 							A__		(	__SCREAMING_SNAKE_CASE  ,   unittest.TestCase):
      _UpperCAmelCase				:    List[str]           =			AttnSkipDownBlockaD  # noqa F405
      _UpperCAmelCase				:    int           =			"""down"""
      @property
      def 						UpperCamelCase__							(      self      ):
       return super().get_dummy_input(include_skip_sample=__magic_name__      )






      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	Union[str, Any]							=      [0.5_539, 0.1_609, 0.4_924, 0.0_537, -0.1_995, 0.4_050, 0.0_979, -0.2_721, -0.0_642]
       super().test_output(__magic_name__      )





class 							A__		(	__SCREAMING_SNAKE_CASE  ,   unittest.TestCase):
      _UpperCAmelCase				:    Optional[Any]           =			DownEncoderBlockaD  # noqa F405
      _UpperCAmelCase				:    Tuple           =			"""down"""
      @property
      def 						UpperCamelCase__							(      self      ):
       return super().get_dummy_input(include_temb=__magic_name__      )
      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	str							=      {
           """in_channels""": 3_2,
           """out_channels""": 3_2,
       }
       lowerCamelCase		:	str							=      self.dummy_input
       return init_dict, inputs_dict






      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	Tuple							=      [1.1_102, 0.5_302, 0.4_872, -0.0_023, -0.8_042, 0.0_483, -0.3_489, -0.5_632, 0.7_626]
       super().test_output(__magic_name__      )





class 							A__		(	__SCREAMING_SNAKE_CASE  ,   unittest.TestCase):
      _UpperCAmelCase				:    Dict           =			AttnDownEncoderBlockaD  # noqa F405
      _UpperCAmelCase				:    Any           =			"""down"""
      @property
      def 						UpperCamelCase__							(      self      ):
       return super().get_dummy_input(include_temb=__magic_name__      )
      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	Any							=      {
           """in_channels""": 3_2,
           """out_channels""": 3_2,
       }
       lowerCamelCase		:	Optional[int]							=      self.dummy_input
       return init_dict, inputs_dict






      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	Union[str, Any]							=      [0.8_966, -0.1_486, 0.8_568, 0.8_141, -0.9_046, -0.1_342, -0.0_972, -0.7_417, 0.1_538]
       super().test_output(__magic_name__      )





class 							A__		(	__SCREAMING_SNAKE_CASE  ,   unittest.TestCase):
      _UpperCAmelCase				:    str           =			UNetMidBlockaD  # noqa F405
      _UpperCAmelCase				:    Optional[Any]           =			"""mid"""
      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	Optional[Any]							=      {
           """in_channels""": 3_2,
           """temb_channels""": 1_2_8,
       }
       lowerCamelCase		:	int							=      self.dummy_input
       return init_dict, inputs_dict






      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	Dict							=      [-0.1_062, 1.7_248, 0.3_494, 1.4_569, -0.0_910, -1.2_421, -0.9_984, 0.6_736, 1.0_028]
       super().test_output(__magic_name__      )





class 							A__		(	__SCREAMING_SNAKE_CASE  ,   unittest.TestCase):
      _UpperCAmelCase				:    List[Any]           =			UNetMidBlockaDCrossAttn  # noqa F405
      _UpperCAmelCase				:    List[Any]           =			"""mid"""
      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase			,    lowerCamelCase		:	Tuple							=      super().prepare_init_args_and_inputs_for_common()
       lowerCamelCase		:	Tuple							=      3_2
       return init_dict, inputs_dict






      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	List[Any]							=      [0.0_187, 2.4_220, 0.4_484, 1.1_203, -0.6_121, -1.5_122, -0.8_270, 0.7_851, 1.8_335]
       super().test_output(__magic_name__      )





class 							A__		(	__SCREAMING_SNAKE_CASE  ,   unittest.TestCase):
      _UpperCAmelCase				:    Optional[Any]           =			UNetMidBlockaDSimpleCrossAttn  # noqa F405
      _UpperCAmelCase				:    List[Any]           =			"""mid"""
      @property
      def 						UpperCamelCase__							(      self      ):
       return super().get_dummy_input(include_encoder_hidden_states=__magic_name__      )
      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase			,    lowerCamelCase		:	Union[str, Any]							=      super().prepare_init_args_and_inputs_for_common()
       lowerCamelCase		:	str							=      3_2
       return init_dict, inputs_dict






      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	List[Any]							=      [0.7_143, 1.9_974, 0.5_448, 1.3_977, 0.1_282, -1.1_237, -1.4_238, 0.5_530, 0.8_880]
       super().test_output(__magic_name__      )





class 							A__		(	__SCREAMING_SNAKE_CASE  ,   unittest.TestCase):
      _UpperCAmelCase				:    int           =			UpBlockaD  # noqa F405
      _UpperCAmelCase				:    Any           =			"""up"""
      @property
      def 						UpperCamelCase__							(      self      ):
       return super().get_dummy_input(include_res_hidden_states_tuple=__magic_name__      )






      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	Any							=      [-0.2_041, -0.4_165, -0.3_022, 0.0_041, -0.6_628, -0.7_053, 0.1_928, -0.0_325, 0.0_523]
       super().test_output(__magic_name__      )





class 							A__		(	__SCREAMING_SNAKE_CASE  ,   unittest.TestCase):
      _UpperCAmelCase				:    Dict           =			ResnetUpsampleBlockaD  # noqa F405
      _UpperCAmelCase				:    Union[str, Any]           =			"""up"""
      @property
      def 						UpperCamelCase__							(      self      ):
       return super().get_dummy_input(include_res_hidden_states_tuple=__magic_name__      )






      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	Tuple							=      [0.2_287, 0.3_549, -0.1_346, 0.4_797, -0.1_715, -0.9_649, 0.7_305, -0.5_864, -0.6_244]
       super().test_output(__magic_name__      )





class 							A__		(	__SCREAMING_SNAKE_CASE  ,   unittest.TestCase):
      _UpperCAmelCase				:    Optional[int]           =			CrossAttnUpBlockaD  # noqa F405
      _UpperCAmelCase				:    int           =			"""up"""
      @property
      def 						UpperCamelCase__							(      self      ):
       return super().get_dummy_input(include_res_hidden_states_tuple=__magic_name__      )
      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase			,    lowerCamelCase		:	Optional[int]							=      super().prepare_init_args_and_inputs_for_common()
       lowerCamelCase		:	Optional[Any]							=      3_2
       return init_dict, inputs_dict






      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	Optional[int]							=      [-0.1_403, -0.3_515, -0.0_420, -0.1_425, 0.3_167, 0.5_094, -0.2_181, 0.5_931, 0.5_582]
       super().test_output(__magic_name__      )





class 							A__		(	__SCREAMING_SNAKE_CASE  ,   unittest.TestCase):
      _UpperCAmelCase				:    Union[str, Any]           =			SimpleCrossAttnUpBlockaD  # noqa F405
      _UpperCAmelCase				:    int           =			"""up"""
      @property
      def 						UpperCamelCase__							(      self      ):
       return super().get_dummy_input(include_res_hidden_states_tuple=__magic_name__    ,  include_encoder_hidden_states=__magic_name__      )
      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase			,    lowerCamelCase		:	Dict							=      super().prepare_init_args_and_inputs_for_common()
       lowerCamelCase		:	str							=      3_2
       return init_dict, inputs_dict






      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	Any							=      [0.2_645, 0.1_480, 0.0_909, 0.8_044, -0.9_758, -0.9_083, 0.0_994, -1.1_453, -0.7_402]
       super().test_output(__magic_name__      )





class 							A__		(	__SCREAMING_SNAKE_CASE  ,   unittest.TestCase):
      _UpperCAmelCase				:    List[Any]           =			AttnUpBlockaD  # noqa F405
      _UpperCAmelCase				:    List[Any]           =			"""up"""
      @property
      def 						UpperCamelCase__							(      self      ):
       return super().get_dummy_input(include_res_hidden_states_tuple=__magic_name__      )






      @unittest.skipIf(torch_device == """mps"""    ,  """MPS result is not consistent"""      )
      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	Union[str, Any]							=      [0.0_979, 0.1_326, 0.0_021, 0.0_659, 0.2_249, 0.0_059, 0.1_132, 0.5_952, 0.1_033]
       super().test_output(__magic_name__      )





class 							A__		(	__SCREAMING_SNAKE_CASE  ,   unittest.TestCase):
      _UpperCAmelCase				:    Optional[int]           =			SkipUpBlockaD  # noqa F405
      _UpperCAmelCase				:    Optional[int]           =			"""up"""
      @property
      def 						UpperCamelCase__							(      self      ):
       return super().get_dummy_input(include_res_hidden_states_tuple=__magic_name__      )






      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	Tuple							=      [-0.0_893, -0.1_234, -0.1_506, -0.0_332, 0.0_123, -0.0_211, 0.0_566, 0.0_143, 0.0_362]
       super().test_output(__magic_name__      )





class 							A__		(	__SCREAMING_SNAKE_CASE  ,   unittest.TestCase):
      _UpperCAmelCase				:    Any           =			AttnSkipUpBlockaD  # noqa F405
      _UpperCAmelCase				:    Any           =			"""up"""
      @property
      def 						UpperCamelCase__							(      self      ):
       return super().get_dummy_input(include_res_hidden_states_tuple=__magic_name__      )






      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	int							=      [0.0_361, 0.0_617, 0.2_787, -0.0_350, 0.0_342, 0.3_421, -0.0_843, 0.0_913, 0.3_015]
       super().test_output(__magic_name__      )





class 							A__		(	__SCREAMING_SNAKE_CASE  ,   unittest.TestCase):
      _UpperCAmelCase				:    int           =			UpDecoderBlockaD  # noqa F405
      _UpperCAmelCase				:    str           =			"""up"""
      @property
      def 						UpperCamelCase__							(      self      ):
       return super().get_dummy_input(include_temb=__magic_name__      )
      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	Any							=      {"""in_channels""": 3_2, """out_channels""": 3_2}

       lowerCamelCase		:	Any							=      self.dummy_input
       return init_dict, inputs_dict






      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	List[Any]							=      [0.4_404, 0.1_998, -0.9_886, -0.3_320, -0.3_128, -0.7_034, -0.6_955, -0.2_338, -0.3_137]
       super().test_output(__magic_name__      )





class 							A__		(	__SCREAMING_SNAKE_CASE  ,   unittest.TestCase):
      _UpperCAmelCase				:    List[str]           =			AttnUpDecoderBlockaD  # noqa F405
      _UpperCAmelCase				:    List[str]           =			"""up"""
      @property
      def 						UpperCamelCase__							(      self      ):
       return super().get_dummy_input(include_temb=__magic_name__      )
      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	Optional[Any]							=      {"""in_channels""": 3_2, """out_channels""": 3_2}

       lowerCamelCase		:	int							=      self.dummy_input
       return init_dict, inputs_dict






      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	Optional[Any]							=      [0.6_738, 0.4_491, 0.1_055, 1.0_710, 0.7_316, 0.3_339, 0.3_352, 0.1_023, 0.3_568]
       super().test_output(__magic_name__      )






import copy
from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging
from ..auto import CONFIG_MAPPING


_lowerCamelCase					   =logging.get_logger(__name__)

_lowerCamelCase					   ={
    """microsoft/conditional-detr-resnet-50""": (
        """https://huggingface.co/microsoft/conditional-detr-resnet-50/resolve/main/config.json"""
    ),
}





class 							A__		(	__SCREAMING_SNAKE_CASE):
      _UpperCAmelCase				:    Union[str, Any]           =			"""conditional_detr"""
      _UpperCAmelCase				:    Optional[int]           =			["""past_key_values"""]
      _UpperCAmelCase				:    Optional[Any]           =			{
          """hidden_size""": """d_model""",
          """num_attention_heads""": """encoder_attention_heads""",
      }
      def __init__(      self    ,  __magic_name__=True    ,  __magic_name__=None    ,  __magic_name__=3    ,  __magic_name__=3_0_0    ,  __magic_name__=6    ,  __magic_name__=2_0_4_8    ,  __magic_name__=8    ,  __magic_name__=6    ,  __magic_name__=2_0_4_8    ,  __magic_name__=8    ,  __magic_name__=0.0    ,  __magic_name__=0.0    ,  __magic_name__=True    ,  __magic_name__="relu"    ,  __magic_name__=2_5_6    ,  __magic_name__=0.1    ,  __magic_name__=0.0    ,  __magic_name__=0.0    ,  __magic_name__=0.02    ,  __magic_name__=1.0    ,  __magic_name__=False    ,  __magic_name__="sine"    ,  __magic_name__="resnet50"    ,  __magic_name__=True    ,  __magic_name__=False    ,  __magic_name__=2    ,  __magic_name__=5    ,  __magic_name__=2    ,  __magic_name__=1    ,  __magic_name__=1    ,  __magic_name__=2    ,  __magic_name__=5    ,  __magic_name__=2    ,  __magic_name__=0.25    ,  **__magic_name__    ,  ):
       if backbone_config is not None and use_timm_backbone:
        raise ValueError("""You can't specify both `backbone_config` and `use_timm_backbone`."""      )

       if not use_timm_backbone:
        if backbone_config is None:
         logger.info("""`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone."""      )
         lowerCamelCase		:	Optional[int]							=      CONFIG_MAPPING["""resnet"""](out_features=["""stage4"""]      )
        elif isinstance(__magic_name__    ,  __magic_name__      ):
         lowerCamelCase		:	List[Any]							=      backbone_config.get("""model_type"""      )
         lowerCamelCase		:	Dict							=      CONFIG_MAPPING[backbone_model_type]
         lowerCamelCase		:	str							=      config_class.from_dict(__magic_name__      )

       lowerCamelCase		:	Dict							=      use_timm_backbone
       lowerCamelCase		:	str							=      backbone_config
       lowerCamelCase		:	Tuple							=      num_channels
       lowerCamelCase		:	Dict							=      num_queries
       lowerCamelCase		:	Any							=      d_model
       lowerCamelCase		:	Optional[Any]							=      encoder_ffn_dim
       lowerCamelCase		:	List[str]							=      encoder_layers
       lowerCamelCase		:	Union[str, Any]							=      encoder_attention_heads
       lowerCamelCase		:	Any							=      decoder_ffn_dim
       lowerCamelCase		:	Dict							=      decoder_layers
       lowerCamelCase		:	Union[str, Any]							=      decoder_attention_heads
       lowerCamelCase		:	Dict							=      dropout
       lowerCamelCase		:	List[str]							=      attention_dropout
       lowerCamelCase		:	Union[str, Any]							=      activation_dropout
       lowerCamelCase		:	Optional[int]							=      activation_function
       lowerCamelCase		:	int							=      init_std
       lowerCamelCase		:	str							=      init_xavier_std
       lowerCamelCase		:	Tuple							=      encoder_layerdrop
       lowerCamelCase		:	str							=      decoder_layerdrop
       lowerCamelCase		:	Tuple							=      encoder_layers
       lowerCamelCase		:	Optional[int]							=      auxiliary_loss
       lowerCamelCase		:	Optional[Any]							=      position_embedding_type
       lowerCamelCase		:	Optional[int]							=      backbone
       lowerCamelCase		:	Union[str, Any]							=      use_pretrained_backbone
       lowerCamelCase		:	str							=      dilation
       # Hungarian matcher
       lowerCamelCase		:	Optional[Any]							=      class_cost
       lowerCamelCase		:	Dict							=      bbox_cost
       lowerCamelCase		:	Tuple							=      giou_cost
       # Loss coefficients
       lowerCamelCase		:	Union[str, Any]							=      mask_loss_coefficient
       lowerCamelCase		:	Dict							=      dice_loss_coefficient
       lowerCamelCase		:	Optional[int]							=      cls_loss_coefficient
       lowerCamelCase		:	Optional[int]							=      bbox_loss_coefficient
       lowerCamelCase		:	Optional[int]							=      giou_loss_coefficient
       lowerCamelCase		:	Optional[int]							=      focal_alpha
       super().__init__(is_encoder_decoder=__magic_name__    ,  **__magic_name__      )
      @property
      def 						UpperCamelCase__							(      self      ):
       return self.encoder_attention_heads
      @property
      def 						UpperCamelCase__							(      self      ):
       return self.d_model






      def 						UpperCamelCase__							(      self      ):
       lowerCamelCase		:	Optional[int]							=      copy.deepcopy(self.__dict__      )
       if self.backbone_config is not None:
        lowerCamelCase		:	Optional[int]							=      self.backbone_config.to_dict()
       lowerCamelCase		:	Optional[Any]							=      self.__class__.model_type
       return output





class 							A__		(	__SCREAMING_SNAKE_CASE):
      _UpperCAmelCase				:    Any           =			version.parse("""1.11""")
      @property
      def 						UpperCamelCase__							(      self      ):
       return OrderedDict(
           [
               ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
               ("""pixel_mask""", {0: """batch"""}),
           ]      )
      @property
      def 						UpperCamelCase__							(      self      ):
       return 1e-5






      @property
      def 						UpperCamelCase__							(      self      ):
       return 1_2




