




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

      def __init__(		self   :int    , __snake_case   :Any    , __snake_case   :Dict=13    , __snake_case   :Tuple=7    , __snake_case   :Tuple=False    , __snake_case   :str=True    , __snake_case   :str=False    , __snake_case   :Union[str, Any]=False    , __snake_case   :int=19    , __snake_case   :Optional[Any]=32    , __snake_case   :Optional[Any]=5    , __snake_case   :Tuple=4    , __snake_case   :List[Any]=37    , __snake_case   :List[Any]="gelu"    , __snake_case   :Dict=0.1    , __snake_case   :Any=0.1    , __snake_case   :Optional[Any]=5_12    , __snake_case   :Tuple=16    , __snake_case   :int=2    , __snake_case   :List[str]=0.02    , __snake_case   :List[Any]=3    , __snake_case   :Dict=4    , __snake_case   :str=None    , ):
          '''simple docstring'''

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

      def     A__						(		self   :Optional[Any] ):
          '''simple docstring'''

          __magic_name__	:	Any								=ids_tensor([self.batch_size, self.seq_length]    , self.vocab_size )

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

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

          __magic_name__	:	Tuple								=self.get_config()

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

      def     A__						(		self   :Any ):
          '''simple docstring'''

          __magic_name__	:	Optional[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=__A    , esmfold_config={"""trunk""": {"""num_blocks""": 2}, """fp16_esm""": False}    , )
          return config

      def     A__						(		self   :Tuple    , __snake_case   :Tuple    , __snake_case   :Any    , __snake_case   :Union[str, Any]    , __snake_case   :Tuple    , __snake_case   :str    , __snake_case   :int ):
          '''simple docstring'''

          __magic_name__	:	Tuple								=EsmForProteinFolding(config=__A ).float()
          model.to(__A )
          model.eval()
          __magic_name__	:	List[str]								=model(__A    , attention_mask=__A )
          __magic_name__	:	str								=model(__A )
          __magic_name__	:	str								=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     A__						(		self   :Any ):
          '''simple docstring'''

          __magic_name__	:	str								=self.prepare_config_and_inputs()
          (
              (
              __magic_name__				
          )				, (
              __magic_name__				
          )				, (
              __magic_name__				
          )				, (
              __magic_name__				
          )				, (
              __magic_name__				
          )				, (
              __magic_name__				
          )				, 				
          )	:	Optional[Any]								=config_and_inputs
          __magic_name__	:	Optional[Any]								={"""input_ids""": input_ids, """attention_mask""": input_mask}
          return config, inputs_dict




@require_torch
class 		__A      (			__lowercase					,						__lowercase					,						unittest.TestCase			):
      UpperCamelCase     						=					False

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

      def     A__						(		self   :Optional[Any] ):
          '''simple docstring'''

          __magic_name__	:	Any								=EsmFoldModelTester(self )
          __magic_name__	:	Optional[Any]								=ConfigTester(self    , config_class=__A    , hidden_size=37 )

      def     A__						(		self   :Any ):
          '''simple docstring'''

          self.config_tester.run_common_tests()

      def     A__						(		self   :Optional[int] ):
          '''simple docstring'''

          __magic_name__	:	Union[str, Any]								=self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*__A )

      @unittest.skip("""Does not support attention outputs""" )
      def     A__						(		self   :Optional[int] ):
          '''simple docstring'''

          pass

      @unittest.skip
      def     A__						(		self   :Optional[int] ):
          '''simple docstring'''

          pass

      @unittest.skip("""Esm does not support embedding resizing""" )
      def     A__						(		self   :Dict ):
          '''simple docstring'''

          pass

      @unittest.skip("""Esm does not support embedding resizing""" )
      def     A__						(		self   :int ):
          '''simple docstring'''

          pass

      @unittest.skip("""ESMFold does not support passing input embeds!""" )
      def     A__						(		self   :int ):
          '''simple docstring'''

          pass

      @unittest.skip("""ESMFold does not support head pruning.""" )
      def     A__						(		self   :Optional[Any] ):
          '''simple docstring'''

          pass

      @unittest.skip("""ESMFold does not support head pruning.""" )
      def     A__						(		self   :Union[str, Any] ):
          '''simple docstring'''

          pass

      @unittest.skip("""ESMFold does not support head pruning.""" )
      def     A__						(		self   :List[Any] ):
          '''simple docstring'''

          pass

      @unittest.skip("""ESMFold does not support head pruning.""" )
      def     A__						(		self   :List[Any] ):
          '''simple docstring'''

          pass

      @unittest.skip("""ESMFold does not support head pruning.""" )
      def     A__						(		self   :List[str] ):
          '''simple docstring'''

          pass

      @unittest.skip("""ESMFold does not output hidden states in the normal way.""" )
      def     A__						(		self   :str ):
          '''simple docstring'''

          pass

      @unittest.skip("""ESMfold does not output hidden states in the normal way.""" )
      def     A__						(		self   :Dict ):
          '''simple docstring'''

          pass

      @unittest.skip("""ESMFold only has one output format.""" )
      def     A__						(		self   :Union[str, Any] ):
          '''simple docstring'''

          pass

      @unittest.skip("""This test doesn\'t work for ESMFold and doesn\'t test core functionality""" )
      def     A__						(		self   :Optional[int] ):
          '''simple docstring'''

          pass

      @unittest.skip("""ESMFold does not support input chunking.""" )
      def     A__						(		self   :Union[str, Any] ):
          '''simple docstring'''

          pass

      @unittest.skip("""ESMFold doesn\'t respect you and it certainly doesn\'t respect your initialization arguments.""" )
      def     A__						(		self   :Dict ):
          '''simple docstring'''

          pass

      @unittest.skip("""ESMFold doesn\'t support torchscript compilation.""" )
      def     A__						(		self   :int ):
          '''simple docstring'''

          pass

      @unittest.skip("""ESMFold doesn\'t support torchscript compilation.""" )
      def     A__						(		self   :str ):
          '''simple docstring'''

          pass

      @unittest.skip("""ESMFold doesn\'t support torchscript compilation.""" )
      def     A__						(		self   :Optional[Any] ):
          '''simple docstring'''

          pass

      @unittest.skip("""ESMFold doesn\'t support data parallel.""" )
      def     A__						(		self   :Union[str, Any] ):
          '''simple docstring'''

          pass


      @unittest.skip("""Will be fixed soon by reducing the size of the model used for common tests.""" )
      def     A__						(		self   :Dict ):
          '''simple docstring'''

          pass




@require_torch
class 		__A      (			__lowercase			):

      @slow
      def     A__						(		self   :int ):
          '''simple docstring'''

          __magic_name__	:	str								=EsmForProteinFolding.from_pretrained("""facebook/esmfold_v1""" ).float()
          model.eval()
          __magic_name__	:	List[Any]								=torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]] )
          __magic_name__	:	Optional[int]								=model(__A )["""positions"""]
          __magic_name__	:	Tuple								=torch.tensor([2.5828, 0.7993, -10.9334]    , dtype=torch.floataa )
          self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]    , __A    , atol=1E-4 ) )










import pytest

import datasets


# Import fixture modules as plugins
UpperCAmelCase_		:				Union[str, Any]									=     ["tests.fixtures.files", "tests.fixtures.hub", "tests.fixtures.fsspec"]




def 		lowerCAmelCase_   (	lowerCamelCase	,     lowerCamelCase   ):
				# Mark tests as "unit" by default if not marked as "integration" (or already marked as "unit")
				for item in items:
								if any(marker in item.keywords for marker in ["""integration""", """unit"""]   ):
												continue
								item.add_marker(pytest.mark.unit   )




def 		lowerCAmelCase_   (	lowerCamelCase   ):
				config.addinivalue_line("""markers"""	,     """torchaudio_latest: mark test to run with torchaudio>=0.12"""   )




@pytest.fixture(autouse=lowerCamelCase   )
def 		lowerCAmelCase_   (	lowerCamelCase	,     lowerCamelCase   ):
				# test_hf_cache_home = tmp_path_factory.mktemp("cache")  # TODO: why a cache dir per test function does not work?
				__magic_name__	:	Tuple								=tmp_path_factory.getbasetemp() / """cache"""
				__magic_name__	:	Optional[int]								=test_hf_cache_home / """datasets"""
				__magic_name__	:	List[str]								=test_hf_cache_home / """metrics"""
				__magic_name__	:	List[str]								=test_hf_cache_home / """modules"""
				monkeypatch.setattr("""datasets.config.HF_DATASETS_CACHE"""	,     str(lowerCamelCase   )   )
				monkeypatch.setattr("""datasets.config.HF_METRICS_CACHE"""	,     str(lowerCamelCase   )   )
				monkeypatch.setattr("""datasets.config.HF_MODULES_CACHE"""	,     str(lowerCamelCase   )   )
				__magic_name__	:	Optional[Any]								=test_hf_datasets_cache / """downloads"""
				monkeypatch.setattr("""datasets.config.DOWNLOADED_DATASETS_PATH"""	,     str(lowerCamelCase   )   )
				__magic_name__	:	Tuple								=test_hf_datasets_cache / """downloads""" / """extracted"""
				monkeypatch.setattr("""datasets.config.EXTRACTED_DATASETS_PATH"""	,     str(lowerCamelCase   )   )




@pytest.fixture(autouse=lowerCamelCase	,     scope="""session"""   )
def 		lowerCAmelCase_   (	):
				datasets.disable_progress_bar()




@pytest.fixture(autouse=lowerCamelCase   )
def 		lowerCAmelCase_   (	lowerCamelCase   ):
				# don't take tests into account when counting downloads
				monkeypatch.setattr("""datasets.config.HF_UPDATE_DOWNLOAD_COUNTS"""	,     lowerCamelCase   )




@pytest.fixture
def 		lowerCAmelCase_   (	lowerCamelCase   ):
				# Required to suppress RemovedIn20Warning when feature(s) are not compatible with SQLAlchemy 2.0
				# To be removed once SQLAlchemy 2.0 supported
				monkeypatch.setattr("""sqlalchemy.util.deprecations.SILENCE_UBER_WARNING"""	,     lowerCamelCase   )




