




import unittest

from transformers import ElectraConfig, is_torch_available
from transformers.models.auto import get_values
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 (
							    MODEL_FOR_PRETRAINING_MAPPING,
							    ElectraForCausalLM,
							    ElectraForMaskedLM,
							    ElectraForMultipleChoice,
							    ElectraForPreTraining,
							    ElectraForQuestionAnswering,
							    ElectraForSequenceClassification,
							    ElectraForTokenClassification,
							    ElectraModel,
							)
							from transformers.models.electra.modeling_electra import ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST


class 					__SCREAMING_SNAKE_CASE							:

					def __init__(    self			,	__lowercase			,	__lowercase=13			,	__lowercase=7			,	__lowercase=True			,	__lowercase=True			,	__lowercase=True			,	__lowercase=True			,	__lowercase=99			,	__lowercase=32			,	__lowercase=5			,	__lowercase=4			,	__lowercase=37			,	__lowercase="gelu"			,	__lowercase=0.1			,	__lowercase=0.1			,	__lowercase=512			,	__lowercase=16			,	__lowercase=2			,	__lowercase=0.02			,	__lowercase=3			,	__lowercase=4			,	__lowercase=None			,	):







						'''simple docstring'''




						lowerCamelCase_							:		Dict							       =							parent
						lowerCamelCase_							:		List[str]							       =							batch_size
						lowerCamelCase_							:		Dict							       =							seq_length
						lowerCamelCase_							:		List[str]							       =							is_training
						lowerCamelCase_							:		List[Any]							       =							use_input_mask
						lowerCamelCase_							:		Optional[Any]							       =							use_token_type_ids
						lowerCamelCase_							:		Optional[int]							       =							use_labels
						lowerCamelCase_							:		List[str]							       =							vocab_size
						lowerCamelCase_							:		Any							       =							hidden_size
						lowerCamelCase_							:		List[Any]							       =							num_hidden_layers
						lowerCamelCase_							:		Any							       =							num_attention_heads
						lowerCamelCase_							:		Dict							       =							intermediate_size
						lowerCamelCase_							:		Optional[Any]							       =							hidden_act
						lowerCamelCase_							:		Optional[int]							       =							hidden_dropout_prob
						lowerCamelCase_							:		List[Any]							       =							attention_probs_dropout_prob
						lowerCamelCase_							:		Optional[Any]							       =							max_position_embeddings
						lowerCamelCase_							:		Optional[Any]							       =							type_vocab_size
						lowerCamelCase_							:		List[Any]							       =							type_sequence_label_size
						lowerCamelCase_							:		Tuple							       =							initializer_range
						lowerCamelCase_							:		List[str]							       =							num_labels
						lowerCamelCase_							:		Optional[Any]							       =							num_choices
						lowerCamelCase_							:		List[str]							       =							scope

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		List[str]							       =							ids_tensor([self.batch_size, self.seq_length]			,	self.vocab_size )

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

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

						lowerCamelCase_							:		str							       =							None
						lowerCamelCase_							:		Optional[int]							       =							None
						lowerCamelCase_							:		Tuple							       =							None
						if self.use_labels:
							lowerCamelCase_							:		Optional[int]							       =							ids_tensor([self.batch_size]			,	self.type_sequence_label_size )
							lowerCamelCase_							:		List[Any]							       =							ids_tensor([self.batch_size, self.seq_length]			,	self.num_labels )
							lowerCamelCase_							:		str							       =							ids_tensor([self.batch_size]			,	self.num_choices )
							lowerCamelCase_							:		Tuple							       =							ids_tensor([self.batch_size, self.seq_length]			,	1 )

						lowerCamelCase_							:		Any							       =							self.get_config()

						return (
						    config,
						    input_ids,
						    token_type_ids,
						    input_mask,
						    sequence_labels,
						    token_labels,
						    choice_labels,
						    fake_token_labels,
						)

					def      lowercase_							(    self ):







						'''simple docstring'''




						return ElectraConfig(
						    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			,	is_decoder=snake_case_			,	initializer_range=self.initializer_range			,	)

					def      lowercase_							(    self ):







						'''simple docstring'''




						(
						    lowerCamelCase_   
						)							:		int							       =							self.prepare_config_and_inputs()

						lowerCamelCase_							:		str							       =							True
						lowerCamelCase_							:		List[str]							       =							floats_tensor([self.batch_size, self.seq_length, self.hidden_size] )
						lowerCamelCase_							:		Optional[Any]							       =							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      lowercase_							(    self			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	):







						'''simple docstring'''




						lowerCamelCase_							:		List[Any]							       =							ElectraModel(config=snake_case_ )
						model.to(snake_case_ )
						model.eval()
						lowerCamelCase_							:		List[Any]							       =							model(snake_case_			,	attention_mask=snake_case_			,	token_type_ids=snake_case_ )
						lowerCamelCase_							:		Optional[int]							       =							model(snake_case_			,	token_type_ids=snake_case_ )
						lowerCamelCase_							:		List[str]							       =							model(snake_case_ )
						self.parent.assertEqual(result.last_hidden_state.shape			,	(self.batch_size, self.seq_length, self.hidden_size) )

					def      lowercase_							(    self			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	):







						'''simple docstring'''




						lowerCamelCase_							:		Optional[int]							       =							True
						lowerCamelCase_							:		List[str]							       =							ElectraModel(snake_case_ )
						model.to(snake_case_ )
						model.eval()
						lowerCamelCase_							:		Tuple							       =							model(
						    snake_case_			,	attention_mask=snake_case_			,	token_type_ids=snake_case_			,	encoder_hidden_states=snake_case_			,	encoder_attention_mask=snake_case_			,	)
						lowerCamelCase_							:		Dict							       =							model(
						    snake_case_			,	attention_mask=snake_case_			,	token_type_ids=snake_case_			,	encoder_hidden_states=snake_case_			,	)
						lowerCamelCase_							:		Any							       =							model(snake_case_			,	attention_mask=snake_case_			,	token_type_ids=snake_case_ )
						self.parent.assertEqual(result.last_hidden_state.shape			,	(self.batch_size, self.seq_length, self.hidden_size) )

					def      lowercase_							(    self			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	):







						'''simple docstring'''




						lowerCamelCase_							:		Tuple							       =							ElectraForMaskedLM(config=snake_case_ )
						model.to(snake_case_ )
						model.eval()
						lowerCamelCase_							:		Optional[int]							       =							model(snake_case_			,	attention_mask=snake_case_			,	token_type_ids=snake_case_			,	labels=snake_case_ )
						self.parent.assertEqual(result.logits.shape			,	(self.batch_size, self.seq_length, self.vocab_size) )

					def      lowercase_							(    self			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	):







						'''simple docstring'''




						lowerCamelCase_							:		Union[str, Any]							       =							ElectraForCausalLM(config=snake_case_ )
						model.to(snake_case_ )
						model.eval()
						lowerCamelCase_							:		Any							       =							model(snake_case_			,	attention_mask=snake_case_			,	token_type_ids=snake_case_			,	labels=snake_case_ )
						self.parent.assertEqual(result.logits.shape			,	(self.batch_size, self.seq_length, self.vocab_size) )

					def      lowercase_							(    self			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	):







						'''simple docstring'''




						lowerCamelCase_							:		Dict							       =							self.num_labels
						lowerCamelCase_							:		int							       =							ElectraForTokenClassification(config=snake_case_ )
						model.to(snake_case_ )
						model.eval()
						lowerCamelCase_							:		Optional[Any]							       =							model(snake_case_			,	attention_mask=snake_case_			,	token_type_ids=snake_case_			,	labels=snake_case_ )
						self.parent.assertEqual(result.logits.shape			,	(self.batch_size, self.seq_length, self.num_labels) )

					def      lowercase_							(    self			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	):







						'''simple docstring'''




						lowerCamelCase_							:		Tuple							       =							self.num_labels
						lowerCamelCase_							:		Optional[int]							       =							ElectraForPreTraining(config=snake_case_ )
						model.to(snake_case_ )
						model.eval()
						lowerCamelCase_							:		str							       =							model(snake_case_			,	attention_mask=snake_case_			,	token_type_ids=snake_case_			,	labels=snake_case_ )
						self.parent.assertEqual(result.logits.shape			,	(self.batch_size, self.seq_length) )

					def      lowercase_							(    self			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	):







						'''simple docstring'''




						lowerCamelCase_							:		List[str]							       =							self.num_labels
						lowerCamelCase_							:		Union[str, Any]							       =							ElectraForSequenceClassification(snake_case_ )
						model.to(snake_case_ )
						model.eval()
						lowerCamelCase_							:		Dict							       =							model(snake_case_			,	attention_mask=snake_case_			,	token_type_ids=snake_case_			,	labels=snake_case_ )
						self.parent.assertEqual(result.logits.shape			,	(self.batch_size, self.num_labels) )

					def      lowercase_							(    self			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	):







						'''simple docstring'''




						lowerCamelCase_							:		List[str]							       =							ElectraForQuestionAnswering(config=snake_case_ )
						model.to(snake_case_ )
						model.eval()
						lowerCamelCase_							:		Any							       =							model(
						    snake_case_			,	attention_mask=snake_case_			,	token_type_ids=snake_case_			,	start_positions=snake_case_			,	end_positions=snake_case_			,	)
						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      lowercase_							(    self			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	):







						'''simple docstring'''




						lowerCamelCase_							:		Optional[Any]							       =							self.num_choices
						lowerCamelCase_							:		List[Any]							       =							ElectraForMultipleChoice(config=snake_case_ )
						model.to(snake_case_ )
						model.eval()
						lowerCamelCase_							:		Optional[int]							       =							input_ids.unsqueeze(1 ).expand(-1			,	self.num_choices			,	-1 ).contiguous()
						lowerCamelCase_							:		Any							       =							token_type_ids.unsqueeze(1 ).expand(-1			,	self.num_choices			,	-1 ).contiguous()
						lowerCamelCase_							:		Optional[Any]							       =							input_mask.unsqueeze(1 ).expand(-1			,	self.num_choices			,	-1 ).contiguous()
						lowerCamelCase_							:		Dict							       =							model(
						    snake_case_			,	attention_mask=snake_case_			,	token_type_ids=snake_case_			,	labels=snake_case_			,	)
						self.parent.assertEqual(result.logits.shape			,	(self.batch_size, self.num_choices) )





					def      lowercase_							(    self ):







						'''simple docstring'''




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


@require_torch
class 					__SCREAMING_SNAKE_CASE							(		_a       ,					_a       ,					unittest.TestCase  ):
					_lowerCamelCase		  =			(
					    (
					        ElectraModel,
					        ElectraForPreTraining,
					        ElectraForMaskedLM,
					        ElectraForCausalLM,
					        ElectraForMultipleChoice,
					        ElectraForTokenClassification,
					        ElectraForSequenceClassification,
					        ElectraForQuestionAnswering,
					    )
					    if is_torch_available()
					    else ()
					)
					_lowerCamelCase		  =			(
					    {
					        """feature-extraction""": ElectraModel,
					        """fill-mask""": ElectraForMaskedLM,
					        """question-answering""": ElectraForQuestionAnswering,
					        """text-classification""": ElectraForSequenceClassification,
					        """text-generation""": ElectraForCausalLM,
					        """token-classification""": ElectraForTokenClassification,
					        """zero-shot""": ElectraForSequenceClassification,
					    }
					    if is_torch_available()
					    else {}
					)
					_lowerCamelCase		  =			True

					def      lowercase_							(    self			,	__lowercase			,	__lowercase			,	__lowercase=False ):







						'''simple docstring'''




						lowerCamelCase_							:		Tuple							       =							super()._prepare_for_class(snake_case_			,	snake_case_			,	return_labels=snake_case_ )

						if return_labels:
							if model_class in get_values(snake_case_ ):
								lowerCamelCase_							:		List[Any]							       =							torch.zeros(
								    (self.model_tester.batch_size, self.model_tester.seq_length)			,	dtype=torch.long			,	device=snake_case_ )
						return inputs_dict

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Tuple							       =							ElectraModelTester(self )
						lowerCamelCase_							:		List[str]							       =							ConfigTester(self			,	config_class=snake_case_			,	hidden_size=37 )

					def      lowercase_							(    self ):







						'''simple docstring'''




						self.config_tester.run_common_tests()

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Dict							       =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_electra_model(*snake_case_ )

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		List[Any]							       =							self.model_tester.prepare_config_and_inputs_for_decoder()
						self.model_tester.create_and_check_electra_model_as_decoder(*snake_case_ )

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Dict							       =							self.model_tester.prepare_config_and_inputs()
						for type in ["absolute", "relative_key", "relative_key_query"]:
							lowerCamelCase_							:		str							       =							type
							self.model_tester.create_and_check_electra_model(*snake_case_ )

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Union[str, Any]							       =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_electra_for_masked_lm(*snake_case_ )

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Dict							       =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_electra_for_token_classification(*snake_case_ )

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		List[str]							       =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_electra_for_pretraining(*snake_case_ )

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		int							       =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_electra_for_sequence_classification(*snake_case_ )

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Optional[Any]							       =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_electra_for_question_answering(*snake_case_ )

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		List[Any]							       =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_electra_for_multiple_choice(*snake_case_ )

					@slow
					def      lowercase_							(    self ):







						'''simple docstring'''




						for model_name in ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							lowerCamelCase_							:		str							       =							ElectraModel.from_pretrained(snake_case_ )
							self.assertIsNotNone(snake_case_ )





					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Any							       =							self.model_tester.prepare_config_and_inputs_for_decoder()
						self.model_tester.create_and_check_electra_for_causal_lm(*snake_case_ )


@require_torch
class 					__SCREAMING_SNAKE_CASE							(		unittest.TestCase  ):

					@slow
					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		List[Any]							       =							ElectraModel.from_pretrained('google/electra-small-discriminator' )
						lowerCamelCase_							:		Union[str, Any]							       =							torch.tensor([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]] )
						lowerCamelCase_							:		Dict							       =							torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]] )
						lowerCamelCase_							:		Optional[Any]							       =							model(snake_case_			,	attention_mask=snake_case_ )[0]
						lowerCamelCase_							:		List[str]							       =							torch.Size((1, 11, 256) )
						self.assertEqual(output.shape			,	snake_case_ )
						lowerCamelCase_							:		Optional[int]							       =							torch.tensor(
						    [[[0.44_71, 0.68_21, -0.32_65], [0.46_27, 0.52_55, -0.36_68], [0.45_32, 0.33_13, -0.43_44]]] )

						self.assertTrue(torch.allclose(output[:, 1:4, 1:4]			,	snake_case_			,	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     __SCREAMING_SNAKE_CASE							(		lowerCamelCase       ,					unittest.TestCase  ):
					_lowerCamelCase		  =			KandinskyVaaPriorEmbaEmbPipeline
					_lowerCamelCase		  =			["""prompt""", """image"""]
					_lowerCamelCase		  =			["""prompt""", """image"""]
					_lowerCamelCase		  =			[
					    """num_images_per_prompt""",
					    """strength""",
					    """generator""",
					    """num_inference_steps""",
					    """latents""",
					    """negative_prompt""",
					    """guidance_scale""",
					    """output_type""",
					    """return_dict""",
					]
					_lowerCamelCase		  =			False

					@property
					def      lowercase_							(    self ):







						'''simple docstring'''




						return 32

					@property
					def      lowercase_							(    self ):







						'''simple docstring'''




						return 32

					@property
					def      lowercase_							(    self ):







						'''simple docstring'''




						return self.time_input_dim

					@property
					def      lowercase_							(    self ):







						'''simple docstring'''




						return self.time_input_dim * 4

					@property
					def      lowercase_							(    self ):







						'''simple docstring'''




						return 100

					@property
					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Dict							       =							CLIPTokenizer.from_pretrained('hf-internal-testing/tiny-random-clip' )
						return tokenizer

					@property
					def      lowercase_							(    self ):







						'''simple docstring'''




						torch.manual_seed(0 )
						lowerCamelCase_							:		Dict							       =							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=1_000			,	)
						return CLIPTextModelWithProjection(__lowercase )

					@property
					def      lowercase_							(    self ):







						'''simple docstring'''




						torch.manual_seed(0 )

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

						lowerCamelCase_							:		str							       =							PriorTransformer(**__lowercase )
						# 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
						lowerCamelCase_							:		Dict							       =							nn.Parameter(torch.ones(model.clip_std.shape ) )
						return model

					@property
					def      lowercase_							(    self ):







						'''simple docstring'''




						torch.manual_seed(0 )
						lowerCamelCase_							:		str							       =							CLIPVisionConfig(
						    hidden_size=self.text_embedder_hidden_size			,	image_size=224			,	projection_dim=self.text_embedder_hidden_size			,	intermediate_size=37			,	num_attention_heads=4			,	num_channels=3			,	num_hidden_layers=5			,	patch_size=14			,	)

						lowerCamelCase_							:		List[str]							       =							CLIPVisionModelWithProjection(__lowercase )
						return model

					@property
					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		int							       =							CLIPImageProcessor(
						    crop_size=224			,	do_center_crop=__lowercase			,	do_normalize=__lowercase			,	do_resize=__lowercase			,	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=224			,	)

						return image_processor

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		List[Any]							       =							self.dummy_prior
						lowerCamelCase_							:		str							       =							self.dummy_image_encoder
						lowerCamelCase_							:		Tuple							       =							self.dummy_text_encoder
						lowerCamelCase_							:		str							       =							self.dummy_tokenizer
						lowerCamelCase_							:		int							       =							self.dummy_image_processor

						lowerCamelCase_							:		Dict							       =							UnCLIPScheduler(
						    variance_type='fixed_small_log'			,	prediction_type='sample'			,	num_train_timesteps=1_000			,	clip_sample=__lowercase			,	clip_sample_range=10.0			,	)

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

						return components

					def      lowercase_							(    self			,	__lowercase			,	__lowercase=0 ):







						'''simple docstring'''




						if str(__lowercase ).startswith('mps' ):
							lowerCamelCase_							:		Union[str, Any]							       =							torch.manual_seed(__lowercase )
						else:
							lowerCamelCase_							:		Optional[Any]							       =							torch.Generator(device=__lowercase ).manual_seed(__lowercase )

						lowerCamelCase_							:		Optional[int]							       =							floats_tensor((1, 3, 64, 64)			,	rng=random.Random(__lowercase ) ).to(__lowercase )
						lowerCamelCase_							:		Any							       =							image.cpu().permute(0			,	2			,	3			,	1 )[0]
						lowerCamelCase_							:		List[Any]							       =							Image.fromarray(np.uinta(__lowercase ) ).convert('RGB' ).resize((256, 256) )

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

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		str							       =							'cpu'

						lowerCamelCase_							:		Union[str, Any]							       =							self.get_dummy_components()

						lowerCamelCase_							:		str							       =							self.pipeline_class(**__lowercase )
						lowerCamelCase_							:		Optional[Any]							       =							pipe.to(__lowercase )

						pipe.set_progress_bar_config(disable=__lowercase )

						lowerCamelCase_							:		List[str]							       =							pipe(**self.get_dummy_inputs(__lowercase ) )
						lowerCamelCase_							:		Union[str, Any]							       =							output.image_embeds

						lowerCamelCase_							:		List[str]							       =							pipe(
						    **self.get_dummy_inputs(__lowercase )			,	return_dict=__lowercase			,	)[0]

						lowerCamelCase_							:		List[Any]							       =							image[0, -10:]
						lowerCamelCase_							:		List[Any]							       =							image_from_tuple[0, -10:]

						assert image.shape == (1, 32)

						lowerCamelCase_							:		Any							       =							np.array(
						    [
						        0.1_07_12_84,
						        1.3_33_02_71,
						        0.61_26_02_23,
						        -0.6_69_10_65,
						        -0.3_84_68_52,
						        -1.0_30_36_61,
						        0.22_71_61_11,
						        0.03_34_89_01,
						        0.30_04_06_75,
						        -0.24_80_50_29,
						    ] )

						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      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		int							       =							torch_device == 'cpu'
						lowerCamelCase_							:		Union[str, Any]							       =							True
						lowerCamelCase_							:		str							       =							False

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





					@skip_mps
					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Optional[Any]							       =							torch_device == 'cpu'
						lowerCamelCase_							:		Optional[Any]							       =							False

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