



'''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 							lowercase__     :





	def __init__(			self :    str			,lowerCamelCase__ :    List[str]			,lowerCamelCase__ :    List[str]=13			,lowerCamelCase__ :    Optional[int]=7			,lowerCamelCase__ :    List[Any]=False			,lowerCamelCase__ :    int=True			,lowerCamelCase__ :    str=False			,lowerCamelCase__ :    List[str]=False			,lowerCamelCase__ :    Dict=19			,lowerCamelCase__ :    Optional[int]=32			,lowerCamelCase__ :    Optional[int]=5			,lowerCamelCase__ :    str=4			,lowerCamelCase__ :    Tuple=37			,lowerCamelCase__ :    List[str]="gelu"			,lowerCamelCase__ :    Tuple=0.1			,lowerCamelCase__ :    List[str]=0.1			,lowerCamelCase__ :    Any=512			,lowerCamelCase__ :    Tuple=16			,lowerCamelCase__ :    Optional[Any]=2			,lowerCamelCase__ :    Union[str, Any]=0.0_2			,lowerCamelCase__ :    Optional[int]=3			,lowerCamelCase__ :    List[Any]=4			,lowerCamelCase__ :    Optional[Any]=None			,):







							'''simple docstring'''
							_UpperCamelCase :		Dict			    =       parent
							_UpperCamelCase :		List[str]			    =       batch_size
							_UpperCamelCase :		Optional[int]			    =       seq_length
							_UpperCamelCase :		int			    =       is_training
							_UpperCamelCase :		Dict			    =       use_input_mask
							_UpperCamelCase :		str			    =       use_token_type_ids
							_UpperCamelCase :		Union[str, Any]			    =       use_labels
							_UpperCamelCase :		Union[str, Any]			    =       vocab_size
							_UpperCamelCase :		List[Any]			    =       hidden_size
							_UpperCamelCase :		Dict			    =       num_hidden_layers
							_UpperCamelCase :		Optional[int]			    =       num_attention_heads
							_UpperCamelCase :		Optional[int]			    =       intermediate_size
							_UpperCamelCase :		Tuple			    =       hidden_act
							_UpperCamelCase :		str			    =       hidden_dropout_prob
							_UpperCamelCase :		str			    =       attention_probs_dropout_prob
							_UpperCamelCase :		Tuple			    =       max_position_embeddings
							_UpperCamelCase :		Optional[Any]			    =       type_vocab_size
							_UpperCamelCase :		Optional[int]			    =       type_sequence_label_size
							_UpperCamelCase :		Tuple			    =       initializer_range
							_UpperCamelCase :		List[str]			    =       num_labels
							_UpperCamelCase :		Optional[int]			    =       num_choices
							_UpperCamelCase :		Optional[Any]			    =       scope





	def      UpperCamelCase_  (			self :    int			):







							'''simple docstring'''
							_UpperCamelCase :		Union[str, Any]			    =       ids_tensor([self.batch_size, self.seq_length]			,self.vocab_size			)

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

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

							_UpperCamelCase :		int			    =       self.get_config()

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





	def      UpperCamelCase_  (			self :    Tuple			):







							'''simple docstring'''
							_UpperCamelCase :		Optional[int]			    =       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 :    Union[str, Any]			,lowerCamelCase__ :    int			,lowerCamelCase__ :    Optional[int]			,lowerCamelCase__ :    Dict			,lowerCamelCase__ :    Optional[int]			,lowerCamelCase__ :    Tuple			,lowerCamelCase__ :    Optional[int]			):







							'''simple docstring'''
							_UpperCamelCase :		Optional[Any]			    =       EsmForProteinFolding(config=lowerCamelCase__			).float()
							model.to(lowerCamelCase__			)
							model.eval()
							_UpperCamelCase :		List[Any]			    =       model(lowerCamelCase__			,attention_mask=lowerCamelCase__			)
							_UpperCamelCase :		List[str]			    =       model(lowerCamelCase__			)
							_UpperCamelCase :		Dict			    =       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 :    Tuple			):







							'''simple docstring'''
							_UpperCamelCase :		List[str]			    =       self.prepare_config_and_inputs()
							(
							    (
							    _UpperCamelCase
							)    ,      (
							    _UpperCamelCase
							)    ,      (
							    _UpperCamelCase
							)    ,      (
							    _UpperCamelCase
							)    ,      (
							    _UpperCamelCase
							)    ,      (
							    _UpperCamelCase
							)    ,      
							) :		Dict			    =       config_and_inputs
							_UpperCamelCase :		List[Any]			    =       {'input_ids': input_ids, 'attention_mask': input_mask}
							return config, inputs_dict






@require_torch
class 							lowercase__     (							lowercase						, lowercase						, unittest.TestCase       ):
	lowercase__      =      False

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





	def      UpperCamelCase_  (			self :    Any			):







							'''simple docstring'''
							_UpperCamelCase :		List[Any]			    =       EsmFoldModelTester(self			)
							_UpperCamelCase :		Optional[Any]			    =       ConfigTester(self			,config_class=lowerCamelCase__			,hidden_size=37			)





	def      UpperCamelCase_  (			self :    str			):







							'''simple docstring'''
							self.config_tester.run_common_tests()





	def      UpperCamelCase_  (			self :    Tuple			):







							'''simple docstring'''
							_UpperCamelCase :		Optional[int]			    =       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 :    Union[str, Any]			):







							'''simple docstring'''
							pass





	@unittest.skip
	def      UpperCamelCase_  (			self :    Dict			):







							'''simple docstring'''
							pass





	@unittest.skip('Esm does not support embedding resizing'			)
	def      UpperCamelCase_  (			self :    Any			):







							'''simple docstring'''
							pass





	@unittest.skip('Esm does not support embedding resizing'			)
	def      UpperCamelCase_  (			self :    List[Any]			):







							'''simple docstring'''
							pass





	@unittest.skip('ESMFold does not support passing input embeds!'			)
	def      UpperCamelCase_  (			self :    List[str]			):







							'''simple docstring'''
							pass





	@unittest.skip('ESMFold does not support head pruning.'			)
	def      UpperCamelCase_  (			self :    Optional[Any]			):







							'''simple docstring'''
							pass





	@unittest.skip('ESMFold does not support head pruning.'			)
	def      UpperCamelCase_  (			self :    Any			):







							'''simple docstring'''
							pass





	@unittest.skip('ESMFold does not support head pruning.'			)
	def      UpperCamelCase_  (			self :    Optional[Any]			):







							'''simple docstring'''
							pass





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







							'''simple docstring'''
							pass





	@unittest.skip('ESMFold does not support head pruning.'			)
	def      UpperCamelCase_  (			self :    int			):







							'''simple docstring'''
							pass





	@unittest.skip('ESMFold does not output hidden states in the normal way.'			)
	def      UpperCamelCase_  (			self :    Any			):







							'''simple docstring'''
							pass





	@unittest.skip('ESMfold does not output hidden states in the normal way.'			)
	def      UpperCamelCase_  (			self :    List[str]			):







							'''simple docstring'''
							pass





	@unittest.skip('ESMFold only has one output format.'			)
	def      UpperCamelCase_  (			self :    Any			):







							'''simple docstring'''
							pass





	@unittest.skip('This test doesn\'t work for ESMFold and doesn\'t test core functionality'			)
	def      UpperCamelCase_  (			self :    Dict			):







							'''simple docstring'''
							pass





	@unittest.skip('ESMFold does not support input chunking.'			)
	def      UpperCamelCase_  (			self :    Tuple			):







							'''simple docstring'''
							pass





	@unittest.skip('ESMFold doesn\'t respect you and it certainly doesn\'t respect your initialization arguments.'			)
	def      UpperCamelCase_  (			self :    Tuple			):







							'''simple docstring'''
							pass





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







							'''simple docstring'''
							pass





	@unittest.skip('ESMFold doesn\'t support torchscript compilation.'			)
	def      UpperCamelCase_  (			self :    Any			):







							'''simple docstring'''
							pass





	@unittest.skip('ESMFold doesn\'t support torchscript compilation.'			)
	def      UpperCamelCase_  (			self :    Any			):







							'''simple docstring'''
							pass





	@unittest.skip('ESMFold doesn\'t support data parallel.'			)
	def      UpperCamelCase_  (			self :    Optional[int]			):







							'''simple docstring'''
							pass





	@unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.'			)
	def      UpperCamelCase_  (			self :    Optional[Any]			):







							'''simple docstring'''
							pass






@require_torch
class 							lowercase__     (							lowercase       ):





	@slow
	def      UpperCamelCase_  (			self :    Optional[Any]			):







							'''simple docstring'''
							_UpperCamelCase :		Optional[int]			    =       EsmForProteinFolding.from_pretrained('facebook/esmfold_v1'			).float()
							model.eval()
							_UpperCamelCase :		str			    =       torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]			)
							_UpperCamelCase :		Union[str, Any]			    =       model(lowerCamelCase__			)['positions']
							_UpperCamelCase :		Optional[Any]			    =       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'''
from torch import nn






def A__   (					UpperCAmelCase_							):
						if act_fn in ["swish", "silu"]:
												return nn.SiLU()
						elif act_fn == "mish":
												return nn.Mish()
						elif act_fn == "gelu":
												return nn.GELU()
						else:
												raise ValueError(f'Unsupported activation function: {act_fn}'							)


