


'''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							:      Tuple ,  lowerCAmelCase							:      List[str] ,  lowerCAmelCase							:      List[Any]=13 ,  lowerCAmelCase							:      Union[str, Any]=7 ,  lowerCAmelCase							:      int=False ,  lowerCAmelCase							:      Optional[Any]=True ,  lowerCAmelCase							:      Tuple=False ,  lowerCAmelCase							:      Tuple=False ,  lowerCAmelCase							:      Any=19 ,  lowerCAmelCase							:      Any=32 ,  lowerCAmelCase							:      Optional[Any]=5 ,  lowerCAmelCase							:      List[str]=4 ,  lowerCAmelCase							:      Optional[int]=37 ,  lowerCAmelCase							:      List[Any]="gelu" ,  lowerCAmelCase							:      Optional[Any]=0.1 ,  lowerCAmelCase							:      Union[str, Any]=0.1 ,  lowerCAmelCase							:      Dict=5_12 ,  lowerCAmelCase							:      Optional[int]=16 ,  lowerCAmelCase							:      Dict=2 ,  lowerCAmelCase							:      List[Any]=0.0_2 ,  lowerCAmelCase							:      Dict=3 ,  lowerCAmelCase							:      Dict=4 ,  lowerCAmelCase							:      str=None ,  ):
													A_			    =		parent
													A_			    =		batch_size
													A_			    =		seq_length
													A_			    =		is_training
													A_			    =		use_input_mask
													A_			    =		use_token_type_ids
													A_			    =		use_labels
													A_			    =		vocab_size
													A_			    =		hidden_size
													A_			    =		num_hidden_layers
													A_			    =		num_attention_heads
													A_			    =		intermediate_size
													A_			    =		hidden_act
													A_			    =		hidden_dropout_prob
													A_			    =		attention_probs_dropout_prob
													A_			    =		max_position_embeddings
													A_			    =		type_vocab_size
													A_			    =		type_sequence_label_size
													A_			    =		initializer_range
													A_			    =		num_labels
													A_			    =		num_choices
													A_			    =		scope






						def 				_UpperCAmelCase       (  self							:      Any	):
													A_			    =		ids_tensor([self.batch_size, self.seq_length] ,  self.vocab_size	)

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

													A_			    =		None
													A_			    =		None
													A_			    =		None
													if self.use_labels:
																				A_			    =		ids_tensor([self.batch_size] ,  self.type_sequence_label_size	)
																				A_			    =		ids_tensor([self.batch_size, self.seq_length] ,  self.num_labels	)
																				A_			    =		ids_tensor([self.batch_size] ,  self.num_choices	)

													A_			    =		self.get_config()

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






						def 				_UpperCAmelCase       (  self							:      Dict	):
													A_			    =		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 				_UpperCAmelCase       (  self							:      Optional[Any] ,  lowerCAmelCase							:      Tuple ,  lowerCAmelCase							:      int ,  lowerCAmelCase							:      str ,  lowerCAmelCase							:      Dict ,  lowerCAmelCase							:      Dict ,  lowerCAmelCase							:      int	):
													A_			    =		EsmForProteinFolding(config=lowerCAmelCase	).float()
													model.to(lowerCAmelCase	)
													model.eval()
													A_			    =		model(lowerCAmelCase ,  attention_mask=lowerCAmelCase	)
													A_			    =		model(lowerCAmelCase	)
													A_			    =		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 				_UpperCAmelCase       (  self							:      Any	):
													A_			    =		self.prepare_config_and_inputs()
													(
													    (
													    A_
													)    ,					(
													    A_
													)    ,					(
													    A_
													)    ,					(
													    A_
													)    ,					(
													    A_
													)    ,					(
													    A_
													)    ,					
													)			    =		config_and_inputs
													A_			    =		{"input_ids": input_ids, "attention_mask": input_mask}
													return config, inputs_dict






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

						"""simple docstring"""






						_UpperCAmelCase		:       Optional[Any]   						=False

						_UpperCAmelCase		:       Optional[Any]   						=(EsmForProteinFolding,) if is_torch_available() else ()
						_UpperCAmelCase		:       Optional[int]   						=()
						_UpperCAmelCase		:       Tuple   						={} if is_torch_available() else {}
						_UpperCAmelCase		:       Tuple   						=False






						def 				_UpperCAmelCase       (  self							:      Optional[int]	):
													A_			    =		EsmFoldModelTester(self	)
													A_			    =		ConfigTester(self ,  config_class=lowerCAmelCase ,  hidden_size=37	)






						def 				_UpperCAmelCase       (  self							:      Any	):
													self.config_tester.run_common_tests()






						def 				_UpperCAmelCase       (  self							:      Any	):
													A_			    =		self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_model(*lowerCAmelCase	)






						@unittest.skip("Does not support attention outputs"	)
						def 				_UpperCAmelCase       (  self							:      int	):
													pass






						@unittest.skip
						def 				_UpperCAmelCase       (  self							:      Tuple	):
													pass






						@unittest.skip("Esm does not support embedding resizing"	)
						def 				_UpperCAmelCase       (  self							:      List[str]	):
													pass






						@unittest.skip("Esm does not support embedding resizing"	)
						def 				_UpperCAmelCase       (  self							:      Union[str, Any]	):
													pass






						@unittest.skip("ESMFold does not support passing input embeds!"	)
						def 				_UpperCAmelCase       (  self							:      str	):
													pass






						@unittest.skip("ESMFold does not support head pruning."	)
						def 				_UpperCAmelCase       (  self							:      List[Any]	):
													pass






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






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






						@unittest.skip("ESMFold does not support head pruning."	)
						def 				_UpperCAmelCase       (  self							:      int	):
													pass






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






						@unittest.skip("ESMFold does not output hidden states in the normal way."	)
						def 				_UpperCAmelCase       (  self							:      Optional[int]	):
													pass






						@unittest.skip("ESMfold does not output hidden states in the normal way."	)
						def 				_UpperCAmelCase       (  self							:      int	):
													pass






						@unittest.skip("ESMFold only has one output format."	)
						def 				_UpperCAmelCase       (  self							:      str	):
													pass






						@unittest.skip("This test doesn't work for ESMFold and doesn't test core functionality"	)
						def 				_UpperCAmelCase       (  self							:      List[str]	):
													pass






						@unittest.skip("ESMFold does not support input chunking."	)
						def 				_UpperCAmelCase       (  self							:      Dict	):
													pass






						@unittest.skip("ESMFold doesn't respect you and it certainly doesn't respect your initialization arguments."	)
						def 				_UpperCAmelCase       (  self							:      List[str]	):
													pass






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






						@unittest.skip("ESMFold doesn't support torchscript compilation."	)
						def 				_UpperCAmelCase       (  self							:      Dict	):
													pass






						@unittest.skip("ESMFold doesn't support torchscript compilation."	)
						def 				_UpperCAmelCase       (  self							:      Any	):
													pass






						@unittest.skip("ESMFold doesn't support data parallel."	)
						def 				_UpperCAmelCase       (  self							:      str	):
													pass






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






@require_torch
class 					__lowerCAmelCase   (   lowercase						):

						"""simple docstring"""






						@slow
						def 				_UpperCAmelCase       (  self							:      Union[str, Any]	):
													A_			    =		EsmForProteinFolding.from_pretrained("facebook/esmfold_v1"	).float()
													model.eval()
													A_			    =		torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]	)
													A_			    =		model(lowerCAmelCase	)["positions"]
													A_			    =		torch.tensor([2.5_8_2_8, 0.7_9_9_3, -1_0.9_3_3_4] ,  dtype=torch.floataa	)
													self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0] ,  lowerCAmelCase ,  atol=1e-4	)	)









'''simple docstring'''
import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin






class 					__lowerCAmelCase   (   unittest.TestCase				,			lowercase						):

						"""simple docstring"""






						def 				_UpperCAmelCase       (  self							:      List[str]	):
													A_			    =		load_tool("text-classification"	)
													self.tool.setup()
													A_			    =		load_tool("text-classification" ,  remote=lowerCAmelCase	)






						def 				_UpperCAmelCase       (  self							:      Union[str, Any]	):
													A_			    =		self.tool("That's quite cool" ,  ["positive", "negative"]	)
													self.assertEqual(lowerCAmelCase ,  "positive"	)






						def 				_UpperCAmelCase       (  self							:      str	):
													A_			    =		self.remote_tool("That's quite cool" ,  ["positive", "negative"]	)
													self.assertEqual(lowerCAmelCase ,  "positive"	)






						def 				_UpperCAmelCase       (  self							:      str	):
													A_			    =		self.tool(text="That's quite cool" ,  labels=["positive", "negative"]	)
													self.assertEqual(lowerCAmelCase ,  "positive"	)






						def 				_UpperCAmelCase       (  self							:      List[Any]	):
													A_			    =		self.remote_tool(text="That's quite cool" ,  labels=["positive", "negative"]	)
													self.assertEqual(lowerCAmelCase ,  "positive"	)





