




'''simple docstring'''




from __future__ import annotations

import unittest

from transformers import DistilBertConfig, 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.distilbert.modeling_tf_distilbert import (
         TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
         TFDistilBertForMaskedLM,
         TFDistilBertForMultipleChoice,
         TFDistilBertForQuestionAnswering,
         TFDistilBertForSequenceClassification,
         TFDistilBertForTokenClassification,
         TFDistilBertModel,
     )


class   __UpperCamelCase       :






       def __init__(							self,		lowerCAmelCase,		):



              """simple docstring"""







              lowerCamelCase_							=parent
              lowerCamelCase_							=13
              lowerCamelCase_							=7
              lowerCamelCase_							=True
              lowerCamelCase_							=True
              lowerCamelCase_							=False
              lowerCamelCase_							=True
              lowerCamelCase_							=99
              lowerCamelCase_							=32
              lowerCamelCase_							=2
              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






       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
              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_							=DistilBertConfig(
                  vocab_size=self.vocab_size,		dim=self.hidden_size,		n_layers=self.num_hidden_layers,		n_heads=self.num_attention_heads,		hidden_dim=self.intermediate_size,		hidden_act=self.hidden_act,		dropout=self.hidden_dropout_prob,		attention_dropout=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,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase,		lowerCAmelCase  ):



              """simple docstring"""







              lowerCamelCase_							=TFDistilBertModel(config=_lowerCamelCase  )
              lowerCamelCase_							={'''input_ids''': input_ids, '''attention_mask''': input_mask}

              lowerCamelCase_							=model(_lowerCamelCase  )

              lowerCamelCase_							=[input_ids, input_mask]

              lowerCamelCase_							=model(_lowerCamelCase  )

              self.parent.assertEqual(result.last_hidden_state.shape,		(self.batch_size, self.seq_length, self.hidden_size)  )






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



              """simple docstring"""







              lowerCamelCase_							=TFDistilBertForMaskedLM(config=_lowerCamelCase  )
              lowerCamelCase_							={'''input_ids''': input_ids, '''attention_mask''': input_mask}
              lowerCamelCase_							=model(_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  ):



              """simple docstring"""







              lowerCamelCase_							=TFDistilBertForQuestionAnswering(config=_lowerCamelCase  )
              lowerCamelCase_							={
                  '''input_ids''': input_ids,
                  '''attention_mask''': input_mask,
              }
              lowerCamelCase_							=model(_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  ):



              """simple docstring"""







              lowerCamelCase_							=self.num_labels
              lowerCamelCase_							=TFDistilBertForSequenceClassification(_lowerCamelCase  )
              lowerCamelCase_							={'''input_ids''': input_ids, '''attention_mask''': input_mask}
              lowerCamelCase_							=model(_lowerCamelCase  )
              self.parent.assertEqual(result.logits.shape,		(self.batch_size, self.num_labels)  )






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



              """simple docstring"""







              lowerCamelCase_							=self.num_choices
              lowerCamelCase_							=TFDistilBertForMultipleChoice(_lowerCamelCase  )
              lowerCamelCase_							=tf.tile(tf.expand_dims(_lowerCamelCase,		1  ),		(1, self.num_choices, 1)  )
              lowerCamelCase_							=tf.tile(tf.expand_dims(_lowerCamelCase,		1  ),		(1, self.num_choices, 1)  )
              lowerCamelCase_							={
                  '''input_ids''': multiple_choice_inputs_ids,
                  '''attention_mask''': multiple_choice_input_mask,
              }
              lowerCamelCase_							=model(_lowerCamelCase  )
              self.parent.assertEqual(result.logits.shape,		(self.batch_size, self.num_choices)  )






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



              """simple docstring"""







              lowerCamelCase_							=self.num_labels
              lowerCamelCase_							=TFDistilBertForTokenClassification(_lowerCamelCase  )
              lowerCamelCase_							={'''input_ids''': input_ids, '''attention_mask''': input_mask}
              lowerCamelCase_							=model(_lowerCamelCase  )
              self.parent.assertEqual(result.logits.shape,		(self.batch_size, self.seq_length, self.num_labels)  )






       def      lowercase__     (							self  ):



              """simple docstring"""







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





@require_tf
class   __UpperCamelCase       ( a_			,					a_			,					unittest.TestCase				):
       lowercase	:    Dict      						=(
           (
               TFDistilBertModel,
               TFDistilBertForMaskedLM,
               TFDistilBertForQuestionAnswering,
               TFDistilBertForSequenceClassification,
               TFDistilBertForTokenClassification,
               TFDistilBertForMultipleChoice,
           )
           if is_tf_available()
           else None
       )
       lowercase	:    Union[str, Any]      						=(
           {
               "feature-extraction": TFDistilBertModel,
               "fill-mask": TFDistilBertForMaskedLM,
               "question-answering": TFDistilBertForQuestionAnswering,
               "text-classification": TFDistilBertForSequenceClassification,
               "token-classification": TFDistilBertForTokenClassification,
               "zero-shot": TFDistilBertForSequenceClassification,
           }
           if is_tf_available()
           else {}
       )
       lowercase	:    List[str]      						=False
       lowercase	:    Optional[int]      						=False






       def      lowercase__     (							self  ):



              """simple docstring"""







              lowerCamelCase_							=TFDistilBertModelTester(self  )
              lowerCamelCase_							=ConfigTester(self,		config_class=_lowerCamelCase,		dim=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_distilbert_model(*_lowerCamelCase  )






       def      lowercase__     (							self  ):



              """simple docstring"""







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






       def      lowercase__     (							self  ):



              """simple docstring"""







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






       def      lowercase__     (							self  ):



              """simple docstring"""







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






       def      lowercase__     (							self  ):



              """simple docstring"""







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






       def      lowercase__     (							self  ):



              """simple docstring"""







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






       @slow
       def      lowercase__     (							self  ):



              """simple docstring"""







              for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]  ):
                     lowerCamelCase_							=TFDistilBertModel.from_pretrained(_lowerCamelCase  )
                     self.assertIsNotNone(_lowerCamelCase  )





@require_tf
class   __UpperCamelCase       ( unittest.TestCase				):






       @slow
       def      lowercase__     (							self  ):



              """simple docstring"""







              lowerCamelCase_							=TFDistilBertModel.from_pretrained('''distilbert-base-uncased'''  )
              lowerCamelCase_							=tf.constant([[0, 1, 2, 3, 4, 5]]  )
              lowerCamelCase_							=model(_lowerCamelCase  )[0]

              lowerCamelCase_							=[1, 6, 768]
              self.assertEqual(output.shape,		_lowerCamelCase  )

              lowerCamelCase_							=tf.constant(
                  [
                      [
                          [0.1_9_2_6_1_8_8_5, -0.1_3_7_3_2_9_5_5, 0.4_1_1_9_7_9_9],
                          [0.2_2_1_5_0_1_5_6, -0.0_7_4_2_2_6_6_1, 0.3_9_0_3_7_2_0_4],
                          [0.2_2_7_5_6_0_1_8, -0.0_8_9_6_4_1_4, 0.3_7_0_1_4_6_7],
                      ]
                  ]  )
              tf.debugging.assert_near(output[:, :3, :3],		_lowerCamelCase,		atol=1e-4  )












"""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.''')


