






import copy
import unittest

from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, 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, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch

							from transformers import (
							    MODEL_FOR_MULTIPLE_CHOICE_MAPPING,
							    MODEL_FOR_QUESTION_ANSWERING_MAPPING,
							    MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
							    MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING,
							    LayoutLMvaConfig,
							    LayoutLMvaForQuestionAnswering,
							    LayoutLMvaForSequenceClassification,
							    LayoutLMvaForTokenClassification,
							    LayoutLMvaModel,
							)
							from transformers.models.layoutlmva.modeling_layoutlmva import LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
							from PIL import Image

							from transformers import LayoutLMvaImageProcessor



class      SCREAMING_SNAKE_CASE  :





	"""simple docstring"""




	def __init__(self     ,     lowerCAmelCase_     ,     lowerCAmelCase_=2     ,     lowerCAmelCase_=3     ,     lowerCAmelCase_=4     ,     lowerCAmelCase_=2     ,     lowerCAmelCase_=7     ,     lowerCAmelCase_=True     ,     lowerCAmelCase_=True     ,     lowerCAmelCase_=True     ,     lowerCAmelCase_=True     ,     lowerCAmelCase_=99     ,     lowerCAmelCase_=36     ,     lowerCAmelCase_=3     ,     lowerCAmelCase_=4     ,     lowerCAmelCase_=37     ,     lowerCAmelCase_="gelu"     ,     lowerCAmelCase_=0.1     ,     lowerCAmelCase_=0.1     ,     lowerCAmelCase_=512     ,     lowerCAmelCase_=16     ,     lowerCAmelCase_=2     ,     lowerCAmelCase_=0.02     ,     lowerCAmelCase_=6     ,     lowerCAmelCase_=6     ,     lowerCAmelCase_=3     ,     lowerCAmelCase_=4     ,     lowerCAmelCase_=None     ,     lowerCAmelCase_=1000     ,     ):
		A_		:						Optional[int]	    =   parent
		A_		:						Tuple	    =   batch_size
		A_		:						Optional[Any]	    =   num_channels
		A_		:						Any	    =   image_size
		A_		:						Any	    =   patch_size
		A_		:						int	    =   text_seq_length
		A_		:						int	    =   is_training
		A_		:						Any	    =   use_input_mask
		A_		:						Tuple	    =   use_token_type_ids
		A_		:						List[str]	    =   use_labels
		A_		:						Tuple	    =   vocab_size
		A_		:						Optional[Any]	    =   hidden_size
		A_		:						List[Any]	    =   num_hidden_layers
		A_		:						Any	    =   num_attention_heads
		A_		:						Optional[int]	    =   intermediate_size
		A_		:						List[Any]	    =   hidden_act
		A_		:						Optional[int]	    =   hidden_dropout_prob
		A_		:						str	    =   attention_probs_dropout_prob
		A_		:						List[Any]	    =   max_position_embeddings
		A_		:						List[str]	    =   type_vocab_size
		A_		:						List[Any]	    =   type_sequence_label_size
		A_		:						Optional[Any]	    =   initializer_range
		A_		:						Tuple	    =   coordinate_size
		A_		:						Tuple	    =   shape_size
		A_		:						Tuple	    =   num_labels
		A_		:						Any	    =   num_choices
		A_		:						Tuple	    =   scope
		A_		:						Any	    =   range_bbox

		# LayoutLMv3's sequence length equals the number of text tokens + number of patches + 1 (we add 1 for the CLS token)
		A_		:						Optional[int]	    =   text_seq_length
		A_		:						Any	    =   (image_size // patch_size) ** 2 + 1
		A_		:						Optional[Any]	    =   self.text_seq_length + self.image_seq_length





	def    lowerCamelCase(self							):
		A_		:						int	    =   ids_tensor([self.batch_size, self.text_seq_length]     ,     self.vocab_size							)

		A_		:						List[str]	    =   ids_tensor([self.batch_size, self.text_seq_length, 4]     ,     self.range_bbox							)
		# Ensure that bbox is legal
		for i in range(bbox.shape[0]							):
			for j in range(bbox.shape[1]							):
				if bbox[i, j, 3] < bbox[i, j, 1]:
					A_		:						Union[str, Any]	    =   bbox[i, j, 3]
					A_		:						Optional[int]	    =   bbox[i, j, 1]
					A_		:						Any	    =   t
				if bbox[i, j, 2] < bbox[i, j, 0]:
					A_		:						str	    =   bbox[i, j, 2]
					A_		:						List[Any]	    =   bbox[i, j, 0]
					A_		:						Union[str, Any]	    =   t

		A_		:						Any	    =   floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]							)

		A_		:						Dict	    =   None
		if self.use_input_mask:
			A_		:						Optional[int]	    =   random_attention_mask([self.batch_size, self.text_seq_length]							)

		A_		:						Dict	    =   None
		if self.use_token_type_ids:
			A_		:						str	    =   ids_tensor([self.batch_size, self.text_seq_length]     ,     self.type_vocab_size							)

		A_		:						Dict	    =   None
		A_		:						Tuple	    =   None
		if self.use_labels:
			A_		:						Any	    =   ids_tensor([self.batch_size]     ,     self.type_sequence_label_size							)
			A_		:						str	    =   ids_tensor([self.batch_size, self.text_seq_length]     ,     self.num_labels							)

		A_		:						List[str]	    =   LayoutLMvaConfig(
		    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     ,     initializer_range=self.initializer_range     ,     coordinate_size=self.coordinate_size     ,     shape_size=self.shape_size     ,     input_size=self.image_size     ,     patch_size=self.patch_size     ,     )

		return config, input_ids, bbox, pixel_values, token_type_ids, input_mask, sequence_labels, token_labels





	def    lowerCamelCase(self     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_							):
		A_		:						Dict	    =   LayoutLMvaModel(config=lowerCAmelCase_							)
		model.to(lowerCAmelCase_							)
		model.eval()

		# text + image
		A_		:						Optional[int]	    =   model(lowerCAmelCase_     ,     pixel_values=lowerCAmelCase_							)
		A_		:						Optional[Any]	    =   model(
		    lowerCAmelCase_     ,     bbox=lowerCAmelCase_     ,     pixel_values=lowerCAmelCase_     ,     attention_mask=lowerCAmelCase_     ,     token_type_ids=lowerCAmelCase_							)
		A_		:						List[str]	    =   model(lowerCAmelCase_     ,     bbox=lowerCAmelCase_     ,     pixel_values=lowerCAmelCase_     ,     token_type_ids=lowerCAmelCase_							)
		A_		:						Tuple	    =   model(lowerCAmelCase_     ,     bbox=lowerCAmelCase_     ,     pixel_values=lowerCAmelCase_							)

		self.parent.assertEqual(result.last_hidden_state.shape     ,     (self.batch_size, self.seq_length, self.hidden_size)							)

		# text only
		A_		:						str	    =   model(lowerCAmelCase_							)
		self.parent.assertEqual(
		    result.last_hidden_state.shape     ,     (self.batch_size, self.text_seq_length, self.hidden_size)							)

		# image only
		A_		:						List[Any]	    =   model(pixel_values=lowerCAmelCase_							)
		self.parent.assertEqual(
		    result.last_hidden_state.shape     ,     (self.batch_size, self.image_seq_length, self.hidden_size)							)





	def    lowerCamelCase(self     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_							):
		A_		:						List[str]	    =   self.num_labels
		A_		:						int	    =   LayoutLMvaForSequenceClassification(lowerCAmelCase_							)
		model.to(lowerCAmelCase_							)
		model.eval()
		A_		:						Any	    =   model(
		    lowerCAmelCase_     ,     bbox=lowerCAmelCase_     ,     pixel_values=lowerCAmelCase_     ,     attention_mask=lowerCAmelCase_     ,     token_type_ids=lowerCAmelCase_     ,     labels=lowerCAmelCase_     ,     )
		self.parent.assertEqual(result.logits.shape     ,     (self.batch_size, self.num_labels)							)





	def    lowerCamelCase(self     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_							):
		A_		:						List[Any]	    =   self.num_labels
		A_		:						Union[str, Any]	    =   LayoutLMvaForTokenClassification(config=lowerCAmelCase_							)
		model.to(lowerCAmelCase_							)
		model.eval()
		A_		:						List[Any]	    =   model(
		    lowerCAmelCase_     ,     bbox=lowerCAmelCase_     ,     pixel_values=lowerCAmelCase_     ,     attention_mask=lowerCAmelCase_     ,     token_type_ids=lowerCAmelCase_     ,     labels=lowerCAmelCase_     ,     )
		self.parent.assertEqual(result.logits.shape     ,     (self.batch_size, self.text_seq_length, self.num_labels)							)





	def    lowerCamelCase(self     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_							):
		A_		:						str	    =   LayoutLMvaForQuestionAnswering(config=lowerCAmelCase_							)
		model.to(lowerCAmelCase_							)
		model.eval()
		A_		:						Optional[Any]	    =   model(
		    lowerCAmelCase_     ,     bbox=lowerCAmelCase_     ,     pixel_values=lowerCAmelCase_     ,     attention_mask=lowerCAmelCase_     ,     token_type_ids=lowerCAmelCase_     ,     start_positions=lowerCAmelCase_     ,     end_positions=lowerCAmelCase_     ,     )
		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    lowerCamelCase(self							):
		A_		:						Optional[int]	    =   self.prepare_config_and_inputs()
		(
		    A_     
		)		:						Optional[Any]	    =   config_and_inputs
		A_		:						str	    =   {
		    """input_ids""": input_ids,
		    """bbox""": bbox,
		    """pixel_values""": pixel_values,
		    """token_type_ids""": token_type_ids,
		    """attention_mask""": input_mask,
		}
		return config, inputs_dict






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





	"""simple docstring"""




	_A       :				Dict    =				False
	_A       :				Union[str, Any]    =				False
	_A       :				Any    =				False

	_A       :				Optional[Any]    =				(
	    (
	        LayoutLMvaModel,
	        LayoutLMvaForSequenceClassification,
	        LayoutLMvaForTokenClassification,
	        LayoutLMvaForQuestionAnswering,
	    )
	    if is_torch_available()
	    else ()
	)
	_A       :				Optional[int]    =				(
	    {"""document-question-answering""": LayoutLMvaForQuestionAnswering, """feature-extraction""": LayoutLMvaModel}
	    if is_torch_available()
	    else {}
	)





	def    lowerCamelCase(self     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_							):
		# `DocumentQuestionAnsweringPipeline` is expected to work with this model, but it combines the text and visual
		# embedding along the sequence dimension (dim 1), which causes an error during post-processing as `p_mask` has
		# the sequence dimension of the text embedding only.
		# (see the line `embedding_output = torch.cat([embedding_output, visual_embeddings], dim=1)`)
		return True





	def    lowerCamelCase(self							):
		A_		:						Optional[Any]	    =   LayoutLMvaModelTester(self							)
		A_		:						Optional[int]	    =   ConfigTester(self     ,     config_class=lowerCAmelCase_     ,     hidden_size=37							)





	def    lowerCamelCase(self     ,     lowerCAmelCase_     ,     lowerCAmelCase_     ,     lowerCAmelCase_=False							):
		A_		:						Any	    =   copy.deepcopy(lowerCAmelCase_							)
		if model_class in get_values(lowerCAmelCase_							):
			A_		:						List[str]	    =   {
			    k: v.unsqueeze(1							).expand(-1     ,     self.model_tester.num_choices     ,     -1							).contiguous()
			    if isinstance(lowerCAmelCase_     ,     torch.Tensor							) and v.ndim > 1
			    else v
			    for k, v in inputs_dict.items()
			}
		if return_labels:
			if model_class in get_values(lowerCAmelCase_							):
				A_		:						int	    =   torch.ones(self.model_tester.batch_size     ,     dtype=torch.long     ,     device=lowerCAmelCase_							)
			elif model_class in get_values(lowerCAmelCase_							):
				A_		:						Any	    =   torch.zeros(
				    self.model_tester.batch_size     ,     dtype=torch.long     ,     device=lowerCAmelCase_							)
				A_		:						Optional[Any]	    =   torch.zeros(
				    self.model_tester.batch_size     ,     dtype=torch.long     ,     device=lowerCAmelCase_							)
			elif model_class in [
			    *get_values(lowerCAmelCase_							),
			]:
				A_		:						Any	    =   torch.zeros(
				    self.model_tester.batch_size     ,     dtype=torch.long     ,     device=lowerCAmelCase_							)
			elif model_class in [
			    *get_values(lowerCAmelCase_							),
			]:
				A_		:						Optional[int]	    =   torch.zeros(
				    (self.model_tester.batch_size, self.model_tester.text_seq_length)     ,     dtype=torch.long     ,     device=lowerCAmelCase_     ,     )

		return inputs_dict





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





	def    lowerCamelCase(self							):
		A_		:						Union[str, Any]	    =   self.model_tester.prepare_config_and_inputs()
		self.model_tester.create_and_check_model(*lowerCAmelCase_							)





	def    lowerCamelCase(self							):
		A_		:						Union[str, Any]	    =   self.model_tester.prepare_config_and_inputs()
		for type in ["absolute", "relative_key", "relative_key_query"]:
			A_		:						Tuple	    =   type
			self.model_tester.create_and_check_model(*lowerCAmelCase_							)





	def    lowerCamelCase(self							):
		A_		:						Tuple	    =   self.model_tester.prepare_config_and_inputs()
		self.model_tester.create_and_check_for_sequence_classification(*lowerCAmelCase_							)





	def    lowerCamelCase(self							):
		A_		:						Tuple	    =   self.model_tester.prepare_config_and_inputs()
		self.model_tester.create_and_check_for_token_classification(*lowerCAmelCase_							)





	def    lowerCamelCase(self							):
		A_		:						Optional[int]	    =   self.model_tester.prepare_config_and_inputs()
		self.model_tester.create_and_check_for_question_answering(*lowerCAmelCase_							)





	@slow
	def    lowerCamelCase(self							):
		for model_name in LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
			A_		:						str	    =   LayoutLMvaModel.from_pretrained(lowerCAmelCase_							)
			self.assertIsNotNone(lowerCAmelCase_							)






def 			__UpperCamelCase	(		):
	A_		:						List[str]	    =   Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""					)
	return image




@require_torch
class      SCREAMING_SNAKE_CASE  (				unittest.TestCase						):





	"""simple docstring"""




	@cached_property
	def    lowerCamelCase(self							):
		return LayoutLMvaImageProcessor(apply_ocr=lowerCAmelCase_							) if is_vision_available() else None





	@slow
	def    lowerCamelCase(self							):
		A_		:						Optional[int]	    =   LayoutLMvaModel.from_pretrained("""microsoft/layoutlmv3-base"""							).to(lowerCAmelCase_							)

		A_		:						List[Any]	    =   self.default_image_processor
		A_		:						str	    =   prepare_img()
		A_		:						Union[str, Any]	    =   image_processor(images=lowerCAmelCase_     ,     return_tensors="""pt"""							).pixel_values.to(lowerCAmelCase_							)

		A_		:						Optional[int]	    =   torch.tensor([[1, 2]]							)
		A_		:						Dict	    =   torch.tensor([[1, 2, 3, 4], [5, 6, 7, 8]]							).unsqueeze(0							)

		# forward pass
		A_		:						Optional[Any]	    =   model(
		    input_ids=input_ids.to(lowerCAmelCase_							)     ,     bbox=bbox.to(lowerCAmelCase_							)     ,     pixel_values=pixel_values.to(lowerCAmelCase_							)     ,     )

		# verify the logits
		A_		:						Optional[int]	    =   torch.Size((1, 199, 768)							)
		self.assertEqual(outputs.last_hidden_state.shape     ,     lowerCAmelCase_							)

		A_		:						Union[str, Any]	    =   torch.tensor(
		    [[-0.0529, 0.3618, 0.1632], [-0.1587, -0.1667, -0.0400], [-0.1557, -0.1671, -0.0505]]							).to(lowerCAmelCase_							)

		self.assertTrue(torch.allclose(outputs.last_hidden_state[0, :3, :3]     ,     lowerCAmelCase_     ,     atol=1e-4							)							)









"""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							)

