


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       __magic_name__	:


     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=512							,	lowerCamelCase__							:     Optional[int]=16							,	lowerCamelCase__							:     Dict=2							,	lowerCamelCase__							:     Optional[int]=0.02							,	lowerCamelCase__							:     List[Any]=3							,	lowerCamelCase__							:     Any=4							,	lowerCamelCase__							:     Optional[int]=None							,	)  ->      int:





      '''simple docstring'''






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


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





      '''simple docstring'''






      UpperCamelCase__					:    int          =   ids_tensor([self.batch_size, self.seq_length]							,	self.vocab_size			)

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

      UpperCamelCase__					:    List[Any]          =   None
      UpperCamelCase__					:    List[str]          =   None
      UpperCamelCase__					:    Union[str, Any]          =   None
      if self.use_labels:
       UpperCamelCase__					:    Dict          =   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__					:    Optional[int]          =   ids_tensor([self.batch_size]							,	self.num_choices			)

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

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


     def      UpperCAmelCase__	(      self							:     List[Any]			)  ->      List[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							:     List[str]							,	lowerCamelCase__							:     Union[str, Any]							,	lowerCamelCase__							:     Tuple							,	lowerCamelCase__							:     Optional[Any]							,	lowerCamelCase__							:     List[str]							,	lowerCamelCase__							:     List[str]							,	lowerCamelCase__							:     List[str]			)  ->      List[Any]:





      '''simple docstring'''






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





      '''simple docstring'''






      UpperCamelCase__					:    List[str]          =   self.prepare_config_and_inputs()
      (
          UpperCamelCase__				
      )					:    str          =   config_and_inputs
      UpperCamelCase__					:    List[str]          =   {'''input_ids''': input_ids, '''attention_mask''': input_mask}
      return config, inputs_dict



@require_torch
class       __magic_name__	(     __lowerCAmelCase					,				__lowerCAmelCase					,				unittest.TestCase):
     A:		Tuple			=      False

     A:		Tuple			=      (EsmForProteinFolding,) if is_torch_available() else ()
     A:		Any			=      ()
     A:		Any			=      {} if is_torch_available() else {}
     A:		Any			=      False


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





      '''simple docstring'''






      UpperCamelCase__					:    List[Any]          =   EsmFoldModelTester(self			)
      UpperCamelCase__					:    List[Any]          =   ConfigTester(self							,	config_class=lowerCamelCase__							,	hidden_size=37			)


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





      '''simple docstring'''






      self.config_tester.run_common_tests()


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





      '''simple docstring'''






      UpperCamelCase__					:    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							:     List[Any]			)  ->      Any:





      '''simple docstring'''






      pass


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





      '''simple docstring'''






      pass


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





      '''simple docstring'''






      pass


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





      '''simple docstring'''






      pass


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





      '''simple docstring'''






      pass


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





      '''simple docstring'''






      pass


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





      '''simple docstring'''






      pass


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





      '''simple docstring'''






      pass


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





      '''simple docstring'''






      pass


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





      '''simple docstring'''






      pass


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





      '''simple docstring'''






      pass


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





      '''simple docstring'''






      pass


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





      '''simple docstring'''






      pass


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





      '''simple docstring'''






      pass


     @unittest.skip('''ESMFold does not support input chunking.'''			)
     def      UpperCAmelCase__	(      self							:     str			)  ->      Any:





      '''simple docstring'''






      pass


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





      '''simple docstring'''






      pass


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





      '''simple docstring'''






      pass


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





      '''simple docstring'''






      pass


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





      '''simple docstring'''






      pass


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





      '''simple docstring'''






      pass


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





      '''simple docstring'''






      pass



@require_torch
class       __magic_name__	(     __lowerCAmelCase):


     @slow
     def      UpperCAmelCase__	(      self							:     Any			)  ->      List[Any]:





      '''simple docstring'''






      UpperCamelCase__					:    Optional[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__					:    Optional[Any]          =   model(lowerCamelCase__			)['''positions''']
      UpperCamelCase__					:    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			)			)






from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_speech_available,
    is_torch_available,
)


__UpperCamelCase       :       Dict						       =				{
    "configuration_trocr": ["TROCR_PRETRAINED_CONFIG_ARCHIVE_MAP", "TrOCRConfig"],
    "processing_trocr": ["TrOCRProcessor"],
}


try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __UpperCamelCase       :       Optional[int]						       =				[
           "TROCR_PRETRAINED_MODEL_ARCHIVE_LIST",
           "TrOCRForCausalLM",
           "TrOCRPreTrainedModel",
       ]


if TYPE_CHECKING:
       from .configuration_trocr import TROCR_PRETRAINED_CONFIG_ARCHIVE_MAP, TrOCRConfig
       from .processing_trocr import TrOCRProcessor

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_trocr import TROCR_PRETRAINED_MODEL_ARCHIVE_LIST, TrOCRForCausalLM, TrOCRPreTrainedModel

else:
       import sys

       __UpperCamelCase       :       Tuple						       =				_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)


