





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

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







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

							def 			UpperCAmelCase__		(							self							:   Optional[Any]      )    ->				str:







													"""simple docstring"""
													UpperCAmelCase_	:					Tuple     =     ids_tensor([self.batch_size, self.seq_length]				,   self.vocab_size      )

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

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

													UpperCAmelCase_	:					Any     =     self.get_config()

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

							def 			UpperCAmelCase__		(							self							:   List[str]      )    ->				str:







													"""simple docstring"""
													UpperCAmelCase_	:					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 			UpperCAmelCase__		(							self							:   str				,   __magic_name__							:   Union[str, Any]				,   __magic_name__							:   Optional[int]				,   __magic_name__							:   Dict				,   __magic_name__							:   int				,   __magic_name__							:   Any				,   __magic_name__							:   Union[str, Any]      )    ->				Optional[int]:







													"""simple docstring"""
													UpperCAmelCase_	:					List[Any]     =     EsmForProteinFolding(config=_lowerCAmelCase      ).float()
													model.to(_lowerCAmelCase      )
													model.eval()
													UpperCAmelCase_	:					List[Any]     =     model(_lowerCAmelCase				,   attention_mask=_lowerCAmelCase      )
													UpperCAmelCase_	:					int     =     model(_lowerCAmelCase      )
													UpperCAmelCase_	:					Optional[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 			UpperCAmelCase__		(							self							:   Optional[Any]      )    ->				Optional[int]:







													"""simple docstring"""
													UpperCAmelCase_	:					Tuple     =     self.prepare_config_and_inputs()
													(
													    UpperCAmelCase_			
													)	:					str     =     config_and_inputs
													UpperCAmelCase_	:					Dict     =     {"input_ids": input_ids, "attention_mask": input_mask}
													return config, inputs_dict





@require_torch
class     __a					(lowerCamelCase				,						lowerCamelCase				,						unittest.TestCase   ):
							__a    :      Any  	=				False

							__a    :      Optional[Any]  	=				(EsmForProteinFolding,) if is_torch_available() else ()
							__a    :      Optional[Any]  	=				()
							__a    :      List[Any]  	=				{} if is_torch_available() else {}
							__a    :      List[str]  	=				False

							def 			UpperCAmelCase__		(							self							:   List[str]      )    ->				Optional[int]:







													"""simple docstring"""
													UpperCAmelCase_	:					Union[str, Any]     =     EsmFoldModelTester(self      )
													UpperCAmelCase_	:					List[str]     =     ConfigTester(self				,   config_class=_lowerCAmelCase				,   hidden_size=37      )

							def 			UpperCAmelCase__		(							self							:   Any      )    ->				int:







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

							def 			UpperCAmelCase__		(							self							:   Union[str, Any]      )    ->				Optional[Any]:







													"""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]      )    ->				Union[str, Any]:







													"""simple docstring"""
													pass

							@unittest.skip
							def 			UpperCAmelCase__		(							self							:   Optional[int]      )    ->				Union[str, Any]:







													"""simple docstring"""
													pass

							@unittest.skip('''Esm does not support embedding resizing'''      )
							def 			UpperCAmelCase__		(							self							:   Tuple      )    ->				Tuple:







													"""simple docstring"""
													pass

							@unittest.skip('''Esm does not support embedding resizing'''      )
							def 			UpperCAmelCase__		(							self							:   Dict      )    ->				int:







													"""simple docstring"""
													pass

							@unittest.skip('''ESMFold does not support passing input embeds!'''      )
							def 			UpperCAmelCase__		(							self							:   List[Any]      )    ->				List[Any]:







													"""simple docstring"""
													pass

							@unittest.skip('''ESMFold does not support head pruning.'''      )
							def 			UpperCAmelCase__		(							self							:   Optional[int]      )    ->				Dict:







													"""simple docstring"""
													pass

							@unittest.skip('''ESMFold does not support head pruning.'''      )
							def 			UpperCAmelCase__		(							self							:   List[Any]      )    ->				Dict:







													"""simple docstring"""
													pass

							@unittest.skip('''ESMFold does not support head pruning.'''      )
							def 			UpperCAmelCase__		(							self							:   List[Any]      )    ->				List[str]:







													"""simple docstring"""
													pass

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







													"""simple docstring"""
													pass

							@unittest.skip('''ESMFold does not support head pruning.'''      )
							def 			UpperCAmelCase__		(							self							:   Dict      )    ->				List[str]:







													"""simple docstring"""
													pass

							@unittest.skip('''ESMFold does not output hidden states in the normal way.'''      )
							def 			UpperCAmelCase__		(							self							:   List[str]      )    ->				Optional[Any]:







													"""simple docstring"""
													pass

							@unittest.skip('''ESMfold does not output hidden states in the normal way.'''      )
							def 			UpperCAmelCase__		(							self							:   Union[str, Any]      )    ->				int:







													"""simple docstring"""
													pass

							@unittest.skip('''ESMFold only has one output format.'''      )
							def 			UpperCAmelCase__		(							self							:   Any      )    ->				Tuple:







													"""simple docstring"""
													pass

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







													"""simple docstring"""
													pass

							@unittest.skip('''ESMFold does not support input chunking.'''      )
							def 			UpperCAmelCase__		(							self							:   int      )    ->				Optional[int]:







													"""simple docstring"""
													pass

							@unittest.skip('''ESMFold doesn\'t respect you and it certainly doesn\'t respect your initialization arguments.'''      )
							def 			UpperCAmelCase__		(							self							:   str      )    ->				List[str]:







													"""simple docstring"""
													pass

							@unittest.skip('''ESMFold doesn\'t support torchscript compilation.'''      )
							def 			UpperCAmelCase__		(							self							:   List[str]      )    ->				Dict:







													"""simple docstring"""
													pass

							@unittest.skip('''ESMFold doesn\'t support torchscript compilation.'''      )
							def 			UpperCAmelCase__		(							self							:   List[Any]      )    ->				int:







													"""simple docstring"""
													pass

							@unittest.skip('''ESMFold doesn\'t support torchscript compilation.'''      )
							def 			UpperCAmelCase__		(							self							:   Optional[Any]      )    ->				Optional[int]:







													"""simple docstring"""
													pass

							@unittest.skip('''ESMFold doesn\'t support data parallel.'''      )
							def 			UpperCAmelCase__		(							self							:   int      )    ->				Dict:







													"""simple docstring"""
													pass



							@unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''      )
							def 			UpperCAmelCase__		(							self							:   Tuple      )    ->				int:







													"""simple docstring"""
													pass





@require_torch
class     __a					(lowerCamelCase   ):

							@slow
							def 			UpperCAmelCase__		(							self							:   Tuple      )    ->				Any:







													"""simple docstring"""
													UpperCAmelCase_	:					List[Any]     =     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_	:					List[str]     =     model(_lowerCAmelCase      )["positions"]
													UpperCAmelCase_	:					List[str]     =     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      )      )











import os

import pytest
from attr import dataclass


_UpperCAmelCase		:  List[str]	=   "us-east-1"  # defaults region




@dataclass
class       __lowerCAmelCase				:
       _a           =  42
       _a           =  '''arn:aws:iam::558105141721:role/sagemaker_execution_role'''
       _a           =  {
           '''task_name''': '''mnli''',
           '''per_device_train_batch_size''': 16,
           '''per_device_eval_batch_size''': 16,
           '''do_train''': True,
           '''do_eval''': True,
           '''do_predict''': True,
           '''output_dir''': '''/opt/ml/model''',
           '''overwrite_output_dir''': True,
           '''max_steps''': 500,
           '''save_steps''': 5500,
       }
       _a           =  {**hyperparameters, '''max_steps''': 1000}






       @property
       def     SCREAMING_SNAKE_CASE			(      self:    str ):
         if self.framework == "pytorch":
           return [
               {"Name": "train_runtime", "Regex": r"train_runtime.*=\D*(.*?)$"},
               {"Name": "eval_accuracy", "Regex": r"eval_accuracy.*=\D*(.*?)$"},
               {"Name": "eval_loss", "Regex": r"eval_loss.*=\D*(.*?)$"},
           ]
         else:
           return [
               {"Name": "train_runtime", "Regex": r"train_runtime.*=\D*(.*?)$"},
               {"Name": "eval_accuracy", "Regex": r"loss.*=\D*(.*?)]?$"},
               {"Name": "eval_loss", "Regex": r"sparse_categorical_accuracy.*=\D*(.*?)]?$"},
           ]






       @property
       def     SCREAMING_SNAKE_CASE			(      self:    Dict ):
         return F"{self.framework}-transfromers-test"






       @property
       def     SCREAMING_SNAKE_CASE			(      self:    Any ):
         return F"./tests/sagemaker/scripts/{self.framework}"






       @property
       def     SCREAMING_SNAKE_CASE			(      self:    Optional[int] ):
         if self.framework == "pytorch":
           return "763104351884.dkr.ecr.us-east-1.amazonaws.com/huggingface-pytorch-training:1.7.1-transformers4.6.1-gpu-py36-cu110-ubuntu18.04"
         else:
           return "763104351884.dkr.ecr.us-east-1.amazonaws.com/huggingface-tensorflow-training:2.4.1-transformers4.6.1-gpu-py37-cu110-ubuntu18.04"







@pytest.fixture(scope="class"      )
def 					UpperCAmelCase__     (   lowerCamelCase      ):
  lowercase			:Union[str, Any]							=  SageMakerTestEnvironment(framework=request.cls.framework      )



