






from __future__ import annotations

import inspect
import unittest
from math import floor

import numpy as np

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

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
   import tensorflow as tf

   from transformers import TFCvtForImageClassification, TFCvtModel
   from transformers.models.cvt.modeling_tf_cvt import TF_CVT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
   from PIL import Image

   from transformers import AutoImageProcessor







class 	_UpperCAmelCase  (  lowercase_		):




      """simple docstring"""



      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :int      							=				self.config_class(**self.inputs_dict		)
          self.parent.assertTrue(hasattr(_lowerCAmelCase    ,	"embed_dim"		)		)
          self.parent.assertTrue(hasattr(_lowerCAmelCase    ,	"num_heads"		)		)







class 	_UpperCAmelCase  :




      """simple docstring"""



      def __init__(   self    ,	_lowerCAmelCase    ,	_lowerCAmelCase=13    ,	_lowerCAmelCase=64    ,	_lowerCAmelCase=3    ,	_lowerCAmelCase=[16, 48, 96]    ,	_lowerCAmelCase=[1, 3, 6]    ,	_lowerCAmelCase=[1, 2, 10]    ,	_lowerCAmelCase=[7, 3, 3]    ,	_lowerCAmelCase=[4, 2, 2]    ,	_lowerCAmelCase=[2, 1, 1]    ,	_lowerCAmelCase=[2, 2, 2]    ,	_lowerCAmelCase=[False, False, True]    ,	_lowerCAmelCase=[0.0, 0.0, 0.0]    ,	_lowerCAmelCase=0.02    ,	_lowerCAmelCase=1e-12    ,	_lowerCAmelCase=True    ,	_lowerCAmelCase=True    ,	_lowerCAmelCase=2    ,	):



          '''simple docstring'''
          lowerCAmelCase__   :Optional[Any]      							=				parent
          lowerCAmelCase__   :Any      							=				batch_size
          lowerCAmelCase__   :List[str]      							=				image_size
          lowerCAmelCase__   :List[Any]      							=				patch_sizes
          lowerCAmelCase__   :Tuple      							=				patch_stride
          lowerCAmelCase__   :str      							=				patch_padding
          lowerCAmelCase__   :int      							=				is_training
          lowerCAmelCase__   :Optional[Any]      							=				use_labels
          lowerCAmelCase__   :Union[str, Any]      							=				num_labels
          lowerCAmelCase__   :Tuple      							=				num_channels
          lowerCAmelCase__   :int      							=				embed_dim
          lowerCAmelCase__   :List[str]      							=				num_heads
          lowerCAmelCase__   :List[str]      							=				stride_kv
          lowerCAmelCase__   :Optional[int]      							=				depth
          lowerCAmelCase__   :Dict      							=				cls_token
          lowerCAmelCase__   :List[Any]      							=				attention_drop_rate
          lowerCAmelCase__   :str      							=				initializer_range
          lowerCAmelCase__   :Tuple      							=				layer_norm_eps
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Optional[int]      							=				floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)

          lowerCAmelCase__   :Union[str, Any]      							=				None
          if self.use_labels:
              # create a random int32 tensor of given shape
              lowerCAmelCase__   :int      							=				ids_tensor([self.batch_size]    ,	self.num_labels		)

          lowerCAmelCase__   :Tuple      							=				self.get_config()
          return config, pixel_values, labels
      def 			snake_case_      (   self		):



          '''simple docstring'''
          return CvtConfig(
              image_size=self.image_size    ,	num_labels=self.num_labels    ,	num_channels=self.num_channels    ,	embed_dim=self.embed_dim    ,	num_heads=self.num_heads    ,	patch_sizes=self.patch_sizes    ,	patch_padding=self.patch_padding    ,	patch_stride=self.patch_stride    ,	stride_kv=self.stride_kv    ,	depth=self.depth    ,	cls_token=self.cls_token    ,	attention_drop_rate=self.attention_drop_rate    ,	initializer_range=self.initializer_range    ,	)
      def 			snake_case_      (   self    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase		):



          '''simple docstring'''
          lowerCAmelCase__   :str      							=				TFCvtModel(config=_lowerCAmelCase		)
          lowerCAmelCase__   :Tuple      							=				model(_lowerCAmelCase    ,	training=_lowerCAmelCase		)
          lowerCAmelCase__   :Optional[int]      							=				(self.image_size, self.image_size)
          lowerCAmelCase__							,lowerCAmelCase__   :List[Any]      							=				image_size[0], image_size[1]
          for i in range(len(self.depth		)		):
              lowerCAmelCase__   :Optional[Any]      							=				floor(((height + 2 * self.patch_padding[i] - self.patch_sizes[i]) / self.patch_stride[i]) + 1		)
              lowerCAmelCase__   :str      							=				floor(((width + 2 * self.patch_padding[i] - self.patch_sizes[i]) / self.patch_stride[i]) + 1		)
          self.parent.assertEqual(result.last_hidden_state.shape    ,	(self.batch_size, self.embed_dim[-1], height, width)		)
      def 			snake_case_      (   self    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase		):



          '''simple docstring'''
          lowerCAmelCase__   :Tuple      							=				self.num_labels
          lowerCAmelCase__   :List[Any]      							=				TFCvtForImageClassification(_lowerCAmelCase		)
          lowerCAmelCase__   :List[Any]      							=				model(_lowerCAmelCase    ,	labels=_lowerCAmelCase    ,	training=_lowerCAmelCase		)
          self.parent.assertEqual(result.logits.shape    ,	(self.batch_size, self.num_labels)		)



      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Tuple      							=				self.prepare_config_and_inputs()
          lowerCAmelCase__							,lowerCAmelCase__							,lowerCAmelCase__   :Dict      							=				config_and_inputs
          lowerCAmelCase__   :Optional[int]      							=				{"pixel_values": pixel_values}
          return config, inputs_dict







@require_tf
class 	_UpperCAmelCase  (  lowercase_				,							lowercase_				,							unittest.TestCase		):




      """simple docstring"""



      A          =    (TFCvtModel, TFCvtForImageClassification) if is_tf_available() else ()
      A          =    (
          {'''feature-extraction''': TFCvtModel, '''image-classification''': TFCvtForImageClassification}
          if is_tf_available()
          else {}
      )
      A          =    False
      A          =    False
      A          =    False
      A          =    False
      A          =    False
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Union[str, Any]      							=				TFCvtModelTester(self		)
          lowerCAmelCase__   :Optional[Any]      							=				TFCvtConfigTester(self    ,	config_class=_lowerCAmelCase    ,	has_text_modality=_lowerCAmelCase    ,	hidden_size=37		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          self.config_tester.create_and_test_config_common_properties()
          self.config_tester.create_and_test_config_to_json_string()
          self.config_tester.create_and_test_config_to_json_file()
          self.config_tester.create_and_test_config_from_and_save_pretrained()
          self.config_tester.create_and_test_config_with_num_labels()
          self.config_tester.check_config_can_be_init_without_params()
          self.config_tester.check_config_arguments_init()
      @unittest.skip(reason="Cvt does not output attentions"		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          pass
      @unittest.skip(reason="Cvt does not use inputs_embeds"		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          pass
      @unittest.skip(reason="Cvt does not support input and output embeddings"		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          pass
      @unittest.skipIf(
          not is_tf_available() or len(tf.config.list_physical_devices("GPU"		)		) == 0    ,	reason="TF does not support backprop for grouped convolutions on CPU."    ,	)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          super().test_dataset_conversion()
      @unittest.skipIf(
          not is_tf_available() or len(tf.config.list_physical_devices("GPU"		)		) == 0    ,	reason="TF does not support backprop for grouped convolutions on CPU."    ,	)
      @slow
      def 			snake_case_      (   self		):



          '''simple docstring'''
          super().test_keras_fit()
      @unittest.skip(reason="Get `Failed to determine best cudnn convolution algo.` error after using TF 2.12+cuda 11.8"		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Union[str, Any]      							=				tf.keras.mixed_precision.Policy("mixed_float16"		)
          tf.keras.mixed_precision.set_global_policy(_lowerCAmelCase		)
          super().test_keras_fit()
          tf.keras.mixed_precision.set_global_policy("float32"		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__							,lowerCAmelCase__   :Any      							=				self.model_tester.prepare_config_and_inputs_for_common()

          for model_class in self.all_model_classes:
              lowerCAmelCase__   :Tuple      							=				model_class(_lowerCAmelCase		)
              lowerCAmelCase__   :Dict      							=				inspect.signature(model.call		)
              # signature.parameters is an OrderedDict => so arg_names order is deterministic
              lowerCAmelCase__   :List[Any]      							=				[*signature.parameters.keys()]

              lowerCAmelCase__   :Union[str, Any]      							=				["pixel_values"]
              self.assertListEqual(arg_names[:1]    ,	_lowerCAmelCase		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          def check_hidden_states_output(_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase		):
              lowerCAmelCase__   :str      							=				model_class(_lowerCAmelCase		)

              lowerCAmelCase__   :List[Any]      							=				model(**self._prepare_for_class(_lowerCAmelCase    ,	_lowerCAmelCase		)		)
              lowerCAmelCase__   :Dict      							=				outputs.hidden_states

              lowerCAmelCase__   :Optional[Any]      							=				len(self.model_tester.depth		)
              self.assertEqual(len(_lowerCAmelCase		)    ,	_lowerCAmelCase		)

              # verify the first hidden states (first block)
              self.assertListEqual(
                  list(hidden_states[0].shape[-3:]		)    ,	[
                      self.model_tester.embed_dim[0],
                      self.model_tester.image_size // 4,
                      self.model_tester.image_size // 4,
                  ]    ,	)

          lowerCAmelCase__							,lowerCAmelCase__   :Any      							=				self.model_tester.prepare_config_and_inputs_for_common()

          for model_class in self.all_model_classes:
              lowerCAmelCase__   :List[str]      							=				True
              check_hidden_states_output(_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase		)

              # check that output_hidden_states also work using config
              del inputs_dict["output_hidden_states"]
              lowerCAmelCase__   :Optional[Any]      							=				True

              check_hidden_states_output(_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :str      							=				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*_lowerCAmelCase		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Tuple      							=				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_image_classification(*_lowerCAmelCase		)



      @slow
      def 			snake_case_      (   self		):



          '''simple docstring'''
          for model_name in TF_CVT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              lowerCAmelCase__   :str      							=				TFCvtModel.from_pretrained(_lowerCAmelCase		)
              self.assertIsNotNone(_lowerCAmelCase		)





def 				snake_case__							(							):
    lowerCAmelCase__   :List[str]      							=				Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"       )
    return image







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




      """simple docstring"""



      @cached_property
      def 			snake_case_      (   self		):



          '''simple docstring'''
          return AutoImageProcessor.from_pretrained(TF_CVT_PRETRAINED_MODEL_ARCHIVE_LIST[0]		)



      @slow
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :int      							=				TFCvtForImageClassification.from_pretrained(TF_CVT_PRETRAINED_MODEL_ARCHIVE_LIST[0]		)

          lowerCAmelCase__   :Tuple      							=				self.default_image_processor
          lowerCAmelCase__   :List[Any]      							=				prepare_img()
          lowerCAmelCase__   :List[str]      							=				image_processor(images=_lowerCAmelCase    ,	return_tensors="tf"		)

          # forward pass
          lowerCAmelCase__   :int      							=				model(**_lowerCAmelCase		)

          # verify the logits
          lowerCAmelCase__   :List[Any]      							=				tf.TensorShape((1, 1_000)		)
          self.assertEqual(outputs.logits.shape    ,	_lowerCAmelCase		)

          lowerCAmelCase__   :str      							=				tf.constant([0.9285, 0.9015, -0.3150]		)
          self.assertTrue(np.allclose(outputs.logits[0, :3].numpy()    ,	_lowerCAmelCase    ,	atol=1e-4		)		)











import tempfile

import numpy as np
import torch
from transformers import AutoTokenizer, TaEncoderModel

from diffusers import DDPMScheduler, UNetaDConditionModel
from diffusers.models.attention_processor import AttnAddedKVProcessor
from diffusers.pipelines.deepfloyd_if import IFWatermarker
from diffusers.utils.testing_utils import torch_device

from ..test_pipelines_common import to_np







class 	_UpperCAmelCase  :




      """simple docstring"""



      def 			snake_case_      (   self		):



          '''simple docstring'''
          torch.manual_seed(0		)
          lowerCAmelCase__   :List[str]      							=				TaEncoderModel.from_pretrained("hf-internal-testing/tiny-random-t5"		)

          torch.manual_seed(0		)
          lowerCAmelCase__   :List[Any]      							=				AutoTokenizer.from_pretrained("hf-internal-testing/tiny-random-t5"		)

          torch.manual_seed(0		)
          lowerCAmelCase__   :Tuple      							=				UNetaDConditionModel(
              sample_size=32    ,	layers_per_block=1    ,	block_out_channels=[32, 64]    ,	down_block_types=[
                  "ResnetDownsampleBlock2D",
                  "SimpleCrossAttnDownBlock2D",
              ]    ,	mid_block_type="UNetMidBlock2DSimpleCrossAttn"    ,	up_block_types=["SimpleCrossAttnUpBlock2D", "ResnetUpsampleBlock2D"]    ,	in_channels=3    ,	out_channels=6    ,	cross_attention_dim=32    ,	encoder_hid_dim=32    ,	attention_head_dim=8    ,	addition_embed_type="text"    ,	addition_embed_type_num_heads=2    ,	cross_attention_norm="group_norm"    ,	resnet_time_scale_shift="scale_shift"    ,	act_fn="gelu"    ,	)
          unet.set_attn_processor(AttnAddedKVProcessor()		)  # For reproducibility tests

          torch.manual_seed(0		)
          lowerCAmelCase__   :Dict      							=				DDPMScheduler(
              num_train_timesteps=1_000    ,	beta_schedule="squaredcos_cap_v2"    ,	beta_start=0.0001    ,	beta_end=0.02    ,	thresholding=_lowerCAmelCase    ,	dynamic_thresholding_ratio=0.95    ,	sample_max_value=1.0    ,	prediction_type="epsilon"    ,	variance_type="learned_range"    ,	)

          torch.manual_seed(0		)
          lowerCAmelCase__   :List[str]      							=				IFWatermarker()

          return {
              "text_encoder": text_encoder,
              "tokenizer": tokenizer,
              "unet": unet,
              "scheduler": scheduler,
              "watermarker": watermarker,
              "safety_checker": None,
              "feature_extractor": None,
          }
      def 			snake_case_      (   self		):



          '''simple docstring'''
          torch.manual_seed(0		)
          lowerCAmelCase__   :int      							=				TaEncoderModel.from_pretrained("hf-internal-testing/tiny-random-t5"		)

          torch.manual_seed(0		)
          lowerCAmelCase__   :Dict      							=				AutoTokenizer.from_pretrained("hf-internal-testing/tiny-random-t5"		)

          torch.manual_seed(0		)
          lowerCAmelCase__   :Union[str, Any]      							=				UNetaDConditionModel(
              sample_size=32    ,	layers_per_block=[1, 2]    ,	block_out_channels=[32, 64]    ,	down_block_types=[
                  "ResnetDownsampleBlock2D",
                  "SimpleCrossAttnDownBlock2D",
              ]    ,	mid_block_type="UNetMidBlock2DSimpleCrossAttn"    ,	up_block_types=["SimpleCrossAttnUpBlock2D", "ResnetUpsampleBlock2D"]    ,	in_channels=6    ,	out_channels=6    ,	cross_attention_dim=32    ,	encoder_hid_dim=32    ,	attention_head_dim=8    ,	addition_embed_type="text"    ,	addition_embed_type_num_heads=2    ,	cross_attention_norm="group_norm"    ,	resnet_time_scale_shift="scale_shift"    ,	act_fn="gelu"    ,	class_embed_type="timestep"    ,	mid_block_scale_factor=1.414    ,	time_embedding_act_fn="gelu"    ,	time_embedding_dim=32    ,	)
          unet.set_attn_processor(AttnAddedKVProcessor()		)  # For reproducibility tests

          torch.manual_seed(0		)
          lowerCAmelCase__   :Tuple      							=				DDPMScheduler(
              num_train_timesteps=1_000    ,	beta_schedule="squaredcos_cap_v2"    ,	beta_start=0.0001    ,	beta_end=0.02    ,	thresholding=_lowerCAmelCase    ,	dynamic_thresholding_ratio=0.95    ,	sample_max_value=1.0    ,	prediction_type="epsilon"    ,	variance_type="learned_range"    ,	)

          torch.manual_seed(0		)
          lowerCAmelCase__   :str      							=				DDPMScheduler(
              num_train_timesteps=1_000    ,	beta_schedule="squaredcos_cap_v2"    ,	beta_start=0.0001    ,	beta_end=0.02    ,	)

          torch.manual_seed(0		)
          lowerCAmelCase__   :List[str]      							=				IFWatermarker()

          return {
              "text_encoder": text_encoder,
              "tokenizer": tokenizer,
              "unet": unet,
              "scheduler": scheduler,
              "image_noising_scheduler": image_noising_scheduler,
              "watermarker": watermarker,
              "safety_checker": None,
              "feature_extractor": None,
          }
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Optional[Any]      							=				self.get_dummy_components()
          lowerCAmelCase__   :Any      							=				self.pipeline_class(**_lowerCAmelCase		)
          pipe.to(_lowerCAmelCase		)
          pipe.set_progress_bar_config(disable=_lowerCAmelCase		)

          lowerCAmelCase__   :int      							=				self.get_dummy_inputs(_lowerCAmelCase		)

          lowerCAmelCase__   :Optional[int]      							=				inputs["prompt"]
          lowerCAmelCase__   :Tuple      							=				inputs["generator"]
          lowerCAmelCase__   :List[Any]      							=				inputs["num_inference_steps"]
          lowerCAmelCase__   :Tuple      							=				inputs["output_type"]

          if "image" in inputs:
              lowerCAmelCase__   :Dict      							=				inputs["image"]
          else:
              lowerCAmelCase__   :Union[str, Any]      							=				None

          if "mask_image" in inputs:
              lowerCAmelCase__   :int      							=				inputs["mask_image"]
          else:
              lowerCAmelCase__   :str      							=				None

          if "original_image" in inputs:
              lowerCAmelCase__   :List[Any]      							=				inputs["original_image"]
          else:
              lowerCAmelCase__   :Dict      							=				None

          lowerCAmelCase__							,lowerCAmelCase__   :int      							=				pipe.encode_prompt(_lowerCAmelCase		)

          # inputs with prompt converted to embeddings
          lowerCAmelCase__   :Optional[Any]      							=				{
              "prompt_embeds": prompt_embeds,
              "negative_prompt_embeds": negative_prompt_embeds,
              "generator": generator,
              "num_inference_steps": num_inference_steps,
              "output_type": output_type,
          }

          if image is not None:
              lowerCAmelCase__   :List[Any]      							=				image

          if mask_image is not None:
              lowerCAmelCase__   :Any      							=				mask_image

          if original_image is not None:
              lowerCAmelCase__   :Tuple      							=				original_image

          # set all optional components to None
          for optional_component in pipe._optional_components:
              setattr(_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase		)

          lowerCAmelCase__   :Optional[int]      							=				pipe(**_lowerCAmelCase		)[0]

          with tempfile.TemporaryDirectory() as tmpdir:
              pipe.save_pretrained(_lowerCAmelCase		)
              lowerCAmelCase__   :str      							=				self.pipeline_class.from_pretrained(_lowerCAmelCase		)
              pipe_loaded.to(_lowerCAmelCase		)
              pipe_loaded.set_progress_bar_config(disable=_lowerCAmelCase		)

          pipe_loaded.unet.set_attn_processor(AttnAddedKVProcessor()		)  # For reproducibility tests

          for optional_component in pipe._optional_components:
              self.assertTrue(
                  getattr(_lowerCAmelCase    ,	_lowerCAmelCase		) is None    ,	f'''`{optional_component}` did not stay set to None after loading.'''    ,	)

          lowerCAmelCase__   :Any      							=				self.get_dummy_inputs(_lowerCAmelCase		)

          lowerCAmelCase__   :Tuple      							=				inputs["generator"]
          lowerCAmelCase__   :Union[str, Any]      							=				inputs["num_inference_steps"]
          lowerCAmelCase__   :str      							=				inputs["output_type"]

          # inputs with prompt converted to embeddings
          lowerCAmelCase__   :Union[str, Any]      							=				{
              "prompt_embeds": prompt_embeds,
              "negative_prompt_embeds": negative_prompt_embeds,
              "generator": generator,
              "num_inference_steps": num_inference_steps,
              "output_type": output_type,
          }

          if image is not None:
              lowerCAmelCase__   :Tuple      							=				image

          if mask_image is not None:
              lowerCAmelCase__   :str      							=				mask_image

          if original_image is not None:
              lowerCAmelCase__   :Union[str, Any]      							=				original_image

          lowerCAmelCase__   :List[Any]      							=				pipe_loaded(**_lowerCAmelCase		)[0]

          lowerCAmelCase__   :Dict      							=				np.abs(to_np(_lowerCAmelCase		) - to_np(_lowerCAmelCase		)		).max()
          self.assertLess(_lowerCAmelCase    ,	1e-4		)



      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Tuple      							=				self.get_dummy_components()
          lowerCAmelCase__   :Optional[int]      							=				self.pipeline_class(**_lowerCAmelCase		)
          pipe.to(_lowerCAmelCase		)
          pipe.set_progress_bar_config(disable=_lowerCAmelCase		)

          lowerCAmelCase__   :Optional[int]      							=				self.get_dummy_inputs(_lowerCAmelCase		)
          lowerCAmelCase__   :List[str]      							=				pipe(**_lowerCAmelCase		)[0]

          with tempfile.TemporaryDirectory() as tmpdir:
              pipe.save_pretrained(_lowerCAmelCase		)
              lowerCAmelCase__   :Dict      							=				self.pipeline_class.from_pretrained(_lowerCAmelCase		)
              pipe_loaded.to(_lowerCAmelCase		)
              pipe_loaded.set_progress_bar_config(disable=_lowerCAmelCase		)

          pipe_loaded.unet.set_attn_processor(AttnAddedKVProcessor()		)  # For reproducibility tests

          lowerCAmelCase__   :Optional[int]      							=				self.get_dummy_inputs(_lowerCAmelCase		)
          lowerCAmelCase__   :List[Any]      							=				pipe_loaded(**_lowerCAmelCase		)[0]

          lowerCAmelCase__   :str      							=				np.abs(to_np(_lowerCAmelCase		) - to_np(_lowerCAmelCase		)		).max()
          self.assertLess(_lowerCAmelCase    ,	1e-4		)



