
"""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 SCREAMING_SNAKE_CASE       :






	'''simple docstring'''







	def __init__(  self :Union[str, Any]       ,    __magic_name__ :str       ,    __magic_name__ :Union[str, Any]=13       ,    __magic_name__ :Union[str, Any]=7       ,    __magic_name__ :Dict=True       ,    __magic_name__ :List[str]=True       ,    __magic_name__ :str=True       ,    __magic_name__ :Optional[Any]=True       ,    __magic_name__ :List[str]=99       ,    __magic_name__ :List[Any]=32       ,    __magic_name__ :Union[str, Any]=2       ,    __magic_name__ :Optional[int]=4       ,    __magic_name__ :Dict=37       ,    __magic_name__ :int="gelu"       ,    __magic_name__ :List[str]=0.1       ,    __magic_name__ :List[str]=0.1       ,    __magic_name__ :List[Any]=512       ,    __magic_name__ :Optional[int]=16       ,    __magic_name__ :List[str]=2       ,    __magic_name__ :List[str]=0.02       ,    __magic_name__ :Union[str, Any]=3       ,    __magic_name__ :Tuple=4       ,    __magic_name__ :List[str]=None       ,    )			->   Optional[int]:

			'''simple docstring'''






			a__   		=     parent
			a__   		=     13
			a__   		=     7
			a__   		=     True
			a__   		=     True
			a__   		=     True
			a__   		=     True
			a__   		=     99
			a__   		=     32
			a__   		=     2
			a__   		=     4
			a__   		=     37
			a__   		=     '''gelu'''
			a__   		=     0.1
			a__   		=     0.1
			a__   		=     512
			a__   		=     16
			a__   		=     False
			a__   		=     -1
			a__   		=     True
			a__   		=     2
			a__   		=     0.02
			a__   		=     3
			a__   		=     4
			a__   		=     None


	def    _UpperCamelCase							(  self :Dict			)			->   List[str]:

			'''simple docstring'''






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

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

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

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

			a__   		=     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=__magic_name__       ,    )

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


	def    _UpperCamelCase							(  self :Tuple       ,    __magic_name__ :int       ,    __magic_name__ :Any       ,    __magic_name__ :Any       ,    __magic_name__ :Any       ,    __magic_name__ :Union[str, Any]       ,    __magic_name__ :int       ,    __magic_name__ :Dict			)			->   Union[str, Any]:

			'''simple docstring'''






			a__   		=     TFDebertaModel(config=__magic_name__			)
			a__   		=     {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

			a__   		=     [input_ids, input_mask]
			a__   		=     model(__magic_name__			)

			a__   		=     model(__magic_name__			)

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


	def    _UpperCamelCase							(  self :Optional[Any]       ,    __magic_name__ :Dict       ,    __magic_name__ :Dict       ,    __magic_name__ :Dict       ,    __magic_name__ :List[Any]       ,    __magic_name__ :Tuple       ,    __magic_name__ :List[str]       ,    __magic_name__ :List[Any]			)			->   Optional[Any]:

			'''simple docstring'''






			a__   		=     TFDebertaForMaskedLM(config=__magic_name__			)
			a__   		=     {
			    '''input_ids''': input_ids,
			    '''attention_mask''': input_mask,
			    '''token_type_ids''': token_type_ids,
			}
			a__   		=     model(__magic_name__			)
			self.parent.assertEqual(result.logits.shape       ,    (self.batch_size, self.seq_length, self.vocab_size)			)


	def    _UpperCamelCase							(  self :Optional[int]       ,    __magic_name__ :List[str]       ,    __magic_name__ :int       ,    __magic_name__ :List[Any]       ,    __magic_name__ :Union[str, Any]       ,    __magic_name__ :List[Any]       ,    __magic_name__ :Dict       ,    __magic_name__ :int			)			->   Union[str, Any]:

			'''simple docstring'''






			a__   		=     self.num_labels
			a__   		=     TFDebertaForSequenceClassification(config=__magic_name__			)
			a__   		=     {
			    '''input_ids''': input_ids,
			    '''attention_mask''': input_mask,
			    '''token_type_ids''': token_type_ids,
			}

			a__   		=     model(__magic_name__			)
			self.parent.assertEqual(result.logits.shape       ,    (self.batch_size, self.num_labels)			)


	def    _UpperCamelCase							(  self :str       ,    __magic_name__ :Any       ,    __magic_name__ :List[str]       ,    __magic_name__ :Any       ,    __magic_name__ :List[str]       ,    __magic_name__ :int       ,    __magic_name__ :Any       ,    __magic_name__ :Optional[int]			)			->   int:

			'''simple docstring'''






			a__   		=     self.num_labels
			a__   		=     TFDebertaForTokenClassification(config=__magic_name__			)
			a__   		=     {
			    '''input_ids''': input_ids,
			    '''attention_mask''': input_mask,
			    '''token_type_ids''': token_type_ids,
			}
			a__   		=     model(__magic_name__			)
			self.parent.assertEqual(result.logits.shape       ,    (self.batch_size, self.seq_length, self.num_labels)			)


	def    _UpperCamelCase							(  self :List[str]       ,    __magic_name__ :str       ,    __magic_name__ :Dict       ,    __magic_name__ :List[Any]       ,    __magic_name__ :Optional[int]       ,    __magic_name__ :Any       ,    __magic_name__ :int       ,    __magic_name__ :List[Any]			)			->   Tuple:

			'''simple docstring'''






			a__   		=     TFDebertaForQuestionAnswering(config=__magic_name__			)
			a__   		=     {
			    '''input_ids''': input_ids,
			    '''attention_mask''': input_mask,
			    '''token_type_ids''': token_type_ids,
			}

			a__   		=     model(__magic_name__			)
			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 :str			)			->   Any:

			'''simple docstring'''






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

@require_tf
class SCREAMING_SNAKE_CASE       (      lowerCAmelCase					,   lowerCAmelCase					,   unittest.TestCase					):






	'''simple docstring'''







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

	snake_case__							:		Optional[Any]         =		False
	snake_case__							:		str         =		False


	def    _UpperCamelCase							(  self :List[str]			)			->   Tuple:

			'''simple docstring'''






			a__   		=     TFDebertaModelTester(self			)
			a__   		=     ConfigTester(self       ,    config_class=__magic_name__       ,    hidden_size=37			)


	def    _UpperCamelCase							(  self :str			)			->   Any:

			'''simple docstring'''






			self.config_tester.run_common_tests()


	def    _UpperCamelCase							(  self :Tuple			)			->   int:

			'''simple docstring'''






			a__   		=     self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_model(*__magic_name__			)


	def    _UpperCamelCase							(  self :Optional[int]			)			->   Optional[int]:

			'''simple docstring'''






			a__   		=     self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_masked_lm(*__magic_name__			)


	def    _UpperCamelCase							(  self :Dict			)			->   Tuple:

			'''simple docstring'''






			a__   		=     self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_question_answering(*__magic_name__			)


	def    _UpperCamelCase							(  self :List[str]			)			->   Optional[Any]:

			'''simple docstring'''






			a__   		=     self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_sequence_classification(*__magic_name__			)


	def    _UpperCamelCase							(  self :Dict			)			->   Optional[Any]:

			'''simple docstring'''






			a__   		=     self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_token_classification(*__magic_name__			)






	@slow
	def    _UpperCamelCase							(  self :List[str]			)			->   str:

			'''simple docstring'''






			a__   		=     TFDebertaModel.from_pretrained('''kamalkraj/deberta-base'''			)
			self.assertIsNotNone(__magic_name__			)

@require_tf
class SCREAMING_SNAKE_CASE       (      unittest.TestCase					):






	'''simple docstring'''







	@unittest.skip(reason='''Model not available yet'''			)
	def    _UpperCamelCase							(  self :Tuple			)			->   Tuple:

			'''simple docstring'''






			pass






	@slow
	def    _UpperCamelCase							(  self :Tuple			)			->   List[Any]:

			'''simple docstring'''






			a__   		=     TFDebertaModel.from_pretrained('''kamalkraj/deberta-base'''			)
			a__   		=     tf.constant([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]			)
			a__   		=     tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]			)
			a__   		=     model(__magic_name__       ,    attention_mask=__magic_name__			)[0]

			a__   		=     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]       ,    __magic_name__       ,    atol=1e-4			)






"""simple docstring"""




__lowerCAmelCase							:  Any 				=		{
    '''0''': 1,
    '''1''': 1,
    '''2''': 2,
    '''3''': 6,
    '''4''': 24,
    '''5''': 120,
    '''6''': 720,
    '''7''': 5040,
    '''8''': 40320,
    '''9''': 362880,
}

__lowerCAmelCase							:  List[Any] 				=		{145: 145}

__lowerCAmelCase							:  Any 				=		{
    145: 0,
    169: 3,
    36301: 3,
    1454: 3,
    871: 2,
    45361: 2,
    872: 2,
}

def __snake_case (      UpperCamelCase    )       ->    int:


		"""simple docstring"""





		if n in CACHE_SUM_DIGIT_FACTORIALS:
				return CACHE_SUM_DIGIT_FACTORIALS[n]
		a__   		=     sum(DIGIT_FACTORIALS[let] for let in str(UpperCamelCase    )    )
		a__   		=     ret
		return ret

def __snake_case (      UpperCamelCase						,					UpperCamelCase = None    )       ->    int:


		"""simple docstring"""





		a__   		=     previous or set()
		if n in CHAIN_LENGTH_CACHE:
				return CHAIN_LENGTH_CACHE[n]
		a__   		=     sum_digit_factorials(UpperCamelCase    )
		if next_number in previous:
				a__   		=     0
				return 0
		else:
				previous.add(UpperCamelCase    )
				a__   		=     1 + chain_length(UpperCamelCase						,					UpperCamelCase    )
				a__   		=     ret
				return ret

def __snake_case (      UpperCamelCase = 60						,					UpperCamelCase = 1_000_000    )       ->    int:


		"""simple docstring"""





		return sum(1 for i in range(1						,					UpperCamelCase    ) if chain_length(UpperCamelCase    ) == num_terms    )


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




