






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




      def __init__(  self ,   lowerCamelCase ,   lowerCamelCase=13 ,   lowerCamelCase=7 ,   lowerCamelCase=False ,   lowerCamelCase=True ,   lowerCamelCase=False ,   lowerCamelCase=False ,   lowerCamelCase=19 ,   lowerCamelCase=32 ,   lowerCamelCase=5 ,   lowerCamelCase=4 ,   lowerCamelCase=37 ,   lowerCamelCase="gelu" ,   lowerCamelCase=0.1 ,   lowerCamelCase=0.1 ,   lowerCamelCase=512 ,   lowerCamelCase=16 ,   lowerCamelCase=2 ,   lowerCamelCase=0.02 ,   lowerCamelCase=3 ,   lowerCamelCase=4 ,   lowerCamelCase=None ,   )							->Optional[int]:



         '''simple docstring'''
         __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      )							->Optional[int]:



         '''simple docstring'''
         __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      )							->int:



         '''simple docstring'''
         __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=snake_case_ ,   esmfold_config={'trunk': {'num_blocks': 2}, 'fp16_esm': False} ,   )
         return config




      def  __UpperCamelCase							(  self ,   lowerCamelCase ,   lowerCamelCase ,   lowerCamelCase ,   lowerCamelCase ,   lowerCamelCase ,   lowerCamelCase      )							->Tuple:



         '''simple docstring'''
         __a				     =    EsmForProteinFolding(config=snake_case_      ).float()
         model.to(snake_case_      )
         model.eval()
         __a				     =    model(snake_case_ ,   attention_mask=snake_case_      )
         __a				     =    model(snake_case_      )
         __a				     =    model(snake_case_      )

         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      )							->int:



         '''simple docstring'''
         __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 							__SCREAMING_SNAKE_CASE       (							_a      ,      _a      ,      unittest.TestCase     ):
      __a  					=False

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




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



         '''simple docstring'''
         __a				     =    EsmFoldModelTester(self      )
         __a				     =    ConfigTester(self ,   config_class=snake_case_ ,   hidden_size=37      )




      def  __UpperCamelCase							(  self      )							->Optional[int]:



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




      def  __UpperCamelCase							(  self      )							->int:



         '''simple docstring'''
         __a				     =    self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*snake_case_      )




      @unittest.skip('Does not support attention outputs'      )
      def  __UpperCamelCase							(  self      )							->Dict:



         '''simple docstring'''
         pass




      @unittest.skip
      def  __UpperCamelCase							(  self      )							->List[str]:



         '''simple docstring'''
         pass




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



         '''simple docstring'''
         pass




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



         '''simple docstring'''
         pass




      @unittest.skip('ESMFold does not support passing input embeds!'      )
      def  __UpperCamelCase							(  self      )							->Union[str, Any]:



         '''simple docstring'''
         pass




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



         '''simple docstring'''
         pass




      @unittest.skip('ESMFold does not support head pruning.'      )
      def  __UpperCamelCase							(  self      )							->Dict:



         '''simple docstring'''
         pass




      @unittest.skip('ESMFold does not support head pruning.'      )
      def  __UpperCamelCase							(  self      )							->Tuple:



         '''simple docstring'''
         pass




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



         '''simple docstring'''
         pass




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



         '''simple docstring'''
         pass




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



         '''simple docstring'''
         pass




      @unittest.skip('ESMfold does not output hidden states in the normal way.'      )
      def  __UpperCamelCase							(  self      )							->Tuple:



         '''simple docstring'''
         pass




      @unittest.skip('ESMFold only has one output format.'      )
      def  __UpperCamelCase							(  self      )							->Optional[int]:



         '''simple docstring'''
         pass




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



         '''simple docstring'''
         pass




      @unittest.skip('ESMFold does not support input chunking.'      )
      def  __UpperCamelCase							(  self      )							->List[str]:



         '''simple docstring'''
         pass




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



         '''simple docstring'''
         pass




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



         '''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      )							->Tuple:



         '''simple docstring'''
         pass




      @unittest.skip('ESMFold doesn\'t support data parallel.'      )
      def  __UpperCamelCase							(  self      )							->List[Any]:



         '''simple docstring'''
         pass






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



         '''simple docstring'''
         pass







@require_torch
class 							__SCREAMING_SNAKE_CASE       (							_a     ):




      @slow
      def  __UpperCamelCase							(  self      )							->int:



         '''simple docstring'''
         __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(snake_case_      )['positions']
         __a				     =    torch.tensor([2.5828, 0.7993, -10.9334] ,   dtype=torch.floataa      )
         self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0] ,   snake_case_ ,   atol=1e-4      )      )








'''simple docstring'''



from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__UpperCamelCase      :       Dict      			=      logging.get_logger(__name__)

__UpperCamelCase      :       Optional[int]      			=      {
    """facebook/xmod-base""": """https://huggingface.co/facebook/xmod-base/resolve/main/config.json""",
    """facebook/xmod-large-prenorm""": """https://huggingface.co/facebook/xmod-large-prenorm/resolve/main/config.json""",
    """facebook/xmod-base-13-125k""": """https://huggingface.co/facebook/xmod-base-13-125k/resolve/main/config.json""",
    """facebook/xmod-base-30-125k""": """https://huggingface.co/facebook/xmod-base-30-125k/resolve/main/config.json""",
    """facebook/xmod-base-30-195k""": """https://huggingface.co/facebook/xmod-base-30-195k/resolve/main/config.json""",
    """facebook/xmod-base-60-125k""": """https://huggingface.co/facebook/xmod-base-60-125k/resolve/main/config.json""",
    """facebook/xmod-base-60-265k""": """https://huggingface.co/facebook/xmod-base-60-265k/resolve/main/config.json""",
    """facebook/xmod-base-75-125k""": """https://huggingface.co/facebook/xmod-base-75-125k/resolve/main/config.json""",
    """facebook/xmod-base-75-269k""": """https://huggingface.co/facebook/xmod-base-75-269k/resolve/main/config.json""",
}
class 							__SCREAMING_SNAKE_CASE       (							_lowerCAmelCase     ):
      __a  					="xmod"




      def __init__(  self ,   lowerCamelCase=3_0522 ,   lowerCamelCase=768 ,   lowerCamelCase=12 ,   lowerCamelCase=12 ,   lowerCamelCase=3072 ,   lowerCamelCase="gelu" ,   lowerCamelCase=0.1 ,   lowerCamelCase=0.1 ,   lowerCamelCase=512 ,   lowerCamelCase=2 ,   lowerCamelCase=0.02 ,   lowerCamelCase=1e-12 ,   lowerCamelCase=1 ,   lowerCamelCase=0 ,   lowerCamelCase=2 ,   lowerCamelCase="absolute" ,   lowerCamelCase=True ,   lowerCamelCase=None ,   lowerCamelCase=False ,   lowerCamelCase=2 ,   lowerCamelCase=False ,   lowerCamelCase=True ,   lowerCamelCase=True ,   lowerCamelCase=("en_XX",) ,   lowerCamelCase=None ,   **lowerCamelCase ,   )							->Any:



         '''simple docstring'''
         super().__init__(pad_token_id=lowerCamelCase ,   bos_token_id=lowerCamelCase ,   eos_token_id=lowerCamelCase ,   **lowerCamelCase      )

         __a				     =    vocab_size
         __a				     =    hidden_size
         __a				     =    num_hidden_layers
         __a				     =    num_attention_heads
         __a				     =    hidden_act
         __a				     =    intermediate_size
         __a				     =    hidden_dropout_prob
         __a				     =    attention_probs_dropout_prob
         __a				     =    max_position_embeddings
         __a				     =    type_vocab_size
         __a				     =    initializer_range
         __a				     =    layer_norm_eps
         __a				     =    position_embedding_type
         __a				     =    use_cache
         __a				     =    classifier_dropout
         __a				     =    pre_norm
         __a				     =    adapter_reduction_factor
         __a				     =    adapter_layer_norm
         __a				     =    adapter_reuse_layer_norm
         __a				     =    ln_before_adapter
         __a				     =    list(lowerCamelCase      )
         __a				     =    default_language







class 							__SCREAMING_SNAKE_CASE       (							_lowerCAmelCase     ):




      @property
      def  __UpperCamelCase							(  self      )							->Mapping[str, Mapping[int, str]]:



         '''simple docstring'''
         if self.task == "multiple-choice":
            __a				     =    {0: 'batch', 1: 'choice', 2: 'sequence'}
         else:
            __a				     =    {0: 'batch', 1: 'sequence'}
         return OrderedDict(
             [
                 ('input_ids', dynamic_axis),
                 ('attention_mask', dynamic_axis),
             ]      )