





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 MobileNetVaImageProcessor


class    __SCREAMING_SNAKE_CASE			( unittest.TestCase					):







       def __init__(      self     :	Any		,					A     :	List[str]		,					A     :	Dict=7		,					A     :	List[Any]=3		,					A     :	int=1_8		,					A     :	Optional[Any]=3_0		,					A     :	List[Any]=4_0_0		,					A     :	Optional[int]=True		,					A     :	List[str]=None		,					A     :	int=True		,					A     :	Optional[int]=None		,					)   ->Dict:
          lowerCamelCase__   :						Union[str, Any]					   =							size if size is not None else {'shortest_edge': 2_0}
          lowerCamelCase__   :						int					   =							crop_size if crop_size is not None else {'height': 1_8, 'width': 1_8}
          lowerCamelCase__   :						Optional[int]					   =							parent
          lowerCamelCase__   :						Union[str, Any]					   =							batch_size
          lowerCamelCase__   :						int					   =							num_channels
          lowerCamelCase__   :						Union[str, Any]					   =							image_size
          lowerCamelCase__   :						Any					   =							min_resolution
          lowerCamelCase__   :						Dict					   =							max_resolution
          lowerCamelCase__   :						Optional[Any]					   =							do_resize
          lowerCamelCase__   :						Optional[Any]					   =							size
          lowerCamelCase__   :						List[Any]					   =							do_center_crop
          lowerCamelCase__   :						Dict					   =							crop_size







       def 						__lowerCamelCase    (      self     :	Any			)   ->Tuple:
          return {
              "do_resize": self.do_resize,
              "size": self.size,
              "do_center_crop": self.do_center_crop,
              "crop_size": self.crop_size,
          }


@require_torch
@require_vision
class    __SCREAMING_SNAKE_CASE			( __snake_case     ,unittest.TestCase					):
       _UpperCAmelCase      :  str     =    MobileNetVaImageProcessor if is_vision_available() else None







       def 						__lowerCamelCase    (      self     :	Dict			)   ->Optional[int]:
          lowerCamelCase__   :						List[str]					   =							MobileNetVaImageProcessingTester(self			)







       @property
       def 						__lowerCamelCase    (      self     :	List[str]			)   ->Union[str, Any]:
          return self.image_processor_tester.prepare_image_processor_dict()







       def 						__lowerCamelCase    (      self     :	Tuple			)   ->Optional[int]:
          lowerCamelCase__   :						Any					   =							self.image_processing_class(**self.image_processor_dict			)
          self.assertTrue(hasattr(A		,					'''do_resize'''			)			)
          self.assertTrue(hasattr(A		,					'''size'''			)			)
          self.assertTrue(hasattr(A		,					'''do_center_crop'''			)			)
          self.assertTrue(hasattr(A		,					'''crop_size'''			)			)







       def 						__lowerCamelCase    (      self     :	str			)   ->Union[str, Any]:
          lowerCamelCase__   :						Optional[int]					   =							self.image_processing_class.from_dict(self.image_processor_dict			)
          self.assertEqual(image_processor.size		,					{'''shortest_edge''': 2_0}			)
          self.assertEqual(image_processor.crop_size		,					{'''height''': 1_8, '''width''': 1_8}			)

          lowerCamelCase__   :						Tuple					   =							self.image_processing_class.from_dict(self.image_processor_dict		,					size=4_2		,					crop_size=8_4			)
          self.assertEqual(image_processor.size		,					{'''shortest_edge''': 4_2}			)
          self.assertEqual(image_processor.crop_size		,					{'''height''': 8_4, '''width''': 8_4}			)







       def 						__lowerCamelCase    (      self     :	Dict			)   ->Tuple:
          pass







       def 						__lowerCamelCase    (      self     :	Union[str, Any]			)   ->int:
          # Initialize image_processing
          lowerCamelCase__   :						int					   =							self.image_processing_class(**self.image_processor_dict			)
          # create random PIL images
          lowerCamelCase__   :						Optional[Any]					   =							prepare_image_inputs(self.image_processor_tester		,					equal_resolution=A			)
          for image in image_inputs:
             self.assertIsInstance(A		,					Image.Image			)

          # Test not batched input
          lowerCamelCase__   :						Optional[Any]					   =							image_processing(image_inputs[0]		,					return_tensors='''pt'''			).pixel_values
          self.assertEqual(
              encoded_images.shape		,					(
                  1,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size['''height'''],
                  self.image_processor_tester.crop_size['''width'''],
              )		,					)

          # Test batched
          lowerCamelCase__   :						int					   =							image_processing(A		,					return_tensors='''pt'''			).pixel_values
          self.assertEqual(
              encoded_images.shape		,					(
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size['''height'''],
                  self.image_processor_tester.crop_size['''width'''],
              )		,					)







       def 						__lowerCamelCase    (      self     :	List[str]			)   ->List[Any]:
          # Initialize image_processing
          lowerCamelCase__   :						Any					   =							self.image_processing_class(**self.image_processor_dict			)
          # create random numpy tensors
          lowerCamelCase__   :						Optional[int]					   =							prepare_image_inputs(self.image_processor_tester		,					equal_resolution=A		,					numpify=A			)
          for image in image_inputs:
             self.assertIsInstance(A		,					np.ndarray			)

          # Test not batched input
          lowerCamelCase__   :						List[Any]					   =							image_processing(image_inputs[0]		,					return_tensors='''pt'''			).pixel_values
          self.assertEqual(
              encoded_images.shape		,					(
                  1,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size['''height'''],
                  self.image_processor_tester.crop_size['''width'''],
              )		,					)

          # Test batched
          lowerCamelCase__   :						Optional[int]					   =							image_processing(A		,					return_tensors='''pt'''			).pixel_values
          self.assertEqual(
              encoded_images.shape		,					(
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size['''height'''],
                  self.image_processor_tester.crop_size['''width'''],
              )		,					)







       def 						__lowerCamelCase    (      self     :	Any			)   ->Tuple:
          # Initialize image_processing
          lowerCamelCase__   :						int					   =							self.image_processing_class(**self.image_processor_dict			)
          # create random PyTorch tensors
          lowerCamelCase__   :						List[Any]					   =							prepare_image_inputs(self.image_processor_tester		,					equal_resolution=A		,					torchify=A			)
          for image in image_inputs:
             self.assertIsInstance(A		,					torch.Tensor			)

          # Test not batched input
          lowerCamelCase__   :						str					   =							image_processing(image_inputs[0]		,					return_tensors='''pt'''			).pixel_values
          self.assertEqual(
              encoded_images.shape		,					(
                  1,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size['''height'''],
                  self.image_processor_tester.crop_size['''width'''],
              )		,					)

          # Test batched
          lowerCamelCase__   :						Any					   =							image_processing(A		,					return_tensors='''pt'''			).pixel_values
          self.assertEqual(
              encoded_images.shape		,					(
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size['''height'''],
                  self.image_processor_tester.crop_size['''width'''],
              )		,					)






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						,   a						,   a=13						,   a=7						,   a=False						,   a=True						,   a=False						,   a=False						,   a=19						,   a=32						,   a=5						,   a=4						,   a=37						,   a="gelu"						,   a=0.1						,   a=0.1						,   a=512						,   a=16						,   a=2						,   a=0.02						,   a=3						,   a=4						,   a=None						,   ):
         lowercase__    :   Optional[Any]      =       parent
         lowercase__    :   Dict      =       batch_size
         lowercase__    :   Union[str, Any]      =       seq_length
         lowercase__    :   Optional[Any]      =       is_training
         lowercase__    :   Tuple      =       use_input_mask
         lowercase__    :   List[str]      =       use_token_type_ids
         lowercase__    :   Optional[Any]      =       use_labels
         lowercase__    :   List[str]      =       vocab_size
         lowercase__    :   Optional[int]      =       hidden_size
         lowercase__    :   List[str]      =       num_hidden_layers
         lowercase__    :   Any      =       num_attention_heads
         lowercase__    :   int      =       intermediate_size
         lowercase__    :   Any      =       hidden_act
         lowercase__    :   Any      =       hidden_dropout_prob
         lowercase__    :   str      =       attention_probs_dropout_prob
         lowercase__    :   List[Any]      =       max_position_embeddings
         lowercase__    :   int      =       type_vocab_size
         lowercase__    :   List[Any]      =       type_sequence_label_size
         lowercase__    :   str      =       initializer_range
         lowercase__    :   List[str]      =       num_labels
         lowercase__    :   Union[str, Any]      =       num_choices
         lowercase__    :   Optional[int]      =       scope





    def       snake_case_				(      self):
         lowercase__    :   List[Any]      =       ids_tensor([self.batch_size, self.seq_length]						,   self.vocab_size)

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

         lowercase__    :   int      =       None
         lowercase__    :   Optional[int]      =       None
         lowercase__    :   Optional[int]      =       None
         if self.use_labels:
              lowercase__    :   Optional[int]      =       ids_tensor([self.batch_size]						,   self.type_sequence_label_size)
              lowercase__    :   str      =       ids_tensor([self.batch_size, self.seq_length]						,   self.num_labels)
              lowercase__    :   str      =       ids_tensor([self.batch_size]						,   self.num_choices)

         lowercase__    :   int      =       self.get_config()

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





    def       snake_case_				(      self):
         lowercase__    :   str      =       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=a						,   esmfold_config={'trunk': {'num_blocks': 2}, 'fp16_esm': False}						,   )
         return config





    def       snake_case_				(      self						,   a						,   a						,   a						,   a						,   a						,   a):
         lowercase__    :   Dict      =       EsmForProteinFolding(config=a).float()
         model.to(a)
         model.eval()
         lowercase__    :   Union[str, Any]      =       model(a						,   attention_mask=a)
         lowercase__    :   Dict      =       model(a)
         lowercase__    :   int      =       model(a)

         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       snake_case_				(      self):
         lowercase__    :   List[str]      =       self.prepare_config_and_inputs()
         (
             (
             lowercase__
         )      , (
             lowercase__
         )      , (
             lowercase__
         )      , (
             lowercase__
         )      , (
             lowercase__
         )      , (
             lowercase__
         )      , 
         )    :   int      =       config_and_inputs
         lowercase__    :   Optional[int]      =       {'input_ids': input_ids, 'attention_mask': input_mask}
         return config, inputs_dict



@require_torch
class       SCREAMING_SNAKE_CASE__					(__snake_case		,       __snake_case		,       unittest.TestCase     ):
    __lowerCamelCase						:       Dict														=     False

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





    def       snake_case_				(      self):
         lowercase__    :   Tuple      =       EsmFoldModelTester(self)
         lowercase__    :   List[Any]      =       ConfigTester(self						,   config_class=a						,   hidden_size=37)





    def       snake_case_				(      self):
         self.config_tester.run_common_tests()





    def       snake_case_				(      self):
         lowercase__    :   Optional[int]      =       self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*a)





    @unittest.skip('Does not support attention outputs')
    def       snake_case_				(      self):
         pass





    @unittest.skip
    def       snake_case_				(      self):
         pass





    @unittest.skip('Esm does not support embedding resizing')
    def       snake_case_				(      self):
         pass





    @unittest.skip('Esm does not support embedding resizing')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold does not support passing input embeds!')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold does not support head pruning.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold does not support head pruning.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold does not support head pruning.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold does not support head pruning.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold does not support head pruning.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold does not output hidden states in the normal way.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMfold does not output hidden states in the normal way.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold only has one output format.')
    def       snake_case_				(      self):
         pass





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





    @unittest.skip('ESMFold does not support input chunking.')
    def       snake_case_				(      self):
         pass





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





    @unittest.skip('ESMFold doesn\'t support torchscript compilation.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold doesn\'t support torchscript compilation.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold doesn\'t support torchscript compilation.')
    def       snake_case_				(      self):
         pass





    @unittest.skip('ESMFold doesn\'t support data parallel.')
    def       snake_case_				(      self):
         pass





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



@require_torch
class       SCREAMING_SNAKE_CASE__					(__snake_case     ):





    @slow
    def       snake_case_				(      self):
         lowercase__    :   Dict      =       EsmForProteinFolding.from_pretrained('facebook/esmfold_v1').float()
         model.eval()
         lowercase__    :   Optional[Any]      =       torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]])
         lowercase__    :   Optional[int]      =       model(a)['positions']
         lowercase__    :   Dict      =       torch.tensor([2.5_828, 0.7_993, -10.9_334]						,   dtype=torch.floataa)
         self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]						,   a						,   atol=1e-4))

