


'''simple docstring'''






import copy
import inspect
import unittest

import numpy as np
from huggingface_hub import hf_hub_download

from transformers import VideoMAEConfig
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

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


if is_torch_available():
					import torch
					from torch import nn

					from transformers import (
					    MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING,
					    VideoMAEForPreTraining,
					    VideoMAEForVideoClassification,
					    VideoMAEModel,
					)
					from transformers.models.videomae.modeling_videomae import VIDEOMAE_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
					from transformers import VideoMAEImageProcessor
class 						__UpperCamelCase	:





							def __init__(  self		:Dict  ,_UpperCamelCase		:int  ,_UpperCamelCase		:Optional[Any]=1_3  ,_UpperCamelCase		:List[str]=1_0  ,_UpperCamelCase		:Optional[int]=3  ,_UpperCamelCase		:int=2  ,_UpperCamelCase		:str=2  ,_UpperCamelCase		:Any=2  ,_UpperCamelCase		:List[Any]=True  ,_UpperCamelCase		:List[str]=True  ,_UpperCamelCase		:List[str]=3_2  ,_UpperCamelCase		:Dict=5  ,_UpperCamelCase		:Any=4  ,_UpperCamelCase		:Optional[Any]=3_7  ,_UpperCamelCase		:Dict="gelu"  ,_UpperCamelCase		:Tuple=0.1  ,_UpperCamelCase		:List[str]=0.1  ,_UpperCamelCase		:Optional[Any]=1_0  ,_UpperCamelCase		:Tuple=0.02  ,_UpperCamelCase		:Dict=0.9  ,_UpperCamelCase		:Tuple=None  ,):
									snake_case_		:							Tuple			       =						parent
									snake_case_		:							Union[str, Any]			       =						batch_size
									snake_case_		:							List[str]			       =						image_size
									snake_case_		:							List[Any]			       =						num_channels
									snake_case_		:							str			       =						patch_size
									snake_case_		:							Optional[int]			       =						tubelet_size
									snake_case_		:							Dict			       =						num_frames
									snake_case_		:							Optional[Any]			       =						is_training
									snake_case_		:							Dict			       =						use_labels
									snake_case_		:							Tuple			       =						hidden_size
									snake_case_		:							Any			       =						num_hidden_layers
									snake_case_		:							List[Any]			       =						num_attention_heads
									snake_case_		:							Dict			       =						intermediate_size
									snake_case_		:							str			       =						hidden_act
									snake_case_		:							str			       =						hidden_dropout_prob
									snake_case_		:							str			       =						attention_probs_dropout_prob
									snake_case_		:							Tuple			       =						type_sequence_label_size
									snake_case_		:							List[str]			       =						initializer_range
									snake_case_		:							str			       =						mask_ratio
									snake_case_		:							Any			       =						scope

									# in VideoMAE, the number of tokens equals num_frames/tubelet_size * num_patches per frame
									snake_case_		:							Tuple			       =						(image_size // patch_size) ** 2
									snake_case_		:							Dict			       =						(num_frames // tubelet_size) * self.num_patches_per_frame

									# use this variable to define bool_masked_pos
									snake_case_		:							str			       =						int(mask_ratio * self.seq_length			)





							def 		a__   (  self		:Any			):
									snake_case_		:							Optional[Any]			       =						floats_tensor(
									    [self.batch_size, self.num_frames, self.num_channels, self.image_size, self.image_size]			)

									snake_case_		:							List[str]			       =						None
									if self.use_labels:
											snake_case_		:							List[Any]			       =						ids_tensor([self.batch_size]  ,self.type_sequence_label_size			)

									snake_case_		:							Dict			       =						self.get_config()

									return config, pixel_values, labels





							def 		a__   (  self		:Dict			):
									return VideoMAEConfig(
									    image_size=self.image_size  ,patch_size=self.patch_size  ,num_channels=self.num_channels  ,num_frames=self.num_frames  ,tubelet_size=self.tubelet_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  ,is_decoder=_UpperCamelCase  ,initializer_range=self.initializer_range  ,)





							def 		a__   (  self		:Any  ,_UpperCamelCase		:Tuple  ,_UpperCamelCase		:Optional[int]  ,_UpperCamelCase		:Optional[int]			):
									snake_case_		:							Any			       =						VideoMAEModel(config=_UpperCamelCase			)
									model.to(_UpperCamelCase			)
									model.eval()
									snake_case_		:							Optional[Any]			       =						model(_UpperCamelCase			)
									self.parent.assertEqual(result.last_hidden_state.shape  ,(self.batch_size, self.seq_length, self.hidden_size)			)





							def 		a__   (  self		:str  ,_UpperCamelCase		:Tuple  ,_UpperCamelCase		:List[str]  ,_UpperCamelCase		:Union[str, Any]			):
									snake_case_		:							Any			       =						VideoMAEForPreTraining(_UpperCamelCase			)
									model.to(_UpperCamelCase			)
									model.eval()
									# important: each video needs to have the same number of masked patches
									# hence we define a single mask, which we then repeat for each example in the batch
									snake_case_		:							str			       =						torch.ones((self.num_masks,)			)
									snake_case_		:							str			       =						torch.cat([mask, torch.zeros(self.seq_length - mask.size(0			)			)]			)
									snake_case_		:							List[str]			       =						mask.expand(self.batch_size  ,-1			).bool()

									snake_case_		:							List[str]			       =						model(_UpperCamelCase  ,_UpperCamelCase			)
									# model only returns predictions for masked patches
									snake_case_		:							int			       =						mask.sum().item()
									snake_case_		:							Dict			       =						3 * self.tubelet_size * self.patch_size**2
									self.parent.assertEqual(result.logits.shape  ,(self.batch_size, num_masked_patches, decoder_num_labels)			)





							def 		a__   (  self		:int			):
									snake_case_		:							Optional[Any]			       =						self.prepare_config_and_inputs()
									snake_case_		:							Union[str, Any]			       =						config_and_inputs
									snake_case_		:							List[Any]			       =						{'''pixel_values''': pixel_values}
									return config, inputs_dict





@require_torch
class 						__UpperCamelCase	(						UpperCamelCase_						,  UpperCamelCase_						,  unittest.TestCase							):
							lowercase			:		int   		=  (
							    (VideoMAEModel, VideoMAEForPreTraining, VideoMAEForVideoClassification) if is_torch_available() else ()
							)
							lowercase			:		str   		=  (
							    {'feature-extraction': VideoMAEModel, 'video-classification': VideoMAEForVideoClassification}
							    if is_torch_available()
							    else {}
							)

							lowercase			:		Union[str, Any]   		=  False
							lowercase			:		List[str]   		=  False
							lowercase			:		List[Any]   		=  False
							lowercase			:		Union[str, Any]   		=  False





							def 		a__   (  self		:int			):
									snake_case_		:							Optional[int]			       =						VideoMAEModelTester(self			)
									snake_case_		:							Tuple			       =						ConfigTester(self  ,config_class=_UpperCamelCase  ,has_text_modality=_UpperCamelCase  ,hidden_size=3_7			)





							def 		a__   (  self		:Tuple  ,_UpperCamelCase		:Dict  ,_UpperCamelCase		:Optional[int]  ,_UpperCamelCase		:str=False			):
									snake_case_		:							Union[str, Any]			       =						copy.deepcopy(_UpperCamelCase			)

									if model_class == VideoMAEForPreTraining:
											# important: each video needs to have the same number of masked patches
											# hence we define a single mask, which we then repeat for each example in the batch
											snake_case_		:							str			       =						torch.ones((self.model_tester.num_masks,)			)
											snake_case_		:							int			       =						torch.cat([mask, torch.zeros(self.model_tester.seq_length - mask.size(0			)			)]			)
											snake_case_		:							int			       =						mask.expand(self.model_tester.batch_size  ,-1			).bool()
											snake_case_		:							Union[str, Any]			       =						bool_masked_pos.to(_UpperCamelCase			)

									if return_labels:
											if model_class in [
											    *get_values(_UpperCamelCase			),
											]:
													snake_case_		:							Dict			       =						torch.zeros(
													    self.model_tester.batch_size  ,dtype=torch.long  ,device=_UpperCamelCase			)

									return inputs_dict





							def 		a__   (  self		:Optional[Any]			):
									self.config_tester.run_common_tests()





							@unittest.skip(reason="""VideoMAE does not use inputs_embeds"""			)
							def 		a__   (  self		:Optional[Any]			):
									pass





							def 		a__   (  self		:Union[str, Any]			):
									snake_case_		:							Tuple			       =						self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
											snake_case_		:							Optional[Any]			       =						model_class(_UpperCamelCase			)
											self.assertIsInstance(model.get_input_embeddings()  ,(nn.Module)			)
											snake_case_		:							Dict			       =						model.get_output_embeddings()
											self.assertTrue(x is None or isinstance(_UpperCamelCase  ,nn.Linear			)			)





							def 		a__   (  self		:Dict			):
									snake_case_		:							Optional[Any]			       =						self.model_tester.prepare_config_and_inputs_for_common()

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

											snake_case_		:							Tuple			       =						['''pixel_values''']
											self.assertListEqual(arg_names[:1]  ,_UpperCamelCase			)





							def 		a__   (  self		:Any			):
									snake_case_		:							Any			       =						self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*_UpperCamelCase			)





							def 		a__   (  self		:Union[str, Any]			):
									snake_case_		:							List[Any]			       =						self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_pretraining(*_UpperCamelCase			)





							@slow
							def 		a__   (  self		:Tuple			):
									for model_name in VIDEOMAE_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											snake_case_		:							int			       =						VideoMAEModel.from_pretrained(_UpperCamelCase			)
											self.assertIsNotNone(_UpperCamelCase			)





							def 		a__   (  self		:List[str]			):
									if not self.has_attentions:
											pass

									else:
											snake_case_		:							List[Any]			       =						self.model_tester.prepare_config_and_inputs_for_common()
											snake_case_		:							int			       =						True

											for model_class in self.all_model_classes:
													snake_case_		:							Dict			       =						self.model_tester.seq_length - self.model_tester.num_masks
													snake_case_		:							Union[str, Any]			       =						(
													    num_visible_patches if model_class == VideoMAEForPreTraining else self.model_tester.seq_length
													)

													snake_case_		:							Union[str, Any]			       =						True
													snake_case_		:							Optional[Any]			       =						False
													snake_case_		:							Optional[int]			       =						True
													snake_case_		:							Union[str, Any]			       =						model_class(_UpperCamelCase			)
													model.to(_UpperCamelCase			)
													model.eval()
													with torch.no_grad():
															snake_case_		:							int			       =						model(**self._prepare_for_class(_UpperCamelCase  ,_UpperCamelCase			)			)
													snake_case_		:							Any			       =						outputs.attentions
													self.assertEqual(len(_UpperCamelCase			)  ,self.model_tester.num_hidden_layers			)

													# check that output_attentions also work using config
													del inputs_dict["output_attentions"]
													snake_case_		:							Optional[Any]			       =						True
													snake_case_		:							List[Any]			       =						model_class(_UpperCamelCase			)
													model.to(_UpperCamelCase			)
													model.eval()
													with torch.no_grad():
															snake_case_		:							Dict			       =						model(**self._prepare_for_class(_UpperCamelCase  ,_UpperCamelCase			)			)
													snake_case_		:							Optional[Any]			       =						outputs.attentions
													self.assertEqual(len(_UpperCamelCase			)  ,self.model_tester.num_hidden_layers			)

													self.assertListEqual(
													    list(attentions[0].shape[-3:]			)  ,[self.model_tester.num_attention_heads, seq_len, seq_len]  ,)
													snake_case_		:							Union[str, Any]			       =						len(_UpperCamelCase			)

													# Check attention is always last and order is fine
													snake_case_		:							Optional[int]			       =						True
													snake_case_		:							Optional[Any]			       =						True
													snake_case_		:							List[Any]			       =						model_class(_UpperCamelCase			)
													model.to(_UpperCamelCase			)
													model.eval()
													with torch.no_grad():
															snake_case_		:							Optional[Any]			       =						model(**self._prepare_for_class(_UpperCamelCase  ,_UpperCamelCase			)			)

													self.assertEqual(out_len + 1  ,len(_UpperCamelCase			)			)

													snake_case_		:							Optional[int]			       =						outputs.attentions

													self.assertEqual(len(_UpperCamelCase			)  ,self.model_tester.num_hidden_layers			)
													self.assertListEqual(
													    list(self_attentions[0].shape[-3:]			)  ,[self.model_tester.num_attention_heads, seq_len, seq_len]  ,)





							def 		a__   (  self		:Union[str, Any]			):
									def check_hidden_states_output(_UpperCamelCase		:str  ,_UpperCamelCase		:int  ,_UpperCamelCase		:Optional[int]			):
											snake_case_		:							int			       =						model_class(_UpperCamelCase			)
											model.to(_UpperCamelCase			)
											model.eval()

											with torch.no_grad():
													snake_case_		:							Dict			       =						model(**self._prepare_for_class(_UpperCamelCase  ,_UpperCamelCase			)			)

											snake_case_		:							Any			       =						outputs.hidden_states
											snake_case_		:							int			       =						self.model_tester.num_hidden_layers + 1
											self.assertEqual(len(_UpperCamelCase			)  ,_UpperCamelCase			)

											snake_case_		:							str			       =						self.model_tester.seq_length - self.model_tester.num_masks
											snake_case_		:							Optional[int]			       =						num_visible_patches if model_class == VideoMAEForPreTraining else self.model_tester.seq_length

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

									snake_case_		:							int			       =						self.model_tester.prepare_config_and_inputs_for_common()

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

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

											check_hidden_states_output(_UpperCamelCase  ,_UpperCamelCase  ,_UpperCamelCase			)





							@unittest.skip("""Will be fixed soon by reducing the size of the model used for common tests."""			)
							def 		a__   (  self		:Union[str, Any]			):
									pass





def      UpperCAmelCase      (		):







		'''simple docstring'''
		snake_case_		:							Optional[int]			       =						hf_hub_download(
		    repo_id="""hf-internal-testing/spaghetti-video"""				,      filename="""eating_spaghetti.npy"""				,      repo_type="""dataset""" )
		snake_case_		:							List[str]			       =						np.load(snake_case_ )
		return list(snake_case_ )






@require_torch
@require_vision
class 						__UpperCamelCase	(						unittest.TestCase							):





							@cached_property
							def 		a__   (  self		:str			):
									# logits were tested with a different mean and std, so we use the same here
									return (
									    VideoMAEImageProcessor(image_mean=[0.5, 0.5, 0.5]  ,image_std=[0.5, 0.5, 0.5]			)
									    if is_vision_available()
									    else None
									)





							@slow
							def 		a__   (  self		:Optional[Any]			):
									snake_case_		:							Dict			       =						VideoMAEForVideoClassification.from_pretrained("""MCG-NJU/videomae-base-finetuned-kinetics"""			).to(
									    _UpperCamelCase			)

									snake_case_		:							Dict			       =						self.default_image_processor
									snake_case_		:							Any			       =						prepare_video()
									snake_case_		:							List[Any]			       =						image_processor(_UpperCamelCase  ,return_tensors="""pt"""			).to(_UpperCamelCase			)

									# forward pass
									with torch.no_grad():
											snake_case_		:							Union[str, Any]			       =						model(**_UpperCamelCase			)

									# verify the logits
									snake_case_		:							Any			       =						torch.Size((1, 4_0_0)			)
									self.assertEqual(outputs.logits.shape  ,_UpperCamelCase			)

									snake_case_		:							Optional[Any]			       =						torch.tensor([0.36_69, -0.06_88, -0.24_21]			).to(_UpperCamelCase			)

									self.assertTrue(torch.allclose(outputs.logits[0, :3]  ,_UpperCamelCase  ,atol=1E-4			)			)





							@slow
							def 		a__   (  self		:Optional[Any]			):
									snake_case_		:							int			       =						VideoMAEForPreTraining.from_pretrained("""MCG-NJU/videomae-base-short"""			).to(_UpperCamelCase			)

									snake_case_		:							List[Any]			       =						self.default_image_processor
									snake_case_		:							Dict			       =						prepare_video()
									snake_case_		:							int			       =						image_processor(_UpperCamelCase  ,return_tensors="""pt"""			).to(_UpperCamelCase			)

									# add boolean mask, indicating which patches to mask
									snake_case_		:							List[Any]			       =						hf_hub_download(repo_id="""hf-internal-testing/bool-masked-pos"""  ,filename="""bool_masked_pos.pt"""			)
									snake_case_		:							List[Any]			       =						torch.load(_UpperCamelCase			)

									# forward pass
									with torch.no_grad():
											snake_case_		:							str			       =						model(**_UpperCamelCase			)

									# verify the logits
									snake_case_		:							Tuple			       =						torch.Size([1, 1_4_0_8, 1_5_3_6]			)
									snake_case_		:							Optional[int]			       =						torch.tensor(
									    [[0.79_94, 0.96_12, 0.85_08], [0.74_01, 0.89_58, 0.83_02], [0.58_62, 0.74_68, 0.73_25]]  ,device=_UpperCamelCase			)
									self.assertEqual(outputs.logits.shape  ,_UpperCamelCase			)
									self.assertTrue(torch.allclose(outputs.logits[0, :3, :3]  ,_UpperCamelCase  ,atol=1E-4			)			)

									# verify the loss (`config.norm_pix_loss` = `True`)
									snake_case_		:							str			       =						torch.tensor([0.51_42]  ,device=_UpperCamelCase			)
									self.assertTrue(torch.allclose(outputs.loss  ,_UpperCamelCase  ,atol=1E-4			)			)

									# verify the loss (`config.norm_pix_loss` = `False`)
									snake_case_		:							Dict			       =						VideoMAEForPreTraining.from_pretrained("""MCG-NJU/videomae-base-short"""  ,norm_pix_loss=_UpperCamelCase			).to(
									    _UpperCamelCase			)

									with torch.no_grad():
											snake_case_		:							List[Any]			       =						model(**_UpperCamelCase			)

									snake_case_		:							Optional[Any]			       =						torch.tensor(torch.tensor([0.64_69]			)  ,device=_UpperCamelCase			)
									self.assertTrue(torch.allclose(outputs.loss  ,_UpperCamelCase  ,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 KandinskyVaaPriorPipeline, 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	(						lowercase__						,  unittest.TestCase							):
							lowercase			:		List[str]   		=  KandinskyVaaPriorPipeline
							lowercase			:		Optional[Any]   		=  ['prompt']
							lowercase			:		Dict   		=  ['prompt', 'negative_prompt']
							lowercase			:		Dict   		=  [
							    'num_images_per_prompt',
							    'generator',
							    'num_inference_steps',
							    'latents',
							    'negative_prompt',
							    'guidance_scale',
							    'output_type',
							    'return_dict',
							]
							lowercase			:		int   		=  False





							@property
							def 		a__   (  self		:int			):
									return 3_2





							@property
							def 		a__   (  self		:Any			):
									return 3_2





							@property
							def 		a__   (  self		:Union[str, Any]			):
									return self.time_input_dim





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





							@property
							def 		a__   (  self		:Dict			):
									return 1_0_0





							@property
							def 		a__   (  self		:List[Any]			):
									snake_case_		:							List[Any]			       =						CLIPTokenizer.from_pretrained("""hf-internal-testing/tiny-random-clip"""			)
									return tokenizer





							@property
							def 		a__   (  self		:int			):
									torch.manual_seed(0			)
									snake_case_		:							Optional[Any]			       =						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-0_5  ,num_attention_heads=4  ,num_hidden_layers=5  ,pad_token_id=1  ,vocab_size=1_0_0_0  ,)
									return CLIPTextModelWithProjection(_UpperCamelCase			)





							@property
							def 		a__   (  self		:Dict			):
									torch.manual_seed(0			)

									snake_case_		:							Tuple			       =						{
									    """num_attention_heads""": 2,
									    """attention_head_dim""": 1_2,
									    """embedding_dim""": self.text_embedder_hidden_size,
									    """num_layers""": 1,
									}

									snake_case_		:							int			       =						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_		:							Any			       =						nn.Parameter(torch.ones(model.clip_std.shape			)			)
									return model





							@property
							def 		a__   (  self		:Optional[int]			):
									torch.manual_seed(0			)
									snake_case_		:							Any			       =						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  ,)

									snake_case_		:							Optional[Any]			       =						CLIPVisionModelWithProjection(_UpperCamelCase			)
									return model





							@property
							def 		a__   (  self		:List[Any]			):
									snake_case_		:							Any			       =						CLIPImageProcessor(
									    crop_size=2_2_4  ,do_center_crop=_UpperCamelCase  ,do_normalize=_UpperCamelCase  ,do_resize=_UpperCamelCase  ,image_mean=[0.48_14_54_66, 0.4_57_82_75, 0.40_82_10_73]  ,image_std=[0.26_86_29_54, 0.26_13_02_58, 0.27_57_77_11]  ,resample=3  ,size=2_2_4  ,)

									return image_processor





							def 		a__   (  self		:List[Any]			):
									snake_case_		:							Tuple			       =						self.dummy_prior
									snake_case_		:							Any			       =						self.dummy_image_encoder
									snake_case_		:							Optional[int]			       =						self.dummy_text_encoder
									snake_case_		:							Any			       =						self.dummy_tokenizer
									snake_case_		:							Union[str, Any]			       =						self.dummy_image_processor

									snake_case_		:							Tuple			       =						UnCLIPScheduler(
									    variance_type="""fixed_small_log"""  ,prediction_type="""sample"""  ,num_train_timesteps=1_0_0_0  ,clip_sample=_UpperCamelCase  ,clip_sample_range=10.0  ,)

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

									return components





							def 		a__   (  self		:Dict  ,_UpperCamelCase		:str  ,_UpperCamelCase		:Union[str, Any]=0			):
									if str(_UpperCamelCase			).startswith("""mps"""			):
											snake_case_		:							Optional[int]			       =						torch.manual_seed(_UpperCamelCase			)
									else:
											snake_case_		:							int			       =						torch.Generator(device=_UpperCamelCase			).manual_seed(_UpperCamelCase			)
									snake_case_		:							Dict			       =						{
									    """prompt""": """horse""",
									    """generator""": generator,
									    """guidance_scale""": 4.0,
									    """num_inference_steps""": 2,
									    """output_type""": """np""",
									}
									return inputs





							def 		a__   (  self		:int			):
									snake_case_		:							Union[str, Any]			       =						"""cpu"""

									snake_case_		:							int			       =						self.get_dummy_components()

									snake_case_		:							int			       =						self.pipeline_class(**_UpperCamelCase			)
									snake_case_		:							Union[str, Any]			       =						pipe.to(_UpperCamelCase			)

									pipe.set_progress_bar_config(disable=_UpperCamelCase			)

									snake_case_		:							Any			       =						pipe(**self.get_dummy_inputs(_UpperCamelCase			)			)
									snake_case_		:							List[Any]			       =						output.image_embeds

									snake_case_		:							List[Any]			       =						pipe(
									    **self.get_dummy_inputs(_UpperCamelCase			)  ,return_dict=_UpperCamelCase  ,)[0]

									snake_case_		:							Dict			       =						image[0, -1_0:]
									snake_case_		:							Optional[Any]			       =						image_from_tuple[0, -1_0:]

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

									snake_case_		:							Optional[int]			       =						np.array(
									    [-0.05_32, 1.71_20, 0.36_56, -1.08_52, -0.89_46, -1.17_56, 0.43_48, 0.24_82, 0.51_46, -0.11_56]			)

									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 		a__   (  self		:List[Any]			):
									snake_case_		:							Any			       =						torch_device == """cpu"""
									snake_case_		:							Any			       =						True
									snake_case_		:							Dict			       =						False

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





							@skip_mps
							def 		a__   (  self		:str			):
									snake_case_		:							str			       =						torch_device == """cpu"""
									snake_case_		:							List[str]			       =						False

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