



from __future__ import annotations

import inspect
import unittest

import numpy as np

from transformers import SwinConfig
from transformers.testing_utils import require_tf, require_vision, slow, to_atuple
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.models.swin.modeling_tf_swin import (
							    TF_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST,
							    TFSwinForImageClassification,
							    TFSwinForMaskedImageModeling,
							    TFSwinModel,
							)


if is_vision_available():
							from PIL import Image

							from transformers import AutoImageProcessor

class 						lowerCamelCase_     :






						'''simple docstring'''







						def __init__(						self   :      Any						,						__lowerCamelCase   :      str						,						__lowerCamelCase   :      Union[str, Any]=13						,						__lowerCamelCase   :      Tuple=32						,						__lowerCamelCase   :      List[str]=2						,						__lowerCamelCase   :      Union[str, Any]=3						,						__lowerCamelCase   :      List[Any]=16						,						__lowerCamelCase   :      Tuple=[1, 2, 1]						,						__lowerCamelCase   :      Optional[Any]=[2, 2, 4]						,						__lowerCamelCase   :      str=2						,						__lowerCamelCase   :      Optional[int]=2.0						,						__lowerCamelCase   :      List[Any]=True						,						__lowerCamelCase   :      Tuple=0.0						,						__lowerCamelCase   :      int=0.0						,						__lowerCamelCase   :      List[Any]=0.1						,						__lowerCamelCase   :      Union[str, Any]="gelu"						,						__lowerCamelCase   :      str=False						,						__lowerCamelCase   :      List[Any]=True						,						__lowerCamelCase   :      Optional[Any]=0.02						,						__lowerCamelCase   :      Dict=1e-5						,						__lowerCamelCase   :      List[str]=True						,						__lowerCamelCase   :      Dict=None						,						__lowerCamelCase   :      str=True						,						__lowerCamelCase   :      List[str]=10						,						__lowerCamelCase   :      List[Any]=8						,						)   ->					str:
									A				:       Dict														=    parent
									A				:       int														=    batch_size
									A				:       Optional[int]														=    image_size
									A				:       List[Any]														=    patch_size
									A				:       List[Any]														=    num_channels
									A				:       Tuple														=    embed_dim
									A				:       int														=    depths
									A				:       Tuple														=    num_heads
									A				:       List[Any]														=    window_size
									A				:       Tuple														=    mlp_ratio
									A				:       Optional[int]														=    qkv_bias
									A				:       int														=    hidden_dropout_prob
									A				:       str														=    attention_probs_dropout_prob
									A				:       Optional[Any]														=    drop_path_rate
									A				:       int														=    hidden_act
									A				:       Union[str, Any]														=    use_absolute_embeddings
									A				:       str														=    patch_norm
									A				:       Optional[int]														=    layer_norm_eps
									A				:       str														=    initializer_range
									A				:       Optional[Any]														=    is_training
									A				:       Dict														=    scope
									A				:       Tuple														=    use_labels
									A				:       List[Any]														=    type_sequence_label_size
									A				:       List[str]														=    encoder_stride







						def       SCREAMING_SNAKE_CASE__		(						self   :      int			)   ->					List[Any]:
									A				:       Optional[int]														=    floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]			)

									A				:       int														=    None
									if self.use_labels:
												A				:       Optional[Any]														=    ids_tensor([self.batch_size]						,						self.type_sequence_label_size			)

									A				:       Union[str, Any]														=    self.get_config()

									return config, pixel_values, labels







						def       SCREAMING_SNAKE_CASE__		(						self   :      Optional[int]			)   ->					Optional[Any]:
									return SwinConfig(
									    image_size=self.image_size						,						patch_size=self.patch_size						,						num_channels=self.num_channels						,						embed_dim=self.embed_dim						,						depths=self.depths						,						num_heads=self.num_heads						,						window_size=self.window_size						,						mlp_ratio=self.mlp_ratio						,						qkv_bias=self.qkv_bias						,						hidden_dropout_prob=self.hidden_dropout_prob						,						attention_probs_dropout_prob=self.attention_probs_dropout_prob						,						drop_path_rate=self.drop_path_rate						,						hidden_act=self.hidden_act						,						use_absolute_embeddings=self.use_absolute_embeddings						,						path_norm=self.patch_norm						,						layer_norm_eps=self.layer_norm_eps						,						initializer_range=self.initializer_range						,						encoder_stride=self.encoder_stride						,						)







						def       SCREAMING_SNAKE_CASE__		(						self   :      Dict						,						__lowerCamelCase   :      Dict						,						__lowerCamelCase   :      Any						,						__lowerCamelCase   :      List[Any]			)   ->					Optional[Any]:
									A				:       Optional[int]														=    TFSwinModel(config=_UpperCAmelCase			)
									A				:       Any														=    model(_UpperCAmelCase			)

									A				:       Union[str, Any]														=    ((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths			) - 1))
									A				:       Any														=    int(config.embed_dim * 2 ** (len(config.depths			) - 1)			)

									self.parent.assertEqual(result.last_hidden_state.shape						,						(self.batch_size, expected_seq_len, expected_dim)			)







						def       SCREAMING_SNAKE_CASE__		(						self   :      int						,						__lowerCamelCase   :      Union[str, Any]						,						__lowerCamelCase   :      int						,						__lowerCamelCase   :      str			)   ->					Tuple:
									A				:       Tuple														=    TFSwinForMaskedImageModeling(config=_UpperCAmelCase			)
									A				:       Optional[Any]														=    model(_UpperCAmelCase			)
									self.parent.assertEqual(
									    result.logits.shape						,						(self.batch_size, self.num_channels, self.image_size, self.image_size)			)

									# test greyscale images
									A				:       Union[str, Any]														=    1
									A				:       Optional[Any]														=    TFSwinForMaskedImageModeling(_UpperCAmelCase			)

									A				:       Dict														=    floats_tensor([self.batch_size, 1, self.image_size, self.image_size]			)
									A				:       Optional[Any]														=    model(_UpperCAmelCase			)
									self.parent.assertEqual(result.logits.shape						,						(self.batch_size, 1, self.image_size, self.image_size)			)







						def       SCREAMING_SNAKE_CASE__		(						self   :      Union[str, Any]						,						__lowerCamelCase   :      Optional[Any]						,						__lowerCamelCase   :      List[str]						,						__lowerCamelCase   :      Optional[Any]			)   ->					str:
									A				:       Union[str, Any]														=    self.type_sequence_label_size
									A				:       int														=    TFSwinForImageClassification(_UpperCAmelCase			)
									A				:       Dict														=    model(_UpperCAmelCase						,						labels=_UpperCAmelCase			)
									self.parent.assertEqual(result.logits.shape						,						(self.batch_size, self.type_sequence_label_size)			)

									# test greyscale images
									A				:       Optional[int]														=    1
									A				:       int														=    TFSwinForImageClassification(_UpperCAmelCase			)
									A				:       Tuple														=    floats_tensor([self.batch_size, 1, self.image_size, self.image_size]			)
									A				:       List[str]														=    model(_UpperCAmelCase			)
									self.parent.assertEqual(result.logits.shape						,						(self.batch_size, self.type_sequence_label_size)			)







						def       SCREAMING_SNAKE_CASE__		(						self   :      Dict			)   ->					Union[str, Any]:
									A				:       Optional[int]														=    self.prepare_config_and_inputs()
									A							,			A							,			A				:       str														=    config_and_inputs
									A				:       str														=    {"pixel_values": pixel_values}
									return config, inputs_dict







@require_tf
class 						lowerCamelCase_     (			lowerCamelCase__    ,lowerCamelCase__    ,unittest.TestCase    ):






						'''simple docstring'''
						a__ =	(
						    (
						        TFSwinModel,
						        TFSwinForImageClassification,
						        TFSwinForMaskedImageModeling,
						    )
						    if is_tf_available()
						    else ()
						)
						a__ =	(
						    {"feature-extraction": TFSwinModel, "image-classification": TFSwinForImageClassification}
						    if is_tf_available()
						    else {}
						)

						a__ =	False
						a__ =	False
						a__ =	False
						a__ =	False







						def       SCREAMING_SNAKE_CASE__		(						self   :      Optional[int]			)   ->					Optional[Any]:
									A				:       Optional[Any]														=    TFSwinModelTester(self			)
									A				:       List[str]														=    ConfigTester(self						,						config_class=_UpperCAmelCase						,						embed_dim=37			)







						def       SCREAMING_SNAKE_CASE__		(						self   :      str			)   ->					List[Any]:
									self.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()







						def       SCREAMING_SNAKE_CASE__		(						self   :      List[Any]			)   ->					Tuple:
									return







						def       SCREAMING_SNAKE_CASE__		(						self   :      Optional[Any]			)   ->					Any:
									A				:       List[str]														=    self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*_UpperCAmelCase			)







						def       SCREAMING_SNAKE_CASE__		(						self   :      Tuple			)   ->					Tuple:
									A				:       Union[str, Any]														=    self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_masked_image_modeling(*_UpperCAmelCase			)







						def       SCREAMING_SNAKE_CASE__		(						self   :      str			)   ->					Optional[Any]:
									A				:       List[str]														=    self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_image_classification(*_UpperCAmelCase			)







						@unittest.skip(reason="Swin does not use inputs_embeds"			)
						def       SCREAMING_SNAKE_CASE__		(						self   :      List[str]			)   ->					Union[str, Any]:
									pass







						def       SCREAMING_SNAKE_CASE__		(						self   :      Tuple			)   ->					str:
									A							,			A				:       str														=    self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
												A				:       Dict														=    model_class(_UpperCAmelCase			)
												self.assertIsInstance(model.get_input_embeddings()						,						tf.keras.layers.Layer			)
												A				:       Tuple														=    model.get_output_embeddings()
												self.assertTrue(x is None or isinstance(_UpperCAmelCase						,						tf.keras.layers.Dense			)			)







						def       SCREAMING_SNAKE_CASE__		(						self   :      Union[str, Any]			)   ->					Optional[int]:
									A							,			A				:       List[str]														=    self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
												A				:       Union[str, Any]														=    model_class(_UpperCAmelCase			)
												A				:       List[Any]														=    inspect.signature(model.call			)
												# signature.parameters is an OrderedDict => so arg_names order is deterministic
												A				:       Any														=    [*signature.parameters.keys()]

												A				:       str														=    ["pixel_values"]
												self.assertListEqual(arg_names[:1]						,						_UpperCAmelCase			)







						def       SCREAMING_SNAKE_CASE__		(						self   :      str			)   ->					Dict:
									A							,			A				:       Optional[Any]														=    self.model_tester.prepare_config_and_inputs_for_common()
									A				:       Optional[int]														=    True

									for model_class in self.all_model_classes:
												A				:       Tuple														=    True
												A				:       Union[str, Any]														=    False
												A				:       Tuple														=    True
												A				:       Dict														=    model_class(_UpperCAmelCase			)
												A				:       List[str]														=    model(**self._prepare_for_class(_UpperCAmelCase						,						_UpperCAmelCase			)			)
												A				:       Dict														=    outputs.attentions
												A				:       Optional[Any]														=    len(self.model_tester.depths			)
												self.assertEqual(len(_UpperCAmelCase			)						,						_UpperCAmelCase			)

												# check that output_attentions also work using config
												del inputs_dict["output_attentions"]
												A				:       int														=    True
												A				:       Optional[Any]														=    config.window_size**2
												A				:       Any														=    model_class(_UpperCAmelCase			)
												A				:       Dict														=    model(**self._prepare_for_class(_UpperCAmelCase						,						_UpperCAmelCase			)			)
												A				:       List[str]														=    outputs.attentions
												self.assertEqual(len(_UpperCAmelCase			)						,						_UpperCAmelCase			)

												self.assertListEqual(
												    list(attentions[0].shape[-3:]			)						,						[self.model_tester.num_heads[0], window_size_squared, window_size_squared]						,						)
												A				:       Union[str, Any]														=    len(_UpperCAmelCase			)

												# Check attention is always last and order is fine
												A				:       List[str]														=    True
												A				:       Any														=    True
												A				:       List[str]														=    model_class(_UpperCAmelCase			)
												A				:       int														=    model(**self._prepare_for_class(_UpperCAmelCase						,						_UpperCAmelCase			)			)

												if hasattr(self.model_tester						,						"num_hidden_states_types"			):
															A				:       Any														=    self.model_tester.num_hidden_states_types
												else:
															# also another +1 for reshaped_hidden_states
															A				:       List[Any]														=    2
												self.assertEqual(out_len + added_hidden_states						,						len(_UpperCAmelCase			)			)

												A				:       List[Any]														=    outputs.attentions

												self.assertEqual(len(_UpperCAmelCase			)						,						_UpperCAmelCase			)

												self.assertListEqual(
												    list(self_attentions[0].shape[-3:]			)						,						[self.model_tester.num_heads[0], window_size_squared, window_size_squared]						,						)







						def       SCREAMING_SNAKE_CASE__		(						self   :      Any						,						__lowerCamelCase   :      str						,						__lowerCamelCase   :      str						,						__lowerCamelCase   :      str						,						__lowerCamelCase   :      Dict			)   ->					str:
									A				:       Optional[Any]														=    model_class(_UpperCAmelCase			)
									A				:       Optional[int]														=    model(**self._prepare_for_class(_UpperCAmelCase						,						_UpperCAmelCase			)			)
									A				:       List[str]														=    outputs.hidden_states

									A				:       int														=    getattr(
									    self.model_tester						,						"expected_num_hidden_layers"						,						len(self.model_tester.depths			) + 1			)
									self.assertEqual(len(_UpperCAmelCase			)						,						_UpperCAmelCase			)

									# Swin has a different seq_length
									A				:       Any														=    to_atuple(config.patch_size			)

									A				:       Any														=    (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])

									self.assertListEqual(
									    list(hidden_states[0].shape[-2:]			)						,						[num_patches, self.model_tester.embed_dim]						,						)

									A				:       List[Any]														=    outputs.reshaped_hidden_states
									self.assertEqual(len(_UpperCAmelCase			)						,						_UpperCAmelCase			)

									A							,			A							,			A							,			A				:       Any														=    reshaped_hidden_states[0].shape

									A				:       Union[str, Any]														=    tf.reshape(reshaped_hidden_states[0]						,						(batch_size, num_channels, height * width)			)
									A				:       Optional[Any]														=    tf.transpose(_UpperCAmelCase						,						(0, 2, 1)			)

									self.assertListEqual(
									    list(reshaped_hidden_states.shape[-2:]			)						,						[num_patches, self.model_tester.embed_dim]						,						)







						def       SCREAMING_SNAKE_CASE__		(						self   :      List[Any]			)   ->					str:
									A							,			A				:       List[Any]														=    self.model_tester.prepare_config_and_inputs_for_common()

									A				:       Dict														=    to_atuple(self.model_tester.image_size			)

									for model_class in self.all_model_classes:
												A				:       List[Any]														=    True
												self.check_hidden_states_output(_UpperCAmelCase						,						_UpperCAmelCase						,						_UpperCAmelCase						,						_UpperCAmelCase			)

												# check that output_hidden_states also work using config
												del inputs_dict["output_hidden_states"]
												A				:       str														=    True

												self.check_hidden_states_output(_UpperCAmelCase						,						_UpperCAmelCase						,						_UpperCAmelCase						,						_UpperCAmelCase			)







						def       SCREAMING_SNAKE_CASE__		(						self   :      str			)   ->					Dict:
									A							,			A				:       List[Any]														=    self.model_tester.prepare_config_and_inputs_for_common()
									A				:       Union[str, Any]														=    3

									A				:       Tuple														=    to_atuple(self.model_tester.image_size			)
									A				:       Optional[int]														=    to_atuple(config.patch_size			)

									A				:       str														=    image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
									A				:       Optional[Any]														=    image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

									for model_class in self.all_model_classes:
												A				:       Union[str, Any]														=    True
												self.check_hidden_states_output(_UpperCAmelCase						,						_UpperCAmelCase						,						_UpperCAmelCase						,						(padded_height, padded_width)			)

												# check that output_hidden_states also work using config
												del inputs_dict["output_hidden_states"]
												A				:       Any														=    True
												self.check_hidden_states_output(_UpperCAmelCase						,						_UpperCAmelCase						,						_UpperCAmelCase						,						(padded_height, padded_width)			)







						@slow
						def       SCREAMING_SNAKE_CASE__		(						self   :      str			)   ->					int:
									for model_name in TF_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
												A				:       Tuple														=    TFSwinModel.from_pretrained(_UpperCAmelCase			)
												self.assertIsNotNone(_UpperCAmelCase			)







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






						'''simple docstring'''







						@cached_property
						def       SCREAMING_SNAKE_CASE__		(						self   :      Tuple			)   ->					Optional[int]:
									return (
									    AutoImageProcessor.from_pretrained("microsoft/swin-tiny-patch4-window7-224"			)
									    if is_vision_available()
									    else None
									)







						@slow
						def       SCREAMING_SNAKE_CASE__		(						self   :      List[str]			)   ->					List[Any]:
									A				:       Dict														=    TFSwinForImageClassification.from_pretrained("microsoft/swin-tiny-patch4-window7-224"			)
									A				:       Any														=    self.default_image_processor

									A				:       str														=    Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"			)
									A				:       Union[str, Any]														=    image_processor(images=_UpperCAmelCase						,						return_tensors="tf"			)

									# forward pass
									A				:       Tuple														=    model(_UpperCAmelCase			)

									# verify the logits
									A				:       Optional[Any]														=    tf.TensorShape((1, 10_00)			)
									self.assertEqual(outputs.logits.shape						,						_UpperCAmelCase			)
									A				:       Any														=    tf.constant([-0.0948, -0.6454, -0.0921]			)
									self.assertTrue(np.allclose(outputs.logits[0, :3]						,						_UpperCAmelCase						,						atol=1e-4			)			)



import random
import unittest

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

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

from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()







class lowerCAmelCase_		(					lowerCamelCase__   ,		unittest.TestCase			):

 '''simple docstring'''

 __snake_case				=    KandinskyVaaPriorEmbaEmbPipeline
 __snake_case				=    ["prompt", "image"]
 __snake_case				=    ["prompt", "image"]
 __snake_case				=    [
     "num_images_per_prompt",
     "strength",
     "generator",
     "num_inference_steps",
     "latents",
     "negative_prompt",
     "guidance_scale",
     "output_type",
     "return_dict",
 ]
 __snake_case				=    False



 @property
 def 		UpperCamelCase__	(      self   ):
       return 32



 @property
 def 		UpperCamelCase__	(      self   ):
       return 32



 @property
 def 		UpperCamelCase__	(      self   ):
       return self.time_input_dim



 @property
 def 		UpperCamelCase__	(      self   ):
       return self.time_input_dim * 4



 @property
 def 		UpperCamelCase__	(      self   ):
       return 1_00



 @property
 def 		UpperCamelCase__	(      self   ):
       snake_case_			= CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''   )
       return tokenizer



 @property
 def 		UpperCamelCase__	(      self   ):
       torch.manual_seed(0   )
       snake_case_			= 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=37						, layer_norm_eps=1E-05						, num_attention_heads=4						, num_hidden_layers=5						, pad_token_id=1						, vocab_size=10_00						, )
       return CLIPTextModelWithProjection(_UpperCAmelCase   )



 @property
 def 		UpperCamelCase__	(      self   ):
       torch.manual_seed(0   )

       snake_case_			= {
           '''num_attention_heads''': 2,
           '''attention_head_dim''': 12,
           '''embedding_dim''': self.text_embedder_hidden_size,
           '''num_layers''': 1,
       }

       snake_case_			= PriorTransformer(**_UpperCAmelCase   )
       # 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
       snake_case_			= nn.Parameter(torch.ones(model.clip_std.shape   )   )
       return model



 @property
 def 		UpperCamelCase__	(      self   ):
       torch.manual_seed(0   )
       snake_case_			= CLIPVisionConfig(
           hidden_size=self.text_embedder_hidden_size						, image_size=2_24						, projection_dim=self.text_embedder_hidden_size						, intermediate_size=37						, num_attention_heads=4						, num_channels=3						, num_hidden_layers=5						, patch_size=14						, )

       snake_case_			= CLIPVisionModelWithProjection(_UpperCAmelCase   )
       return model



 @property
 def 		UpperCamelCase__	(      self   ):
       snake_case_			= CLIPImageProcessor(
           crop_size=2_24						, do_center_crop=_UpperCAmelCase						, do_normalize=_UpperCAmelCase						, do_resize=_UpperCAmelCase						, 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_24						, )

       return image_processor



 def 		UpperCamelCase__	(      self   ):
       snake_case_			= self.dummy_prior
       snake_case_			= self.dummy_image_encoder
       snake_case_			= self.dummy_text_encoder
       snake_case_			= self.dummy_tokenizer
       snake_case_			= self.dummy_image_processor

       snake_case_			= UnCLIPScheduler(
           variance_type='''fixed_small_log'''						, prediction_type='''sample'''						, num_train_timesteps=10_00						, clip_sample=_UpperCAmelCase						, clip_sample_range=10.0						, )

       snake_case_			= {
           '''prior''': prior,
           '''image_encoder''': image_encoder,
           '''text_encoder''': text_encoder,
           '''tokenizer''': tokenizer,
           '''scheduler''': scheduler,
           '''image_processor''': image_processor,
       }

       return components



 def 		UpperCamelCase__	(      self						, _UpperCAmelCase						, _UpperCAmelCase=0   ):
       if str(_UpperCAmelCase   ).startswith('''mps'''   ):
             snake_case_			= torch.manual_seed(_UpperCAmelCase   )
       else:
             snake_case_			= torch.Generator(device=_UpperCAmelCase   ).manual_seed(_UpperCAmelCase   )

       snake_case_			= floats_tensor((1, 3, 64, 64)						, rng=random.Random(_UpperCAmelCase   )   ).to(_UpperCAmelCase   )
       snake_case_			= image.cpu().permute(0						, 2						, 3						, 1   )[0]
       snake_case_			= Image.fromarray(np.uinta(_UpperCAmelCase   )   ).convert('''RGB'''   ).resize((2_56, 2_56)   )

       snake_case_			= {
           '''prompt''': '''horse''',
           '''image''': init_image,
           '''strength''': 0.5,
           '''generator''': generator,
           '''guidance_scale''': 4.0,
           '''num_inference_steps''': 2,
           '''output_type''': '''np''',
       }
       return inputs



 def 		UpperCamelCase__	(      self   ):
       snake_case_			= '''cpu'''

       snake_case_			= self.get_dummy_components()

       snake_case_			= self.pipeline_class(**_UpperCAmelCase   )
       snake_case_			= pipe.to(_UpperCAmelCase   )

       pipe.set_progress_bar_config(disable=_UpperCAmelCase   )

       snake_case_			= pipe(**self.get_dummy_inputs(_UpperCAmelCase   )   )
       snake_case_			= output.image_embeds

       snake_case_			= pipe(
           **self.get_dummy_inputs(_UpperCAmelCase   )						, return_dict=_UpperCAmelCase						, )[0]

       snake_case_			= image[0, -10:]
       snake_case_			= image_from_tuple[0, -10:]

       assert image.shape == (1, 32)

       snake_case_			= np.array(
           [
               0.1_071_284,
               1.3_330_271,
               0.61_260_223,
               -0.6_691_065,
               -0.3_846_852,
               -1.0_303_661,
               0.22_716_111,
               0.03_348_901,
               0.30_040_675,
               -0.24_805_029,
           ]   )

       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   ):
       snake_case_			= torch_device == '''cpu'''
       snake_case_			= True
       snake_case_			= False

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





 @skip_mps
 def 		UpperCamelCase__	(      self   ):
       snake_case_			= torch_device == '''cpu'''
       snake_case_			= False

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