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   ,				SCREAMING_SNAKE_CASE_   ,				SCREAMING_SNAKE_CASE_=13   ,				SCREAMING_SNAKE_CASE_=7   ,				SCREAMING_SNAKE_CASE_=False   ,				SCREAMING_SNAKE_CASE_=True   ,				SCREAMING_SNAKE_CASE_=False   ,				SCREAMING_SNAKE_CASE_=False   ,				SCREAMING_SNAKE_CASE_=19   ,				SCREAMING_SNAKE_CASE_=32   ,				SCREAMING_SNAKE_CASE_=5   ,				SCREAMING_SNAKE_CASE_=4   ,				SCREAMING_SNAKE_CASE_=37   ,				SCREAMING_SNAKE_CASE_="gelu"   ,				SCREAMING_SNAKE_CASE_=0.1   ,				SCREAMING_SNAKE_CASE_=0.1   ,				SCREAMING_SNAKE_CASE_=512   ,				SCREAMING_SNAKE_CASE_=16   ,				SCREAMING_SNAKE_CASE_=2   ,				SCREAMING_SNAKE_CASE_=0.02   ,				SCREAMING_SNAKE_CASE_=3   ,				SCREAMING_SNAKE_CASE_=4   ,				SCREAMING_SNAKE_CASE_=None   ,				)		->      Any:





       '''simple docstring'''





       UpperCamelCase__										=      parent
       UpperCamelCase__										=      batch_size
       UpperCamelCase__										=      seq_length
       UpperCamelCase__										=      is_training
       UpperCamelCase__										=      use_input_mask
       UpperCamelCase__										=      use_token_type_ids
       UpperCamelCase__										=      use_labels
       UpperCamelCase__										=      vocab_size
       UpperCamelCase__										=      hidden_size
       UpperCamelCase__										=      num_hidden_layers
       UpperCamelCase__										=      num_attention_heads
       UpperCamelCase__										=      intermediate_size
       UpperCamelCase__										=      hidden_act
       UpperCamelCase__										=      hidden_dropout_prob
       UpperCamelCase__										=      attention_probs_dropout_prob
       UpperCamelCase__										=      max_position_embeddings
       UpperCamelCase__										=      type_vocab_size
       UpperCamelCase__										=      type_sequence_label_size
       UpperCamelCase__										=      initializer_range
       UpperCamelCase__										=      num_labels
       UpperCamelCase__										=      num_choices
       UpperCamelCase__										=      scope






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





       '''simple docstring'''





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

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

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

       UpperCamelCase__										=      self.get_config()

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






  def 		_a					(self	)		->      Optional[int]:





       '''simple docstring'''





       UpperCamelCase__										=      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=SCREAMING_SNAKE_CASE_   ,				esmfold_config={'''trunk''': {'''num_blocks''': 2}, '''fp16_esm''': False}   ,				)
       return config






  def 		_a					(self   ,				SCREAMING_SNAKE_CASE_   ,				SCREAMING_SNAKE_CASE_   ,				SCREAMING_SNAKE_CASE_   ,				SCREAMING_SNAKE_CASE_   ,				SCREAMING_SNAKE_CASE_   ,				SCREAMING_SNAKE_CASE_	)		->      str:





       '''simple docstring'''





       UpperCamelCase__										=      EsmForProteinFolding(config=SCREAMING_SNAKE_CASE_	).float()
       model.to(SCREAMING_SNAKE_CASE_	)
       model.eval()
       UpperCamelCase__										=      model(SCREAMING_SNAKE_CASE_   ,				attention_mask=SCREAMING_SNAKE_CASE_	)
       UpperCamelCase__										=      model(SCREAMING_SNAKE_CASE_	)
       UpperCamelCase__										=      model(SCREAMING_SNAKE_CASE_	)

       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	)		->      Union[str, Any]:





       '''simple docstring'''





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



@require_torch
class     _A   (    __UpperCamelCase	, __UpperCamelCase	, unittest.TestCase							):
  SCREAMING_SNAKE_CASE_	:	int						=False

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






  def 		_a					(self	)		->      int:





       '''simple docstring'''





       UpperCamelCase__										=      EsmFoldModelTester(self	)
       UpperCamelCase__										=      ConfigTester(self   ,				config_class=SCREAMING_SNAKE_CASE_   ,				hidden_size=37	)






  def 		_a					(self	)		->      int:





       '''simple docstring'''





       self.config_tester.run_common_tests()






  def 		_a					(self	)		->      Tuple:





       '''simple docstring'''





       UpperCamelCase__										=      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE_	)






  @unittest.skip('''Does not support attention outputs'''	)
  def 		_a					(self	)		->      str:





       '''simple docstring'''





       pass






  @unittest.skip
  def 		_a					(self	)		->      Any:





       '''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	)		->      Tuple:





       '''simple docstring'''





       pass






  @unittest.skip('''ESMFold does not support passing input embeds!'''	)
  def 		_a					(self	)		->      List[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	)		->      Optional[Any]:





       '''simple docstring'''





       pass






  @unittest.skip('''ESMFold does not support head pruning.'''	)
  def 		_a					(self	)		->      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	)		->      Optional[int]:





       '''simple docstring'''





       pass






  @unittest.skip('''ESMFold does not output hidden states in the normal way.'''	)
  def 		_a					(self	)		->      Optional[int]:





       '''simple docstring'''





       pass






  @unittest.skip('''ESMfold does not output hidden states in the normal way.'''	)
  def 		_a					(self	)		->      int:





       '''simple docstring'''





       pass






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





       '''simple docstring'''





       pass






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





       '''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	)		->      int:





       '''simple docstring'''





       pass






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





       '''simple docstring'''





       pass






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





       '''simple docstring'''





       pass






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





       '''simple docstring'''





       pass






  @unittest.skip('''ESMFold doesn\'t support data parallel.'''	)
  def 		_a					(self	)		->      List[str]:





       '''simple docstring'''





       pass






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





       '''simple docstring'''





       pass



@require_torch
class     _A   (    __UpperCamelCase							):






  @slow
  def 		_a					(self	)		->      Any:





       '''simple docstring'''





       UpperCamelCase__										=      EsmForProteinFolding.from_pretrained('''facebook/esmfold_v1'''	).float()
       model.eval()
       UpperCamelCase__										=      torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]	)
       UpperCamelCase__										=      model(SCREAMING_SNAKE_CASE_	)['''positions''']
       UpperCamelCase__										=      torch.tensor([2.5828, 0.7993, -10.9334]   ,				dtype=torch.floataa	)
       self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]   ,				SCREAMING_SNAKE_CASE_   ,				atol=1E-4	)	)




__magic_name__								={
    '''Pillow''': '''Pillow<10.0.0''',
    '''accelerate''': '''accelerate>=0.20.3''',
    '''av''': '''av==9.2.0''',
    '''beautifulsoup4''': '''beautifulsoup4''',
    '''black''': '''black~=23.1''',
    '''codecarbon''': '''codecarbon==1.2.0''',
    '''cookiecutter''': '''cookiecutter==1.7.3''',
    '''dataclasses''': '''dataclasses''',
    '''datasets''': '''datasets!=2.5.0''',
    '''decord''': '''decord==0.6.0''',
    '''deepspeed''': '''deepspeed>=0.9.3''',
    '''diffusers''': '''diffusers''',
    '''dill''': '''dill<0.3.5''',
    '''evaluate''': '''evaluate>=0.2.0''',
    '''fairscale''': '''fairscale>0.3''',
    '''faiss-cpu''': '''faiss-cpu''',
    '''fastapi''': '''fastapi''',
    '''filelock''': '''filelock''',
    '''flax''': '''flax>=0.4.1,<=0.7.0''',
    '''ftfy''': '''ftfy''',
    '''fugashi''': '''fugashi>=1.0''',
    '''GitPython''': '''GitPython<3.1.19''',
    '''hf-doc-builder''': '''hf-doc-builder>=0.3.0''',
    '''huggingface-hub''': '''huggingface-hub>=0.14.1,<1.0''',
    '''importlib_metadata''': '''importlib_metadata''',
    '''ipadic''': '''ipadic>=1.0.0,<2.0''',
    '''isort''': '''isort>=5.5.4''',
    '''jax''': '''jax>=0.2.8,!=0.3.2,<=0.4.13''',
    '''jaxlib''': '''jaxlib>=0.1.65,<=0.4.13''',
    '''jieba''': '''jieba''',
    '''kenlm''': '''kenlm''',
    '''keras-nlp''': '''keras-nlp>=0.3.1''',
    '''librosa''': '''librosa''',
    '''nltk''': '''nltk''',
    '''natten''': '''natten>=0.14.6''',
    '''numpy''': '''numpy>=1.17''',
    '''onnxconverter-common''': '''onnxconverter-common''',
    '''onnxruntime-tools''': '''onnxruntime-tools>=1.4.2''',
    '''onnxruntime''': '''onnxruntime>=1.4.0''',
    '''opencv-python''': '''opencv-python''',
    '''optuna''': '''optuna''',
    '''optax''': '''optax>=0.0.8,<=0.1.4''',
    '''packaging''': '''packaging>=20.0''',
    '''parameterized''': '''parameterized''',
    '''phonemizer''': '''phonemizer''',
    '''protobuf''': '''protobuf''',
    '''psutil''': '''psutil''',
    '''pyyaml''': '''pyyaml>=5.1''',
    '''pydantic''': '''pydantic<2''',
    '''pytest''': '''pytest>=7.2.0''',
    '''pytest-timeout''': '''pytest-timeout''',
    '''pytest-xdist''': '''pytest-xdist''',
    '''python''': '''python>=3.8.0''',
    '''ray[tune]''': '''ray[tune]''',
    '''regex''': '''regex!=2019.12.17''',
    '''requests''': '''requests''',
    '''rhoknp''': '''rhoknp>=1.1.0,<1.3.1''',
    '''rjieba''': '''rjieba''',
    '''rouge-score''': '''rouge-score!=0.0.7,!=0.0.8,!=0.1,!=0.1.1''',
    '''ruff''': '''ruff>=0.0.241,<=0.0.259''',
    '''sacrebleu''': '''sacrebleu>=1.4.12,<2.0.0''',
    '''sacremoses''': '''sacremoses''',
    '''safetensors''': '''safetensors>=0.3.1''',
    '''sagemaker''': '''sagemaker>=2.31.0''',
    '''scikit-learn''': '''scikit-learn''',
    '''sentencepiece''': '''sentencepiece>=0.1.91,!=0.1.92''',
    '''sigopt''': '''sigopt''',
    '''starlette''': '''starlette''',
    '''sudachipy''': '''sudachipy>=0.6.6''',
    '''sudachidict_core''': '''sudachidict_core>=20220729''',
    '''tensorflow-cpu''': '''tensorflow-cpu>=2.6,<2.14''',
    '''tensorflow''': '''tensorflow>=2.6,<2.14''',
    '''tensorflow-text''': '''tensorflow-text<2.14''',
    '''tf2onnx''': '''tf2onnx''',
    '''timeout-decorator''': '''timeout-decorator''',
    '''timm''': '''timm''',
    '''tokenizers''': '''tokenizers>=0.11.1,!=0.11.3,<0.14''',
    '''torch''': '''torch>=1.9,!=1.12.0''',
    '''torchaudio''': '''torchaudio''',
    '''torchvision''': '''torchvision''',
    '''pyctcdecode''': '''pyctcdecode>=0.4.0''',
    '''tqdm''': '''tqdm>=4.27''',
    '''unidic''': '''unidic>=1.0.2''',
    '''unidic_lite''': '''unidic_lite>=1.0.7''',
    '''urllib3''': '''urllib3<2.0.0''',
    '''uvicorn''': '''uvicorn''',
}



