



'''simple docstring'''





import unittest

from transformers import EsmConfig, is_torch_available
from transformers.testing_utils import TestCasePlus, require_torch, slow, torch_device

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.models.esm.modeling_esmfold import EsmForProteinFolding

class 	lowerCamelCase_    :






						'''simple docstring'''







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







						def 			SCREAMING_SNAKE_CASE__		(	self      :			Union[str, Any] )      ->				int:
									A							:					int              =						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							:					List[Any]              =						None
									A							:					List[str]              =						None
									A							:					Union[str, Any]              =						None
									if self.use_labels:
												A							:					Dict              =						ids_tensor([self.batch_size]	,	self.type_sequence_label_size )
												A							:					List[str]              =						ids_tensor([self.batch_size, self.seq_length]	,	self.num_labels )
												A							:					Optional[int]              =						ids_tensor([self.batch_size]	,	self.num_choices )

									A							:					List[Any]              =						self.get_config()

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







						def 			SCREAMING_SNAKE_CASE__		(	self      :			List[Any] )      ->				List[str]:
									A							:					Any              =						EsmConfig(
									    vocab_size=33	,	hidden_size=self.hidden_size	,	pad_token_id=1	,	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	,	is_folding_model=lowerCamelCase__	,	esmfold_config={"trunk": {"num_blocks": 2}, "fp16_esm": False}	,	)
									return config







						def 			SCREAMING_SNAKE_CASE__		(	self      :			List[str]	,	__lowerCamelCase      :			Union[str, Any]	,	__lowerCamelCase      :			Tuple	,	__lowerCamelCase      :			Optional[Any]	,	__lowerCamelCase      :			List[str]	,	__lowerCamelCase      :			List[str]	,	__lowerCamelCase      :			List[str] )      ->				List[Any]:
									A							:					int              =						EsmForProteinFolding(config=lowerCamelCase__ ).float()
									model.to(lowerCamelCase__ )
									model.eval()
									A							:					Optional[Any]              =						model(lowerCamelCase__	,	attention_mask=lowerCamelCase__ )
									A							:					List[str]              =						model(lowerCamelCase__ )
									A							:					Any              =						model(lowerCamelCase__ )

									self.parent.assertEqual(result.positions.shape	,	(8, self.batch_size, self.seq_length, 14, 3) )
									self.parent.assertEqual(result.angles.shape	,	(8, self.batch_size, self.seq_length, 7, 2) )







						def 			SCREAMING_SNAKE_CASE__		(	self      :			Tuple )      ->				str:
									A							:					List[str]              =						self.prepare_config_and_inputs()
									(
									    A				
									)							:					str              =						config_and_inputs
									A							:					List[str]              =						{'''input_ids''': input_ids, '''attention_mask''': input_mask}
									return config, inputs_dict







@require_torch
class 	lowerCamelCase_    ( __lowerCAmelCase						,__lowerCAmelCase						,unittest.TestCase						):






						'''simple docstring'''
						a__   =  False

						a__   =  (EsmForProteinFolding,) if is_torch_available() else ()
						a__   =  ()
						a__   =  {} if is_torch_available() else {}
						a__   =  False







						def 			SCREAMING_SNAKE_CASE__		(	self      :			str )      ->				Union[str, Any]:
									A							:					List[Any]              =						EsmFoldModelTester(self )
									A							:					List[Any]              =						ConfigTester(self	,	config_class=lowerCamelCase__	,	hidden_size=37 )







						def 			SCREAMING_SNAKE_CASE__		(	self      :			List[str] )      ->				List[str]:
									self.config_tester.run_common_tests()







						def 			SCREAMING_SNAKE_CASE__		(	self      :			Union[str, Any] )      ->				Union[str, Any]:
									A							:					int              =						self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*lowerCamelCase__ )







						@unittest.skip("Does not support attention outputs" )
						def 			SCREAMING_SNAKE_CASE__		(	self      :			List[Any] )      ->				Any:
									pass







						@unittest.skip
						def 			SCREAMING_SNAKE_CASE__		(	self      :			Tuple )      ->				Optional[Any]:
									pass







						@unittest.skip("Esm does not support embedding resizing" )
						def 			SCREAMING_SNAKE_CASE__		(	self      :			Optional[int] )      ->				Any:
									pass







						@unittest.skip("Esm does not support embedding resizing" )
						def 			SCREAMING_SNAKE_CASE__		(	self      :			Optional[int] )      ->				Tuple:
									pass







						@unittest.skip("ESMFold does not support passing input embeds!" )
						def 			SCREAMING_SNAKE_CASE__		(	self      :			int )      ->				List[Any]:
									pass







						@unittest.skip("ESMFold does not support head pruning." )
						def 			SCREAMING_SNAKE_CASE__		(	self      :			Any )      ->				Any:
									pass







						@unittest.skip("ESMFold does not support head pruning." )
						def 			SCREAMING_SNAKE_CASE__		(	self      :			Any )      ->				str:
									pass







						@unittest.skip("ESMFold does not support head pruning." )
						def 			SCREAMING_SNAKE_CASE__		(	self      :			Union[str, Any] )      ->				Any:
									pass







						@unittest.skip("ESMFold does not support head pruning." )
						def 			SCREAMING_SNAKE_CASE__		(	self      :			List[str] )      ->				int:
									pass







						@unittest.skip("ESMFold does not support head pruning." )
						def 			SCREAMING_SNAKE_CASE__		(	self      :			str )      ->				Tuple:
									pass







						@unittest.skip("ESMFold does not output hidden states in the normal way." )
						def 			SCREAMING_SNAKE_CASE__		(	self      :			str )      ->				str:
									pass







						@unittest.skip("ESMfold does not output hidden states in the normal way." )
						def 			SCREAMING_SNAKE_CASE__		(	self      :			List[str] )      ->				Any:
									pass







						@unittest.skip("ESMFold only has one output format." )
						def 			SCREAMING_SNAKE_CASE__		(	self      :			Optional[Any] )      ->				Union[str, Any]:
									pass







						@unittest.skip("This test doesn\'t work for ESMFold and doesn\'t test core functionality" )
						def 			SCREAMING_SNAKE_CASE__		(	self      :			Tuple )      ->				Any:
									pass







						@unittest.skip("ESMFold does not support input chunking." )
						def 			SCREAMING_SNAKE_CASE__		(	self      :			str )      ->				Any:
									pass







						@unittest.skip("ESMFold doesn\'t respect you and it certainly doesn\'t respect your initialization arguments." )
						def 			SCREAMING_SNAKE_CASE__		(	self      :			int )      ->				Dict:
									pass







						@unittest.skip("ESMFold doesn\'t support torchscript compilation." )
						def 			SCREAMING_SNAKE_CASE__		(	self      :			List[Any] )      ->				Tuple:
									pass







						@unittest.skip("ESMFold doesn\'t support torchscript compilation." )
						def 			SCREAMING_SNAKE_CASE__		(	self      :			Any )      ->				int:
									pass







						@unittest.skip("ESMFold doesn\'t support torchscript compilation." )
						def 			SCREAMING_SNAKE_CASE__		(	self      :			Union[str, Any] )      ->				int:
									pass







						@unittest.skip("ESMFold doesn\'t support data parallel." )
						def 			SCREAMING_SNAKE_CASE__		(	self      :			Optional[Any] )      ->				Dict:
									pass







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







@require_torch
class 	lowerCamelCase_    ( __lowerCAmelCase						):






						'''simple docstring'''







						@slow
						def 			SCREAMING_SNAKE_CASE__		(	self      :			Any )      ->				List[Any]:
									A							:					Optional[Any]              =						EsmForProteinFolding.from_pretrained("facebook/esmfold_v1" ).float()
									model.eval()
									A							:					str              =						torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]] )
									A							:					Optional[Any]              =						model(lowerCamelCase__ )['''positions''']
									A							:					Dict              =						torch.tensor([2.5828, 0.7993, -10.9334]	,	dtype=torch.floataa )
									self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]	,	lowerCamelCase__	,	atol=1e-4 ) )




import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow


if is_torch_available():
							import torch

							from transformers import XLMRobertaModel

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






						'''simple docstring'''







						@slow
						def 			SCREAMING_SNAKE_CASE__		(	self      :			Any )      ->				Union[str, Any]:
									A							:					Union[str, Any]              =						XLMRobertaModel.from_pretrained("xlm-roberta-base" )
									A							:					Tuple              =						torch.tensor([[0, 5_81, 1_02_69, 83, 9_99_42, 1_36, 6_07_42, 23, 70, 8_05_83, 1_82_76, 2]] )
									# The dog is cute and lives in the garden house

									A							:					Tuple              =						torch.Size((1, 12, 7_68) )  # batch_size, sequence_length, embedding_vector_dim
									A							:					List[str]              =						torch.tensor(
									    [[-0.0101, 0.1218, -0.0803, 0.0801, 0.1327, 0.0776, -0.1215, 0.2383, 0.3338, 0.3106, 0.0300, 0.0252]] )
									#  xlmr = torch.hub.load('pytorch/fairseq', 'xlmr.base')
									#  xlmr.eval()
									#  expected_output_values_last_dim = xlmr.extract_features(input_ids[0])[:, :, -1]
									with torch.no_grad():
												A							:					Tuple              =						model(__lowerCamelCase )["last_hidden_state"].detach()
									self.assertEqual(output.shape	,	__lowerCamelCase )
									# compare the actual values for a slice of last dim
									self.assertTrue(torch.allclose(output[:, :, -1]	,	__lowerCamelCase	,	atol=1e-3 ) )







						@slow
						def 			SCREAMING_SNAKE_CASE__		(	self      :			Optional[int] )      ->				int:
									A							:					str              =						XLMRobertaModel.from_pretrained("xlm-roberta-large" )
									A							:					List[Any]              =						torch.tensor([[0, 5_81, 1_02_69, 83, 9_99_42, 1_36, 6_07_42, 23, 70, 8_05_83, 1_82_76, 2]] )
									# The dog is cute and lives in the garden house

									A							:					Optional[Any]              =						torch.Size((1, 12, 10_24) )  # batch_size, sequence_length, embedding_vector_dim
									A							:					List[Any]              =						torch.tensor(
									    [[-0.0699, -0.0318, 0.0705, -0.1241, 0.0999, -0.0520, 0.1004, -0.1838, -0.4704, 0.1437, 0.0821, 0.0126]] )
									#  xlmr = torch.hub.load('pytorch/fairseq', 'xlmr.large')
									#  xlmr.eval()
									#  expected_output_values_last_dim = xlmr.extract_features(input_ids[0])[:, :, -1]
									with torch.no_grad():
												A							:					Optional[int]              =						model(__lowerCamelCase )["last_hidden_state"].detach()
									self.assertEqual(output.shape	,	__lowerCamelCase )
									# compare the actual values for a slice of last dim
									self.assertTrue(torch.allclose(output[:, :, -1]	,	__lowerCamelCase	,	atol=1e-3 ) )