"""simple docstring"""






from __future__ import annotations

import unittest

from transformers import MobileBertConfig, is_tf_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_tf, slow

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


if is_tf_available():
       import tensorflow as tf

       from transformers import (
           TF_MODEL_FOR_PRETRAINING_MAPPING,
           TFMobileBertForMaskedLM,
           TFMobileBertForMultipleChoice,
           TFMobileBertForNextSentencePrediction,
           TFMobileBertForPreTraining,
           TFMobileBertForQuestionAnswering,
           TFMobileBertForSequenceClassification,
           TFMobileBertForTokenClassification,
           TFMobileBertModel,
       )





@require_tf
class  _A						(       lowerCAmelCase  ,    lowerCAmelCase  ,    unittest.TestCase	):
      snake_case__			:   Any							  =	(
          (
              TFMobileBertModel,
              TFMobileBertForMaskedLM,
              TFMobileBertForNextSentencePrediction,
              TFMobileBertForPreTraining,
              TFMobileBertForQuestionAnswering,
              TFMobileBertForSequenceClassification,
              TFMobileBertForTokenClassification,
              TFMobileBertForMultipleChoice,
          )
          if is_tf_available()
          else ()
      )
      snake_case__			:   Optional[int]							  =	(
          {
              'feature-extraction': TFMobileBertModel,
              'fill-mask': TFMobileBertForMaskedLM,
              'question-answering': TFMobileBertForQuestionAnswering,
              'text-classification': TFMobileBertForSequenceClassification,
              'token-classification': TFMobileBertForTokenClassification,
              'zero-shot': TFMobileBertForSequenceClassification,
          }
          if is_tf_available()
          else {}
      )
      snake_case__			:   str							  =	False
      snake_case__			:   List[str]							  =	False

      def 				A__       (						self		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase=False						):







            """simple docstring"""



            lowercase														=	super()._prepare_for_class(__lowerCAmelCase		,       __lowerCAmelCase		,       return_labels=__lowerCAmelCase						)

            if return_labels:
                  if model_class in get_values(__lowerCAmelCase						):
                        lowercase														=	tf.zeros(self.model_tester.batch_size		,       dtype=tf.intaa						)

            return inputs_dict





      class  _A						(       lowerCAmelCase	):

            def __init__(						self		,       __lowerCAmelCase		,       __lowerCAmelCase=13		,       __lowerCAmelCase=7		,       __lowerCAmelCase=True		,       __lowerCAmelCase=True		,       __lowerCAmelCase=True		,       __lowerCAmelCase=True		,       __lowerCAmelCase=99		,       __lowerCAmelCase=32		,       __lowerCAmelCase=32		,       __lowerCAmelCase=2		,       __lowerCAmelCase=4		,       __lowerCAmelCase=37		,       __lowerCAmelCase="gelu"		,       __lowerCAmelCase=0.1		,       __lowerCAmelCase=0.1		,       __lowerCAmelCase=512		,       __lowerCAmelCase=16		,       __lowerCAmelCase=2		,       __lowerCAmelCase=0.0_2		,       __lowerCAmelCase=3		,       __lowerCAmelCase=4		,       __lowerCAmelCase=None		,       ):







                  """simple docstring"""



                  lowercase														=	parent
                  lowercase														=	batch_size
                  lowercase														=	seq_length
                  lowercase														=	is_training
                  lowercase														=	use_input_mask
                  lowercase														=	use_token_type_ids
                  lowercase														=	use_labels
                  lowercase														=	vocab_size
                  lowercase														=	hidden_size
                  lowercase														=	num_hidden_layers
                  lowercase														=	num_attention_heads
                  lowercase														=	intermediate_size
                  lowercase														=	hidden_act
                  lowercase														=	hidden_dropout_prob
                  lowercase														=	attention_probs_dropout_prob
                  lowercase														=	max_position_embeddings
                  lowercase														=	type_vocab_size
                  lowercase														=	type_sequence_label_size
                  lowercase														=	initializer_range
                  lowercase														=	num_labels
                  lowercase														=	num_choices
                  lowercase														=	scope
                  lowercase														=	embedding_size

            def 				A__       (						self						):







                  """simple docstring"""



                  lowercase														=	ids_tensor([self.batch_size, self.seq_length]		,       self.vocab_size						)

                  lowercase														=	None
                  if self.use_input_mask:
                        lowercase														=	random_attention_mask([self.batch_size, self.seq_length]						)

                  lowercase														=	None
                  if self.use_token_type_ids:
                        lowercase														=	ids_tensor([self.batch_size, self.seq_length]		,       self.type_vocab_size						)

                  lowercase														=	None
                  lowercase														=	None
                  lowercase														=	None
                  if self.use_labels:
                        lowercase														=	ids_tensor([self.batch_size]		,       self.type_sequence_label_size						)
                        lowercase														=	ids_tensor([self.batch_size, self.seq_length]		,       self.num_labels						)
                        lowercase														=	ids_tensor([self.batch_size]		,       self.num_choices						)

                  lowercase														=	MobileBertConfig(
                      vocab_size=self.vocab_size		,       hidden_size=self.hidden_size		,       num_hidden_layers=self.num_hidden_layers		,       num_attention_heads=self.num_attention_heads		,       intermediate_size=self.intermediate_size		,       hidden_act=self.hidden_act		,       hidden_dropout_prob=self.hidden_dropout_prob		,       attention_probs_dropout_prob=self.attention_probs_dropout_prob		,       max_position_embeddings=self.max_position_embeddings		,       type_vocab_size=self.type_vocab_size		,       initializer_range=self.initializer_range		,       embedding_size=self.embedding_size		,       )

                  return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels

            def 				A__       (						self		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase						):







                  """simple docstring"""



                  lowercase														=	TFMobileBertModel(config=__lowerCAmelCase						)
                  lowercase														=	{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
                  lowercase														=	model(__lowerCAmelCase						)

                  lowercase														=	[input_ids, input_mask]
                  lowercase														=	model(__lowerCAmelCase						)

                  lowercase														=	model(__lowerCAmelCase						)

                  self.parent.assertEqual(
                      result.last_hidden_state.shape		,       (self.batch_size, self.seq_length, self.hidden_size)						)
                  self.parent.assertEqual(result.pooler_output.shape		,       (self.batch_size, self.hidden_size)						)

            def 				A__       (						self		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase						):







                  """simple docstring"""



                  lowercase														=	TFMobileBertForMaskedLM(config=__lowerCAmelCase						)
                  lowercase														=	{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
                  lowercase														=	model(__lowerCAmelCase						)
                  self.parent.assertEqual(result.logits.shape		,       (self.batch_size, self.seq_length, self.vocab_size)						)

            def 				A__       (						self		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase						):







                  """simple docstring"""



                  lowercase														=	TFMobileBertForNextSentencePrediction(config=__lowerCAmelCase						)
                  lowercase														=	{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
                  lowercase														=	model(__lowerCAmelCase						)
                  self.parent.assertEqual(result.logits.shape		,       (self.batch_size, 2)						)

            def 				A__       (						self		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase						):







                  """simple docstring"""



                  lowercase														=	TFMobileBertForPreTraining(config=__lowerCAmelCase						)
                  lowercase														=	{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
                  lowercase														=	model(__lowerCAmelCase						)
                  self.parent.assertEqual(
                      result.prediction_logits.shape		,       (self.batch_size, self.seq_length, self.vocab_size)						)
                  self.parent.assertEqual(result.seq_relationship_logits.shape		,       (self.batch_size, 2)						)

            def 				A__       (						self		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase						):







                  """simple docstring"""



                  lowercase														=	self.num_labels
                  lowercase														=	TFMobileBertForSequenceClassification(config=__lowerCAmelCase						)
                  lowercase														=	{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
                  lowercase														=	model(__lowerCAmelCase						)
                  self.parent.assertEqual(result.logits.shape		,       (self.batch_size, self.num_labels)						)

            def 				A__       (						self		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase						):







                  """simple docstring"""



                  lowercase														=	self.num_choices
                  lowercase														=	TFMobileBertForMultipleChoice(config=__lowerCAmelCase						)
                  lowercase														=	tf.tile(tf.expand_dims(__lowerCAmelCase		,       1						)		,       (1, self.num_choices, 1)						)
                  lowercase														=	tf.tile(tf.expand_dims(__lowerCAmelCase		,       1						)		,       (1, self.num_choices, 1)						)
                  lowercase														=	tf.tile(tf.expand_dims(__lowerCAmelCase		,       1						)		,       (1, self.num_choices, 1)						)
                  lowercase														=	{
                      """input_ids""": multiple_choice_inputs_ids,
                      """attention_mask""": multiple_choice_input_mask,
                      """token_type_ids""": multiple_choice_token_type_ids,
                  }
                  lowercase														=	model(__lowerCAmelCase						)
                  self.parent.assertEqual(result.logits.shape		,       (self.batch_size, self.num_choices)						)

            def 				A__       (						self		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase						):







                  """simple docstring"""



                  lowercase														=	self.num_labels
                  lowercase														=	TFMobileBertForTokenClassification(config=__lowerCAmelCase						)
                  lowercase														=	{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
                  lowercase														=	model(__lowerCAmelCase						)
                  self.parent.assertEqual(result.logits.shape		,       (self.batch_size, self.seq_length, self.num_labels)						)

            def 				A__       (						self		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase						):







                  """simple docstring"""



                  lowercase														=	TFMobileBertForQuestionAnswering(config=__lowerCAmelCase						)
                  lowercase														=	{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
                  lowercase														=	model(__lowerCAmelCase						)
                  self.parent.assertEqual(result.start_logits.shape		,       (self.batch_size, self.seq_length)						)
                  self.parent.assertEqual(result.end_logits.shape		,       (self.batch_size, self.seq_length)						)







            def 				A__       (						self						):







                  """simple docstring"""



                  lowercase														=	self.prepare_config_and_inputs()
                  (
                      (
                      lowercase
                  )							,							(
                      lowercase
                  )							,							(
                      lowercase
                  )							,							(
                      lowercase
                  )							,							(
                      lowercase
                  )							,							(
                      lowercase
                  )							,							(
                      lowercase
                  )							,							
                  )														=	config_and_inputs
                  lowercase														=	{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
                  return config, inputs_dict






      def 				A__       (						self						):







            """simple docstring"""



            lowercase														=	TFMobileBertModelTest.TFMobileBertModelTester(self						)
            lowercase														=	ConfigTester(self		,       config_class=__lowerCAmelCase		,       hidden_size=37						)

      def 				A__       (						self						):







            """simple docstring"""



            self.config_tester.run_common_tests()

      def 				A__       (						self						):







            """simple docstring"""



            lowercase														=	self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_mobilebert_model(*__lowerCAmelCase						)

      def 				A__       (						self						):







            """simple docstring"""



            lowercase														=	self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_mobilebert_for_masked_lm(*__lowerCAmelCase						)

      def 				A__       (						self						):







            """simple docstring"""



            lowercase														=	self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_mobilebert_for_multiple_choice(*__lowerCAmelCase						)

      def 				A__       (						self						):







            """simple docstring"""



            lowercase														=	self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*__lowerCAmelCase						)

      def 				A__       (						self						):







            """simple docstring"""



            lowercase														=	self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_mobilebert_for_pretraining(*__lowerCAmelCase						)

      def 				A__       (						self						):







            """simple docstring"""



            lowercase														=	self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_mobilebert_for_question_answering(*__lowerCAmelCase						)

      def 				A__       (						self						):







            """simple docstring"""



            lowercase														=	self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_mobilebert_for_sequence_classification(*__lowerCAmelCase						)

      def 				A__       (						self						):







            """simple docstring"""



            lowercase														=	self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_mobilebert_for_token_classification(*__lowerCAmelCase						)







      @slow
      def 				A__       (						self						):







            """simple docstring"""



            for model_name in ["google/mobilebert-uncased"]:
                  lowercase														=	TFMobileBertModel.from_pretrained(__lowerCAmelCase						)
                  self.assertIsNotNone(__lowerCAmelCase						)






@require_tf
class  _A						(       unittest.TestCase	):

      @slow
      def 				A__       (						self						):







            """simple docstring"""



            lowercase														=	TFMobileBertForPreTraining.from_pretrained("""google/mobilebert-uncased"""						)
            lowercase														=	tf.constant([[0, 1, 2, 3, 4, 5]]						)
            lowercase														=	model(__lowerCAmelCase						)[0]

            lowercase														=	[1, 6, 3_0522]
            self.assertEqual(output.shape		,       __lowerCAmelCase						)

            lowercase														=	tf.constant(
                [
                    [
                        [-4.5_9_1_9_5_4_7, -9.2_4_8_2_9_5, -9.6_4_5_2_5_6],
                        [-6.7_3_0_6_1_7_5, -6.4_4_0_2_8_4, -6.6_0_5_2_8_3_7],
                        [-7.2_7_4_3_5_0_6, -6.7_8_4_7_9_1_5, -6.0_2_4_6_7_3],
                    ]
                ]						)
            tf.debugging.assert_near(output[:, :3, :3]		,       __lowerCAmelCase		,       atol=1E-4						)




"""simple docstring"""






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  _A						:

      def 				A__       (						self						):







            """simple docstring"""



            torch.manual_seed(0						)
            lowercase														=	TaEncoderModel.from_pretrained("""hf-internal-testing/tiny-random-t5"""						)

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

            torch.manual_seed(0						)
            lowercase														=	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						)
            lowercase														=	DDPMScheduler(
                num_train_timesteps=1000		,       beta_schedule="""squaredcos_cap_v2"""		,       beta_start=0.0_0_0_1		,       beta_end=0.0_2		,       thresholding=__lowerCAmelCase		,       dynamic_thresholding_ratio=0.9_5		,       sample_max_value=1.0		,       prediction_type="""epsilon"""		,       variance_type="""learned_range"""		,       )

            torch.manual_seed(0						)
            lowercase														=	IFWatermarker()

            return {
                "text_encoder": text_encoder,
                "tokenizer": tokenizer,
                "unet": unet,
                "scheduler": scheduler,
                "watermarker": watermarker,
                "safety_checker": None,
                "feature_extractor": None,
            }

      def 				A__       (						self						):







            """simple docstring"""



            torch.manual_seed(0						)
            lowercase														=	TaEncoderModel.from_pretrained("""hf-internal-testing/tiny-random-t5"""						)

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

            torch.manual_seed(0						)
            lowercase														=	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.4_1_4		,       time_embedding_act_fn="""gelu"""		,       time_embedding_dim=32		,       )
            unet.set_attn_processor(AttnAddedKVProcessor()						)  # For reproducibility tests

            torch.manual_seed(0						)
            lowercase														=	DDPMScheduler(
                num_train_timesteps=1000		,       beta_schedule="""squaredcos_cap_v2"""		,       beta_start=0.0_0_0_1		,       beta_end=0.0_2		,       thresholding=__lowerCAmelCase		,       dynamic_thresholding_ratio=0.9_5		,       sample_max_value=1.0		,       prediction_type="""epsilon"""		,       variance_type="""learned_range"""		,       )

            torch.manual_seed(0						)
            lowercase														=	DDPMScheduler(
                num_train_timesteps=1000		,       beta_schedule="""squaredcos_cap_v2"""		,       beta_start=0.0_0_0_1		,       beta_end=0.0_2		,       )

            torch.manual_seed(0						)
            lowercase														=	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 				A__       (						self						):







            """simple docstring"""



            lowercase														=	self.get_dummy_components()
            lowercase														=	self.pipeline_class(**__lowerCAmelCase						)
            pipe.to(__lowerCAmelCase						)
            pipe.set_progress_bar_config(disable=__lowerCAmelCase						)

            lowercase														=	self.get_dummy_inputs(__lowerCAmelCase						)

            lowercase														=	inputs["""prompt"""]
            lowercase														=	inputs["""generator"""]
            lowercase														=	inputs["""num_inference_steps"""]
            lowercase														=	inputs["""output_type"""]

            if "image" in inputs:
                  lowercase														=	inputs["""image"""]
            else:
                  lowercase														=	None

            if "mask_image" in inputs:
                  lowercase														=	inputs["""mask_image"""]
            else:
                  lowercase														=	None

            if "original_image" in inputs:
                  lowercase														=	inputs["""original_image"""]
            else:
                  lowercase														=	None

            lowercase							,							lowercase														=	pipe.encode_prompt(__lowerCAmelCase						)

            # inputs with prompt converted to embeddings
            lowercase														=	{
                """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:
                  lowercase														=	image

            if mask_image is not None:
                  lowercase														=	mask_image

            if original_image is not None:
                  lowercase														=	original_image

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

            lowercase														=	pipe(**__lowerCAmelCase						)[0]

            with tempfile.TemporaryDirectory() as tmpdir:
                  pipe.save_pretrained(__lowerCAmelCase						)
                  lowercase														=	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.'		,       )

            lowercase														=	self.get_dummy_inputs(__lowerCAmelCase						)

            lowercase														=	inputs["""generator"""]
            lowercase														=	inputs["""num_inference_steps"""]
            lowercase														=	inputs["""output_type"""]

            # inputs with prompt converted to embeddings
            lowercase														=	{
                """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:
                  lowercase														=	image

            if mask_image is not None:
                  lowercase														=	mask_image

            if original_image is not None:
                  lowercase														=	original_image

            lowercase														=	pipe_loaded(**__lowerCAmelCase						)[0]

            lowercase														=	np.abs(to_np(__lowerCAmelCase						) - to_np(__lowerCAmelCase						)						).max()
            self.assertLess(__lowerCAmelCase		,       1E-4						)







      def 				A__       (						self						):







            """simple docstring"""



            lowercase														=	self.get_dummy_components()
            lowercase														=	self.pipeline_class(**__lowerCAmelCase						)
            pipe.to(__lowerCAmelCase						)
            pipe.set_progress_bar_config(disable=__lowerCAmelCase						)

            lowercase														=	self.get_dummy_inputs(__lowerCAmelCase						)
            lowercase														=	pipe(**__lowerCAmelCase						)[0]

            with tempfile.TemporaryDirectory() as tmpdir:
                  pipe.save_pretrained(__lowerCAmelCase						)
                  lowercase														=	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

            lowercase														=	self.get_dummy_inputs(__lowerCAmelCase						)
            lowercase														=	pipe_loaded(**__lowerCAmelCase						)[0]

            lowercase														=	np.abs(to_np(__lowerCAmelCase						) - to_np(__lowerCAmelCase						)						).max()
            self.assertLess(__lowerCAmelCase		,       1E-4						)



