"""simple docstring"""





import unittest

from transformers import MPNetConfig, is_torch_available
from transformers.testing_utils import 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 (
           MPNetForMaskedLM,
           MPNetForMultipleChoice,
           MPNetForQuestionAnswering,
           MPNetForSequenceClassification,
           MPNetForTokenClassification,
           MPNetModel,
       )


class 	UpperCAmelCase_      :


      def __init__(  self						,     a						,     a=1_3						,     a=7						,     a=True						,     a=True						,     a=False						,     a=True						,     a=9_9						,     a=6_4						,     a=5						,     a=4						,     a=6_4						,     a="gelu"						,     a=0.1						,     a=0.1						,     a=5_1_2						,     a=1_6						,     a=2						,     a=0.02						,     a=3						,     a=4						,     a=None						,     )			->   Optional[Any]:
             lowercase__     :						Dict         =      parent
             lowercase__     :						List[Any]         =      batch_size
             lowercase__     :						Any         =      seq_length
             lowercase__     :						Tuple         =      is_training
             lowercase__     :						List[Any]         =      use_input_mask
             lowercase__     :						Union[str, Any]         =      use_token_type_ids
             lowercase__     :						Union[str, Any]         =      use_labels
             lowercase__     :						str         =      vocab_size
             lowercase__     :						int         =      hidden_size
             lowercase__     :						Tuple         =      num_hidden_layers
             lowercase__     :						List[Any]         =      num_attention_heads
             lowercase__     :						Union[str, Any]         =      intermediate_size
             lowercase__     :						Optional[Any]         =      hidden_act
             lowercase__     :						Dict         =      hidden_dropout_prob
             lowercase__     :						Union[str, Any]         =      attention_probs_dropout_prob
             lowercase__     :						Dict         =      max_position_embeddings
             lowercase__     :						List[str]         =      type_vocab_size
             lowercase__     :						str         =      type_sequence_label_size
             lowercase__     :						List[Any]         =      initializer_range
             lowercase__     :						Dict         =      num_labels
             lowercase__     :						Optional[int]         =      num_choices
             lowercase__     :						Optional[int]         =      scope


      def 						_UpperCAmelCase			(  self				)			->   List[str]:
             return MPNetConfig.from_pretrained('microsoft/mpnet-base'				)


      def 						_UpperCAmelCase			(  self				)			->   int:
             lowercase__     :						Optional[Any]         =      ids_tensor([self.batch_size, self.seq_length]						,     self.vocab_size				)

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

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

             lowercase__     :						Union[str, Any]         =      self.get_config()
             return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels


      def 						_UpperCAmelCase			(  self				)			->   Dict:
             return 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						,     )


      def 						_UpperCAmelCase			(  self						,     a						,     a						,     a						,     a						,     a						,     a				)			->   Optional[int]:
             lowercase__     :						Optional[int]         =      MPNetModel(config=a				)
             model.to(a				)
             model.eval()
             lowercase__     :						Tuple         =      model(a						,     a				)
             lowercase__     :						int         =      model(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						,     a						,     a						,     a						,     a						,     a						,     a				)			->   int:
             lowercase__     :						Optional[Any]         =      MPNetForQuestionAnswering(config=a				)
             model.to(a				)
             model.eval()
             lowercase__     :						Optional[int]         =      model(
                 a						,     attention_mask=a						,     start_positions=a						,     end_positions=a						,     )
             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 						_UpperCAmelCase			(  self						,     a						,     a						,     a						,     a						,     a						,     a				)			->   int:
             lowercase__     :						Optional[Any]         =      self.num_labels
             lowercase__     :						Dict         =      MPNetForSequenceClassification(a				)
             model.to(a				)
             model.eval()
             lowercase__     :						List[Any]         =      model(a						,     attention_mask=a						,     labels=a				)
             self.parent.assertEqual(result.logits.shape						,     (self.batch_size, self.num_labels)				)


      def 						_UpperCAmelCase			(  self						,     a						,     a						,     a						,     a						,     a						,     a				)			->   List[str]:
             lowercase__     :						Optional[Any]         =      self.num_choices
             lowercase__     :						Optional[int]         =      MPNetForMultipleChoice(config=a				)
             model.to(a				)
             model.eval()
             lowercase__     :						Optional[Any]         =      input_ids.unsqueeze(1				).expand(-1						,     self.num_choices						,     -1				).contiguous()
             lowercase__     :						Tuple         =      input_mask.unsqueeze(1				).expand(-1						,     self.num_choices						,     -1				).contiguous()
             lowercase__     :						List[Any]         =      model(
                 a						,     attention_mask=a						,     labels=a						,     )
             self.parent.assertEqual(result.logits.shape						,     (self.batch_size, self.num_choices)				)


      def 						_UpperCAmelCase			(  self						,     a						,     a						,     a						,     a						,     a						,     a				)			->   List[str]:
             lowercase__     :						Tuple         =      self.num_labels
             lowercase__     :						List[str]         =      MPNetForTokenClassification(config=a				)
             model.to(a				)
             model.eval()
             lowercase__     :						List[Any]         =      model(a						,     attention_mask=a						,     labels=a				)
             self.parent.assertEqual(result.logits.shape						,     (self.batch_size, self.seq_length, self.num_labels)				)


      def 						_UpperCAmelCase			(  self				)			->   Optional[Any]:
             lowercase__     :						Any         =      self.prepare_config_and_inputs()
             (lowercase__)     :						Optional[Any]         =      config_and_inputs
             lowercase__     :						List[str]         =      {"input_ids": input_ids, "attention_mask": input_mask}
             return config, inputs_dict





@require_torch
class 	UpperCAmelCase_      (       __A					,				__A					,				unittest.TestCase):
      lowerCamelCase__						:       Tuple					    =    (
          (
              MPNetForMaskedLM,
              MPNetForMultipleChoice,
              MPNetForQuestionAnswering,
              MPNetForSequenceClassification,
              MPNetForTokenClassification,
              MPNetModel,
          )
          if is_torch_available()
          else ()
      )
      lowerCamelCase__						:       Tuple					    =    (
          {
              "feature-extraction": MPNetModel,
              "fill-mask": MPNetForMaskedLM,
              "question-answering": MPNetForQuestionAnswering,
              "text-classification": MPNetForSequenceClassification,
              "token-classification": MPNetForTokenClassification,
              "zero-shot": MPNetForSequenceClassification,
          }
          if is_torch_available()
          else {}
      )
      lowerCamelCase__						:       List[Any]					    =    False
      lowerCamelCase__						:       Optional[int]					    =    True


      def 						_UpperCAmelCase			(  self				)			->   Tuple:
             lowercase__     :						List[str]         =      MPNetModelTester(self				)
             lowercase__     :						str         =      ConfigTester(self						,     config_class=a						,     hidden_size=3_7				)


      def 						_UpperCAmelCase			(  self				)			->   List[str]:
             self.config_tester.run_common_tests()


      def 						_UpperCAmelCase			(  self				)			->   Optional[int]:
             lowercase__     :						str         =      self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mpnet_model(*a				)


      def 						_UpperCAmelCase			(  self				)			->   str:
             lowercase__     :						Tuple         =      self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mpnet_for_sequence_classification(*a				)


      def 						_UpperCAmelCase			(  self				)			->   List[Any]:
             lowercase__     :						List[Any]         =      self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mpnet_for_multiple_choice(*a				)


      def 						_UpperCAmelCase			(  self				)			->   int:
             lowercase__     :						Optional[int]         =      self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mpnet_for_token_classification(*a				)


      def 						_UpperCAmelCase			(  self				)			->   List[str]:
             lowercase__     :						Tuple         =      self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mpnet_for_question_answering(*a				)





@require_torch
class 	UpperCAmelCase_      (       unittest.TestCase):


      @slow
      def 						_UpperCAmelCase			(  self				)			->   Optional[Any]:
             lowercase__     :						List[str]         =      MPNetModel.from_pretrained('microsoft/mpnet-base'				)
             lowercase__     :						Optional[int]         =      torch.tensor([[0, 3_4_5, 2_3_2, 3_2_8, 7_4_0, 1_4_0, 1_6_9_5, 6_9, 6_0_7_8, 1_5_8_8, 2]]				)
             lowercase__     :						List[str]         =      model(a				)[0]
             lowercase__     :						Tuple         =      torch.Size((1, 1_1, 7_6_8)				)
             self.assertEqual(output.shape						,     a				)
             lowercase__     :						List[Any]         =      torch.tensor(
                 [[[-0.0_550, 0.1_943, -0.0_740], [-0.0_562, 0.2_211, -0.0_579], [-0.0_437, 0.3_337, -0.0_641]]]				)
             # compare the actual values for a slice.
             self.assertTrue(torch.allclose(output[:, :3, :3]						,     a						,     atol=1e-4				)				)




def 			lowerCamelCase__			(       _a):
	if not isinstance(_a				,      _a):
		SCREAMING_SNAKE_CASE :   Tuple					  =							f"Input value of [number={number}] must be an integer"
		raise TypeError(_a)
	if number < 0:
		return False
	SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							number * number
	while number > 0:
		if number % 10 != number_square % 10:
			return False
		number //= 10
		number_square //= 10
	return True


if __name__ == "__main__":
			import doctest

			doctest.testmod()