



'''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 				a__:







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







    def      lowercase_			( self					:    Tuple      ):
      a		:   Optional[int]	  =	ids_tensor([self.batch_size, self.seq_length]		,     self.vocab_size      )

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

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

      a		:   str	  =	self.get_config()

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







    def      lowercase_			( self					:    List[Any]      ):
      a		:   Tuple	  =	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=__snake_case		,     esmfold_config={'trunk': {'num_blocks': 2}, 'fp16_esm': False}		,     )
      return config







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

@require_torch
class 				a__(   lowerCamelCase__						,					lowerCamelCase__						,					unittest.TestCase      ):
    lowercase__					=       False

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







    def      lowercase_			( self					:    str      ):
      a		:   Optional[int]	  =	EsmFoldModelTester(self      )
      a		:   List[Any]	  =	ConfigTester(self		,     config_class=__snake_case		,     hidden_size=37      )







    def      lowercase_			( self					:    Optional[Any]      ):
      self.config_tester.run_common_tests()







    def      lowercase_			( self					:    List[Any]      ):
      a		:   Optional[Any]	  =	self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*__snake_case      )







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







    @unittest.skip
    def      lowercase_			( self					:    Any      ):
      pass







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







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







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







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







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







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







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







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







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







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







    @unittest.skip('ESMFold only has one output format.'      )
    def      lowercase_			( self					:    List[str]      ):
      pass







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







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







    @unittest.skip('ESMFold doesn\'t respect you and it certainly doesn\'t respect your initialization arguments.'      )
    def      lowercase_			( self					:    Union[str, Any]      ):
      pass







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







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







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







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







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

@require_torch
class 				a__(   lowerCamelCase__      ):







    @slow
    def      lowercase_			( self					:    int      ):
      a		:   Optional[int]	  =	EsmForProteinFolding.from_pretrained('facebook/esmfold_v1'      ).float()
      model.eval()
      a		:   int	  =	torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]      )
      a		:   Any	  =	model(__snake_case      )['positions']
      a		:   int	  =	torch.tensor([2.5828, 0.7993, -10.9334]		,     dtype=torch.floataa      )
      self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]		,     __snake_case		,     atol=1e-4      )      )




'''simple docstring'''






from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCAmelCase:   List[str]					=		logging.get_logger(__name__)

lowerCAmelCase:   Union[str, Any]					=		{
    'SCUT-DLVCLab/lilt-roberta-en-base': (
        'https://huggingface.co/SCUT-DLVCLab/lilt-roberta-en-base/resolve/main/config.json'
    ),
}

class 				a__(   lowerCamelCase__      ):
    lowercase__					=       """lilt"""







    def __init__( self					:    str		,     __snake_case					:    Dict=3_05_22		,     __snake_case					:    int=7_68		,     __snake_case					:    Union[str, Any]=12		,     __snake_case					:    Optional[Any]=12		,     __snake_case					:    Dict=30_72		,     __snake_case					:    Tuple="gelu"		,     __snake_case					:    Dict=0.1		,     __snake_case					:    List[Any]=0.1		,     __snake_case					:    List[str]=5_12		,     __snake_case					:    List[str]=2		,     __snake_case					:    str=0.02		,     __snake_case					:    Dict=1e-1_2		,     __snake_case					:    int=0		,     __snake_case					:    Any="absolute"		,     __snake_case					:    Tuple=None		,     __snake_case					:    Tuple=4		,     __snake_case					:    List[str]=10_24		,     **__snake_case					:    Union[str, Any]		,     ):
      super().__init__(pad_token_id=__snake_case		,     **__snake_case      )

      a		:   str	  =	vocab_size
      a		:   Optional[Any]	  =	hidden_size
      a		:   Union[str, Any]	  =	num_hidden_layers
      a		:   Tuple	  =	num_attention_heads
      a		:   Optional[Any]	  =	hidden_act
      a		:   Union[str, Any]	  =	intermediate_size
      a		:   Optional[Any]	  =	hidden_dropout_prob
      a		:   Tuple	  =	attention_probs_dropout_prob
      a		:   str	  =	max_position_embeddings
      a		:   Any	  =	type_vocab_size
      a		:   Union[str, Any]	  =	initializer_range
      a		:   int	  =	layer_norm_eps
      a		:   Any	  =	position_embedding_type
      a		:   Any	  =	classifier_dropout
      a		:   str	  =	channel_shrink_ratio
      a		:   Optional[Any]	  =	max_ad_position_embeddings