






import unittest

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

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch

							from transformers import (
							    FalconForCausalLM,
							    FalconForQuestionAnswering,
							    FalconForSequenceClassification,
							    FalconForTokenClassification,
							    FalconModel,
							)



class      SCREAMING_SNAKE_CASE  :





	"""simple docstring"""




	def __init__(self     ,     lowerCAmelCase_     ,     lowerCAmelCase_=3     ,     lowerCAmelCase_=7     ,     lowerCAmelCase_=True     ,     lowerCAmelCase_=True     ,     lowerCAmelCase_=False     ,     lowerCAmelCase_=True     ,     lowerCAmelCase_=99     ,     lowerCAmelCase_=32     ,     lowerCAmelCase_=5     ,     lowerCAmelCase_=4     ,     lowerCAmelCase_=37     ,     lowerCAmelCase_="gelu"     ,     lowerCAmelCase_=0.1     ,     lowerCAmelCase_=0.1     ,     lowerCAmelCase_=512     ,     lowerCAmelCase_=16     ,     lowerCAmelCase_=2     ,     lowerCAmelCase_=0.02     ,     lowerCAmelCase_=3     ,     lowerCAmelCase_=4     ,     lowerCAmelCase_=None     ,     ):
		A_		:						str	    =   parent
		A_		:						Any	    =   batch_size
		A_		:						Any	    =   seq_length
		A_		:						Optional[int]	    =   is_training
		A_		:						List[str]	    =   use_input_mask
		A_		:						Union[str, Any]	    =   use_token_type_ids
		A_		:						List[str]	    =   use_labels
		A_		:						List[str]	    =   vocab_size
		A_		:						int	    =   hidden_size
		A_		:						Union[str, Any]	    =   num_hidden_layers
		A_		:						int	    =   num_attention_heads
		A_		:						List[str]	    =   intermediate_size
		A_		:						Tuple	    =   hidden_act
		A_		:						Optional[int]	    =   hidden_dropout_prob
		A_		:						Any	    =   attention_probs_dropout_prob
		A_		:						Tuple	    =   max_position_embeddings
		A_		:						Tuple	    =   type_vocab_size
		A_		:						Dict	    =   type_sequence_label_size
		A_		:						str	    =   initializer_range
		A_		:						str	    =   num_labels
		A_		:						Any	    =   num_choices
		A_		:						Dict	    =   scope





	def    lowerCamelCase(self							):
		A_		:						List[str]	    =   ids_tensor([self.batch_size, self.seq_length]     ,     self.vocab_size							)

		A_		:						List[Any]	    =   None
		if self.use_input_mask:
			A_		:						List[Any]	    =   random_attention_mask([self.batch_size, self.seq_length]							)

		A_		:						Dict	    =   None

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

		A_		:						Optional[int]	    =   self.get_config()

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





	def    lowerCamelCase(self							):
		return FalconConfig(
		    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=_A     ,     initializer_range=self.initializer_range     ,     pad_token_id=1     ,     new_decoder_architecture=_A     ,     )





	def    lowerCamelCase(self     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_							):
		A_		:						List[Any]	    =   FalconModel(config=_A							)
		model.to(_A							)
		model.eval()
		A_		:						Tuple	    =   model(_A     ,     attention_mask=_A							)
		A_		:						Dict	    =   model(_A							)
		self.parent.assertEqual(result.last_hidden_state.shape     ,     (self.batch_size, self.seq_length, self.hidden_size)							)





	def    lowerCamelCase(self     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     ):
		A_		:						List[str]	    =   True
		A_		:						str	    =   FalconModel(_A							)
		model.to(_A							)
		model.eval()
		A_		:						Optional[Any]	    =   model(
		    _A     ,     attention_mask=_A     ,     encoder_hidden_states=_A     ,     encoder_attention_mask=_A     ,     )
		A_		:						Union[str, Any]	    =   model(
		    _A     ,     attention_mask=_A     ,     encoder_hidden_states=_A     ,     )
		A_		:						Optional[Any]	    =   model(_A     ,     attention_mask=_A							)
		self.parent.assertEqual(result.last_hidden_state.shape     ,     (self.batch_size, self.seq_length, self.hidden_size)							)





	def    lowerCamelCase(self     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     ):
		A_		:						List[str]	    =   FalconForCausalLM(config=_A							)
		model.to(_A							)
		model.eval()
		A_		:						Tuple	    =   model(_A     ,     attention_mask=_A     ,     labels=_A							)
		self.parent.assertEqual(result.logits.shape     ,     (self.batch_size, self.seq_length, self.vocab_size)							)





	def    lowerCamelCase(self     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     ):
		A_		:						int	    =   True
		A_		:						Union[str, Any]	    =   True
		A_		:						int	    =   FalconForCausalLM(config=_A							)
		model.to(_A							)
		model.eval()

		# first forward pass
		A_		:						Optional[int]	    =   model(
		    _A     ,     attention_mask=_A     ,     encoder_hidden_states=_A     ,     encoder_attention_mask=_A     ,     use_cache=_A     ,     )
		A_		:						int	    =   outputs.past_key_values

		# create hypothetical multiple next token and extent to next_input_ids
		A_		:						List[Any]	    =   ids_tensor((self.batch_size, 3)     ,     config.vocab_size							)
		A_		:						Optional[Any]	    =   ids_tensor((self.batch_size, 3)     ,     vocab_size=2							)

		# append to next input_ids and
		A_		:						Dict	    =   torch.cat([input_ids, next_tokens]     ,     dim=-1							)
		A_		:						Union[str, Any]	    =   torch.cat([input_mask, next_mask]     ,     dim=-1							)

		A_		:						str	    =   model(
		    _A     ,     attention_mask=_A     ,     encoder_hidden_states=_A     ,     encoder_attention_mask=_A     ,     output_hidden_states=_A     ,     )['hidden_states'][0]
		A_		:						Optional[Any]	    =   model(
		    _A     ,     attention_mask=_A     ,     encoder_hidden_states=_A     ,     encoder_attention_mask=_A     ,     past_key_values=_A     ,     output_hidden_states=_A     ,     )['hidden_states'][0]

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

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

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





	def    lowerCamelCase(self							):
		A_		:						Tuple	    =   self.prepare_config_and_inputs()
		(
		    A_					
		)		:						int	    =   config_and_inputs
		A_		:						Tuple	    =   {'input_ids': input_ids, 'attention_mask': input_mask}
		return config, inputs_dict






@require_torch
class      SCREAMING_SNAKE_CASE  (				a__       ,       a__       ,       a__       ,       unittest.TestCase						):





	"""simple docstring"""




	_A       :				Any    =				(
	    (
	        FalconModel,
	        FalconForCausalLM,
	        FalconForSequenceClassification,
	        FalconForTokenClassification,
	        FalconForQuestionAnswering,
	    )
	    if is_torch_available()
	    else ()
	)
	_A       :				Tuple    =				(FalconForCausalLM,) if is_torch_available() else ()
	_A       :				int    =				(
	    {
	        """feature-extraction""": FalconModel,
	        """text-classification""": FalconForSequenceClassification,
	        """text-generation""": FalconForCausalLM,
	        """question-answering""": FalconForQuestionAnswering,
	        """token-classification""": FalconForTokenClassification,
	        """zero-shot""": FalconForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)
	_A       :				Dict    =				False
	_A       :				int    =				False





	def    lowerCamelCase(self							):
		A_		:						str	    =   FalconModelTester(self							)
		A_		:						int	    =   ConfigTester(self     ,     config_class=_A     ,     hidden_size=37							)





	def    lowerCamelCase(self							):
		self.config_tester.run_common_tests()





	def    lowerCamelCase(self							):
		A_		:						List[Any]	    =   self.model_tester.prepare_config_and_inputs()
		self.model_tester.create_and_check_model(*_A							)





	def    lowerCamelCase(self							):
		A_		:						List[Any]	    =   self.model_tester.prepare_config_and_inputs()
		for alibi in [True, False]:
			A_		:						Optional[int]	    =   alibi
			self.model_tester.create_and_check_model(_A     ,     *_A							)





	def    lowerCamelCase(self							):
		A_		:						Optional[int]	    =   self.model_tester.prepare_config_and_inputs_for_common()
		A_		:						List[Any]	    =   3
		A_		:						Optional[Any]	    =   input_dict['input_ids']
		A_		:						Union[str, Any]	    =   input_ids.ne(1							).to(_A							)
		A_		:						Tuple	    =   ids_tensor([self.model_tester.batch_size]     ,     self.model_tester.type_sequence_label_size							)
		A_		:						Optional[int]	    =   FalconForSequenceClassification(_A							)
		model.to(_A							)
		model.eval()
		A_		:						List[Any]	    =   model(_A     ,     attention_mask=_A     ,     labels=_A							)
		self.assertEqual(result.logits.shape     ,     (self.model_tester.batch_size, self.model_tester.num_labels)							)





	def    lowerCamelCase(self							):
		A_		:						Optional[int]	    =   self.model_tester.prepare_config_and_inputs_for_common()
		A_		:						Any	    =   3
		A_		:						Dict	    =   'single_label_classification'
		A_		:						Union[str, Any]	    =   input_dict['input_ids']
		A_		:						Optional[Any]	    =   input_ids.ne(1							).to(_A							)
		A_		:						str	    =   ids_tensor([self.model_tester.batch_size]     ,     self.model_tester.type_sequence_label_size							)
		A_		:						Optional[int]	    =   FalconForSequenceClassification(_A							)
		model.to(_A							)
		model.eval()
		A_		:						int	    =   model(_A     ,     attention_mask=_A     ,     labels=_A							)
		self.assertEqual(result.logits.shape     ,     (self.model_tester.batch_size, self.model_tester.num_labels)							)





	def    lowerCamelCase(self							):
		A_		:						Any	    =   self.model_tester.prepare_config_and_inputs_for_common()
		A_		:						List[str]	    =   input_dict['input_ids']
		A_		:						int	    =   FalconForCausalLM(_A							)
		model.to(_A							)
		model.eval()
		A_		:						Optional[Any]	    =   model(_A     ,     use_cache=_A							)
		A_		:						str	    =   input_ids.shape[0]
		A_		:						Optional[Any]	    =   model._convert_to_rw_cache(result.past_key_values							)
		A_		:						int	    =   model._convert_cache_to_standard_format(_A     ,     _A							)
		for layer in range(len(_A							)							):
			for tensor_idx in range(2							):
				self.assertTrue(rw_cache[layer][tensor_idx].ndim == 3							)
				self.assertTrue(result.past_key_values[layer][tensor_idx].ndim == 4							)
				self.assertTrue(
				    torch.all(result.past_key_values[layer][tensor_idx] == standard_cache[layer][tensor_idx]							)							)





	def    lowerCamelCase(self							):
		A_		:						Any	    =   self.model_tester.prepare_config_and_inputs_for_common()
		A_		:						Union[str, Any]	    =   3
		A_		:						Optional[Any]	    =   'multi_label_classification'
		A_		:						List[str]	    =   input_dict['input_ids']
		A_		:						Optional[Any]	    =   input_ids.ne(1							).to(_A							)
		A_		:						int	    =   ids_tensor(
		    [self.model_tester.batch_size, config.num_labels]     ,     self.model_tester.type_sequence_label_size							).to(torch.float							)
		A_		:						Tuple	    =   FalconForSequenceClassification(_A							)
		model.to(_A							)
		model.eval()
		A_		:						int	    =   model(_A     ,     attention_mask=_A     ,     labels=_A							)
		self.assertEqual(result.logits.shape     ,     (self.model_tester.batch_size, self.model_tester.num_labels)							)





	def    lowerCamelCase(self							):

		for model_class in self.all_generative_model_classes:
			A_		:						List[Any]	    =   self.model_tester.prepare_config_and_inputs_for_common()

			# If it doesn't support cache, pass the test
			if not hasattr(_A     ,     """use_cache"""							):
				return

			A_		:						Dict	    =   model_class(_A							).to(_A							)
			if "use_cache" not in inputs:
				A_		:						Tuple	    =   True
			A_		:						Any	    =   model(**_A							)

			# If "past_key_values" is not returned, pass the test (e.g. RWKV uses a different cache name and format)
			if "past_key_values" not in outputs:
				return

			A_		:						List[Any]	    =   (
			    getattr(_A     ,     """decoder_layers"""     ,     _A							)
			    or getattr(_A     ,     """num_decoder_layers"""     ,     _A							)
			    or config.num_hidden_layers
			)
			A_		:						Dict	    =   getattr(_A     ,     """num_kv_heads"""     ,     config.num_attention_heads							)
			A_		:						Any	    =   getattr(_A     ,     """d_model"""     ,     config.hidden_size							)
			A_		:						Dict	    =   embed_dim // num_attention_heads

			A_		:						Optional[Any]	    =   outputs['past_key_values']
			self.assertEqual(len(_A							)     ,     _A							)

			A_		:						Any	    =   inputs['input_ids'].shape
			for i in range(_A							):
				if config.new_decoder_architecture:
					A_		:						int	    =   config.num_attention_heads
				elif config.multi_query:
					A_		:						Tuple	    =   1
				self.assertEqual(len(past_kv[0]							)     ,     2							)  # K V for the decoder = 2
				self.assertEqual(
				    past_kv[i][0].shape     ,     (batch_size, num_attention_heads, seq_length, per_head_embed_dim)							)
				self.assertEqual(
				    past_kv[i][1].shape     ,     (batch_size, num_attention_heads, seq_length, per_head_embed_dim)							)






@require_torch
class      SCREAMING_SNAKE_CASE  (				unittest.TestCase						):





	"""simple docstring"""




	@slow
	def    lowerCamelCase(self							):
		A_		:						Tuple	    =   AutoTokenizer.from_pretrained("""Rocketknight1/falcon-rw-1b"""							)
		A_		:						int	    =   FalconForCausalLM.from_pretrained("""Rocketknight1/falcon-rw-1b"""							)
		model.eval()
		model.to(_A							)
		A_		:						str	    =   tokenizer("""My favorite food is"""     ,     return_tensors="""pt"""							).to(_A							)

		A_		:						int	    =   (
		    'My favorite food is pizza. I love it so much that I have a pizza party every year for my birthday.'
		)

		A_		:						Optional[int]	    =   model.generate(**_A     ,     do_sample=_A     ,     max_new_tokens=19							)
		A_		:						List[Any]	    =   tokenizer.batch_decode(_A							)[0]

		self.assertEqual(_A     ,     _A							)





	@slow
	def    lowerCamelCase(self							):

		for repo in ["Rocketknight1/tiny-random-falcon-7b", "Rocketknight1/tiny-random-falcon-40b"]:
			A_		:						List[str]	    =   AutoTokenizer.from_pretrained(_A							)
			A_		:						Optional[Any]	    =   FalconForCausalLM.from_pretrained(_A							)
			model.eval()
			model.to(_A							)
			A_		:						Optional[Any]	    =   tokenizer("""My favorite food is"""     ,     return_tensors="""pt"""							).to(_A							)

			# We just test that these run without errors - the models are randomly initialized
			# and so the actual text outputs will be garbage
			model.generate(**_A     ,     do_sample=_A     ,     max_new_tokens=4							)
			model.generate(**_A     ,     do_sample=_A     ,     max_new_tokens=4							)
			model.generate(**_A     ,     num_beams=2     ,     max_new_tokens=4							)





	@slow
	def    lowerCamelCase(self							):

		with torch.no_grad():
			for repo in [
			    "Rocketknight1/falcon-rw-1b",
			    "Rocketknight1/tiny-random-falcon-7b",
			    "Rocketknight1/tiny-random-falcon-40b",
			]:
				A_		:						Union[str, Any]	    =   AutoTokenizer.from_pretrained(_A							)
				A_		:						List[Any]	    =   FalconForCausalLM.from_pretrained(_A							)
				model.eval()
				model.to(device=_A							)
				A_		:						Optional[Any]	    =   tokenizer("""My favorite food is"""     ,     return_tensors="""pt"""							).to(_A							)

				# Test results are the same with and without cache
				A_		:						Optional[int]	    =   model.generate(**_A     ,     do_sample=_A     ,     max_new_tokens=20     ,     use_cache=_A							)
				A_		:						Union[str, Any]	    =   model.generate(**_A     ,     do_sample=_A     ,     max_new_tokens=20     ,     use_cache=_A							)
				self.assertTrue((outputs_cache - outputs_no_cache).sum().item() == 0							)









"""simple docstring"""
import gc
import inspect
import unittest

import torch
from parameterized import parameterized

from diffusers import PriorTransformer
from diffusers.utils import floats_tensor, slow, torch_all_close, torch_device
from diffusers.utils.testing_utils import enable_full_determinism

from .test_modeling_common import ModelTesterMixin


enable_full_determinism()



class      SCREAMING_SNAKE_CASE  (				_SCREAMING_SNAKE_CASE       ,       unittest.TestCase						):





	"""simple docstring"""




	_A       :				int    =				PriorTransformer
	_A       :				Dict    =				"""hidden_states"""





	@property
	def    lowerCamelCase(self							):
		A_		:						Tuple	    =   4
		A_		:						Dict	    =   8
		A_		:						str	    =   7

		A_		:						Dict	    =   floats_tensor((batch_size, embedding_dim)							).to(lowerCAmelCase_							)

		A_		:						str	    =   floats_tensor((batch_size, embedding_dim)							).to(lowerCAmelCase_							)
		A_		:						List[str]	    =   floats_tensor((batch_size, num_embeddings, embedding_dim)							).to(lowerCAmelCase_							)

		return {
		    "hidden_states": hidden_states,
		    "timestep": 2,
		    "proj_embedding": proj_embedding,
		    "encoder_hidden_states": encoder_hidden_states,
		}





	def    lowerCamelCase(self     ,     lowerCAmelCase_=0							):
		torch.manual_seed(lowerCAmelCase_							)
		A_		:						Optional[Any]	    =   4
		A_		:						Tuple	    =   8
		A_		:						Tuple	    =   7

		A_		:						int	    =   torch.randn((batch_size, embedding_dim)							).to(lowerCAmelCase_							)

		A_		:						List[str]	    =   torch.randn((batch_size, embedding_dim)							).to(lowerCAmelCase_							)
		A_		:						Tuple	    =   torch.randn((batch_size, num_embeddings, embedding_dim)							).to(lowerCAmelCase_							)

		return {
		    "hidden_states": hidden_states,
		    "timestep": 2,
		    "proj_embedding": proj_embedding,
		    "encoder_hidden_states": encoder_hidden_states,
		}





	@property
	def    lowerCamelCase(self							):
		return (4, 8)





	@property
	def    lowerCamelCase(self							):
		return (4, 8)





	def    lowerCamelCase(self							):
		A_		:						int	    =   {
		    """num_attention_heads""": 2,
		    """attention_head_dim""": 4,
		    """num_layers""": 2,
		    """embedding_dim""": 8,
		    """num_embeddings""": 7,
		    """additional_embeddings""": 4,
		}
		A_		:						Dict	    =   self.dummy_input
		return init_dict, inputs_dict





	def    lowerCamelCase(self							):
		A_    ,     A_		:						Optional[int]	    =   PriorTransformer.from_pretrained(
		    """hf-internal-testing/prior-dummy"""     ,     output_loading_info=lowerCAmelCase_							)
		self.assertIsNotNone(lowerCAmelCase_							)
		self.assertEqual(len(loading_info["""missing_keys"""]							)     ,     0							)

		model.to(lowerCAmelCase_							)
		A_		:						List[Any]	    =   model(**self.dummy_input							)[0]

		assert hidden_states is not None, "Make sure output is not None"





	def    lowerCamelCase(self							):
		A_    ,     A_		:						Union[str, Any]	    =   self.prepare_init_args_and_inputs_for_common()

		A_		:						Union[str, Any]	    =   self.model_class(**lowerCAmelCase_							)
		A_		:						Tuple	    =   inspect.signature(model.forward							)
		# signature.parameters is an OrderedDict => so arg_names order is deterministic
		A_		:						Tuple	    =   [*signature.parameters.keys()]

		A_		:						List[str]	    =   ["""hidden_states""", """timestep"""]
		self.assertListEqual(arg_names[:2]     ,     lowerCAmelCase_							)





	def    lowerCamelCase(self							):
		A_		:						int	    =   PriorTransformer.from_pretrained("""hf-internal-testing/prior-dummy"""							)
		A_		:						Optional[Any]	    =   model.to(lowerCAmelCase_							)

		if hasattr(lowerCAmelCase_     ,     """set_default_attn_processor"""							):
			model.set_default_attn_processor()

		A_		:						int	    =   self.get_dummy_seed_input()

		with torch.no_grad():
			A_		:						int	    =   model(**lowerCAmelCase_							)[0]

		A_		:						Any	    =   output[0, :5].flatten().cpu()
		print(lowerCAmelCase_							)

		# Since the VAE Gaussian prior's generator is seeded on the appropriate device,
		# the expected output slices are not the same for CPU and GPU.
		A_		:						Optional[int]	    =   torch.tensor([-1.3436, -0.2870, 0.7538, 0.4368, -0.0239]							)
		self.assertTrue(torch_all_close(lowerCAmelCase_     ,     lowerCAmelCase_     ,     rtol=1e-2							)							)






@slow
class      SCREAMING_SNAKE_CASE  (				unittest.TestCase						):





	"""simple docstring"""




	def    lowerCamelCase(self     ,     lowerCAmelCase_=1     ,     lowerCAmelCase_=768     ,     lowerCAmelCase_=77     ,     lowerCAmelCase_=0							):
		torch.manual_seed(lowerCAmelCase_							)
		A_		:						Tuple	    =   batch_size
		A_		:						Any	    =   embedding_dim
		A_		:						Tuple	    =   num_embeddings

		A_		:						Any	    =   torch.randn((batch_size, embedding_dim)							).to(lowerCAmelCase_							)

		A_		:						Union[str, Any]	    =   torch.randn((batch_size, embedding_dim)							).to(lowerCAmelCase_							)
		A_		:						Tuple	    =   torch.randn((batch_size, num_embeddings, embedding_dim)							).to(lowerCAmelCase_							)

		return {
		    "hidden_states": hidden_states,
		    "timestep": 2,
		    "proj_embedding": proj_embedding,
		    "encoder_hidden_states": encoder_hidden_states,
		}





	def    lowerCamelCase(self							):
		# clean up the VRAM after each test
		super().tearDown()
		gc.collect()
		torch.cuda.empty_cache()





	@parameterized.expand(
	    [
	        # fmt: off
	        [13, [-0.5861,  0.1283, -0.0931,  0.0882,  0.4476,  0.1329, -0.0498,  0.0640]],
	        [37, [-0.4913,  0.0110, -0.0483,  0.0541,  0.4954, -0.0170,  0.0354,  0.1651]],
	        # fmt: on
	    ]							)
	def    lowerCamelCase(self     ,     lowerCAmelCase_     ,     lowerCAmelCase_							):
		A_		:						List[Any]	    =   PriorTransformer.from_pretrained("""kandinsky-community/kandinsky-2-1-prior"""     ,     subfolder="""prior"""							)
		model.to(lowerCAmelCase_							)
		A_		:						int	    =   self.get_dummy_seed_input(seed=lowerCAmelCase_							)

		with torch.no_grad():
			A_		:						Tuple	    =   model(**lowerCAmelCase_							)[0]

		assert list(sample.shape							) == [1, 768]

		A_		:						Tuple	    =   sample[0, :8].flatten().cpu()
		print(lowerCAmelCase_							)
		A_		:						Optional[int]	    =   torch.tensor(lowerCAmelCase_							)

		assert torch_all_close(lowerCAmelCase_     ,     lowerCAmelCase_     ,     atol=1e-3							)

