






"""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 import EsmForMaskedLM, EsmForSequenceClassification, EsmForTokenClassification, EsmModel
 from transformers.models.esm.modeling_esm import (
     ESM_PRETRAINED_MODEL_ARCHIVE_LIST,
     EsmEmbeddings,
     create_position_ids_from_input_ids,
 )



class        UpperCamelCase__ :







    """simple docstring"""







    def __init__(		self :	List[Any]				,    UpperCamelCase_ :	List[Any]				,    UpperCamelCase_ :	Tuple=1_3				,    UpperCamelCase_ :	Tuple=7				,    UpperCamelCase_ :	Optional[Any]=False				,    UpperCamelCase_ :	List[Any]=True				,    UpperCamelCase_ :	Any=False				,    UpperCamelCase_ :	Tuple=True				,    UpperCamelCase_ :	Dict=3_3				,    UpperCamelCase_ :	Tuple=3_2				,    UpperCamelCase_ :	Any=5				,    UpperCamelCase_ :	Optional[Any]=4				,    UpperCamelCase_ :	List[Any]=3_7				,    UpperCamelCase_ :	List[Any]="gelu"				,    UpperCamelCase_ :	Optional[Any]=0.1				,    UpperCamelCase_ :	List[Any]=0.1				,    UpperCamelCase_ :	Any=5_1_2				,    UpperCamelCase_ :	str=1_6				,    UpperCamelCase_ :	Tuple=2				,    UpperCamelCase_ :	Optional[Any]=0.02				,    UpperCamelCase_ :	Union[str, Any]=3				,    UpperCamelCase_ :	Optional[int]=4				,    UpperCamelCase_ :	int=None				,    ):





           '''simple docstring'''

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







    def 				a__			(		self :	Optional[Any] ):





           '''simple docstring'''

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

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

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

           __magic_name__      				=    self.get_config()

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







    def 				a__			(		self :	Union[str, Any] ):





           '''simple docstring'''

           return EsmConfig(
               vocab_size=self.vocab_size				,    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				,    )







    def 				a__			(		self :	int				,    UpperCamelCase_ :	int				,    UpperCamelCase_ :	int				,    UpperCamelCase_ :	Tuple				,    UpperCamelCase_ :	List[Any]				,    UpperCamelCase_ :	List[str]				,    UpperCamelCase_ :	List[Any] ):





           '''simple docstring'''

           __magic_name__      				=    EsmModel(config=UpperCamelCase_ )
           model.to(UpperCamelCase_ )
           model.eval()
           __magic_name__      				=    model(UpperCamelCase_				,    attention_mask=UpperCamelCase_ )
           __magic_name__      				=    model(UpperCamelCase_ )
           __magic_name__      				=    model(UpperCamelCase_ )

           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 				a__			(		self :	List[str]				,    UpperCamelCase_ :	List[str]				,    UpperCamelCase_ :	Any				,    UpperCamelCase_ :	Dict				,    UpperCamelCase_ :	Tuple				,    UpperCamelCase_ :	Optional[Any]				,    UpperCamelCase_ :	Union[str, Any] ):





           '''simple docstring'''

           __magic_name__      				=    EsmForMaskedLM(config=UpperCamelCase_ )
           model.to(UpperCamelCase_ )
           model.eval()
           __magic_name__      				=    model(UpperCamelCase_				,    attention_mask=UpperCamelCase_				,    labels=UpperCamelCase_ )
           self.parent.assertEqual(result.logits.shape				,    (self.batch_size, self.seq_length, self.vocab_size) )







    def 				a__			(		self :	str				,    UpperCamelCase_ :	Optional[int]				,    UpperCamelCase_ :	str				,    UpperCamelCase_ :	Tuple				,    UpperCamelCase_ :	Union[str, Any]				,    UpperCamelCase_ :	Optional[Any]				,    UpperCamelCase_ :	str ):





           '''simple docstring'''

           __magic_name__      				=    self.num_labels
           __magic_name__      				=    EsmForTokenClassification(config=UpperCamelCase_ )
           model.to(UpperCamelCase_ )
           model.eval()
           __magic_name__      				=    model(UpperCamelCase_				,    attention_mask=UpperCamelCase_				,    labels=UpperCamelCase_ )
           self.parent.assertEqual(result.logits.shape				,    (self.batch_size, self.seq_length, self.num_labels) )







    def 				a__			(		self :	Tuple ):





           '''simple docstring'''

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



@require_torch
class        UpperCamelCase__ (				a_							,	a_							,	unittest.TestCase):







    """simple docstring"""
    __UpperCAmelCase           = False

    __UpperCAmelCase           = (
        (
            EsmForMaskedLM,
            EsmModel,
            EsmForSequenceClassification,
            EsmForTokenClassification,
        )
        if is_torch_available()
        else ()
    )
    __UpperCAmelCase           = ()
    __UpperCAmelCase           = (
        {
            """feature-extraction""": EsmModel,
            """fill-mask""": EsmForMaskedLM,
            """text-classification""": EsmForSequenceClassification,
            """token-classification""": EsmForTokenClassification,
            """zero-shot""": EsmForSequenceClassification,
        }
        if is_torch_available()
        else {}
    )
    __UpperCAmelCase           = True







    def 				a__			(		self :	Optional[Any] ):





           '''simple docstring'''

           __magic_name__      				=    EsmModelTester(self )
           __magic_name__      				=    ConfigTester(self				,    config_class=UpperCamelCase_				,    hidden_size=3_7 )







    def 				a__			(		self :	List[str] ):





           '''simple docstring'''

           self.config_tester.run_common_tests()







    def 				a__			(		self :	List[Any] ):





           '''simple docstring'''

           __magic_name__      				=    self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*UpperCamelCase_ )







    def 				a__			(		self :	Dict ):





           '''simple docstring'''

           __magic_name__      				=    self.model_tester.prepare_config_and_inputs()
           for type in ["absolute", "relative_key", "relative_key_query"]:
                  __magic_name__      				=    type
                  self.model_tester.create_and_check_model(*UpperCamelCase_ )







    def 				a__			(		self :	Optional[Any] ):





           '''simple docstring'''

           __magic_name__      				=    self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_masked_lm(*UpperCamelCase_ )







    def 				a__			(		self :	List[str] ):





           '''simple docstring'''

           __magic_name__      				=    self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_token_classification(*UpperCamelCase_ )







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





           '''simple docstring'''

           for model_name in ESM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                  __magic_name__      				=    EsmModel.from_pretrained(UpperCamelCase_ )
                  self.assertIsNotNone(UpperCamelCase_ )







    def 				a__			(		self :	Dict ):





           '''simple docstring'''

           __magic_name__      				=    self.model_tester.prepare_config_and_inputs()[0]
           __magic_name__      				=    EsmEmbeddings(config=UpperCamelCase_ )

           __magic_name__      				=    torch.as_tensor([[1_2, 3_1, 1_3, model.padding_idx]] )
           __magic_name__      				=    torch.as_tensor(
               [
                   [
                       0 + model.padding_idx + 1,
                       1 + model.padding_idx + 1,
                       2 + model.padding_idx + 1,
                       model.padding_idx,
                   ]
               ] )
           __magic_name__      				=    create_position_ids_from_input_ids(UpperCamelCase_				,    model.padding_idx )
           self.assertEqual(position_ids.shape				,    expected_positions.shape )
           self.assertTrue(torch.all(torch.eq(UpperCamelCase_				,    UpperCamelCase_ ) ) )







    def 				a__			(		self :	Dict ):





           '''simple docstring'''

           __magic_name__      				=    self.model_tester.prepare_config_and_inputs()[0]
           __magic_name__      				=    EsmEmbeddings(config=UpperCamelCase_ )

           __magic_name__      				=    torch.empty(2				,    4				,    3_0 )
           __magic_name__      				=    [
               0 + embeddings.padding_idx + 1,
               1 + embeddings.padding_idx + 1,
               2 + embeddings.padding_idx + 1,
               3 + embeddings.padding_idx + 1,
           ]
           __magic_name__      				=    torch.as_tensor([expected_single_positions, expected_single_positions] )
           __magic_name__      				=    embeddings.create_position_ids_from_inputs_embeds(UpperCamelCase_ )
           self.assertEqual(position_ids.shape				,    expected_positions.shape )
           self.assertTrue(torch.all(torch.eq(UpperCamelCase_				,    UpperCamelCase_ ) ) )







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





           '''simple docstring'''

           pass







    @unittest.skip('Esm does not support embedding resizing' )
    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 :	Optional[int] ):





           '''simple docstring'''

           pass



@require_torch
class        UpperCamelCase__ (				a_):







    """simple docstring"""







    @slow
    def 				a__			(		self :	List[Any] ):





           '''simple docstring'''

           with torch.no_grad():
                  __magic_name__      				=    EsmForMaskedLM.from_pretrained('facebook/esm2_t6_8M_UR50D' )
                  model.eval()
                  __magic_name__      				=    torch.tensor([[0, 1, 2, 3, 4, 5]] )
                  __magic_name__      				=    model(UpperCamelCase_ )[0]

                  __magic_name__      				=    3_3

                  __magic_name__      				=    torch.Size((1, 6, vocab_size) )
                  self.assertEqual(output.shape				,    UpperCamelCase_ )

                  __magic_name__      				=    torch.tensor(
                      [[[8.9_215, -10.5_898, -6.4_671], [-6.3_967, -13.9_114, -1.1_212], [-7.7_812, -13.9_516, -3.7_406]]] )
                  self.assertTrue(torch.allclose(output[:, :3, :3]				,    UpperCamelCase_				,    atol=1e-4 ) )







    @slow
    def 				a__			(		self :	str ):





           '''simple docstring'''

           with torch.no_grad():
                  __magic_name__      				=    EsmModel.from_pretrained('facebook/esm2_t6_8M_UR50D' )
                  model.eval()

                  __magic_name__      				=    torch.tensor([[0, 6, 4, 1_3, 5, 4, 1_6, 1_2, 1_1, 7, 2]] )
                  __magic_name__      				=    model(UpperCamelCase_ )[0]
                  # compare the actual values for a slice.
                  __magic_name__      				=    torch.tensor(
                      [[[0.1_444, 0.5_413, 0.3_248], [0.3_034, 0.0_053, 0.3_108], [0.3_228, -0.2_499, 0.3_415]]] )
                  self.assertTrue(torch.allclose(output[:, :3, :3]				,    UpperCamelCase_				,    atol=1e-4 ) )







"""simple docstring"""
from maths.prime_check import is_prime


def 							A						(				__snake_case: int  )    ->		int:

       """simple docstring"""





       if not isinstance(__snake_case ,     __snake_case  ):
              __magic_name__      				=    F"""Input value of [number={number}] must be an integer"""
              raise TypeError(__snake_case  )
       if is_prime(__snake_case  ) and is_prime(number + 2  ):
              return number + 2
       else:
              return -1


if __name__ == "__main__":
 import doctest

 doctest.testmod()