




'''simple docstring'''





from __future__ import annotations

import unittest

from transformers import MPNetConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

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


if is_tf_available():
   import tensorflow as tf

   from transformers.models.mpnet.modeling_tf_mpnet import (
       TFMPNetForMaskedLM,
       TFMPNetForMultipleChoice,
       TFMPNetForQuestionAnswering,
       TFMPNetForSequenceClassification,
       TFMPNetForTokenClassification,
       TFMPNetModel,
   )

class    _a				:






     def __init__( self					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE=13					,_SCREAMING_SNAKE_CASE=7					,_SCREAMING_SNAKE_CASE=True					,_SCREAMING_SNAKE_CASE=True					,_SCREAMING_SNAKE_CASE=False					,_SCREAMING_SNAKE_CASE=True					,_SCREAMING_SNAKE_CASE=99					,_SCREAMING_SNAKE_CASE=64					,_SCREAMING_SNAKE_CASE=2					,_SCREAMING_SNAKE_CASE=4					,_SCREAMING_SNAKE_CASE=64					,_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.0_2					,_SCREAMING_SNAKE_CASE=3					,_SCREAMING_SNAKE_CASE=4					,_SCREAMING_SNAKE_CASE=None					,)							->			Any:
          _snake_case							=      parent
          _snake_case							=      batch_size
          _snake_case							=      seq_length
          _snake_case							=      is_training
          _snake_case							=      use_input_mask
          _snake_case							=      use_token_type_ids
          _snake_case							=      use_labels
          _snake_case							=      vocab_size
          _snake_case							=      hidden_size
          _snake_case							=      num_hidden_layers
          _snake_case							=      num_attention_heads
          _snake_case							=      intermediate_size
          _snake_case							=      hidden_act
          _snake_case							=      hidden_dropout_prob
          _snake_case							=      attention_probs_dropout_prob
          _snake_case							=      max_position_embeddings
          _snake_case							=      type_vocab_size
          _snake_case							=      type_sequence_label_size
          _snake_case							=      initializer_range
          _snake_case							=      num_labels
          _snake_case							=      num_choices
          _snake_case							=      scope






     def 				_lowercase	( self    )							->			Union[str, Any]:
          _snake_case							=      ids_tensor([self.batch_size, self.seq_length]					,self.vocab_size    )

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

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

          _snake_case							=      MPNetConfig(
              vocab_size=self.vocab_size					,hidden_size=self.hidden_size					,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					,initializer_range=self.initializer_range					,)
          return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels






     def 				_lowercase	( self					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE    )							->			List[Any]:
          _snake_case							=      TFMPNetModel(config=_UpperCamelCase    )
          _snake_case							=      {"input_ids": input_ids, "attention_mask": input_mask}
          _snake_case							=      model(_UpperCamelCase    )
          _snake_case							=      [input_ids, input_mask]
          _snake_case							=      model(_UpperCamelCase    )
          self.parent.assertEqual(result.last_hidden_state.shape					,(self.batch_size, self.seq_length, self.hidden_size)    )






     def 				_lowercase	( self					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE    )							->			Optional[Any]:
          _snake_case							=      TFMPNetForMaskedLM(config=_UpperCamelCase    )
          _snake_case							=      {"input_ids": input_ids, "attention_mask": input_mask}
          _snake_case							=      model(_UpperCamelCase    )
          self.parent.assertEqual(result.logits.shape					,(self.batch_size, self.seq_length, self.vocab_size)    )






     def 				_lowercase	( self					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE    )							->			Dict:
          _snake_case							=      TFMPNetForQuestionAnswering(config=_UpperCamelCase    )
          _snake_case							=      {
              "input_ids": input_ids,
              "attention_mask": input_mask,
          }
          _snake_case							=      model(_UpperCamelCase    )
          self.parent.assertEqual(result.start_logits.shape					,(self.batch_size, self.seq_length)    )
          self.parent.assertEqual(result.end_logits.shape					,(self.batch_size, self.seq_length)    )






     def 				_lowercase	( self					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE    )							->			Union[str, Any]:
          _snake_case							=      self.num_labels
          _snake_case							=      TFMPNetForSequenceClassification(_UpperCamelCase    )
          _snake_case							=      {"input_ids": input_ids, "attention_mask": input_mask}
          _snake_case							=      model(_UpperCamelCase    )
          self.parent.assertEqual(result.logits.shape					,(self.batch_size, self.num_labels)    )






     def 				_lowercase	( self					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE    )							->			Any:
          _snake_case							=      self.num_choices
          _snake_case							=      TFMPNetForMultipleChoice(_UpperCamelCase    )
          _snake_case							=      tf.tile(tf.expand_dims(_UpperCamelCase					,1    )					,(1, self.num_choices, 1)    )
          _snake_case							=      tf.tile(tf.expand_dims(_UpperCamelCase					,1    )					,(1, self.num_choices, 1)    )
          _snake_case							=      {
              "input_ids": multiple_choice_inputs_ids,
              "attention_mask": multiple_choice_input_mask,
          }
          _snake_case							=      model(_UpperCamelCase    )
          self.parent.assertEqual(result.logits.shape					,(self.batch_size, self.num_choices)    )






     def 				_lowercase	( self					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE					,_SCREAMING_SNAKE_CASE    )							->			Optional[int]:
          _snake_case							=      self.num_labels
          _snake_case							=      TFMPNetForTokenClassification(_UpperCamelCase    )
          _snake_case							=      {"input_ids": input_ids, "attention_mask": input_mask}
          _snake_case							=      model(_UpperCamelCase    )
          self.parent.assertEqual(result.logits.shape					,(self.batch_size, self.seq_length, self.num_labels)    )






     def 				_lowercase	( self    )							->			Optional[int]:
          _snake_case							=      self.prepare_config_and_inputs()
          ((_snake_case)							,					(_snake_case)							,					(_snake_case)							,					(_snake_case)							,					(_snake_case)							,					(_snake_case))							=      config_and_inputs
          _snake_case							=      {"input_ids": input_ids, "attention_mask": input_mask}
          return config, inputs_dict







@require_tf
class    _a				(						__lowerCAmelCase					,					__lowerCAmelCase					,					unittest.TestCase							):
     SCREAMING_SNAKE_CASE_							:    Dict    				=						(
         (
             TFMPNetForMaskedLM,
             TFMPNetForMultipleChoice,
             TFMPNetForQuestionAnswering,
             TFMPNetForSequenceClassification,
             TFMPNetForTokenClassification,
             TFMPNetModel,
         )
         if is_tf_available()
         else ()
     )
     SCREAMING_SNAKE_CASE_							:    Optional[Any]    				=						(
         {
             """feature-extraction""": TFMPNetModel,
             """fill-mask""": TFMPNetForMaskedLM,
             """question-answering""": TFMPNetForQuestionAnswering,
             """text-classification""": TFMPNetForSequenceClassification,
             """token-classification""": TFMPNetForTokenClassification,
             """zero-shot""": TFMPNetForSequenceClassification,
         }
         if is_tf_available()
         else {}
     )
     SCREAMING_SNAKE_CASE_							:    List[Any]    				=						False
     SCREAMING_SNAKE_CASE_							:    Optional[int]    				=						False






     def 				_lowercase	( self    )							->			Tuple:
          _snake_case							=      TFMPNetModelTester(self    )
          _snake_case							=      ConfigTester(self					,config_class=_UpperCamelCase					,hidden_size=37    )






     def 				_lowercase	( self    )							->			Union[str, Any]:
          self.config_tester.run_common_tests()






     def 				_lowercase	( self    )							->			List[str]:
          _snake_case							=      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_mpnet_model(*_UpperCamelCase    )






     def 				_lowercase	( self    )							->			List[Any]:
          _snake_case							=      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_mpnet_for_masked_lm(*_UpperCamelCase    )






     def 				_lowercase	( self    )							->			List[str]:
          _snake_case							=      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_mpnet_for_question_answering(*_UpperCamelCase    )






     def 				_lowercase	( self    )							->			Optional[int]:
          _snake_case							=      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_mpnet_for_sequence_classification(*_UpperCamelCase    )






     def 				_lowercase	( self    )							->			int:
          _snake_case							=      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_mpnet_for_multiple_choice(*_UpperCamelCase    )






     def 				_lowercase	( self    )							->			Tuple:
          _snake_case							=      self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_mpnet_for_token_classification(*_UpperCamelCase    )






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

          for model_name in ["microsoft/mpnet-base"]:
               _snake_case							=      TFMPNetModel.from_pretrained(_UpperCamelCase    )
               self.assertIsNotNone(_UpperCamelCase    )







@require_tf
class    _a				(						unittest.TestCase							):






     @slow
     def 				_lowercase	( self    )							->			List[Any]:
          _snake_case							=      TFMPNetModel.from_pretrained("microsoft/mpnet-base"    )
          _snake_case							=      tf.constant([[0, 1, 2, 3, 4, 5]]    )
          _snake_case							=      model(_UpperCamelCase    )[0]

          _snake_case							=      [1, 6, 768]
          self.assertEqual(output.shape					,_UpperCamelCase    )

          _snake_case							=      tf.constant(
              [
                  [
                      [-0.1_0_6_7_1_7_2, 0.0_8_2_1_6_4_7_3, 0.0_0_2_4_5_4_3],
                      [-0.0_3_4_6_5_8_7_9, 0.8_3_5_4_1_1_8, -0.0_3_2_5_2_2_8_8],
                      [-0.0_6_5_6_9_4_7_6, -0.1_2_4_2_4_1_1_1, -0.0_4_9_4_4_3_6],
                  ]
              ]    )
          tf.debugging.assert_near(output[:, :3, :3]					,_UpperCamelCase					,atol=1e-4    )



import math





def 		__lowerCamelCase							(UpperCAmelCase__   :							int     ):

					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(UpperCAmelCase__     ) + 1     )					,       6     ):
										if number % i == 0 or number % (i + 2) == 0:
															return False
					return True





def 		__lowerCamelCase							(UpperCAmelCase__   :							int = 2_0_0_0_0_0_0     ):
					return sum(num for num in range(3					,       UpperCAmelCase__					,       2     ) if is_prime(UpperCAmelCase__     )     ) + 2 if n > 2 else 0


if __name__ == "__main__":
							print(f"""{solution() = }""")




