




import unittest

from transformers import FunnelConfig, FunnelTokenizer, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

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


if is_torch_available():
							import torch

							from transformers import (
							    MODEL_FOR_PRETRAINING_MAPPING,
							    FunnelBaseModel,
							    FunnelForMaskedLM,
							    FunnelForMultipleChoice,
							    FunnelForPreTraining,
							    FunnelForQuestionAnswering,
							    FunnelForSequenceClassification,
							    FunnelForTokenClassification,
							    FunnelModel,
							)


class     __SCREAMING_SNAKE_CASE							:

					def __init__(    self			,	__lowercase			,	__lowercase=13			,	__lowercase=7			,	__lowercase=True			,	__lowercase=True			,	__lowercase=True			,	__lowercase=True			,	__lowercase=99			,	__lowercase=[1, 1, 2]			,	__lowercase=1			,	__lowercase=32			,	__lowercase=4			,	__lowercase=8			,	__lowercase=37			,	__lowercase="gelu_new"			,	__lowercase=0.1			,	__lowercase=0.1			,	__lowercase=0.0			,	__lowercase=512			,	__lowercase=3			,	__lowercase=0.02			,	__lowercase=3			,	__lowercase=4			,	__lowercase=None			,	__lowercase=False			,	):







						'''simple docstring'''




						lowerCamelCase_							:		Optional[int]							       =							parent
						lowerCamelCase_							:		List[str]							       =							batch_size
						lowerCamelCase_							:		Dict							       =							seq_length
						lowerCamelCase_							:		Any							       =							is_training
						lowerCamelCase_							:		List[Any]							       =							use_input_mask
						lowerCamelCase_							:		Any							       =							use_token_type_ids
						lowerCamelCase_							:		List[Any]							       =							use_labels
						lowerCamelCase_							:		Dict							       =							vocab_size
						lowerCamelCase_							:		List[str]							       =							block_sizes
						lowerCamelCase_							:		Dict							       =							num_decoder_layers
						lowerCamelCase_							:		Optional[int]							       =							d_model
						lowerCamelCase_							:		Any							       =							n_head
						lowerCamelCase_							:		Optional[int]							       =							d_head
						lowerCamelCase_							:		str							       =							d_inner
						lowerCamelCase_							:		int							       =							hidden_act
						lowerCamelCase_							:		Optional[int]							       =							hidden_dropout
						lowerCamelCase_							:		List[Any]							       =							attention_dropout
						lowerCamelCase_							:		Dict							       =							activation_dropout
						lowerCamelCase_							:		Tuple							       =							max_position_embeddings
						lowerCamelCase_							:		int							       =							type_vocab_size
						lowerCamelCase_							:		Optional[int]							       =							2
						lowerCamelCase_							:		Dict							       =							num_labels
						lowerCamelCase_							:		str							       =							num_choices
						lowerCamelCase_							:		Dict							       =							scope
						lowerCamelCase_							:		List[str]							       =							initializer_std

						# Used in the tests to check the size of the first attention layer
						lowerCamelCase_							:		Union[str, Any]							       =							n_head
						# Used in the tests to check the size of the first hidden state
						lowerCamelCase_							:		Tuple							       =							self.d_model
						# Used in the tests to check the number of output hidden states/attentions
						lowerCamelCase_							:		Dict							       =							sum(self.block_sizes ) + (0 if base else self.num_decoder_layers)
						# FunnelModel adds two hidden layers: input embeddings and the sum of the upsampled encoder hidden state with
						# the last hidden state of the first block (which is the first hidden state of the decoder).
						if not base:
							lowerCamelCase_							:		Optional[Any]							       =							self.num_hidden_layers + 2

					def      lowercase_							(    self ):







						'''simple docstring'''




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

						lowerCamelCase_							:		List[str]							       =							None
						if self.use_input_mask:
							lowerCamelCase_							:		Union[str, Any]							       =							ids_tensor([self.batch_size, self.seq_length]			,	vocab_size=2 )

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

						lowerCamelCase_							:		Dict							       =							None
						lowerCamelCase_							:		Optional[Any]							       =							None
						lowerCamelCase_							:		str							       =							None
						if self.use_labels:
							lowerCamelCase_							:		Optional[Any]							       =							ids_tensor([self.batch_size]			,	self.type_sequence_label_size )
							lowerCamelCase_							:		Union[str, Any]							       =							ids_tensor([self.batch_size, self.seq_length]			,	self.num_labels )
							lowerCamelCase_							:		Tuple							       =							ids_tensor([self.batch_size]			,	self.num_choices )
							lowerCamelCase_							:		Dict							       =							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 FunnelConfig(
						    vocab_size=self.vocab_size			,	block_sizes=self.block_sizes			,	num_decoder_layers=self.num_decoder_layers			,	d_model=self.d_model			,	n_head=self.n_head			,	d_head=self.d_head			,	d_inner=self.d_inner			,	hidden_act=self.hidden_act			,	hidden_dropout=self.hidden_dropout			,	attention_dropout=self.attention_dropout			,	activation_dropout=self.activation_dropout			,	max_position_embeddings=self.max_position_embeddings			,	type_vocab_size=self.type_vocab_size			,	initializer_std=self.initializer_std			,	)

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







						'''simple docstring'''




						lowerCamelCase_							:		List[Any]							       =							FunnelModel(config=__lowercase )
						model.to(__lowercase )
						model.eval()
						lowerCamelCase_							:		Dict							       =							model(__lowercase			,	attention_mask=__lowercase			,	token_type_ids=__lowercase )
						lowerCamelCase_							:		Any							       =							model(__lowercase			,	token_type_ids=__lowercase )
						lowerCamelCase_							:		List[str]							       =							model(__lowercase )
						self.parent.assertEqual(result.last_hidden_state.shape			,	(self.batch_size, self.seq_length, self.d_model) )

						lowerCamelCase_							:		Dict							       =							False
						lowerCamelCase_							:		str							       =							model(__lowercase )
						self.parent.assertEqual(result.last_hidden_state.shape			,	(self.batch_size, self.seq_length, self.d_model) )

						lowerCamelCase_							:		int							       =							False
						lowerCamelCase_							:		Optional[int]							       =							model(__lowercase )
						self.parent.assertEqual(result.last_hidden_state.shape			,	(self.batch_size, self.seq_length, self.d_model) )

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







						'''simple docstring'''




						lowerCamelCase_							:		Any							       =							FunnelBaseModel(config=__lowercase )
						model.to(__lowercase )
						model.eval()
						lowerCamelCase_							:		Optional[Any]							       =							model(__lowercase			,	attention_mask=__lowercase			,	token_type_ids=__lowercase )
						lowerCamelCase_							:		Optional[Any]							       =							model(__lowercase			,	token_type_ids=__lowercase )
						lowerCamelCase_							:		int							       =							model(__lowercase )
						self.parent.assertEqual(result.last_hidden_state.shape			,	(self.batch_size, 2, self.d_model) )

						lowerCamelCase_							:		List[Any]							       =							False
						lowerCamelCase_							:		str							       =							model(__lowercase )
						self.parent.assertEqual(result.last_hidden_state.shape			,	(self.batch_size, 3, self.d_model) )

						lowerCamelCase_							:		Union[str, Any]							       =							False
						lowerCamelCase_							:		Optional[Any]							       =							model(__lowercase )
						self.parent.assertEqual(result.last_hidden_state.shape			,	(self.batch_size, 2, self.d_model) )

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







						'''simple docstring'''




						lowerCamelCase_							:		Any							       =							self.num_labels
						lowerCamelCase_							:		Dict							       =							FunnelForPreTraining(config=__lowercase )
						model.to(__lowercase )
						model.eval()
						lowerCamelCase_							:		str							       =							model(__lowercase			,	attention_mask=__lowercase			,	token_type_ids=__lowercase			,	labels=__lowercase )
						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_							:		Dict							       =							FunnelForMaskedLM(config=__lowercase )
						model.to(__lowercase )
						model.eval()
						lowerCamelCase_							:		int							       =							model(__lowercase			,	attention_mask=__lowercase			,	token_type_ids=__lowercase			,	labels=__lowercase )
						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_							:		Any							       =							self.num_labels
						lowerCamelCase_							:		Optional[Any]							       =							FunnelForSequenceClassification(__lowercase )
						model.to(__lowercase )
						model.eval()
						lowerCamelCase_							:		List[str]							       =							model(__lowercase			,	attention_mask=__lowercase			,	token_type_ids=__lowercase			,	labels=__lowercase )
						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_							:		Union[str, Any]							       =							self.num_choices
						lowerCamelCase_							:		str							       =							FunnelForMultipleChoice(config=__lowercase )
						model.to(__lowercase )
						model.eval()
						lowerCamelCase_							:		List[Any]							       =							input_ids.unsqueeze(1 ).expand(-1			,	self.num_choices			,	-1 ).contiguous()
						lowerCamelCase_							:		Optional[Any]							       =							token_type_ids.unsqueeze(1 ).expand(-1			,	self.num_choices			,	-1 ).contiguous()
						lowerCamelCase_							:		List[Any]							       =							input_mask.unsqueeze(1 ).expand(-1			,	self.num_choices			,	-1 ).contiguous()
						lowerCamelCase_							:		List[Any]							       =							model(
						    __lowercase			,	attention_mask=__lowercase			,	token_type_ids=__lowercase			,	labels=__lowercase			,	)
						self.parent.assertEqual(result.logits.shape			,	(self.batch_size, self.num_choices) )

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







						'''simple docstring'''




						lowerCamelCase_							:		Optional[Any]							       =							self.num_labels
						lowerCamelCase_							:		List[Any]							       =							FunnelForTokenClassification(config=__lowercase )
						model.to(__lowercase )
						model.eval()
						lowerCamelCase_							:		Tuple							       =							model(__lowercase			,	attention_mask=__lowercase			,	token_type_ids=__lowercase			,	labels=__lowercase )
						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_							:		List[str]							       =							FunnelForQuestionAnswering(config=__lowercase )
						model.to(__lowercase )
						model.eval()
						lowerCamelCase_							:		Any							       =							model(
						    __lowercase			,	attention_mask=__lowercase			,	token_type_ids=__lowercase			,	start_positions=__lowercase			,	end_positions=__lowercase			,	)
						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 ):







						'''simple docstring'''




						lowerCamelCase_							:		List[Any]							       =							self.prepare_config_and_inputs()
						(
						    (
						    lowerCamelCase_
						)       ,      (
						    lowerCamelCase_
						)       ,      (
						    lowerCamelCase_
						)       ,      (
						    lowerCamelCase_
						)       ,      (
						    lowerCamelCase_
						)       ,      (
						    lowerCamelCase_
						)       ,      (
						    lowerCamelCase_
						)       ,      (
						    lowerCamelCase_
						)       ,      
						)							:		Tuple							       =							config_and_inputs
						lowerCamelCase_							:		Union[str, Any]							       =							{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
						return config, inputs_dict


@require_torch
class     __SCREAMING_SNAKE_CASE							(		lowerCamelCase       ,					lowerCamelCase       ,					unittest.TestCase  ):
					_lowerCamelCase		  =			False
					_lowerCamelCase		  =			False
					_lowerCamelCase		  =			(
					    (
					        FunnelModel,
					        FunnelForMaskedLM,
					        FunnelForPreTraining,
					        FunnelForQuestionAnswering,
					        FunnelForTokenClassification,
					    )
					    if is_torch_available()
					    else ()
					)
					_lowerCamelCase		  =			(
					    {
					        """feature-extraction""": (FunnelBaseModel, FunnelModel),
					        """fill-mask""": FunnelForMaskedLM,
					        """question-answering""": FunnelForQuestionAnswering,
					        """text-classification""": FunnelForSequenceClassification,
					        """token-classification""": FunnelForTokenClassification,
					        """zero-shot""": FunnelForSequenceClassification,
					    }
					    if is_torch_available()
					    else {}
					)

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







						'''simple docstring'''




						lowerCamelCase_							:		Optional[Any]							       =							super()._prepare_for_class(__lowercase			,	__lowercase			,	return_labels=__lowercase )

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

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		str							       =							FunnelModelTester(self )
						lowerCamelCase_							:		Union[str, Any]							       =							ConfigTester(self			,	config_class=__lowercase )

					def      lowercase_							(    self ):







						'''simple docstring'''




						self.config_tester.run_common_tests()

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		List[Any]							       =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*__lowercase )

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Tuple							       =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_pretraining(*__lowercase )

					def      lowercase_							(    self ):







						'''simple docstring'''




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

					def      lowercase_							(    self ):







						'''simple docstring'''




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

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		int							       =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*__lowercase )





					def      lowercase_							(    self			,	__lowercase ):







						'''simple docstring'''




						if hasattr(__lowercase			,	'weight' ) and module.weight is not None:
							module.weight.data.fill_(3 )
						if hasattr(__lowercase			,	'bias' ) and module.bias is not None:
							module.bias.data.fill_(3 )

						for param in ["r_w_bias", "r_r_bias", "r_kernel", "r_s_bias", "seg_embed"]:
							if hasattr(__lowercase			,	__lowercase ) and getattr(__lowercase			,	__lowercase ) is not None:
								lowerCamelCase_							:		Any							       =							getattr(__lowercase			,	__lowercase )
								weight.data.fill_(3 )


@require_torch
class     __SCREAMING_SNAKE_CASE							(		lowerCamelCase       ,					unittest.TestCase  ):
					_lowerCamelCase		  =			False
					_lowerCamelCase		  =			False
					_lowerCamelCase		  =			(
					    (FunnelBaseModel, FunnelForMultipleChoice, FunnelForSequenceClassification) if is_torch_available() else ()
					)

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Union[str, Any]							       =							FunnelModelTester(self			,	base=__lowercase )
						lowerCamelCase_							:		Any							       =							ConfigTester(self			,	config_class=__lowercase )

					def      lowercase_							(    self ):







						'''simple docstring'''




						self.config_tester.run_common_tests()

					def      lowercase_							(    self ):







						'''simple docstring'''




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

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Any							       =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*__lowercase )

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		str							       =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_multiple_choice(*__lowercase )

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_       ,      lowerCamelCase_							:		int							       =							self.model_tester.prepare_config_and_inputs_for_common()
						lowerCamelCase_							:		Union[str, Any]							       =							True

						for model_class in self.all_model_classes:
							if model_class.__name__ == "FunnelBaseModel":
								continue
							lowerCamelCase_							:		List[Any]							       =							model_class(__lowercase )
							model.to(__lowercase )
							model.train()
							lowerCamelCase_							:		List[Any]							       =							self._prepare_for_class(__lowercase			,	__lowercase			,	return_labels=__lowercase )
							lowerCamelCase_							:		int							       =							model(**__lowercase ).loss
							loss.backward()





					def      lowercase_							(    self			,	__lowercase ):







						'''simple docstring'''




						if hasattr(__lowercase			,	'weight' ) and module.weight is not None:
							module.weight.data.fill_(3 )
						if hasattr(__lowercase			,	'bias' ) and module.bias is not None:
							module.bias.data.fill_(3 )

						for param in ["r_w_bias", "r_r_bias", "r_kernel", "r_s_bias", "seg_embed"]:
							if hasattr(__lowercase			,	__lowercase ) and getattr(__lowercase			,	__lowercase ) is not None:
								lowerCamelCase_							:		str							       =							getattr(__lowercase			,	__lowercase )
								weight.data.fill_(3 )


@require_torch
@require_sentencepiece
@require_tokenizers
class     __SCREAMING_SNAKE_CASE							(		unittest.TestCase  ):

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Optional[Any]							       =							13
						lowerCamelCase_							:		Union[str, Any]							       =							7
						lowerCamelCase_							:		List[Any]							       =							torch.arange(0			,	batch_size * sequence_length ).long().reshape(__lowercase			,	__lowercase )
						lowerCamelCase_							:		Tuple							       =							[0, 1, 2, 3, 4, 5, 6, 4, 1, 3, 5, 0, 1]
						lowerCamelCase_							:		Union[str, Any]							       =							torch.tensor([[2] + [0] * a + [1] * (sequence_length - a - 1) for a in lengths] )

						lowerCamelCase_							:		Tuple							       =							FunnelModel.from_pretrained('sgugger/funnel-random-tiny' )
						lowerCamelCase_							:		Optional[int]							       =							model(__lowercase			,	token_type_ids=__lowercase )[0].abs()

						lowerCamelCase_							:		str							       =							torch.tensor(23_44.83_52 )
						lowerCamelCase_							:		Optional[Any]							       =							torch.tensor(0.80_52 )
						self.assertTrue(torch.allclose(output.sum()			,	__lowercase			,	atol=1E-4 ) )
						self.assertTrue(torch.allclose(output.mean()			,	__lowercase			,	atol=1E-4 ) )

						lowerCamelCase_							:		List[str]							       =							torch.tensor([[1] * 7, [1] * 4 + [0] * 3] * 6 + [[0, 1, 1, 0, 0, 1, 1]] )
						lowerCamelCase_							:		List[str]							       =							model(__lowercase			,	attention_mask=__lowercase			,	token_type_ids=__lowercase )[0].abs()

						lowerCamelCase_							:		Any							       =							torch.tensor(23_43.84_25 )
						lowerCamelCase_							:		Dict							       =							torch.tensor(0.80_49 )
						self.assertTrue(torch.allclose(output.sum()			,	__lowercase			,	atol=1E-4 ) )
						self.assertTrue(torch.allclose(output.mean()			,	__lowercase			,	atol=1E-4 ) )





					@slow
					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Any							       =							FunnelTokenizer.from_pretrained('huggingface/funnel-small' )
						lowerCamelCase_							:		Any							       =							FunnelModel.from_pretrained('huggingface/funnel-small' )
						lowerCamelCase_							:		Dict							       =							tokenizer('Hello! I am the Funnel Transformer model.'			,	return_tensors='pt' )
						lowerCamelCase_							:		Tuple							       =							model(**__lowercase )[0]

						lowerCamelCase_							:		Optional[int]							       =							torch.tensor(2_35.72_46 )
						lowerCamelCase_							:		Tuple							       =							torch.tensor(0.02_56 )
						self.assertTrue(torch.allclose(output.sum()			,	__lowercase			,	atol=1E-4 ) )
						self.assertTrue(torch.allclose(output.mean()			,	__lowercase			,	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			,	)
