


'''simple docstring'''
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							:       Union[str, Any]		,		_A							:       List[Any]		,		_A							:       Any=13		,		_A							:       Optional[int]=7		,		_A							:       Optional[Any]=False		,		_A							:       Tuple=True		,		_A							:       Tuple=False		,		_A							:       Union[str, Any]=False		,		_A							:       Optional[Any]=19		,		_A							:       str=32		,		_A							:       str=5		,		_A							:       Any=4		,		_A							:       Optional[int]=37		,		_A							:       int="gelu"		,		_A							:       Tuple=0.1		,		_A							:       Dict=0.1		,		_A							:       List[str]=512		,		_A							:       Union[str, Any]=16		,		_A							:       Union[str, Any]=2		,		_A							:       Dict=0.0_2		,		_A							:       Union[str, Any]=3		,		_A							:       str=4		,		_A							:       Tuple=None		,		):


          '''simple docstring'''


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






      def lowercase_				(   self							:       List[Any]					):


          '''simple docstring'''


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

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

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

          UpperCAmelCase__     :						Tuple						=							self.get_config()

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






      def lowercase_				(   self							:       str					):


          '''simple docstring'''


          UpperCAmelCase__     :						int						=							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 lowercase_				(   self							:       Optional[int]		,		_A							:       List[Any]		,		_A							:       str		,		_A							:       Optional[int]		,		_A							:       Dict		,		_A							:       Optional[Any]		,		_A							:       Union[str, Any]					):


          '''simple docstring'''


          UpperCAmelCase__     :						str						=							EsmForProteinFolding(config=_A					).float()
          model.to(_A					)
          model.eval()
          UpperCAmelCase__     :						Optional[int]						=							model(_A		,		attention_mask=_A					)
          UpperCAmelCase__     :						Optional[int]						=							model(_A					)
          UpperCAmelCase__     :						Any						=							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 lowercase_				(   self							:       Optional[Any]					):


          '''simple docstring'''


          UpperCAmelCase__     :						List[str]						=							self.prepare_config_and_inputs()
          (
              (
              UpperCAmelCase__
          )		,		(
              UpperCAmelCase__
          )		,		(
              UpperCAmelCase__
          )		,		(
              UpperCAmelCase__
          )		,		(
              UpperCAmelCase__
          )		,		(
              UpperCAmelCase__
          )		,		
          )     :						str						=							config_and_inputs
          UpperCAmelCase__     :						Dict						=							{'''input_ids''': input_ids, '''attention_mask''': input_mask}
          return config, inputs_dict




@require_torch
class      lowerCamelCase_  (      __a	,			__a	,			unittest.TestCase ):
      lowerCAmelCase__							=	False

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






      def lowercase_				(   self							:       Optional[Any]					):


          '''simple docstring'''


          UpperCAmelCase__     :						int						=							EsmFoldModelTester(self					)
          UpperCAmelCase__     :						Dict						=							ConfigTester(self		,		config_class=_A		,		hidden_size=37					)






      def lowercase_				(   self							:       Any					):


          '''simple docstring'''


          self.config_tester.run_common_tests()






      def lowercase_				(   self							:       Any					):


          '''simple docstring'''


          UpperCAmelCase__     :						int						=							self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*_A					)






      @unittest.skip('''Does not support attention outputs'''					)
      def lowercase_				(   self							:       List[Any]					):


          '''simple docstring'''


          pass






      @unittest.skip
      def lowercase_				(   self							:       List[Any]					):


          '''simple docstring'''


          pass






      @unittest.skip('''Esm does not support embedding resizing'''					)
      def lowercase_				(   self							:       List[Any]					):


          '''simple docstring'''


          pass






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


          '''simple docstring'''


          pass






      @unittest.skip('''ESMFold does not support passing input embeds!'''					)
      def lowercase_				(   self							:       Optional[int]					):


          '''simple docstring'''


          pass






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


          '''simple docstring'''


          pass






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


          '''simple docstring'''


          pass






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


          '''simple docstring'''


          pass






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


          '''simple docstring'''


          pass






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


          '''simple docstring'''


          pass






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


          '''simple docstring'''


          pass






      @unittest.skip('''ESMfold does not output hidden states in the normal way.'''					)
      def lowercase_				(   self							:       List[str]					):


          '''simple docstring'''


          pass






      @unittest.skip('''ESMFold only has one output format.'''					)
      def lowercase_				(   self							:       Optional[int]					):


          '''simple docstring'''


          pass






      @unittest.skip('''This test doesn\'t work for ESMFold and doesn\'t test core functionality'''					)
      def lowercase_				(   self							:       Optional[Any]					):


          '''simple docstring'''


          pass






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


          '''simple docstring'''


          pass






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


          '''simple docstring'''


          pass






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


          '''simple docstring'''


          pass






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


          '''simple docstring'''


          pass






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


          '''simple docstring'''


          pass






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


          '''simple docstring'''


          pass






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


          '''simple docstring'''


          pass




@require_torch
class      lowerCamelCase_  (      __a ):






      @slow
      def lowercase_				(   self							:       Optional[Any]					):


          '''simple docstring'''


          UpperCAmelCase__     :						List[str]						=							EsmForProteinFolding.from_pretrained('''facebook/esmfold_v1'''					).float()
          model.eval()
          UpperCAmelCase__     :						Optional[Any]						=							torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]					)
          UpperCAmelCase__     :						Optional[int]						=							model(_A					)['''positions''']
          UpperCAmelCase__     :						Union[str, Any]						=							torch.tensor([2.5_8_2_8, 0.7_9_9_3, -1_0.9_3_3_4]		,		dtype=torch.floataa					)
          self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]		,		_A		,		atol=1e-4					)					)






'''simple docstring'''







from __future__ import annotations

import unittest

import numpy as np

from transformers import BlipTextConfig
from transformers.testing_utils import require_tf, slow
from transformers.utils import is_tf_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask


if is_tf_available():
    import tensorflow as tf

    from transformers import TFBlipTextModel
    from transformers.models.blip.modeling_tf_blip import TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST

class 	_snake_case:






 def __init__(self       :  Any    ,		a       :  str    ,		a       :  Union[str, Any]=12    ,		a       :  List[str]=7    ,		a       :  Dict=True    ,		a       :  Tuple=True    ,		a       :  Any=True    ,		a       :  Optional[Any]=99    ,		a       :  Optional[Any]=32    ,		a       :  Tuple=32    ,		a       :  List[Any]=2    ,		a       :  str=4    ,		a       :  Dict=37    ,		a       :  Optional[Any]=0.1    ,		a       :  List[Any]=0.1    ,		a       :  Dict=5_12    ,		a       :  List[Any]=0.02    ,		a       :  Any=0    ,		a       :  Optional[int]=None    ,		)       ->   List[Any]:






    """simple docstring"""


    A__       =     parent
    A__       =     batch_size
    A__       =     seq_length
    A__       =     is_training
    A__       =     use_input_mask
    A__       =     use_labels
    A__       =     vocab_size
    A__       =     hidden_size
    A__       =     projection_dim
    A__       =     num_hidden_layers
    A__       =     num_attention_heads
    A__       =     intermediate_size
    A__       =     dropout
    A__       =     attention_dropout
    A__       =     max_position_embeddings
    A__       =     initializer_range
    A__       =     scope
    A__       =     bos_token_id






 def 						_UpperCamelCase (self       :  Union[str, Any]    )       ->   List[Any]:






    """simple docstring"""


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

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

    if input_mask is not None:
       A__       =     input_mask.numpy()
       A__  ,			A__       =     input_mask.shape
       A__       =     np.random.randint(1    ,		seq_length - 1    ,		size=(batch_size,)    )
       for batch_idx, start_index in enumerate(a    ):
          A__       =     1
          A__       =     0

    A__       =     self.get_config()

    return config, input_ids, tf.convert_to_tensor(a    )






 def 						_UpperCamelCase (self       :  Tuple    )       ->   Union[str, Any]:






    """simple docstring"""


    return BlipTextConfig(
        vocab_size=self.vocab_size    ,		hidden_size=self.hidden_size    ,		projection_dim=self.projection_dim    ,		num_hidden_layers=self.num_hidden_layers    ,		num_attention_heads=self.num_attention_heads    ,		intermediate_size=self.intermediate_size    ,		dropout=self.dropout    ,		attention_dropout=self.attention_dropout    ,		max_position_embeddings=self.max_position_embeddings    ,		initializer_range=self.initializer_range    ,		bos_token_id=self.bos_token_id    ,		)






 def 						_UpperCamelCase (self       :  Optional[int]    ,		a       :  Any    ,		a       :  List[Any]    ,		a       :  Union[str, Any]    )       ->   Any:






    """simple docstring"""


    A__       =     TFBlipTextModel(config=a    )
    A__       =     model(a    ,		attention_mask=a    ,		training=a    )
    A__       =     model(a    ,		training=a    )
    self.parent.assertEqual(result.last_hidden_state.shape    ,		(self.batch_size, self.seq_length, self.hidden_size)    )
    self.parent.assertEqual(result.pooler_output.shape    ,		(self.batch_size, self.hidden_size)    )






 def 						_UpperCamelCase (self       :  str    )       ->   List[Any]:






    """simple docstring"""


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




@require_tf
class 	_snake_case(			UpperCAmelCase       , unittest.TestCase      ):
 __snake_case:							Optional[int]						=					(TFBlipTextModel,) if is_tf_available() else ()
 __snake_case:							Union[str, Any]						=					False
 __snake_case:							Any						=					False
 __snake_case:							Union[str, Any]						=					False






 def 						_UpperCamelCase (self       :  Optional[Any]    )       ->   List[Any]:






    """simple docstring"""


    A__       =     BlipTextModelTester(self    )
    A__       =     ConfigTester(self    ,		config_class=a    ,		hidden_size=37    )






 def 						_UpperCamelCase (self       :  Tuple    )       ->   str:






    """simple docstring"""


    self.config_tester.run_common_tests()






 def 						_UpperCamelCase (self       :  Any    )       ->   Dict:






    """simple docstring"""


    A__       =     self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_model(*a    )






 def 						_UpperCamelCase (self       :  Dict    )       ->   Dict:






    """simple docstring"""


    pass






 def 						_UpperCamelCase (self       :  str    )       ->   int:






    """simple docstring"""


    pass






 @unittest.skip(reason='Blip does not use inputs_embeds'    )
 def 						_UpperCamelCase (self       :  Union[str, Any]    )       ->   str:






    """simple docstring"""


    pass






 @unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'    )
 def 						_UpperCamelCase (self       :  int    )       ->   List[Any]:






    """simple docstring"""


    pass






 @unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'    )
 def 						_UpperCamelCase (self       :  int    )       ->   Optional[Any]:






    """simple docstring"""


    pass






 @slow
 def 						_UpperCamelCase (self       :  int    )       ->   Optional[Any]:






    """simple docstring"""


    for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       A__       =     TFBlipTextModel.from_pretrained(a    )
       self.assertIsNotNone(a    )






 def 						_UpperCamelCase (self       :  str    ,		a       :  Optional[int]=True    )       ->   List[Any]:






    """simple docstring"""


    super().test_pt_tf_model_equivalence(allow_missing_keys=a    )


