





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

  """simple docstring"""


  def __init__(    self			:		Tuple ,  lowerCAmelCase_			:		Tuple ,  lowerCAmelCase_			:		str=1_3 ,  lowerCAmelCase_			:		Dict=7 ,  lowerCAmelCase_			:		Tuple=False ,  lowerCAmelCase_			:		Optional[int]=True ,  lowerCAmelCase_			:		Optional[Any]=False ,  lowerCAmelCase_			:		List[str]=False ,  lowerCAmelCase_			:		str=1_9 ,  lowerCAmelCase_			:		Dict=3_2 ,  lowerCAmelCase_			:		Optional[Any]=5 ,  lowerCAmelCase_			:		Tuple=4 ,  lowerCAmelCase_			:		int=3_7 ,  lowerCAmelCase_			:		Optional[Any]="gelu" ,  lowerCAmelCase_			:		Any=0.1 ,  lowerCAmelCase_			:		str=0.1 ,  lowerCAmelCase_			:		List[Any]=5_1_2 ,  lowerCAmelCase_			:		Optional[int]=1_6 ,  lowerCAmelCase_			:		List[Any]=2 ,  lowerCAmelCase_			:		Optional[int]=0.02 ,  lowerCAmelCase_			:		int=3 ,  lowerCAmelCase_			:		Any=4 ,  lowerCAmelCase_			:		Optional[Any]=None ,  )							->						Optional[int]:
     __lowerCAmelCase							     =     parent
     __lowerCAmelCase							     =     batch_size
     __lowerCAmelCase							     =     seq_length
     __lowerCAmelCase							     =     is_training
     __lowerCAmelCase							     =     use_input_mask
     __lowerCAmelCase							     =     use_token_type_ids
     __lowerCAmelCase							     =     use_labels
     __lowerCAmelCase							     =     vocab_size
     __lowerCAmelCase							     =     hidden_size
     __lowerCAmelCase							     =     num_hidden_layers
     __lowerCAmelCase							     =     num_attention_heads
     __lowerCAmelCase							     =     intermediate_size
     __lowerCAmelCase							     =     hidden_act
     __lowerCAmelCase							     =     hidden_dropout_prob
     __lowerCAmelCase							     =     attention_probs_dropout_prob
     __lowerCAmelCase							     =     max_position_embeddings
     __lowerCAmelCase							     =     type_vocab_size
     __lowerCAmelCase							     =     type_sequence_label_size
     __lowerCAmelCase							     =     initializer_range
     __lowerCAmelCase							     =     num_labels
     __lowerCAmelCase							     =     num_choices
     __lowerCAmelCase							     =     scope






  def     lowercase		(    self			:		Optional[int]					)							->						Tuple:
     __lowerCAmelCase							     =     ids_tensor([self.batch_size, self.seq_length] ,  self.vocab_size					)

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

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

     __lowerCAmelCase							     =     self.get_config()

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






  def     lowercase		(    self			:		str					)							->						Tuple:
     __lowerCAmelCase							     =     EsmConfig(
         vocab_size=3_3 ,  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     lowercase		(    self			:		List[str] ,  lowerCAmelCase_			:		Optional[Any] ,  lowerCAmelCase_			:		List[str] ,  lowerCAmelCase_			:		Optional[int] ,  lowerCAmelCase_			:		Union[str, Any] ,  lowerCAmelCase_			:		str ,  lowerCAmelCase_			:		int					)							->						List[str]:
     __lowerCAmelCase							     =     EsmForProteinFolding(config=lowerCAmelCase_					).float()
     model.to(lowerCAmelCase_					)
     model.eval()
     __lowerCAmelCase							     =     model(lowerCAmelCase_ ,  attention_mask=lowerCAmelCase_					)
     __lowerCAmelCase							     =     model(lowerCAmelCase_					)
     __lowerCAmelCase							     =     model(lowerCAmelCase_					)

     self.parent.assertEqual(result.positions.shape ,  (8, self.batch_size, self.seq_length, 1_4, 3)					)
     self.parent.assertEqual(result.angles.shape ,  (8, self.batch_size, self.seq_length, 7, 2)					)






  def     lowercase		(    self			:		List[Any]					)							->						str:
     __lowerCAmelCase							     =     self.prepare_config_and_inputs()
     (
         (
         __lowerCAmelCase
     )     ,     (
         __lowerCAmelCase
     )     ,     (
         __lowerCAmelCase
     )     ,     (
         __lowerCAmelCase
     )     ,     (
         __lowerCAmelCase
     )     ,     (
         __lowerCAmelCase
     )     ,     
     )							     =     config_and_inputs
     __lowerCAmelCase							     =     {'input_ids': input_ids, 'attention_mask': input_mask}
     return config, inputs_dict





@require_torch
class     _UpperCAmelCase   (   _UpperCamelCase		,   _UpperCamelCase		,   unittest.TestCase   ):

  """simple docstring"""


  a_      =			False

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






  def     lowercase		(    self			:		Union[str, Any]					)							->						Tuple:
     __lowerCAmelCase							     =     EsmFoldModelTester(self					)
     __lowerCAmelCase							     =     ConfigTester(self ,  config_class=lowerCAmelCase_ ,  hidden_size=3_7					)






  def     lowercase		(    self			:		Optional[Any]					)							->						List[str]:
     self.config_tester.run_common_tests()






  def     lowercase		(    self			:		Tuple					)							->						Optional[Any]:
     __lowerCAmelCase							     =     self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_model(*lowerCAmelCase_					)






  @unittest.skip('Does not support attention outputs'					)
  def     lowercase		(    self			:		Optional[int]					)							->						List[str]:
     pass






  @unittest.skip
  def     lowercase		(    self			:		Dict					)							->						int:
     pass






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






  @unittest.skip('Esm does not support embedding resizing'					)
  def     lowercase		(    self			:		Optional[int]					)							->						Union[str, Any]:
     pass






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






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






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






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






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






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






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






  @unittest.skip('ESMfold does not output hidden states in the normal way.'					)
  def     lowercase		(    self			:		str					)							->						Dict:
     pass






  @unittest.skip('ESMFold only has one output format.'					)
  def     lowercase		(    self			:		Any					)							->						Dict:
     pass






  @unittest.skip('This test doesn\'t work for ESMFold and doesn\'t test core functionality'					)
  def     lowercase		(    self			:		List[Any]					)							->						List[str]:
     pass






  @unittest.skip('ESMFold does not support input chunking.'					)
  def     lowercase		(    self			:		int					)							->						Dict:
     pass






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






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






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






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






  @unittest.skip('ESMFold doesn\'t support data parallel.'					)
  def     lowercase		(    self			:		Union[str, Any]					)							->						int:
     pass






  @unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.'					)
  def     lowercase		(    self			:		List[str]					)							->						Optional[int]:
     pass





@require_torch
class     _UpperCAmelCase   (   _UpperCamelCase   ):

  """simple docstring"""


  @slow
  def     lowercase		(    self			:		Optional[Any]					)							->						Dict:
     __lowerCAmelCase							     =     EsmForProteinFolding.from_pretrained('facebook/esmfold_v1'					).float()
     model.eval()
     __lowerCAmelCase							     =     torch.tensor([[0, 6, 4, 1_3, 5, 4, 1_6, 1_2, 1_1, 7, 2]]					)
     __lowerCAmelCase							     =     model(lowerCAmelCase_					)['positions']
     __lowerCAmelCase							     =     torch.tensor([2.58_28, 0.79_93, -10.93_34] ,  dtype=torch.floataa					)
     self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0] ,  lowerCAmelCase_ ,  atol=1e-4					)					)








from functools import lru_cache

@lru_cache
def   a_   (			lowerCAmelCase_				:      int     ):
   if num < 0:
      raise ValueError('Number should not be negative.'     )

   return 1 if num in (0, 1) else num * factorial(num - 1     )


if __name__ == "__main__":
     import doctest

     doctest.testmod()

