"""simple docstring"""





import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
       import torch

       from transformers import (
           RemBertConfig,
           RemBertForCausalLM,
           RemBertForMaskedLM,
           RemBertForMultipleChoice,
           RemBertForQuestionAnswering,
           RemBertForSequenceClassification,
           RemBertForTokenClassification,
           RemBertModel,
       )
       from transformers.models.rembert.modeling_rembert import REMBERT_PRETRAINED_MODEL_ARCHIVE_LIST


class 					UpperCAmelCase_     :


      def __init__(       self		,      a		,      a=1_3		,      a=7		,      a=True		,      a=True		,      a=True		,      a=True		,      a=9_9		,      a=3_2		,      a=1_8		,      a=4_3		,      a=5		,      a=4		,      a=3_7		,      a="gelu"		,      a=0.1		,      a=0.1		,      a=5_1_2		,      a=1_6		,      a=2		,      a=0.02		,      a=3		,      a=4		,      a=None		,      )	-> Optional[Any]:
        lowercase__      :		Tuple          =     parent
        lowercase__      :		int          =     batch_size
        lowercase__      :		str          =     seq_length
        lowercase__      :		Dict          =     is_training
        lowercase__      :		List[str]          =     use_input_mask
        lowercase__      :		Tuple          =     use_token_type_ids
        lowercase__      :		Optional[int]          =     use_labels
        lowercase__      :		Tuple          =     vocab_size
        lowercase__      :		Any          =     hidden_size
        lowercase__      :		str          =     input_embedding_size
        lowercase__      :		str          =     output_embedding_size
        lowercase__      :		Tuple          =     num_hidden_layers
        lowercase__      :		Any          =     num_attention_heads
        lowercase__      :		Any          =     intermediate_size
        lowercase__      :		Dict          =     hidden_act
        lowercase__      :		Optional[Any]          =     hidden_dropout_prob
        lowercase__      :		str          =     attention_probs_dropout_prob
        lowercase__      :		Union[str, Any]          =     max_position_embeddings
        lowercase__      :		List[Any]          =     type_vocab_size
        lowercase__      :		Dict          =     type_sequence_label_size
        lowercase__      :		Optional[Any]          =     initializer_range
        lowercase__      :		List[Any]          =     num_labels
        lowercase__      :		Optional[int]          =     num_choices
        lowercase__      :		Union[str, Any]          =     scope


      def 		_UpperCAmelCase	(       self							)	-> Dict:
        lowercase__      :		List[Any]          =     ids_tensor([self.batch_size, self.seq_length]		,      self.vocab_size							)

        lowercase__      :		Union[str, Any]          =     None
        if self.use_input_mask:
          lowercase__      :		Union[str, Any]          =     random_attention_mask([self.batch_size, self.seq_length]							)

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

        lowercase__      :		str          =     None
        lowercase__      :		str          =     None
        lowercase__      :		Any          =     None
        if self.use_labels:
          lowercase__      :		Union[str, Any]          =     ids_tensor([self.batch_size]		,      self.type_sequence_label_size							)
          lowercase__      :		Union[str, Any]          =     ids_tensor([self.batch_size, self.seq_length]		,      self.num_labels							)
          lowercase__      :		Tuple          =     ids_tensor([self.batch_size]		,      self.num_choices							)

        lowercase__      :		Dict          =     RemBertConfig(
            vocab_size=self.vocab_size		,      hidden_size=self.hidden_size		,      input_embedding_size=self.input_embedding_size		,      output_embedding_size=self.output_embedding_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		,      is_decoder=a		,      initializer_range=self.initializer_range		,      )

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


      def 		_UpperCAmelCase	(       self							)	-> List[str]:
        (
            lowercase__				
        )      :		str          =     self.prepare_config_and_inputs()

        lowercase__      :		Optional[Any]          =     True
        lowercase__      :		Union[str, Any]          =     floats_tensor([self.batch_size, self.seq_length, self.hidden_size]							)
        lowercase__      :		List[str]          =     ids_tensor([self.batch_size, self.seq_length]		,      vocab_size=2							)

        return (
            config,
            input_ids,
            token_type_ids,
            input_mask,
            sequence_labels,
            token_labels,
            choice_labels,
            encoder_hidden_states,
            encoder_attention_mask,
        )


      def 		_UpperCAmelCase	(       self		,      a		,      a		,      a		,      a		,      a		,      a		,      a							)	-> Optional[int]:
        lowercase__      :		Optional[Any]          =     RemBertModel(config=a							)
        model.to(a							)
        model.eval()
        lowercase__      :		Union[str, Any]          =     model(a		,      attention_mask=a		,      token_type_ids=a							)
        lowercase__      :		Tuple          =     model(a		,      token_type_ids=a							)
        lowercase__      :		List[str]          =     model(a							)
        self.parent.assertEqual(result.last_hidden_state.shape		,      (self.batch_size, self.seq_length, self.hidden_size)							)


      def 		_UpperCAmelCase	(       self		,      a		,      a		,      a		,      a		,      a		,      a		,      a		,      a		,      a		,      )	-> str:
        lowercase__      :		str          =     True
        lowercase__      :		Tuple          =     RemBertModel(a							)
        model.to(a							)
        model.eval()
        lowercase__      :		int          =     model(
            a		,      attention_mask=a		,      token_type_ids=a		,      encoder_hidden_states=a		,      encoder_attention_mask=a		,      )
        lowercase__      :		List[str]          =     model(
            a		,      attention_mask=a		,      token_type_ids=a		,      encoder_hidden_states=a		,      )
        lowercase__      :		str          =     model(a		,      attention_mask=a		,      token_type_ids=a							)
        self.parent.assertEqual(result.last_hidden_state.shape		,      (self.batch_size, self.seq_length, self.hidden_size)							)


      def 		_UpperCAmelCase	(       self		,      a		,      a		,      a		,      a		,      a		,      a		,      a		,      a		,      a		,      )	-> Dict:
        lowercase__      :		Tuple          =     RemBertForCausalLM(config=a							)
        model.to(a							)
        model.eval()
        lowercase__      :		Optional[Any]          =     model(a		,      attention_mask=a		,      token_type_ids=a		,      labels=a							)
        self.parent.assertEqual(result.logits.shape		,      (self.batch_size, self.seq_length, self.vocab_size)							)


      def 		_UpperCAmelCase	(       self		,      a		,      a		,      a		,      a		,      a		,      a		,      a							)	-> List[Any]:
        lowercase__      :		Dict          =     RemBertForMaskedLM(config=a							)
        model.to(a							)
        model.eval()
        lowercase__      :		Tuple          =     model(a		,      attention_mask=a		,      token_type_ids=a		,      labels=a							)
        self.parent.assertEqual(result.logits.shape		,      (self.batch_size, self.seq_length, self.vocab_size)							)


      def 		_UpperCAmelCase	(       self		,      a		,      a		,      a		,      a		,      a		,      a		,      a		,      a		,      a		,      )	-> Optional[int]:
        lowercase__      :		Optional[int]          =     True
        lowercase__      :		Optional[Any]          =     True
        lowercase__      :		Any          =     RemBertForCausalLM(config=a							)
        model.to(a							)
        model.eval()

        # first forward pass
        lowercase__      :		List[str]          =     model(
            a		,      attention_mask=a		,      encoder_hidden_states=a		,      encoder_attention_mask=a		,      use_cache=a		,      )
        lowercase__      :		int          =     outputs.past_key_values

        # create hypothetical multiple next token and extent to next_input_ids
        lowercase__      :		Tuple          =     ids_tensor((self.batch_size, 3)		,      config.vocab_size							)
        lowercase__      :		Any          =     ids_tensor((self.batch_size, 3)		,      vocab_size=2							)

        # append to next input_ids and
        lowercase__      :		str          =     torch.cat([input_ids, next_tokens]		,      dim=-1							)
        lowercase__      :		int          =     torch.cat([input_mask, next_mask]		,      dim=-1							)

        lowercase__      :		Optional[Any]          =     model(
            a		,      attention_mask=a		,      encoder_hidden_states=a		,      encoder_attention_mask=a		,      output_hidden_states=a		,      )['hidden_states'][0]
        lowercase__      :		int          =     model(
            a		,      attention_mask=a		,      encoder_hidden_states=a		,      encoder_attention_mask=a		,      past_key_values=a		,      output_hidden_states=a		,      )['hidden_states'][0]

        # select random slice
        lowercase__      :		Union[str, Any]          =     ids_tensor((1,)		,      output_from_past.shape[-1]							).item()
        lowercase__      :		str          =     output_from_no_past[:, -3:, random_slice_idx].detach()
        lowercase__      :		Any          =     output_from_past[:, :, random_slice_idx].detach()

        self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]							)

        # test that outputs are equal for slice
        self.parent.assertTrue(torch.allclose(a		,      a		,      atol=1e-3							)							)


      def 		_UpperCAmelCase	(       self		,      a		,      a		,      a		,      a		,      a		,      a		,      a							)	-> int:
        lowercase__      :		int          =     RemBertForQuestionAnswering(config=a							)
        model.to(a							)
        model.eval()
        lowercase__      :		Optional[int]          =     model(
            a		,      attention_mask=a		,      token_type_ids=a		,      start_positions=a		,      end_positions=a		,      )
        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 		_UpperCAmelCase	(       self		,      a		,      a		,      a		,      a		,      a		,      a		,      a							)	-> Any:
        lowercase__      :		int          =     self.num_labels
        lowercase__      :		Tuple          =     RemBertForSequenceClassification(a							)
        model.to(a							)
        model.eval()
        lowercase__      :		List[Any]          =     model(a		,      attention_mask=a		,      token_type_ids=a		,      labels=a							)
        self.parent.assertEqual(result.logits.shape		,      (self.batch_size, self.num_labels)							)


      def 		_UpperCAmelCase	(       self		,      a		,      a		,      a		,      a		,      a		,      a		,      a							)	-> List[str]:
        lowercase__      :		Optional[Any]          =     self.num_labels
        lowercase__      :		List[str]          =     RemBertForTokenClassification(config=a							)
        model.to(a							)
        model.eval()
        lowercase__      :		List[str]          =     model(a		,      attention_mask=a		,      token_type_ids=a		,      labels=a							)
        self.parent.assertEqual(result.logits.shape		,      (self.batch_size, self.seq_length, self.num_labels)							)


      def 		_UpperCAmelCase	(       self		,      a		,      a		,      a		,      a		,      a		,      a		,      a							)	-> Union[str, Any]:
        lowercase__      :		Any          =     self.num_choices
        lowercase__      :		List[str]          =     RemBertForMultipleChoice(config=a							)
        model.to(a							)
        model.eval()
        lowercase__      :		int          =     input_ids.unsqueeze(1							).expand(-1		,      self.num_choices		,      -1							).contiguous()
        lowercase__      :		Union[str, Any]          =     token_type_ids.unsqueeze(1							).expand(-1		,      self.num_choices		,      -1							).contiguous()
        lowercase__      :		Tuple          =     input_mask.unsqueeze(1							).expand(-1		,      self.num_choices		,      -1							).contiguous()
        lowercase__      :		int          =     model(
            a		,      attention_mask=a		,      token_type_ids=a		,      labels=a		,      )
        self.parent.assertEqual(result.logits.shape		,      (self.batch_size, self.num_choices)							)


      def 		_UpperCAmelCase	(       self							)	-> List[Any]:
        lowercase__      :		Any          =     self.prepare_config_and_inputs()
        (
            lowercase__				
        )      :		Any          =     config_and_inputs
        lowercase__      :		Dict          =     {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
        return config, inputs_dict





@require_torch
class 					UpperCAmelCase_     (   _a			,							_a			,							unittest.TestCase):
      lowerCamelCase__		:   Dict			  =  (
          (
              RemBertModel,
              RemBertForMaskedLM,
              RemBertForCausalLM,
              RemBertForMultipleChoice,
              RemBertForQuestionAnswering,
              RemBertForSequenceClassification,
              RemBertForTokenClassification,
          )
          if is_torch_available()
          else ()
      )
      lowerCamelCase__		:   int			  =  (RemBertForCausalLM,) if is_torch_available() else ()
      lowerCamelCase__		:   int			  =  (
          {
              "feature-extraction": RemBertModel,
              "fill-mask": RemBertForMaskedLM,
              "question-answering": RemBertForQuestionAnswering,
              "text-classification": RemBertForSequenceClassification,
              "text-generation": RemBertForCausalLM,
              "token-classification": RemBertForTokenClassification,
              "zero-shot": RemBertForSequenceClassification,
          }
          if is_torch_available()
          else {}
      )


      def 		_UpperCAmelCase	(       self							)	-> Dict:
        lowercase__      :		Dict          =     RemBertModelTester(self							)
        lowercase__      :		int          =     ConfigTester(self		,      config_class=a		,      hidden_size=3_7							)


      def 		_UpperCAmelCase	(       self							)	-> List[Any]:
        self.config_tester.run_common_tests()


      def 		_UpperCAmelCase	(       self							)	-> List[str]:
        lowercase__      :		List[str]          =     self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*a							)


      def 		_UpperCAmelCase	(       self							)	-> Any:
        lowercase__      :		List[str]          =     self.model_tester.prepare_config_and_inputs()
        for type in ["absolute", "relative_key", "relative_key_query"]:
          lowercase__      :		List[Any]          =     type
          self.model_tester.create_and_check_model(*a							)


      def 		_UpperCAmelCase	(       self							)	-> Union[str, Any]:
        lowercase__      :		Optional[int]          =     self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_masked_lm(*a							)


      def 		_UpperCAmelCase	(       self							)	-> List[str]:
        lowercase__      :		int          =     self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_multiple_choice(*a							)


      def 		_UpperCAmelCase	(       self							)	-> Any:
        lowercase__      :		Tuple          =     self.model_tester.prepare_config_and_inputs_for_decoder()
        self.model_tester.create_and_check_decoder_model_past_large_inputs(*a							)


      def 		_UpperCAmelCase	(       self							)	-> Dict:
        lowercase__      :		Dict          =     self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_question_answering(*a							)


      def 		_UpperCAmelCase	(       self							)	-> Dict:
        lowercase__      :		Tuple          =     self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_sequence_classification(*a							)


      def 		_UpperCAmelCase	(       self							)	-> Dict:
        lowercase__      :		Optional[Any]          =     self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_token_classification(*a							)


      def 		_UpperCAmelCase	(       self							)	-> Tuple:
        lowercase__      :		int          =     self.model_tester.prepare_config_and_inputs_for_decoder()
        self.model_tester.create_and_check_model_as_decoder(*a							)


      def 		_UpperCAmelCase	(       self							)	-> Any:
        # This regression test was failing with PyTorch < 1.3
        (
            lowercase__				
        )      :		List[str]          =     self.model_tester.prepare_config_and_inputs_for_decoder()

        lowercase__      :		List[Any]          =     None

        self.model_tester.create_and_check_model_as_decoder(
            a		,      a		,      a		,      a		,      a		,      a		,      a		,      a		,      a		,      )


      @slow
      def 		_UpperCAmelCase	(       self							)	-> List[str]:
        for model_name in REMBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
          lowercase__      :		str          =     RemBertModel.from_pretrained(a							)
          self.assertIsNotNone(a							)





@require_torch
class 					UpperCAmelCase_     (   unittest.TestCase):


      @slow
      def 		_UpperCAmelCase	(       self							)	-> str:
        # Test exact values at the last hidden layer
        lowercase__      :		Optional[int]          =     RemBertModel.from_pretrained('google/rembert'							)
        lowercase__      :		Optional[int]          =     torch.tensor([[3_1_2, 5_6_4_9_8, 3_1_3, 2_1_2_5, 3_1_3]]							)
        lowercase__      :		Tuple          =     torch.tensor([[0, 0, 0, 1, 1]]							)
        with torch.no_grad():
          lowercase__      :		List[str]          =     model(a		,      token_type_ids=a		,      output_hidden_states=a							)

        lowercase__      :		Optional[Any]          =     1_1_5_2

        lowercase__      :		Optional[Any]          =     torch.Size((1, 5, hidden_size)							)
        self.assertEqual(output['last_hidden_state'].shape		,      a							)

        lowercase__      :		int          =     torch.tensor(
            [
                [
                    [0.0_754, -0.2_022, 0.1_904],
                    [-0.3_354, -0.3_692, -0.4_791],
                    [-0.2_314, -0.6_729, -0.0_749],
                    [-0.0_396, -0.3_105, -0.4_234],
                    [-0.1_571, -0.0_525, 0.5_353],
                ]
            ]							)

        # Running on the original tf implementation gives slightly different results here.
        # Not clear why this variations is present
        # TODO: Find reason for discrepancy
        # expected_original_implementation = [[
        #     [0.07630594074726105, -0.20146065950393677, 0.19107051193714142],
        #     [-0.3405614495277405, -0.36971670389175415, -0.4808273911476135],
        #     [-0.22587086260318756, -0.6656315922737122, -0.07844287157058716],
        #     [-0.04145475849509239, -0.3077218234539032, -0.42316967248916626],
        #     [-0.15887849032878876, -0.054529931396245956, 0.5356100797653198]
        # ]]

        self.assertTrue(torch.allclose(output['last_hidden_state'][:, :, :3]		,      a		,      atol=1e-4							)							)


"""simple docstring"""





import unittest

import numpy as np
import torch
from torch import nn
from transformers import (
    CLIPImageProcessor,
    CLIPTextConfig,
    CLIPTextModelWithProjection,
    CLIPTokenizer,
    CLIPVisionConfig,
    CLIPVisionModelWithProjection,
)

from diffusers import KandinskyPriorPipeline, PriorTransformer, UnCLIPScheduler
from diffusers.utils import torch_device
from diffusers.utils.testing_utils import enable_full_determinism, skip_mps

from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()


class 					UpperCAmelCase_     (   _a			,							unittest.TestCase):
      lowerCamelCase__		:   Tuple			  =  KandinskyPriorPipeline
      lowerCamelCase__		:   Tuple			  =  ["prompt"]
      lowerCamelCase__		:   List[str]			  =  ["prompt", "negative_prompt"]
      lowerCamelCase__		:   List[Any]			  =  [
          "num_images_per_prompt",
          "generator",
          "num_inference_steps",
          "latents",
          "negative_prompt",
          "guidance_scale",
          "output_type",
          "return_dict",
      ]
      lowerCamelCase__		:   Optional[Any]			  =  False


      @property
      def 		_UpperCAmelCase	(       self							)	-> Union[str, Any]:
             return 3_2


      @property
      def 		_UpperCAmelCase	(       self							)	-> str:
             return 3_2


      @property
      def 		_UpperCAmelCase	(       self							)	-> Optional[Any]:
             return self.time_input_dim


      @property
      def 		_UpperCAmelCase	(       self							)	-> Any:
             return self.time_input_dim * 4


      @property
      def 		_UpperCAmelCase	(       self							)	-> Optional[int]:
             return 1_0_0


      @property
      def 		_UpperCAmelCase	(       self							)	-> List[Any]:
             lowercase__      :		Tuple          =     CLIPTokenizer.from_pretrained('hf-internal-testing/tiny-random-clip'							)
             return tokenizer


      @property
      def 		_UpperCAmelCase	(       self							)	-> Any:
             torch.manual_seed(0							)
             lowercase__      :		Optional[int]          =     CLIPTextConfig(
                 bos_token_id=0		,      eos_token_id=2		,      hidden_size=self.text_embedder_hidden_size		,      projection_dim=self.text_embedder_hidden_size		,      intermediate_size=3_7		,      layer_norm_eps=1e-05		,      num_attention_heads=4		,      num_hidden_layers=5		,      pad_token_id=1		,      vocab_size=1_0_0_0		,      )
             return CLIPTextModelWithProjection(a							)


      @property
      def 		_UpperCAmelCase	(       self							)	-> Union[str, Any]:
             torch.manual_seed(0							)

             lowercase__      :		int          =     {
                 'num_attention_heads': 2,
                 'attention_head_dim': 1_2,
                 'embedding_dim': self.text_embedder_hidden_size,
                 'num_layers': 1,
             }

             lowercase__      :		Tuple          =     PriorTransformer(**a							)
             # clip_std and clip_mean is initialized to be 0 so PriorTransformer.post_process_latents will always return 0 - set clip_std to be 1 so it won't return 0
             lowercase__      :		int          =     nn.Parameter(torch.ones(model.clip_std.shape							)							)
             return model


      @property
      def 		_UpperCAmelCase	(       self							)	-> Optional[int]:
             torch.manual_seed(0							)
             lowercase__      :		Optional[int]          =     CLIPVisionConfig(
                 hidden_size=self.text_embedder_hidden_size		,      image_size=2_2_4		,      projection_dim=self.text_embedder_hidden_size		,      intermediate_size=3_7		,      num_attention_heads=4		,      num_channels=3		,      num_hidden_layers=5		,      patch_size=1_4		,      )

             lowercase__      :		Optional[Any]          =     CLIPVisionModelWithProjection(a							)
             return model


      @property
      def 		_UpperCAmelCase	(       self							)	-> Tuple:
             lowercase__      :		Dict          =     CLIPImageProcessor(
                 crop_size=2_2_4		,      do_center_crop=a		,      do_normalize=a		,      do_resize=a		,      image_mean=[0.48_145_466, 0.4_578_275, 0.40_821_073]		,      image_std=[0.26_862_954, 0.26_130_258, 0.27_577_711]		,      resample=3		,      size=2_2_4		,      )

             return image_processor


      def 		_UpperCAmelCase	(       self							)	-> Dict:
             lowercase__      :		List[str]          =     self.dummy_prior
             lowercase__      :		Tuple          =     self.dummy_image_encoder
             lowercase__      :		Optional[Any]          =     self.dummy_text_encoder
             lowercase__      :		List[str]          =     self.dummy_tokenizer
             lowercase__      :		Optional[int]          =     self.dummy_image_processor

             lowercase__      :		List[Any]          =     UnCLIPScheduler(
                 variance_type='fixed_small_log'		,      prediction_type='sample'		,      num_train_timesteps=1_0_0_0		,      clip_sample=a		,      clip_sample_range=10.0		,      )

             lowercase__      :		List[str]          =     {
                 'prior': prior,
                 'image_encoder': image_encoder,
                 'text_encoder': text_encoder,
                 'tokenizer': tokenizer,
                 'scheduler': scheduler,
                 'image_processor': image_processor,
             }

             return components


      def 		_UpperCAmelCase	(       self		,      a		,      a=0							)	-> Union[str, Any]:
             if str(a							).startswith('mps'							):
                    lowercase__      :		Optional[Any]          =     torch.manual_seed(a							)
             else:
                    lowercase__      :		Any          =     torch.Generator(device=a							).manual_seed(a							)
             lowercase__      :		str          =     {
                 'prompt': 'horse',
                 'generator': generator,
                 'guidance_scale': 4.0,
                 'num_inference_steps': 2,
                 'output_type': 'np',
             }
             return inputs


      def 		_UpperCAmelCase	(       self							)	-> Dict:
             lowercase__      :		Optional[int]          =     'cpu'

             lowercase__      :		Optional[Any]          =     self.get_dummy_components()

             lowercase__      :		Optional[Any]          =     self.pipeline_class(**a							)
             lowercase__      :		Optional[int]          =     pipe.to(a							)

             pipe.set_progress_bar_config(disable=a							)

             lowercase__      :		Optional[int]          =     pipe(**self.get_dummy_inputs(a							)							)
             lowercase__      :		Optional[Any]          =     output.image_embeds

             lowercase__      :		Dict          =     pipe(
                 **self.get_dummy_inputs(a							)		,      return_dict=a		,      )[0]

             lowercase__      :		List[str]          =     image[0, -1_0:]
             lowercase__      :		Optional[Any]          =     image_from_tuple[0, -1_0:]

             assert image.shape == (1, 3_2)

             lowercase__      :		Union[str, Any]          =     np.array(
                 [-0.0_532, 1.7_120, 0.3_656, -1.0_852, -0.8_946, -1.1_756, 0.4_348, 0.2_482, 0.5_146, -0.1_156]							)

             assert np.abs(image_slice.flatten() - expected_slice							).max() < 1e-2
             assert np.abs(image_from_tuple_slice.flatten() - expected_slice							).max() < 1e-2


      @skip_mps
      def 		_UpperCAmelCase	(       self							)	-> List[Any]:
             lowercase__      :		Tuple          =     torch_device == 'cpu'
             lowercase__      :		Union[str, Any]          =     True
             lowercase__      :		int          =     False

             self._test_inference_batch_single_identical(
                 test_max_difference=a		,      relax_max_difference=a		,      test_mean_pixel_difference=a		,      )


      @skip_mps
      def 		_UpperCAmelCase	(       self							)	-> int:
             lowercase__      :		Tuple          =     torch_device == 'cpu'
             lowercase__      :		Any          =     False

             self._test_attention_slicing_forward_pass(
                 test_max_difference=a		,      test_mean_pixel_difference=a		,      )

