




'''simple docstring'''




import unittest

from transformers import MobileBertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, 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 (
         MODEL_FOR_PRETRAINING_MAPPING,
         MobileBertForMaskedLM,
         MobileBertForMultipleChoice,
         MobileBertForNextSentencePrediction,
         MobileBertForPreTraining,
         MobileBertForQuestionAnswering,
         MobileBertForSequenceClassification,
         MobileBertForTokenClassification,
         MobileBertModel,
     )


class   __UpperCamelCase       :






       def __init__(							self,		lowerCAmelCase,		lowerCAmelCase=13,		lowerCAmelCase=7,		lowerCAmelCase=True,		lowerCAmelCase=True,		lowerCAmelCase=True,		lowerCAmelCase=True,		lowerCAmelCase=99,		lowerCAmelCase=64,		lowerCAmelCase=32,		lowerCAmelCase=5,		lowerCAmelCase=4,		lowerCAmelCase=37,		lowerCAmelCase="gelu",		lowerCAmelCase=0.1,		lowerCAmelCase=0.1,		lowerCAmelCase=512,		lowerCAmelCase=16,		lowerCAmelCase=2,		lowerCAmelCase=0.0_2,		lowerCAmelCase=3,		lowerCAmelCase=4,		lowerCAmelCase=None,		):



              """simple docstring"""







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






       def      lowercase__     (							self  ):



              """simple docstring"""







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

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

              lowerCamelCase_							=None
              if self.use_token_type_ids:
                     lowerCamelCase_							=ids_tensor([self.batch_size, self.seq_length],		self.type_vocab_size  )

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

              lowerCamelCase_							=self.get_config()

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






       def      lowercase__     (							self  ):



              """simple docstring"""







              return MobileBertConfig(
                  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,		embedding_size=self.embedding_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,		is_decoder=_lowerCamelCase,		initializer_range=self.initializer_range,		)






       def      lowercase__     (							self,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase  ):



              """simple docstring"""







              lowerCamelCase_							=MobileBertModel(config=_lowerCamelCase  )
              model.to(_lowerCamelCase  )
              model.eval()
              lowerCamelCase_							=model(_lowerCamelCase,		attention_mask=_lowerCamelCase,		token_type_ids=_lowerCamelCase  )
              lowerCamelCase_							=model(_lowerCamelCase,		token_type_ids=_lowerCamelCase  )
              lowerCamelCase_							=model(_lowerCamelCase  )

              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      lowercase__     (							self,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase  ):



              """simple docstring"""







              lowerCamelCase_							=MobileBertForMaskedLM(config=_lowerCamelCase  )
              model.to(_lowerCamelCase  )
              model.eval()
              lowerCamelCase_							=model(_lowerCamelCase,		attention_mask=_lowerCamelCase,		token_type_ids=_lowerCamelCase,		labels=_lowerCamelCase  )
              self.parent.assertEqual(result.logits.shape,		(self.batch_size, self.seq_length, self.vocab_size)  )






       def      lowercase__     (							self,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase  ):



              """simple docstring"""







              lowerCamelCase_							=MobileBertForNextSentencePrediction(config=_lowerCamelCase  )
              model.to(_lowerCamelCase  )
              model.eval()
              lowerCamelCase_							=model(
                  _lowerCamelCase,		attention_mask=_lowerCamelCase,		token_type_ids=_lowerCamelCase,		labels=_lowerCamelCase,		)
              self.parent.assertEqual(result.logits.shape,		(self.batch_size, 2)  )






       def      lowercase__     (							self,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase  ):



              """simple docstring"""







              lowerCamelCase_							=MobileBertForPreTraining(config=_lowerCamelCase  )
              model.to(_lowerCamelCase  )
              model.eval()
              lowerCamelCase_							=model(
                  _lowerCamelCase,		attention_mask=_lowerCamelCase,		token_type_ids=_lowerCamelCase,		labels=_lowerCamelCase,		next_sentence_label=_lowerCamelCase,		)
              self.parent.assertEqual(result.prediction_logits.shape,		(self.batch_size, self.seq_length, self.vocab_size)  )
              self.parent.assertEqual(result.seq_relationship_logits.shape,		(self.batch_size, 2)  )






       def      lowercase__     (							self,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase  ):



              """simple docstring"""







              lowerCamelCase_							=MobileBertForQuestionAnswering(config=_lowerCamelCase  )
              model.to(_lowerCamelCase  )
              model.eval()
              lowerCamelCase_							=model(
                  _lowerCamelCase,		attention_mask=_lowerCamelCase,		token_type_ids=_lowerCamelCase,		start_positions=_lowerCamelCase,		end_positions=_lowerCamelCase,		)
              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,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase  ):



              """simple docstring"""







              lowerCamelCase_							=self.num_labels
              lowerCamelCase_							=MobileBertForSequenceClassification(_lowerCamelCase  )
              model.to(_lowerCamelCase  )
              model.eval()
              lowerCamelCase_							=model(_lowerCamelCase,		attention_mask=_lowerCamelCase,		token_type_ids=_lowerCamelCase,		labels=_lowerCamelCase  )
              self.parent.assertEqual(result.logits.shape,		(self.batch_size, self.num_labels)  )






       def      lowercase__     (							self,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase  ):



              """simple docstring"""







              lowerCamelCase_							=self.num_labels
              lowerCamelCase_							=MobileBertForTokenClassification(config=_lowerCamelCase  )
              model.to(_lowerCamelCase  )
              model.eval()
              lowerCamelCase_							=model(_lowerCamelCase,		attention_mask=_lowerCamelCase,		token_type_ids=_lowerCamelCase,		labels=_lowerCamelCase  )
              self.parent.assertEqual(result.logits.shape,		(self.batch_size, self.seq_length, self.num_labels)  )






       def      lowercase__     (							self,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase  ):



              """simple docstring"""







              lowerCamelCase_							=self.num_choices
              lowerCamelCase_							=MobileBertForMultipleChoice(config=_lowerCamelCase  )
              model.to(_lowerCamelCase  )
              model.eval()
              lowerCamelCase_							=input_ids.unsqueeze(1  ).expand(-1,		self.num_choices,		-1  ).contiguous()
              lowerCamelCase_							=token_type_ids.unsqueeze(1  ).expand(-1,		self.num_choices,		-1  ).contiguous()
              lowerCamelCase_							=input_mask.unsqueeze(1  ).expand(-1,		self.num_choices,		-1  ).contiguous()
              lowerCamelCase_							=model(
                  _lowerCamelCase,		attention_mask=_lowerCamelCase,		token_type_ids=_lowerCamelCase,		labels=_lowerCamelCase,		)
              self.parent.assertEqual(result.logits.shape,		(self.batch_size, self.num_choices)  )






       def      lowercase__     (							self  ):



              """simple docstring"""







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





@require_torch
class   __UpperCamelCase       ( a_			,					a_			,					unittest.TestCase				):
       lowercase	:    Tuple      						=(
           (
               MobileBertModel,
               MobileBertForMaskedLM,
               MobileBertForMultipleChoice,
               MobileBertForNextSentencePrediction,
               MobileBertForPreTraining,
               MobileBertForQuestionAnswering,
               MobileBertForSequenceClassification,
               MobileBertForTokenClassification,
           )
           if is_torch_available()
           else ()
       )
       lowercase	:    List[Any]      						=(
           {
               "feature-extraction": MobileBertModel,
               "fill-mask": MobileBertForMaskedLM,
               "question-answering": MobileBertForQuestionAnswering,
               "text-classification": MobileBertForSequenceClassification,
               "token-classification": MobileBertForTokenClassification,
               "zero-shot": MobileBertForSequenceClassification,
           }
           if is_torch_available()
           else {}
       )
       lowercase	:    Any      						=True






       def      lowercase__     (							self,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase=False  ):



              """simple docstring"""







              lowerCamelCase_							=super()._prepare_for_class(_lowerCamelCase,		_lowerCamelCase,		return_labels=_lowerCamelCase  )

              if return_labels:
                     if model_class in get_values(_lowerCamelCase  ):
                            lowerCamelCase_							=torch.zeros(
                                (self.model_tester.batch_size, self.model_tester.seq_length),		dtype=torch.long,		device=_lowerCamelCase  )
                            lowerCamelCase_							=torch.zeros(
                                self.model_tester.batch_size,		dtype=torch.long,		device=_lowerCamelCase  )
              return inputs_dict






       def      lowercase__     (							self  ):



              """simple docstring"""







              lowerCamelCase_							=MobileBertModelTester(self  )
              lowerCamelCase_							=ConfigTester(self,		config_class=_lowerCamelCase,		hidden_size=37  )






       def      lowercase__     (							self  ):



              """simple docstring"""







              self.config_tester.run_common_tests()






       def      lowercase__     (							self  ):



              """simple docstring"""







              lowerCamelCase_							=self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_mobilebert_model(*_lowerCamelCase  )






       def      lowercase__     (							self  ):



              """simple docstring"""







              lowerCamelCase_							=self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_mobilebert_for_masked_lm(*_lowerCamelCase  )






       def      lowercase__     (							self  ):



              """simple docstring"""







              lowerCamelCase_							=self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_mobilebert_for_multiple_choice(*_lowerCamelCase  )






       def      lowercase__     (							self  ):



              """simple docstring"""







              lowerCamelCase_							=self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*_lowerCamelCase  )






       def      lowercase__     (							self  ):



              """simple docstring"""







              lowerCamelCase_							=self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_mobilebert_for_pretraining(*_lowerCamelCase  )






       def      lowercase__     (							self  ):



              """simple docstring"""







              lowerCamelCase_							=self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_mobilebert_for_question_answering(*_lowerCamelCase  )






       def      lowercase__     (							self  ):



              """simple docstring"""







              lowerCamelCase_							=self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_mobilebert_for_sequence_classification(*_lowerCamelCase  )






       def      lowercase__     (							self  ):



              """simple docstring"""







              lowerCamelCase_							=self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_mobilebert_for_token_classification(*_lowerCamelCase  )





def      a_							(      __snake_case							:			Any   )							->						Any:



       """simple docstring"""
       return torch.tensor(
           __snake_case   ,       dtype=torch.long   ,       device=__snake_case   ,       )


a_      :		Dict							      =       1e-3


@require_torch
@require_sentencepiece
@require_tokenizers
class   __UpperCamelCase       ( unittest.TestCase				):






       @slow
       def      lowercase__     (							self  ):



              """simple docstring"""







              lowerCamelCase_							=MobileBertModel.from_pretrained('''google/mobilebert-uncased'''  ).to(_lowerCamelCase  )
              lowerCamelCase_							=_long_tensor([[101, 7_110, 1_005, 1_056, 2_023, 11_333, 17_413, 1_029, 102]]  )
              with torch.no_grad():
                     lowerCamelCase_							=model(_lowerCamelCase  )[0]
              lowerCamelCase_							=torch.Size((1, 9, 512)  )
              self.assertEqual(output.shape,		_lowerCamelCase  )
              lowerCamelCase_							=torch.tensor(
                  [
                      [
                          [-2.4_736_526e07, 8.2_691_656e04, 1.6_521_838e05],
                          [-5.7_541_704e-01, 3.9_056_022e00, 4.4_011_507e00],
                          [2.6_047_359e00, 1.5_677_652e00, -1.7_324_188e-01],
                      ]
                  ],		device=_lowerCamelCase,		)

              # MobileBERT results range from 10e0 to 10e8. Even a 0.0000001% difference with a value of 10e8 results in a
              # ~1 difference, it's therefore not a good idea to measure using addition.
              # Here, we instead divide the expected result with the result in order to obtain ~1. We then check that the
              # result is held between bounds: 1 - TOLERANCE < expected_result / result < 1 + TOLERANCE
              lowerCamelCase_							=torch.all((expected_slice / output[..., :3, :3]) >= 1 - TOLERANCE  )
              lowerCamelCase_							=torch.all((expected_slice / output[..., :3, :3]) <= 1 + TOLERANCE  )

              self.assertTrue(lower_bound and upper_bound  )












"""simple docstring"""



def 						_SCREAMING_SNAKE_CASE (    __snake_case			:  int    ):





  '''simple docstring'''





  return sum(i for i in range(1		,					number // 2 + 1    ) if number % i == 0    ) == number


if __name__ == "__main__":
    print('Program to check whether a number is a Perfect number or not...')
    _UpperCamelCase		:  Tuple						=		int(input('Enter number: ').strip())
    print(F'''{number} is {'' if perfect(number) else 'not '}a Perfect Number.''')


