


from __future__ import annotations

import collections
import tempfile
import unittest

import numpy as np

from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import is_tf_available, is_vision_available

from ...test_modeling_tf_common import floats_tensor, ids_tensor, random_attention_mask
from ..bert.test_modeling_tf_bert import TFBertModelTester
from ..clip.test_modeling_tf_clip import TFCLIPVisionModelTester
from ..deit.test_modeling_tf_deit import TFDeiTModelTester
from ..roberta.test_modeling_tf_roberta import TFRobertaModelTester
from ..vit.test_modeling_tf_vit import TFViTModelTester


if is_tf_available():
   from transformers import (
       TFBertModel,
       TFCLIPVisionModel,
       TFDeiTModel,
       TFRobertaModel,
       TFVisionTextDualEncoderModel,
       TFViTModel,
       VisionTextDualEncoderConfig,
   )

if is_vision_available():
   from PIL import Image

   from transformers import VisionTextDualEncoderProcessor



def       _lowerCAmelCase    (				lowerCAmelCase_				:Tuple				)->Dict:
   '''simple docstring'''






   if isinstance(lowerCAmelCase_		,    collections.abc.Iterable				):
      return x
   return (x, x)


@require_tf
class      __lowerCAmelCase  :






  """simple docstring"""





  def        lowerCAmelCase__	(  self							:							List[Any]     ,					_lowerCAmelCase							:							Optional[int]     ,					_lowerCAmelCase							:							Dict	) ->			int:




     """simple docstring"""
     pass



  def        lowerCAmelCase__	(  self							:							str	) ->			str:




     """simple docstring"""
     pass



  def        lowerCAmelCase__	(  self							:							List[str]	) ->			Any:




     """simple docstring"""
     pass



  def        lowerCAmelCase__	(  self							:							Tuple     ,					_lowerCAmelCase							:							Dict     ,					_lowerCAmelCase							:							Any     ,					_lowerCAmelCase							:							Optional[Any]     ,					_lowerCAmelCase							:							str     ,					_lowerCAmelCase							:							List[Any]=None     ,					**_lowerCAmelCase							:							str	) ->			List[str]:




     """simple docstring"""
     snake_case_            =       VisionTextDualEncoderConfig.from_vision_text_configs(_lowerCAmelCase     ,					_lowerCAmelCase	)

     snake_case_            =       TFVisionTextDualEncoderModel(_lowerCAmelCase	)

     snake_case_            =       model(input_ids=_lowerCAmelCase     ,					pixel_values=_lowerCAmelCase     ,					attention_mask=_lowerCAmelCase	)

     self.assertEqual(output["text_embeds"].shape     ,					(input_ids.shape[0], config.projection_dim)	)
     self.assertEqual(output["image_embeds"].shape     ,					(pixel_values.shape[0], config.projection_dim)	)



  def        lowerCAmelCase__	(  self							:							str     ,					_lowerCAmelCase							:							Optional[int]     ,					_lowerCAmelCase							:							Dict     ,					_lowerCAmelCase							:							List[str]     ,					_lowerCAmelCase							:							Optional[int]     ,					_lowerCAmelCase							:							List[Any]=None     ,					**_lowerCAmelCase							:							str	) ->			Optional[int]:




     """simple docstring"""
     snake_case_     ,     snake_case_            =       self.get_vision_text_model(_lowerCAmelCase     ,					_lowerCAmelCase	)
     snake_case_            =       TFVisionTextDualEncoderModel(vision_model=_lowerCAmelCase     ,					text_model=_lowerCAmelCase	)

     snake_case_            =       model(input_ids=_lowerCAmelCase     ,					pixel_values=_lowerCAmelCase     ,					attention_mask=_lowerCAmelCase	)

     self.assertEqual(output["text_embeds"].shape     ,					(input_ids.shape[0], model.config.projection_dim)	)
     self.assertEqual(output["image_embeds"].shape     ,					(pixel_values.shape[0], model.config.projection_dim)	)



  def        lowerCAmelCase__	(  self							:							List[str]     ,					_lowerCAmelCase							:							Dict     ,					_lowerCAmelCase							:							List[Any]     ,					_lowerCAmelCase							:							List[Any]     ,					_lowerCAmelCase							:							str     ,					_lowerCAmelCase							:							Dict=None     ,					**_lowerCAmelCase							:							str	) ->			Dict:




     """simple docstring"""
     snake_case_     ,     snake_case_            =       self.get_vision_text_model(_lowerCAmelCase     ,					_lowerCAmelCase	)
     snake_case_            =       {"vision_model": vision_model, "text_model": text_model}
     snake_case_            =       TFVisionTextDualEncoderModel.from_vision_text_pretrained(**_lowerCAmelCase	)

     snake_case_            =       model(input_ids=_lowerCAmelCase     ,					pixel_values=_lowerCAmelCase     ,					attention_mask=_lowerCAmelCase	)

     self.assertEqual(output["text_embeds"].shape     ,					(input_ids.shape[0], model.config.projection_dim)	)
     self.assertEqual(output["image_embeds"].shape     ,					(pixel_values.shape[0], model.config.projection_dim)	)



  def        lowerCAmelCase__	(  self							:							Union[str, Any]     ,					_lowerCAmelCase							:							str     ,					_lowerCAmelCase							:							List[str]     ,					_lowerCAmelCase							:							Optional[int]     ,					_lowerCAmelCase							:							Union[str, Any]     ,					_lowerCAmelCase							:							Optional[int]=None     ,					**_lowerCAmelCase							:							Any	) ->			str:




     """simple docstring"""
     snake_case_     ,     snake_case_            =       self.get_vision_text_model(_lowerCAmelCase     ,					_lowerCAmelCase	)
     snake_case_            =       TFVisionTextDualEncoderModel(vision_model=_lowerCAmelCase     ,					text_model=_lowerCAmelCase	)

     snake_case_            =       model(input_ids=_lowerCAmelCase     ,					pixel_values=_lowerCAmelCase     ,					attention_mask=_lowerCAmelCase	)
     snake_case_            =       output[0].numpy()

     with tempfile.TemporaryDirectory() as tmpdirname:
        model.save_pretrained(_lowerCAmelCase	)
        snake_case_            =       TFVisionTextDualEncoderModel.from_pretrained(_lowerCAmelCase	)

        snake_case_            =       model(input_ids=_lowerCAmelCase     ,					pixel_values=_lowerCAmelCase     ,					attention_mask=_lowerCAmelCase	)
        snake_case_            =       after_output[0].numpy()
        snake_case_            =       np.amax(np.abs(out_a - out_a	)	)
        self.assertLessEqual(_lowerCAmelCase     ,					1e-5	)



  def        lowerCAmelCase__	(  self							:							Any     ,					_lowerCAmelCase							:							Union[str, Any]     ,					_lowerCAmelCase							:							str     ,					_lowerCAmelCase							:							Dict     ,					_lowerCAmelCase							:							List[Any]     ,					_lowerCAmelCase							:							int=None     ,					**_lowerCAmelCase							:							List[str]	) ->			Tuple:




     """simple docstring"""
     snake_case_     ,     snake_case_            =       self.get_vision_text_model(_lowerCAmelCase     ,					_lowerCAmelCase	)
     snake_case_            =       TFVisionTextDualEncoderModel(vision_model=_lowerCAmelCase     ,					text_model=_lowerCAmelCase	)

     snake_case_            =       model(
         input_ids=_lowerCAmelCase     ,					pixel_values=_lowerCAmelCase     ,					attention_mask=_lowerCAmelCase     ,					output_attentions=_lowerCAmelCase	)

     snake_case_            =       output.vision_model_output.attentions
     self.assertEqual(len(_lowerCAmelCase	)     ,					vision_config.num_hidden_layers	)

     # in ViT, the seq_len equals the number of patches + 1 (we add 1 for the [CLS] token)
     snake_case_            =       to_atuple(vision_model.config.image_size	)
     snake_case_            =       to_atuple(vision_model.config.patch_size	)
     snake_case_            =       (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
     snake_case_            =       num_patches + 1
     self.assertEqual(vision_attentions[0].shape[-3:]     ,					(vision_config.num_attention_heads, seq_len, seq_len)	)

     snake_case_            =       output.text_model_output.attentions
     self.assertEqual(len(_lowerCAmelCase	)     ,					text_config.num_hidden_layers	)

     self.assertEqual(
         text_attentions[0].shape[-3:]     ,					(text_config.num_attention_heads, input_ids.shape[-1], input_ids.shape[-1])     ,					)



  def        lowerCAmelCase__	(  self							:							Tuple     ,					_lowerCAmelCase							:							np.ndarray     ,					_lowerCAmelCase							:							np.ndarray     ,					_lowerCAmelCase							:							float	) ->			str:




     """simple docstring"""
     snake_case_            =       np.abs((a - b)	).max()
     self.assertLessEqual(_lowerCAmelCase     ,					_lowerCAmelCase     ,					F'''Difference between torch and flax is {diff} (>= {tol}).'''	)



  def        lowerCAmelCase__	(  self							:							Dict	) ->			Optional[int]:




     """simple docstring"""
     snake_case_            =       self.prepare_config_and_inputs()
     self.check_vision_text_dual_encoder_model(**_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							Union[str, Any]	) ->			int:




     """simple docstring"""
     snake_case_            =       self.prepare_config_and_inputs()
     self.check_model_from_pretrained_configs(**_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							int	) ->			List[Any]:




     """simple docstring"""
     snake_case_            =       self.prepare_config_and_inputs()
     self.check_vision_text_dual_encoder_from_pretrained(**_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							Optional[Any]	) ->			Any:




     """simple docstring"""
     snake_case_            =       self.prepare_config_and_inputs()
     self.check_save_load(**_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							Tuple	) ->			List[str]:




     """simple docstring"""
     snake_case_            =       self.prepare_config_and_inputs()
     self.check_vision_text_output_attention(**_lowerCAmelCase	)



  @slow
  def        lowerCAmelCase__	(  self							:							List[Any]	) ->			List[str]:




     """simple docstring"""
     snake_case_     ,     snake_case_            =       self.get_pretrained_model_and_inputs()

     snake_case_            =       model_a(**_lowerCAmelCase	)
     snake_case_            =       outputs[0].numpy()

     with tempfile.TemporaryDirectory() as tmp_dirname:
        model_a.save_pretrained(_lowerCAmelCase	)
        snake_case_            =       TFVisionTextDualEncoderModel.from_pretrained(_lowerCAmelCase	)

        snake_case_            =       model_a(**_lowerCAmelCase	)
        snake_case_            =       after_outputs[0].numpy()
        snake_case_            =       np.amax(np.abs(out_a - out_a	)	)
        self.assertLessEqual(_lowerCAmelCase     ,					1e-5	)






@require_tf
class      __lowerCAmelCase  (			a			,	unittest.TestCase       ):






  """simple docstring"""





  def        lowerCAmelCase__	(  self							:							Dict	) ->			Union[str, Any]:




     """simple docstring"""
     snake_case_            =       TFVisionTextDualEncoderModel.from_vision_text_pretrained(
         "hf-internal-testing/tiny-random-vit"     ,					"hf-internal-testing/tiny-random-bert"	)
     snake_case_            =       1_3
     snake_case_            =       floats_tensor(
         [
             batch_size,
             model.vision_model.config.num_channels,
             model.vision_model.config.image_size,
             model.vision_model.config.image_size,
         ]	)
     snake_case_            =       ids_tensor([batch_size, 4]     ,					model.text_model.config.vocab_size	)
     snake_case_            =       random_attention_mask([batch_size, 4]	)
     snake_case_            =       {"pixel_values": pixel_values, "input_ids": input_ids, "attention_mask": attention_mask}

     return model, inputs



  def        lowerCAmelCase__	(  self							:							Optional[int]     ,					_lowerCAmelCase							:							Any     ,					_lowerCAmelCase							:							List[str]	) ->			List[str]:




     """simple docstring"""
     snake_case_            =       TFViTModel(_lowerCAmelCase     ,					name="vision_model"	)
     snake_case_            =       TFBertModel(_lowerCAmelCase     ,					name="text_model"	)
     return vision_model, text_model



  def        lowerCAmelCase__	(  self							:							List[Any]	) ->			List[str]:




     """simple docstring"""
     snake_case_            =       TFViTModelTester(self	)
     snake_case_            =       TFBertModelTester(self	)
     snake_case_            =       vit_model_tester.prepare_config_and_inputs()
     snake_case_            =       bert_model_tester.prepare_config_and_inputs()

     snake_case_     ,     snake_case_     ,     snake_case_            =       vision_config_and_inputs

     (
         (
         snake_case_
     )     ,     (
         snake_case_
     )     ,     (
         snake_case_
     )     ,     (
         snake_case_
     )     ,     (
         snake_case_
     )     ,     (
         snake_case_
     )     ,     (
         snake_case_
     )     ,     
     )            =       text_config_and_inputs

     return {
         "text_config": text_config,
         "vision_config": vision_config,
         "pixel_values": pixel_values,
         "attention_mask": input_mask,
         "input_ids": input_ids,
         "text_token_type_ids": token_type_ids,
         "text_sequence_labels": sequence_labels,
         "text_token_labels": token_labels,
         "text_choice_labels": choice_labels,
     }






@require_tf
class      __lowerCAmelCase  (			a			,	unittest.TestCase       ):






  """simple docstring"""





  def        lowerCAmelCase__	(  self							:							List[Any]	) ->			Dict:




     """simple docstring"""
     # DeiT repo doesn't have TF weights, but we don't actually use the weights at all so let's
     # just reinitialize it.
     snake_case_            =       TFVisionTextDualEncoderModel.from_vision_text_pretrained(
         "Rocketknight1/tiny-random-deit-tf"     ,					"hf-internal-testing/tiny-random-roberta"	)
     snake_case_            =       1_3
     snake_case_            =       floats_tensor(
         [
             batch_size,
             model.vision_model.config.num_channels,
             model.vision_model.config.image_size,
             model.vision_model.config.image_size,
         ]	)
     snake_case_            =       ids_tensor([batch_size, 4]     ,					model.text_model.config.vocab_size	)
     snake_case_            =       random_attention_mask([batch_size, 4]	)
     snake_case_            =       {"pixel_values": pixel_values, "input_ids": input_ids, "attention_mask": attention_mask}

     return model, inputs



  def        lowerCAmelCase__	(  self							:							Union[str, Any]     ,					_lowerCAmelCase							:							List[str]     ,					_lowerCAmelCase							:							str     ,					_lowerCAmelCase							:							Tuple     ,					_lowerCAmelCase							:							List[Any]     ,					_lowerCAmelCase							:							List[str]=None     ,					**_lowerCAmelCase							:							List[str]	) ->			Tuple:




     """simple docstring"""
     snake_case_     ,     snake_case_            =       self.get_vision_text_model(_lowerCAmelCase     ,					_lowerCAmelCase	)
     snake_case_            =       TFVisionTextDualEncoderModel(vision_model=_lowerCAmelCase     ,					text_model=_lowerCAmelCase	)

     snake_case_            =       model(
         input_ids=_lowerCAmelCase     ,					pixel_values=_lowerCAmelCase     ,					attention_mask=_lowerCAmelCase     ,					output_attentions=_lowerCAmelCase	)

     snake_case_            =       output.vision_model_output.attentions
     self.assertEqual(len(_lowerCAmelCase	)     ,					vision_config.num_hidden_layers	)

     # in DEiT, the seq_len equals the number of patches + 2 (we add 2 for the [CLS] and distillation tokens)
     snake_case_            =       to_atuple(vision_model.config.image_size	)
     snake_case_            =       to_atuple(vision_model.config.patch_size	)
     snake_case_            =       (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
     snake_case_            =       num_patches + 2
     self.assertEqual(vision_attentions[0].shape[-3:]     ,					(vision_config.num_attention_heads, seq_len, seq_len)	)

     snake_case_            =       output.text_model_output.attentions
     self.assertEqual(len(_lowerCAmelCase	)     ,					text_config.num_hidden_layers	)

     self.assertEqual(
         text_attentions[0].shape[-3:]     ,					(text_config.num_attention_heads, input_ids.shape[-1], input_ids.shape[-1])     ,					)



  def        lowerCAmelCase__	(  self							:							Union[str, Any]     ,					_lowerCAmelCase							:							str     ,					_lowerCAmelCase							:							int	) ->			int:




     """simple docstring"""
     snake_case_            =       TFDeiTModel(_lowerCAmelCase     ,					name="vision_model"	)
     snake_case_            =       TFRobertaModel(_lowerCAmelCase     ,					name="text_model"	)
     return vision_model, text_model



  def        lowerCAmelCase__	(  self							:							int	) ->			Tuple:




     """simple docstring"""
     snake_case_            =       TFDeiTModelTester(self	)
     snake_case_            =       TFRobertaModelTester(self	)
     snake_case_            =       vit_model_tester.prepare_config_and_inputs()
     snake_case_            =       bert_model_tester.prepare_config_and_inputs()

     snake_case_     ,     snake_case_     ,     snake_case_            =       vision_config_and_inputs

     (
         (
         snake_case_
     )     ,     (
         snake_case_
     )     ,     (
         snake_case_
     )     ,     (
         snake_case_
     )     ,     (
         snake_case_
     )     ,     (
         snake_case_
     )     ,     (
         snake_case_
     )     ,     
     )            =       text_config_and_inputs

     return {
         "text_config": text_config,
         "vision_config": vision_config,
         "pixel_values": pixel_values,
         "attention_mask": input_mask,
         "input_ids": input_ids,
         "text_token_type_ids": token_type_ids,
         "text_sequence_labels": sequence_labels,
         "text_token_labels": token_labels,
         "text_choice_labels": choice_labels,
     }






@require_tf
class      __lowerCAmelCase  (			a			,	unittest.TestCase       ):






  """simple docstring"""





  def        lowerCAmelCase__	(  self							:							Optional[Any]	) ->			Any:




     """simple docstring"""
     snake_case_            =       TFVisionTextDualEncoderModel.from_vision_text_pretrained(
         "Rocketknight1/tiny-random-clip-tf"     ,					"hf-internal-testing/tiny-random-bert"	)
     snake_case_            =       1_3
     snake_case_            =       floats_tensor(
         [
             batch_size,
             model.vision_model.config.num_channels,
             model.vision_model.config.image_size,
             model.vision_model.config.image_size,
         ]	)
     snake_case_            =       ids_tensor([batch_size, 4]     ,					model.text_model.config.vocab_size	)
     snake_case_            =       random_attention_mask([batch_size, 4]	)
     snake_case_            =       {"pixel_values": pixel_values, "input_ids": input_ids, "attention_mask": attention_mask}

     return model, inputs



  def        lowerCAmelCase__	(  self							:							Any     ,					_lowerCAmelCase							:							Any     ,					_lowerCAmelCase							:							str	) ->			Optional[int]:




     """simple docstring"""
     snake_case_            =       TFCLIPVisionModel(_lowerCAmelCase     ,					name="vision_model"	)
     snake_case_            =       TFBertModel(_lowerCAmelCase     ,					name="text_model"	)
     return vision_model, text_model



  def        lowerCAmelCase__	(  self							:							List[str]	) ->			List[str]:




     """simple docstring"""
     snake_case_            =       TFCLIPVisionModelTester(self	)
     snake_case_            =       TFBertModelTester(self	)
     snake_case_            =       clip_model_tester.prepare_config_and_inputs()
     snake_case_            =       bert_model_tester.prepare_config_and_inputs()

     snake_case_     ,     snake_case_            =       vision_config_and_inputs

     (
         (
         snake_case_
     )     ,     (
         snake_case_
     )     ,     (
         snake_case_
     )     ,     (
         snake_case_
     )     ,     (
         snake_case_
     )     ,     (
         snake_case_
     )     ,     (
         snake_case_
     )     ,     
     )            =       text_config_and_inputs

     return {
         "text_config": text_config,
         "vision_config": vision_config,
         "pixel_values": pixel_values,
         "attention_mask": input_mask,
         "input_ids": input_ids,
         "text_token_type_ids": token_type_ids,
         "text_sequence_labels": sequence_labels,
         "text_token_labels": token_labels,
         "text_choice_labels": choice_labels,
     }






@require_vision
@require_tf
class      __lowerCAmelCase  (			unittest.TestCase       ):






  """simple docstring"""





  @slow
  def        lowerCAmelCase__	(  self							:							Union[str, Any]	) ->			Any:




     """simple docstring"""
     snake_case_            =       TFVisionTextDualEncoderModel.from_pretrained(
         "clip-italian/clip-italian"     ,					logit_scale_init_value=1.0     ,					from_pt=_lowerCAmelCase	)
     snake_case_            =       VisionTextDualEncoderProcessor.from_pretrained("clip-italian/clip-italian"	)

     snake_case_            =       Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"	)
     snake_case_            =       processor(
         text=["una foto di un gatto", "una foto di un cane"]     ,					images=_lowerCAmelCase     ,					padding=_lowerCAmelCase     ,					return_tensors="np"	)

     snake_case_            =       model(**_lowerCAmelCase	)

     # verify the logits
     self.assertEqual(outputs.logits_per_image.shape     ,					(inputs.pixel_values.shape[0], inputs.input_ids.shape[0])	)
     self.assertEqual(
         outputs.logits_per_text.shape     ,					(inputs.input_ids.shape[0], inputs.pixel_values.shape[0])     ,					)

     snake_case_            =       np.array([[1.2_284_727, 0.3_104_122]]	)

     self.assertTrue(np.allclose(outputs.logits_per_image.numpy()     ,					_lowerCAmelCase     ,					atol=1e-3	)	)








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      __lowerCAmelCase  (			a			,	unittest.TestCase       ):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE		     =							DownBlockaD  # noqa F405
  _SCREAMING_SNAKE_CASE		     =							'down'



  def        lowerCAmelCase__	(  self							:							int	) ->			Tuple:




     """simple docstring"""
     snake_case_            =       [-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(_lowerCAmelCase	)






class      __lowerCAmelCase  (			a			,	unittest.TestCase       ):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE		     =							ResnetDownsampleBlockaD  # noqa F405
  _SCREAMING_SNAKE_CASE		     =							'down'



  def        lowerCAmelCase__	(  self							:							Any	) ->			Union[str, Any]:




     """simple docstring"""
     snake_case_            =       [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(_lowerCAmelCase	)






class      __lowerCAmelCase  (			a			,	unittest.TestCase       ):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE		     =							AttnDownBlockaD  # noqa F405
  _SCREAMING_SNAKE_CASE		     =							'down'



  def        lowerCAmelCase__	(  self							:							Union[str, Any]	) ->			Tuple:




     """simple docstring"""
     snake_case_            =       [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(_lowerCAmelCase	)






class      __lowerCAmelCase  (			a			,	unittest.TestCase       ):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE		     =							CrossAttnDownBlockaD  # noqa F405
  _SCREAMING_SNAKE_CASE		     =							'down'



  def        lowerCAmelCase__	(  self							:							str	) ->			Tuple:




     """simple docstring"""
     snake_case_     ,     snake_case_            =       super().prepare_init_args_and_inputs_for_common()
     snake_case_            =       3_2
     return init_dict, inputs_dict



  def        lowerCAmelCase__	(  self							:							List[Any]	) ->			str:




     """simple docstring"""
     snake_case_            =       [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(_lowerCAmelCase	)






class      __lowerCAmelCase  (			a			,	unittest.TestCase       ):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE		     =							SimpleCrossAttnDownBlockaD  # noqa F405
  _SCREAMING_SNAKE_CASE		     =							'down'



  @property
  def        lowerCAmelCase__	(  self							:							Dict	) ->			Any:




     """simple docstring"""
     return super().get_dummy_input(include_encoder_hidden_states=_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							List[Any]	) ->			Optional[int]:




     """simple docstring"""
     snake_case_     ,     snake_case_            =       super().prepare_init_args_and_inputs_for_common()
     snake_case_            =       3_2
     return init_dict, inputs_dict



  @unittest.skipIf(torch_device == "mps"     ,					"MPS result is not consistent"	)
  def        lowerCAmelCase__	(  self							:							int	) ->			Optional[Any]:




     """simple docstring"""
     snake_case_            =       [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(_lowerCAmelCase	)






class      __lowerCAmelCase  (			a			,	unittest.TestCase       ):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE		     =							SkipDownBlockaD  # noqa F405
  _SCREAMING_SNAKE_CASE		     =							'down'



  @property
  def        lowerCAmelCase__	(  self							:							Union[str, Any]	) ->			Tuple:




     """simple docstring"""
     return super().get_dummy_input(include_skip_sample=_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							Optional[int]	) ->			int:




     """simple docstring"""
     snake_case_            =       [-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(_lowerCAmelCase	)






class      __lowerCAmelCase  (			a			,	unittest.TestCase       ):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE		     =							AttnSkipDownBlockaD  # noqa F405
  _SCREAMING_SNAKE_CASE		     =							'down'



  @property
  def        lowerCAmelCase__	(  self							:							Any	) ->			Dict:




     """simple docstring"""
     return super().get_dummy_input(include_skip_sample=_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							Union[str, Any]	) ->			Any:




     """simple docstring"""
     snake_case_            =       [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(_lowerCAmelCase	)






class      __lowerCAmelCase  (			a			,	unittest.TestCase       ):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE		     =							DownEncoderBlockaD  # noqa F405
  _SCREAMING_SNAKE_CASE		     =							'down'



  @property
  def        lowerCAmelCase__	(  self							:							int	) ->			Optional[Any]:




     """simple docstring"""
     return super().get_dummy_input(include_temb=_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							Union[str, Any]	) ->			Dict:




     """simple docstring"""
     snake_case_            =       {
         "in_channels": 3_2,
         "out_channels": 3_2,
     }
     snake_case_            =       self.dummy_input
     return init_dict, inputs_dict



  def        lowerCAmelCase__	(  self							:							Optional[int]	) ->			List[Any]:




     """simple docstring"""
     snake_case_            =       [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(_lowerCAmelCase	)






class      __lowerCAmelCase  (			a			,	unittest.TestCase       ):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE		     =							AttnDownEncoderBlockaD  # noqa F405
  _SCREAMING_SNAKE_CASE		     =							'down'



  @property
  def        lowerCAmelCase__	(  self							:							str	) ->			Optional[Any]:




     """simple docstring"""
     return super().get_dummy_input(include_temb=_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							int	) ->			Dict:




     """simple docstring"""
     snake_case_            =       {
         "in_channels": 3_2,
         "out_channels": 3_2,
     }
     snake_case_            =       self.dummy_input
     return init_dict, inputs_dict



  def        lowerCAmelCase__	(  self							:							List[str]	) ->			Any:




     """simple docstring"""
     snake_case_            =       [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(_lowerCAmelCase	)






class      __lowerCAmelCase  (			a			,	unittest.TestCase       ):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE		     =							UNetMidBlockaD  # noqa F405
  _SCREAMING_SNAKE_CASE		     =							'mid'



  def        lowerCAmelCase__	(  self							:							Any	) ->			List[Any]:




     """simple docstring"""
     snake_case_            =       {
         "in_channels": 3_2,
         "temb_channels": 1_2_8,
     }
     snake_case_            =       self.dummy_input
     return init_dict, inputs_dict



  def        lowerCAmelCase__	(  self							:							Union[str, Any]	) ->			int:




     """simple docstring"""
     snake_case_            =       [-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(_lowerCAmelCase	)






class      __lowerCAmelCase  (			a			,	unittest.TestCase       ):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE		     =							UNetMidBlockaDCrossAttn  # noqa F405
  _SCREAMING_SNAKE_CASE		     =							'mid'



  def        lowerCAmelCase__	(  self							:							int	) ->			List[Any]:




     """simple docstring"""
     snake_case_     ,     snake_case_            =       super().prepare_init_args_and_inputs_for_common()
     snake_case_            =       3_2
     return init_dict, inputs_dict



  def        lowerCAmelCase__	(  self							:							Tuple	) ->			Any:




     """simple docstring"""
     snake_case_            =       [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(_lowerCAmelCase	)






class      __lowerCAmelCase  (			a			,	unittest.TestCase       ):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE		     =							UNetMidBlockaDSimpleCrossAttn  # noqa F405
  _SCREAMING_SNAKE_CASE		     =							'mid'



  @property
  def        lowerCAmelCase__	(  self							:							Tuple	) ->			Any:




     """simple docstring"""
     return super().get_dummy_input(include_encoder_hidden_states=_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							Optional[Any]	) ->			Union[str, Any]:




     """simple docstring"""
     snake_case_     ,     snake_case_            =       super().prepare_init_args_and_inputs_for_common()
     snake_case_            =       3_2
     return init_dict, inputs_dict



  def        lowerCAmelCase__	(  self							:							Union[str, Any]	) ->			Optional[Any]:




     """simple docstring"""
     snake_case_            =       [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(_lowerCAmelCase	)






class      __lowerCAmelCase  (			a			,	unittest.TestCase       ):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE		     =							UpBlockaD  # noqa F405
  _SCREAMING_SNAKE_CASE		     =							'up'



  @property
  def        lowerCAmelCase__	(  self							:							Dict	) ->			List[Any]:




     """simple docstring"""
     return super().get_dummy_input(include_res_hidden_states_tuple=_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							str	) ->			Any:




     """simple docstring"""
     snake_case_            =       [-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(_lowerCAmelCase	)






class      __lowerCAmelCase  (			a			,	unittest.TestCase       ):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE		     =							ResnetUpsampleBlockaD  # noqa F405
  _SCREAMING_SNAKE_CASE		     =							'up'



  @property
  def        lowerCAmelCase__	(  self							:							str	) ->			int:




     """simple docstring"""
     return super().get_dummy_input(include_res_hidden_states_tuple=_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							Any	) ->			Optional[Any]:




     """simple docstring"""
     snake_case_            =       [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(_lowerCAmelCase	)






class      __lowerCAmelCase  (			a			,	unittest.TestCase       ):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE		     =							CrossAttnUpBlockaD  # noqa F405
  _SCREAMING_SNAKE_CASE		     =							'up'



  @property
  def        lowerCAmelCase__	(  self							:							List[str]	) ->			List[str]:




     """simple docstring"""
     return super().get_dummy_input(include_res_hidden_states_tuple=_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							List[str]	) ->			Optional[Any]:




     """simple docstring"""
     snake_case_     ,     snake_case_            =       super().prepare_init_args_and_inputs_for_common()
     snake_case_            =       3_2
     return init_dict, inputs_dict



  def        lowerCAmelCase__	(  self							:							Union[str, Any]	) ->			List[Any]:




     """simple docstring"""
     snake_case_            =       [-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(_lowerCAmelCase	)






class      __lowerCAmelCase  (			a			,	unittest.TestCase       ):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE		     =							SimpleCrossAttnUpBlockaD  # noqa F405
  _SCREAMING_SNAKE_CASE		     =							'up'



  @property
  def        lowerCAmelCase__	(  self							:							int	) ->			List[Any]:




     """simple docstring"""
     return super().get_dummy_input(include_res_hidden_states_tuple=_lowerCAmelCase     ,					include_encoder_hidden_states=_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							Tuple	) ->			Any:




     """simple docstring"""
     snake_case_     ,     snake_case_            =       super().prepare_init_args_and_inputs_for_common()
     snake_case_            =       3_2
     return init_dict, inputs_dict



  def        lowerCAmelCase__	(  self							:							Union[str, Any]	) ->			Optional[int]:




     """simple docstring"""
     snake_case_            =       [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(_lowerCAmelCase	)






class      __lowerCAmelCase  (			a			,	unittest.TestCase       ):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE		     =							AttnUpBlockaD  # noqa F405
  _SCREAMING_SNAKE_CASE		     =							'up'



  @property
  def        lowerCAmelCase__	(  self							:							List[Any]	) ->			Tuple:




     """simple docstring"""
     return super().get_dummy_input(include_res_hidden_states_tuple=_lowerCAmelCase	)



  @unittest.skipIf(torch_device == "mps"     ,					"MPS result is not consistent"	)
  def        lowerCAmelCase__	(  self							:							List[Any]	) ->			Optional[int]:




     """simple docstring"""
     snake_case_            =       [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(_lowerCAmelCase	)






class      __lowerCAmelCase  (			a			,	unittest.TestCase       ):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE		     =							SkipUpBlockaD  # noqa F405
  _SCREAMING_SNAKE_CASE		     =							'up'



  @property
  def        lowerCAmelCase__	(  self							:							List[str]	) ->			str:




     """simple docstring"""
     return super().get_dummy_input(include_res_hidden_states_tuple=_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							Tuple	) ->			str:




     """simple docstring"""
     snake_case_            =       [-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(_lowerCAmelCase	)






class      __lowerCAmelCase  (			a			,	unittest.TestCase       ):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE		     =							AttnSkipUpBlockaD  # noqa F405
  _SCREAMING_SNAKE_CASE		     =							'up'



  @property
  def        lowerCAmelCase__	(  self							:							int	) ->			List[str]:




     """simple docstring"""
     return super().get_dummy_input(include_res_hidden_states_tuple=_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							Optional[int]	) ->			Dict:




     """simple docstring"""
     snake_case_            =       [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(_lowerCAmelCase	)






class      __lowerCAmelCase  (			a			,	unittest.TestCase       ):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE		     =							UpDecoderBlockaD  # noqa F405
  _SCREAMING_SNAKE_CASE		     =							'up'



  @property
  def        lowerCAmelCase__	(  self							:							Union[str, Any]	) ->			Optional[int]:




     """simple docstring"""
     return super().get_dummy_input(include_temb=_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							Any	) ->			Any:




     """simple docstring"""
     snake_case_            =       {"in_channels": 3_2, "out_channels": 3_2}

     snake_case_            =       self.dummy_input
     return init_dict, inputs_dict



  def        lowerCAmelCase__	(  self							:							str	) ->			List[str]:




     """simple docstring"""
     snake_case_            =       [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(_lowerCAmelCase	)






class      __lowerCAmelCase  (			a			,	unittest.TestCase       ):






  """simple docstring"""





  _SCREAMING_SNAKE_CASE		     =							AttnUpDecoderBlockaD  # noqa F405
  _SCREAMING_SNAKE_CASE		     =							'up'



  @property
  def        lowerCAmelCase__	(  self							:							Tuple	) ->			int:




     """simple docstring"""
     return super().get_dummy_input(include_temb=_lowerCAmelCase	)



  def        lowerCAmelCase__	(  self							:							int	) ->			Dict:




     """simple docstring"""
     snake_case_            =       {"in_channels": 3_2, "out_channels": 3_2}

     snake_case_            =       self.dummy_input
     return init_dict, inputs_dict



  def        lowerCAmelCase__	(  self							:							Optional[int]	) ->			Optional[int]:




     """simple docstring"""
     snake_case_            =       [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(_lowerCAmelCase	)




