




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






       def __init__(      self:    List[str]				,    _lowerCAmelCase:    Tuple				,    _lowerCAmelCase:    Any=13				,    _lowerCAmelCase:    List[Any]=7				,    _lowerCAmelCase:    Tuple=False				,    _lowerCAmelCase:    List[str]=True				,    _lowerCAmelCase:    int=False				,    _lowerCAmelCase:    Any=False				,    _lowerCAmelCase:    List[str]=19				,    _lowerCAmelCase:    Any=32				,    _lowerCAmelCase:    Tuple=5				,    _lowerCAmelCase:    Tuple=4				,    _lowerCAmelCase:    Tuple=37				,    _lowerCAmelCase:    str="gelu"				,    _lowerCAmelCase:    int=0.1				,    _lowerCAmelCase:    Optional[Any]=0.1				,    _lowerCAmelCase:    List[str]=5_12				,    _lowerCAmelCase:    Optional[Any]=16				,    _lowerCAmelCase:    Tuple=2				,    _lowerCAmelCase:    List[Any]=0.02				,    _lowerCAmelCase:    List[str]=3				,    _lowerCAmelCase:    Any=4				,    _lowerCAmelCase:    int=None				,    ):
         lowercase			:Any							=  parent
         lowercase			:int							=  batch_size
         lowercase			:List[Any]							=  seq_length
         lowercase			:int							=  is_training
         lowercase			:Any							=  use_input_mask
         lowercase			:List[str]							=  use_token_type_ids
         lowercase			:Optional[int]							=  use_labels
         lowercase			:List[str]							=  vocab_size
         lowercase			:Dict							=  hidden_size
         lowercase			:Optional[Any]							=  num_hidden_layers
         lowercase			:Any							=  num_attention_heads
         lowercase			:Optional[int]							=  intermediate_size
         lowercase			:Optional[Any]							=  hidden_act
         lowercase			:List[Any]							=  hidden_dropout_prob
         lowercase			:List[Any]							=  attention_probs_dropout_prob
         lowercase			:Union[str, Any]							=  max_position_embeddings
         lowercase			:Any							=  type_vocab_size
         lowercase			:Union[str, Any]							=  type_sequence_label_size
         lowercase			:Dict							=  initializer_range
         lowercase			:Dict							=  num_labels
         lowercase			:Union[str, Any]							=  num_choices
         lowercase			:List[str]							=  scope






       def     SCREAMING_SNAKE_CASE			(      self:    Optional[Any] ):
         lowercase			:Tuple							=  ids_tensor([self.batch_size, self.seq_length]				,    self.vocab_size )

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

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

         lowercase			:Any							=  self.get_config()

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






       def     SCREAMING_SNAKE_CASE			(      self:    List[str] ):
         lowercase			: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     SCREAMING_SNAKE_CASE			(      self:    str				,    _lowerCAmelCase:    Union[str, Any]				,    _lowerCAmelCase:    Optional[int]				,    _lowerCAmelCase:    Dict				,    _lowerCAmelCase:    int				,    _lowerCAmelCase:    Any				,    _lowerCAmelCase:    Union[str, Any] ):
         lowercase			:List[Any]							=  EsmForProteinFolding(config=_lowerCAmelCase ).float()
         model.to(_lowerCAmelCase )
         model.eval()
         lowercase			:List[Any]							=  model(_lowerCAmelCase				,    attention_mask=_lowerCAmelCase )
         lowercase			:int							=  model(_lowerCAmelCase )
         lowercase			: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     SCREAMING_SNAKE_CASE			(      self:    Optional[Any] ):
         lowercase			:Tuple							=  self.prepare_config_and_inputs()
         (
             (
             lowercase
         )		,			(
             lowercase
         )		,			(
             lowercase
         )		,			(
             lowercase
         )		,			(
             lowercase
         )		,			(
             lowercase
         )		,			
         )			:str							=  config_and_inputs
         lowercase			:Dict							=  {"input_ids": input_ids, "attention_mask": input_mask}
         return config, inputs_dict







@require_torch
class       __lowerCAmelCase				(							lowerCAmelCase					,       lowerCAmelCase					,       unittest.TestCase):
       _a           =  False

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






       def     SCREAMING_SNAKE_CASE			(      self:    List[str] ):
         lowercase			:Union[str, Any]							=  EsmFoldModelTester(self )
         lowercase			:List[str]							=  ConfigTester(self				,    config_class=_lowerCAmelCase				,    hidden_size=37 )






       def     SCREAMING_SNAKE_CASE			(      self:    Any ):
         self.config_tester.run_common_tests()






       def     SCREAMING_SNAKE_CASE			(      self:    Union[str, Any] ):
         lowercase			: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     SCREAMING_SNAKE_CASE			(      self:    Union[str, Any] ):
         pass






       @unittest.skip
       def     SCREAMING_SNAKE_CASE			(      self:    Optional[int] ):
         pass






       @unittest.skip("Esm does not support embedding resizing" )
       def     SCREAMING_SNAKE_CASE			(      self:    Tuple ):
         pass






       @unittest.skip("Esm does not support embedding resizing" )
       def     SCREAMING_SNAKE_CASE			(      self:    Dict ):
         pass






       @unittest.skip("ESMFold does not support passing input embeds!" )
       def     SCREAMING_SNAKE_CASE			(      self:    List[Any] ):
         pass






       @unittest.skip("ESMFold does not support head pruning." )
       def     SCREAMING_SNAKE_CASE			(      self:    Optional[int] ):
         pass






       @unittest.skip("ESMFold does not support head pruning." )
       def     SCREAMING_SNAKE_CASE			(      self:    List[Any] ):
         pass






       @unittest.skip("ESMFold does not support head pruning." )
       def     SCREAMING_SNAKE_CASE			(      self:    List[Any] ):
         pass






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






       @unittest.skip("ESMFold does not support head pruning." )
       def     SCREAMING_SNAKE_CASE			(      self:    Dict ):
         pass






       @unittest.skip("ESMFold does not output hidden states in the normal way." )
       def     SCREAMING_SNAKE_CASE			(      self:    List[str] ):
         pass






       @unittest.skip("ESMfold does not output hidden states in the normal way." )
       def     SCREAMING_SNAKE_CASE			(      self:    Union[str, Any] ):
         pass






       @unittest.skip("ESMFold only has one output format." )
       def     SCREAMING_SNAKE_CASE			(      self:    Any ):
         pass






       @unittest.skip("This test doesn't work for ESMFold and doesn't test core functionality" )
       def     SCREAMING_SNAKE_CASE			(      self:    Tuple ):
         pass






       @unittest.skip("ESMFold does not support input chunking." )
       def     SCREAMING_SNAKE_CASE			(      self:    int ):
         pass






       @unittest.skip("ESMFold doesn't respect you and it certainly doesn't respect your initialization arguments." )
       def     SCREAMING_SNAKE_CASE			(      self:    str ):
         pass






       @unittest.skip("ESMFold doesn't support torchscript compilation." )
       def     SCREAMING_SNAKE_CASE			(      self:    List[str] ):
         pass






       @unittest.skip("ESMFold doesn't support torchscript compilation." )
       def     SCREAMING_SNAKE_CASE			(      self:    List[Any] ):
         pass






       @unittest.skip("ESMFold doesn't support torchscript compilation." )
       def     SCREAMING_SNAKE_CASE			(      self:    Optional[Any] ):
         pass






       @unittest.skip("ESMFold doesn't support data parallel." )
       def     SCREAMING_SNAKE_CASE			(      self:    int ):
         pass






       @unittest.skip("Will be fixed soon by reducing the size of the model used for common tests." )
       def     SCREAMING_SNAKE_CASE			(      self:    Tuple ):
         pass







@require_torch
class       __lowerCAmelCase				(							lowerCAmelCase):






       @slow
       def     SCREAMING_SNAKE_CASE			(      self:    Tuple ):
         lowercase			:List[Any]							=  EsmForProteinFolding.from_pretrained("facebook/esmfold_v1" ).float()
         model.eval()
         lowercase			:str							=  torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]] )
         lowercase			:List[str]							=  model(_lowerCAmelCase )["positions"]
         lowercase			:List[str]							=  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 ) )









import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
     import torch

if is_vision_available():
     from PIL import Image

     from transformers import GLPNImageProcessor




class       __lowerCAmelCase				(							unittest.TestCase):






       def __init__(      self:    List[Any]				,    _lowerCAmelCase:    str				,    _lowerCAmelCase:    Dict=7				,    _lowerCAmelCase:    Optional[Any]=3				,    _lowerCAmelCase:    List[Any]=18				,    _lowerCAmelCase:    int=30				,    _lowerCAmelCase:    Union[str, Any]=4_00				,    _lowerCAmelCase:    Any=True				,    _lowerCAmelCase:    Union[str, Any]=32				,    _lowerCAmelCase:    int=True				,    ):
         lowercase			:Any							=  parent
         lowercase			:List[str]							=  batch_size
         lowercase			:Any							=  num_channels
         lowercase			:Optional[Any]							=  image_size
         lowercase			:Optional[Any]							=  min_resolution
         lowercase			:str							=  max_resolution
         lowercase			:str							=  do_resize
         lowercase			:Optional[int]							=  size_divisor
         lowercase			:Tuple							=  do_rescale






       def     SCREAMING_SNAKE_CASE			(      self:    Any ):
         return {
             "do_resize": self.do_resize,
             "size_divisor": self.size_divisor,
             "do_rescale": self.do_rescale,
         }







@require_torch
@require_vision
class       __lowerCAmelCase				(							lowerCAmelCase					,       unittest.TestCase):
       _a           =  GLPNImageProcessor if is_vision_available() else None






       def     SCREAMING_SNAKE_CASE			(      self:    List[str] ):
         lowercase			:int							=  GLPNImageProcessingTester(self )






       @property
       def     SCREAMING_SNAKE_CASE			(      self:    str ):
         return self.image_processor_tester.prepare_image_processor_dict()






       def     SCREAMING_SNAKE_CASE			(      self:    Optional[int] ):
         lowercase			:Optional[Any]							=  self.image_processing_class(**self.image_processor_dict )
         self.assertTrue(hasattr(_lowerCAmelCase				,    "do_resize" ) )
         self.assertTrue(hasattr(_lowerCAmelCase				,    "size_divisor" ) )
         self.assertTrue(hasattr(_lowerCAmelCase				,    "resample" ) )
         self.assertTrue(hasattr(_lowerCAmelCase				,    "do_rescale" ) )






       def     SCREAMING_SNAKE_CASE			(      self:    List[Any] ):
         pass






       def     SCREAMING_SNAKE_CASE			(      self:    Any ):
         # Initialize image_processing
         lowercase			:Union[str, Any]							=  self.image_processing_class(**self.image_processor_dict )
         # create random PIL images
         lowercase			:List[str]							=  prepare_image_inputs(self.image_processor_tester				,    equal_resolution=_lowerCAmelCase )
         for image in image_inputs:
           self.assertIsInstance(_lowerCAmelCase				,    Image.Image )

         # Test not batched input (GLPNImageProcessor doesn't support batching)
         lowercase			:str							=  image_processing(image_inputs[0]				,    return_tensors="pt" ).pixel_values
         self.assertTrue(encoded_images.shape[-1] % self.image_processor_tester.size_divisor == 0 )
         self.assertTrue(encoded_images.shape[-2] % self.image_processor_tester.size_divisor == 0 )






       def     SCREAMING_SNAKE_CASE			(      self:    Dict ):
         # Initialize image_processing
         lowercase			:Union[str, Any]							=  self.image_processing_class(**self.image_processor_dict )
         # create random numpy tensors
         lowercase			:Union[str, Any]							=  prepare_image_inputs(self.image_processor_tester				,    equal_resolution=_lowerCAmelCase				,    numpify=_lowerCAmelCase )
         for image in image_inputs:
           self.assertIsInstance(_lowerCAmelCase				,    np.ndarray )

         # Test not batched input (GLPNImageProcessor doesn't support batching)
         lowercase			:Optional[int]							=  image_processing(image_inputs[0]				,    return_tensors="pt" ).pixel_values
         self.assertTrue(encoded_images.shape[-1] % self.image_processor_tester.size_divisor == 0 )
         self.assertTrue(encoded_images.shape[-2] % self.image_processor_tester.size_divisor == 0 )






       def     SCREAMING_SNAKE_CASE			(      self:    Tuple ):
         # Initialize image_processing
         lowercase			:Optional[Any]							=  self.image_processing_class(**self.image_processor_dict )
         # create random PyTorch tensors
         lowercase			:List[str]							=  prepare_image_inputs(self.image_processor_tester				,    equal_resolution=_lowerCAmelCase				,    torchify=_lowerCAmelCase )
         for image in image_inputs:
           self.assertIsInstance(_lowerCAmelCase				,    torch.Tensor )

         # Test not batched input (GLPNImageProcessor doesn't support batching)
         lowercase			:Dict							=  image_processing(image_inputs[0]				,    return_tensors="pt" ).pixel_values
         self.assertTrue(encoded_images.shape[-1] % self.image_processor_tester.size_divisor == 0 )
         self.assertTrue(encoded_images.shape[-2] % self.image_processor_tester.size_divisor == 0 )



