
'''simple docstring'''





from __future__ import annotations

import unittest

from transformers import DebertaConfig, 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 import (
         TFDebertaForMaskedLM,
         TFDebertaForQuestionAnswering,
         TFDebertaForSequenceClassification,
         TFDebertaForTokenClassification,
         TFDebertaModel,
     )



class 			lowerCAmelCase__ :



  '''simple docstring'''






  def __init__(self	:			List[Any]						,			lowerCAmelCase_	:			Dict						,			lowerCAmelCase_	:			str=13						,			lowerCAmelCase_	:			Dict=7						,			lowerCAmelCase_	:			Dict=True						,			lowerCAmelCase_	:			Dict=True						,			lowerCAmelCase_	:			int=True						,			lowerCAmelCase_	:			List[str]=True						,			lowerCAmelCase_	:			Dict=99						,			lowerCAmelCase_	:			List[str]=32						,			lowerCAmelCase_	:			str=2						,			lowerCAmelCase_	:			List[Any]=4						,			lowerCAmelCase_	:			Optional[Any]=37						,			lowerCAmelCase_	:			str="gelu"						,			lowerCAmelCase_	:			List[Any]=0.1						,			lowerCAmelCase_	:			str=0.1						,			lowerCAmelCase_	:			List[str]=5_12						,			lowerCAmelCase_	:			str=16						,			lowerCAmelCase_	:			str=2						,			lowerCAmelCase_	:			Any=0.02						,			lowerCAmelCase_	:			Any=3						,			lowerCAmelCase_	:			Optional[int]=4						,			lowerCAmelCase_	:			Any=None						,			) ->							Union[str, Any]:
        snake_case_    							=				parent
        snake_case_    							=				13
        snake_case_    							=				7
        snake_case_    							=				True
        snake_case_    							=				True
        snake_case_    							=				True
        snake_case_    							=				True
        snake_case_    							=				99
        snake_case_    							=				32
        snake_case_    							=				2
        snake_case_    							=				4
        snake_case_    							=				37
        snake_case_    							=				"gelu"
        snake_case_    							=				0.1
        snake_case_    							=				0.1
        snake_case_    							=				5_12
        snake_case_    							=				16
        snake_case_    							=				False
        snake_case_    							=				-1
        snake_case_    							=				True
        snake_case_    							=				2
        snake_case_    							=				0.02
        snake_case_    							=				3
        snake_case_    							=				4
        snake_case_    							=				None

  def 		_lowerCamelCase						(self	:			Optional[int]     ) ->							List[str]:
        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
        if self.use_token_type_ids:
              snake_case_    							=				ids_tensor([self.batch_size, self.seq_length]						,			self.type_vocab_size     )

        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_    							=				DebertaConfig(
            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						,			type_vocab_size=self.type_vocab_size						,			relative_attention=self.relative_attention						,			max_relative_positions=self.max_relative_positions						,			position_biased_input=self.position_biased_input						,			initializer_range=self.initializer_range						,			return_dict=lowerCAmelCase_						,			)

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

  def 		_lowerCamelCase						(self	:			Optional[int]						,			lowerCAmelCase_	:			List[Any]						,			lowerCAmelCase_	:			Union[str, Any]						,			lowerCAmelCase_	:			Dict						,			lowerCAmelCase_	:			str						,			lowerCAmelCase_	:			Union[str, Any]						,			lowerCAmelCase_	:			Union[str, Any]						,			lowerCAmelCase_	:			Union[str, Any]     ) ->							int:
        snake_case_    							=				TFDebertaModel(config=lowerCAmelCase_     )
        snake_case_    							=				{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

        snake_case_    							=				[input_ids, input_mask]
        snake_case_    							=				model(lowerCAmelCase_     )

        snake_case_    							=				model(lowerCAmelCase_     )

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

  def 		_lowerCamelCase						(self	:			str						,			lowerCAmelCase_	:			Any						,			lowerCAmelCase_	:			Tuple						,			lowerCAmelCase_	:			List[str]						,			lowerCAmelCase_	:			str						,			lowerCAmelCase_	:			Optional[Any]						,			lowerCAmelCase_	:			Optional[int]						,			lowerCAmelCase_	:			List[str]     ) ->							Optional[Any]:
        snake_case_    							=				TFDebertaForMaskedLM(config=lowerCAmelCase_     )
        snake_case_    							=				{
            "input_ids": input_ids,
            "attention_mask": input_mask,
            "token_type_ids": token_type_ids,
        }
        snake_case_    							=				model(lowerCAmelCase_     )
        self.parent.assertEqual(result.logits.shape						,			(self.batch_size, self.seq_length, self.vocab_size)     )

  def 		_lowerCamelCase						(self	:			Tuple						,			lowerCAmelCase_	:			Tuple						,			lowerCAmelCase_	:			Union[str, Any]						,			lowerCAmelCase_	:			Optional[int]						,			lowerCAmelCase_	:			str						,			lowerCAmelCase_	:			Optional[Any]						,			lowerCAmelCase_	:			List[Any]						,			lowerCAmelCase_	:			int     ) ->							Optional[Any]:
        snake_case_    							=				self.num_labels
        snake_case_    							=				TFDebertaForSequenceClassification(config=lowerCAmelCase_     )
        snake_case_    							=				{
            "input_ids": input_ids,
            "attention_mask": input_mask,
            "token_type_ids": token_type_ids,
        }

        snake_case_    							=				model(lowerCAmelCase_     )
        self.parent.assertEqual(result.logits.shape						,			(self.batch_size, self.num_labels)     )

  def 		_lowerCamelCase						(self	:			Tuple						,			lowerCAmelCase_	:			Optional[Any]						,			lowerCAmelCase_	:			Union[str, Any]						,			lowerCAmelCase_	:			Dict						,			lowerCAmelCase_	:			Union[str, Any]						,			lowerCAmelCase_	:			int						,			lowerCAmelCase_	:			Dict						,			lowerCAmelCase_	:			Optional[int]     ) ->							Union[str, Any]:
        snake_case_    							=				self.num_labels
        snake_case_    							=				TFDebertaForTokenClassification(config=lowerCAmelCase_     )
        snake_case_    							=				{
            "input_ids": input_ids,
            "attention_mask": input_mask,
            "token_type_ids": token_type_ids,
        }
        snake_case_    							=				model(lowerCAmelCase_     )
        self.parent.assertEqual(result.logits.shape						,			(self.batch_size, self.seq_length, self.num_labels)     )

  def 		_lowerCamelCase						(self	:			int						,			lowerCAmelCase_	:			Any						,			lowerCAmelCase_	:			Any						,			lowerCAmelCase_	:			Optional[Any]						,			lowerCAmelCase_	:			Tuple						,			lowerCAmelCase_	:			str						,			lowerCAmelCase_	:			Optional[int]						,			lowerCAmelCase_	:			Optional[Any]     ) ->							Optional[int]:
        snake_case_    							=				TFDebertaForQuestionAnswering(config=lowerCAmelCase_     )
        snake_case_    							=				{
            "input_ids": input_ids,
            "attention_mask": input_mask,
            "token_type_ids": token_type_ids,
        }

        snake_case_    							=				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 		_lowerCamelCase						(self	:			int     ) ->							Any:
        snake_case_    							=				self.prepare_config_and_inputs()
        (
            (
            snake_case_
        )							,						(
            snake_case_
        )							,						(
            snake_case_
        )							,						(
            snake_case_
        )							,						(
            snake_case_
        )							,						(
            snake_case_
        )							,						(
            snake_case_
        )							,						
        )    							=				config_and_inputs
        snake_case_    							=				{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
        return config, inputs_dict



@require_tf
class 			lowerCAmelCase__ (							UpperCamelCase       ,				UpperCamelCase       ,				unittest.TestCase							):



  '''simple docstring'''






  _UpperCamelCase							=			(
      (
          TFDebertaModel,
          TFDebertaForMaskedLM,
          TFDebertaForQuestionAnswering,
          TFDebertaForSequenceClassification,
          TFDebertaForTokenClassification,
      )
      if is_tf_available()
      else ()
  )
  _UpperCamelCase							=			(
      {
          'feature-extraction': TFDebertaModel,
          'fill-mask': TFDebertaForMaskedLM,
          'question-answering': TFDebertaForQuestionAnswering,
          'text-classification': TFDebertaForSequenceClassification,
          'token-classification': TFDebertaForTokenClassification,
          'zero-shot': TFDebertaForSequenceClassification,
      }
      if is_tf_available()
      else {}
  )

  _UpperCamelCase							=			False
  _UpperCamelCase							=			False

  def 		_lowerCamelCase						(self	:			Optional[int]     ) ->							Optional[int]:
        snake_case_    							=				TFDebertaModelTester(self     )
        snake_case_    							=				ConfigTester(self						,			config_class=lowerCAmelCase_						,			hidden_size=37     )

  def 		_lowerCamelCase						(self	:			Optional[Any]     ) ->							List[str]:
        self.config_tester.run_common_tests()

  def 		_lowerCamelCase						(self	:			int     ) ->							List[Any]:
        snake_case_    							=				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*lowerCAmelCase_     )

  def 		_lowerCamelCase						(self	:			Optional[int]     ) ->							List[Any]:
        snake_case_    							=				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_masked_lm(*lowerCAmelCase_     )

  def 		_lowerCamelCase						(self	:			int     ) ->							Tuple:
        snake_case_    							=				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_question_answering(*lowerCAmelCase_     )

  def 		_lowerCamelCase						(self	:			str     ) ->							List[Any]:
        snake_case_    							=				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_sequence_classification(*lowerCAmelCase_     )

  def 		_lowerCamelCase						(self	:			Tuple     ) ->							List[str]:
        snake_case_    							=				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_token_classification(*lowerCAmelCase_     )


  @slow
  def 		_lowerCamelCase						(self	:			List[str]     ) ->							Optional[int]:
        snake_case_    							=				TFDebertaModel.from_pretrained("kamalkraj/deberta-base"     )
        self.assertIsNotNone(lowerCAmelCase_     )



@require_tf
class 			lowerCAmelCase__ (							unittest.TestCase							):



  '''simple docstring'''






  @unittest.skip(reason="Model not available yet"     )
  def 		_lowerCamelCase						(self	:			List[Any]     ) ->							Optional[Any]:
        pass


  @slow
  def 		_lowerCamelCase						(self	:			Union[str, Any]     ) ->							int:
        snake_case_    							=				TFDebertaModel.from_pretrained("kamalkraj/deberta-base"     )
        snake_case_    							=				tf.constant([[0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]]     )
        snake_case_    							=				tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]     )
        snake_case_    							=				model(lowerCAmelCase_						,			attention_mask=lowerCAmelCase_     )[0]

        snake_case_    							=				tf.constant(
            [
                [
                    [-0.59_855_896, -0.80_552_566, -0.8_462_135],
                    [1.4_484_025, -0.93_483_794, -0.80_593_085],
                    [0.3_122_741, 0.00_316_059, -1.4_131_377],
                ]
            ]     )
        tf.debugging.assert_near(output[:, 1:4, 1:4]						,			lowerCAmelCase_						,			atol=1E-4     )







"""simple docstring"""





_lowercase						   =     (1, 1_53, 3_70, 3_71, 16_34, 24_67_80_51, 1_15_13_22_19_01_87_63_99_25_65_09_55_97_97_39_71_52_24_01)
_lowercase						   =     (-1_53, -1, 0, 1.2, 2_00, "A", [], {}, None)

def 		lowerCAmelCase				(			lowerCamelCase		):
						'''simple docstring'''


						if not isinstance(lowerCamelCase   ,      lowerCamelCase		) or n < 1:
												return False

						# Initialization of sum and number of digits.
						snake_case__							:       Optional[Any]				      =       0
						snake_case__							:       Union[str, Any]				      =       0
						snake_case__							:       List[str]				      =       n
						# Calculation of digits of the number
						while temp > 0:
												number_of_digits += 1
												temp //= 10
						# Dividing number into separate digits and find Armstrong number
						snake_case__							:       Optional[int]				      =       n
						while temp > 0:
												snake_case__							:       Optional[int]				      =       temp % 10
												total += rem**number_of_digits
												temp //= 10
						return n == total

def 		lowerCAmelCase				(			lowerCamelCase		):
						'''simple docstring'''


						if not isinstance(lowerCamelCase   ,      lowerCamelCase		) or n < 1:
												return False

						# Init a "histogram" of the digits
						snake_case__							:       Union[str, Any]				      =       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
						snake_case__							:       int				      =       0
						snake_case__							:       int				      =       0
						snake_case__							:       Dict				      =       n
						while temp > 0:
												snake_case__      ,						snake_case__							:       Optional[int]				      =       divmod(lowerCamelCase   ,      10		)
												digit_histogram[rem] += 1
												digit_total += 1

						for cnt, i in zip(lowerCamelCase   ,      range(len(lowerCamelCase		)		)		):
												total += cnt * i**digit_total

						return n == total

def 		lowerCAmelCase				(			lowerCamelCase		):
						'''simple docstring'''


						if not isinstance(lowerCamelCase   ,      lowerCamelCase		) or n < 1:
												return False
						snake_case__							:       Union[str, Any]				      =       len(str(lowerCamelCase		)		)  # the power that all digits will be raised to
						# check if sum of each digit multiplied expo times is equal to number
						return n == sum(int(lowerCamelCase		) ** expo for i in str(lowerCamelCase		)		)

def 		lowerCAmelCase				(			):
						'''simple docstring'''


						snake_case__							:       Dict				      =       int(input('''Enter an integer to see if it is an Armstrong number: '''		).strip()		)
						print(f'''{num} is {'' if armstrong_number(lowerCamelCase		) else 'not '}an Armstrong number.'''		)
						print(f'''{num} is {'' if narcissistic_number(lowerCamelCase		) else 'not '}an Armstrong number.'''		)
						print(f'''{num} is {'' if pluperfect_number(lowerCamelCase		) else 'not '}an Armstrong number.'''		)


if __name__ == "__main__":
							import doctest

							doctest.testmod()
							main()


