

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







   '''simple docstring'''




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





   def      _snake_case		(       self					:			Dict			):
       SCREAMING_SNAKE_CASE										=   ids_tensor([self.batch_size, self.seq_length]     , self.vocab_size			)

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

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

       SCREAMING_SNAKE_CASE										=   self.get_config()

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





   def      _snake_case		(       self					:			List[Any]			):
       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      _snake_case		(       self					:			Tuple     , __lowerCamelCase					:			List[str]     , __lowerCamelCase					:			Optional[Any]     , __lowerCamelCase					:			Any     , __lowerCamelCase					:			Any     , __lowerCamelCase					:			List[str]     , __lowerCamelCase					:			List[Any]			):
       SCREAMING_SNAKE_CASE										=   EsmModel(config=UpperCamelCase__			)
       model.to(UpperCamelCase__			)
       model.eval()
       SCREAMING_SNAKE_CASE										=   model(UpperCamelCase__     , attention_mask=UpperCamelCase__			)
       SCREAMING_SNAKE_CASE										=   model(UpperCamelCase__			)
       SCREAMING_SNAKE_CASE										=   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      _snake_case		(       self					:			List[str]     , __lowerCamelCase					:			Dict     , __lowerCamelCase					:			int     , __lowerCamelCase					:			int     , __lowerCamelCase					:			List[Any]     , __lowerCamelCase					:			Optional[int]     , __lowerCamelCase					:			Optional[int]			):
       SCREAMING_SNAKE_CASE										=   EsmForMaskedLM(config=UpperCamelCase__			)
       model.to(UpperCamelCase__			)
       model.eval()
       SCREAMING_SNAKE_CASE										=   model(UpperCamelCase__     , attention_mask=UpperCamelCase__     , labels=UpperCamelCase__			)
       self.parent.assertEqual(result.logits.shape     , (self.batch_size, self.seq_length, self.vocab_size)			)





   def      _snake_case		(       self					:			int     , __lowerCamelCase					:			Tuple     , __lowerCamelCase					:			List[str]     , __lowerCamelCase					:			Optional[Any]     , __lowerCamelCase					:			Optional[Any]     , __lowerCamelCase					:			List[Any]     , __lowerCamelCase					:			Any			):
       SCREAMING_SNAKE_CASE										=   self.num_labels
       SCREAMING_SNAKE_CASE										=   EsmForTokenClassification(config=UpperCamelCase__			)
       model.to(UpperCamelCase__			)
       model.eval()
       SCREAMING_SNAKE_CASE										=   model(UpperCamelCase__     , attention_mask=UpperCamelCase__     , labels=UpperCamelCase__			)
       self.parent.assertEqual(result.logits.shape     , (self.batch_size, self.seq_length, self.num_labels)			)





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





@require_torch
class 			_SCREAMING_SNAKE_CASE (   _A					,       _A					,       unittest.TestCase		):







   '''simple docstring'''




   lowerCamelCase__				=      False

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





   def      _snake_case		(       self					:			int			):
       SCREAMING_SNAKE_CASE										=   EsmModelTester(self			)
       SCREAMING_SNAKE_CASE										=   ConfigTester(self     , config_class=UpperCamelCase__     , hidden_size=37			)





   def      _snake_case		(       self					:			List[str]			):
       self.config_tester.run_common_tests()





   def      _snake_case		(       self					:			Optional[int]			):
       SCREAMING_SNAKE_CASE										=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*UpperCamelCase__			)





   def      _snake_case		(       self					:			int			):
       SCREAMING_SNAKE_CASE										=   self.model_tester.prepare_config_and_inputs()
       for type in ["absolute", "relative_key", "relative_key_query"]:
           SCREAMING_SNAKE_CASE										=   type
           self.model_tester.create_and_check_model(*UpperCamelCase__			)





   def      _snake_case		(       self					:			Any			):
       SCREAMING_SNAKE_CASE										=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_masked_lm(*UpperCamelCase__			)





   def      _snake_case		(       self					:			List[Any]			):
       SCREAMING_SNAKE_CASE										=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_token_classification(*UpperCamelCase__			)





   @slow
   def      _snake_case		(       self					:			Dict			):






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





   def      _snake_case		(       self					:			Optional[Any]			):
       SCREAMING_SNAKE_CASE										=   self.model_tester.prepare_config_and_inputs()[0]
       SCREAMING_SNAKE_CASE										=   EsmEmbeddings(config=UpperCamelCase__			)

       SCREAMING_SNAKE_CASE										=   torch.as_tensor([[12, 31, 13, model.padding_idx]]			)
       SCREAMING_SNAKE_CASE										=   torch.as_tensor(
           [
               [
                   0 + model.padding_idx + 1,
                   1 + model.padding_idx + 1,
                   2 + model.padding_idx + 1,
                   model.padding_idx,
               ]
           ]			)
       SCREAMING_SNAKE_CASE										=   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      _snake_case		(       self					:			Tuple			):
       SCREAMING_SNAKE_CASE										=   self.model_tester.prepare_config_and_inputs()[0]
       SCREAMING_SNAKE_CASE										=   EsmEmbeddings(config=UpperCamelCase__			)

       SCREAMING_SNAKE_CASE										=   torch.empty(2     , 4     , 30			)
       SCREAMING_SNAKE_CASE										=   [
           0 + embeddings.padding_idx + 1,
           1 + embeddings.padding_idx + 1,
           2 + embeddings.padding_idx + 1,
           3 + embeddings.padding_idx + 1,
       ]
       SCREAMING_SNAKE_CASE										=   torch.as_tensor([expected_single_positions, expected_single_positions]			)
       SCREAMING_SNAKE_CASE										=   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      _snake_case		(       self					:			Union[str, Any]			):
       pass





   @unittest.skip("Esm does not support embedding resizing"			)
   def      _snake_case		(       self					:			List[str]			):
       pass





   @unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."			)
   def      _snake_case		(       self					:			List[str]			):
       pass





@require_torch
class 			_SCREAMING_SNAKE_CASE (   _A		):







   '''simple docstring'''




   @slow
   def      _snake_case		(       self					:			Dict			):






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

           SCREAMING_SNAKE_CASE										=   33

           SCREAMING_SNAKE_CASE										=   torch.Size((1, 6, vocab_size)			)
           self.assertEqual(output.shape     , UpperCamelCase__			)

           SCREAMING_SNAKE_CASE										=   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      _snake_case		(       self					:			int			):






       with torch.no_grad():
           SCREAMING_SNAKE_CASE										=   EsmModel.from_pretrained("facebook/esm2_t6_8M_UR50D"			)
           model.eval()

           SCREAMING_SNAKE_CASE										=   torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]			)
           SCREAMING_SNAKE_CASE										=   model(UpperCamelCase__			)[0]
           # compare the actual values for a slice.
           SCREAMING_SNAKE_CASE										=   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			)			)

import math

def a__       (			A_   ):






  '''simple docstring'''





  if 1 < number < 4:
    # 2 and 3 are primes
    return True
  elif number < 2 or number % 2 == 0 or number % 3 == 0:
    # Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
    return False

  # All primes number are in format of 6k +/- 1
  for i in range(5,	int(math.sqrt(A_   ) + 1   ),	6   ):
    if number % i == 0 or number % (i + 2) == 0:
      return False
  return True

def a__       (			A_ = 0.1   ):






  '''simple docstring'''





  __magic_name__								=			3
  __magic_name__								=			3

  while primes / (2 * j - 1) >= ratio:
    for i in range(j * j + j + 1,	(j + 2) * (j + 2),	j + 1   ):
      primes += is_prime(A_   )
    j += 2
  return j


if __name__ == "__main__":
    import doctest

    doctest.testmod()

