





'''simple docstring'''






from __future__ import annotations

import unittest

from transformers import DebertaVaConfig, 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 (
         TFDebertaVaForMaskedLM,
         TFDebertaVaForQuestionAnswering,
         TFDebertaVaForSequenceClassification,
         TFDebertaVaForTokenClassification,
         TFDebertaVaModel,
     )


class   _lowercase						:


   def __init__( self    ,   _UpperCAmelCase    ,   _UpperCAmelCase=13    ,   _UpperCAmelCase=7    ,   _UpperCAmelCase=True    ,   _UpperCAmelCase=True    ,   _UpperCAmelCase=True    ,   _UpperCAmelCase=True    ,   _UpperCAmelCase=99    ,   _UpperCAmelCase=32    ,   _UpperCAmelCase=2    ,   _UpperCAmelCase=4    ,   _UpperCAmelCase=37    ,   _UpperCAmelCase="gelu"    ,   _UpperCAmelCase=0.1    ,   _UpperCAmelCase=0.1    ,   _UpperCAmelCase=512    ,   _UpperCAmelCase=16    ,   _UpperCAmelCase=2    ,   _UpperCAmelCase=0.02    ,   _UpperCAmelCase=False    ,   _UpperCAmelCase=True    ,   _UpperCAmelCase="None"    ,   _UpperCAmelCase=3    ,   _UpperCAmelCase=4    ,   _UpperCAmelCase=None    ,   ):
       A       :       Union[str, Any]							=						parent
       A       :       List[str]							=						batch_size
       A       :       Union[str, Any]							=						seq_length
       A       :       Any							=						is_training
       A       :       str							=						use_input_mask
       A       :       Dict							=						use_token_type_ids
       A       :       Tuple							=						use_labels
       A       :       List[Any]							=						vocab_size
       A       :       int							=						hidden_size
       A       :       Tuple							=						num_hidden_layers
       A       :       List[Any]							=						num_attention_heads
       A       :       int							=						intermediate_size
       A       :       Dict							=						hidden_act
       A       :       List[str]							=						hidden_dropout_prob
       A       :       List[str]							=						attention_probs_dropout_prob
       A       :       Optional[Any]							=						max_position_embeddings
       A       :       Dict							=						type_vocab_size
       A       :       Dict							=						type_sequence_label_size
       A       :       Any							=						initializer_range
       A       :       str							=						num_labels
       A       :       Tuple							=						num_choices
       A       :       Tuple							=						relative_attention
       A       :       str							=						position_biased_input
       A       :       Any							=						pos_att_type
       A       :       Union[str, Any]							=						scope


   def 					snake_case				( self					):
       A       :       Union[str, Any]							=						ids_tensor([self.batch_size, self.seq_length]    ,   self.vocab_size					)

       A       :       Tuple							=						None
       if self.use_input_mask:
           A       :       str							=						random_attention_mask([self.batch_size, self.seq_length]					)

       A       :       Tuple							=						None
       if self.use_token_type_ids:
           A       :       List[str]							=						ids_tensor([self.batch_size, self.seq_length]    ,   self.type_vocab_size					)

       A       :       List[str]							=						None
       A       :       Dict							=						None
       A       :       int							=						None
       if self.use_labels:
           A       :       str							=						ids_tensor([self.batch_size]    ,   self.type_sequence_label_size					)
           A       :       List[Any]							=						ids_tensor([self.batch_size, self.seq_length]    ,   self.num_labels					)

       A       :       List[Any]							=						DebertaVaConfig(
           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    ,   position_biased_input=self.position_biased_input    ,   initializer_range=self.initializer_range    ,   return_dict=_UpperCAmelCase    ,   )

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


   def 					snake_case				( self    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase					):
       A       :       str							=						TFDebertaVaModel(config=_UpperCAmelCase					)
       A       :       Dict							=						{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

       A       :       Any							=						[input_ids, input_mask]
       A       :       Union[str, Any]							=						model(_UpperCAmelCase					)

       A       :       List[Any]							=						model(_UpperCAmelCase					)

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


   def 					snake_case				( self    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase					):
       A       :       int							=						TFDebertaVaForMaskedLM(config=_UpperCAmelCase					)
       A       :       Dict							=						{
           '''input_ids''': input_ids,
           '''attention_mask''': input_mask,
           '''token_type_ids''': token_type_ids,
       }
       A       :       Dict							=						model(_UpperCAmelCase					)
       self.parent.assertEqual(result.logits.shape    ,   (self.batch_size, self.seq_length, self.vocab_size)					)


   def 					snake_case				( self    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase					):
       A       :       Optional[int]							=						self.num_labels
       A       :       Any							=						TFDebertaVaForSequenceClassification(config=_UpperCAmelCase					)
       A       :       List[str]							=						{
           '''input_ids''': input_ids,
           '''attention_mask''': input_mask,
           '''token_type_ids''': token_type_ids,
       }

       A       :       Dict							=						model(_UpperCAmelCase					)
       self.parent.assertEqual(result.logits.shape    ,   (self.batch_size, self.num_labels)					)


   def 					snake_case				( self    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase					):
       A       :       Dict							=						self.num_labels
       A       :       List[Any]							=						TFDebertaVaForTokenClassification(config=_UpperCAmelCase					)
       A       :       List[str]							=						{
           '''input_ids''': input_ids,
           '''attention_mask''': input_mask,
           '''token_type_ids''': token_type_ids,
       }
       A       :       int							=						model(_UpperCAmelCase					)
       self.parent.assertEqual(result.logits.shape    ,   (self.batch_size, self.seq_length, self.num_labels)					)


   def 					snake_case				( self    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase    ,   _UpperCAmelCase					):
       A       :       Union[str, Any]							=						TFDebertaVaForQuestionAnswering(config=_UpperCAmelCase					)
       A       :       Any							=						{
           '''input_ids''': input_ids,
           '''attention_mask''': input_mask,
           '''token_type_ids''': token_type_ids,
       }

       A       :       List[str]							=						model(_UpperCAmelCase					)
       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 					snake_case				( self					):
       A       :       str							=						self.prepare_config_and_inputs()
       (
           (
           A
       ),	(
           A
       ),	(
           A
       ),	(
           A
       ),	(
           A
       ),	(
           A
       ),	(
           A
       ),	
       )       :       str							=						config_and_inputs
       A       :       Dict							=						{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
       return config, inputs_dict







@require_tf
class   _lowercase						(							a		,					a		,					unittest.TestCase				):
   _UpperCamelCase       		=   (
       (
           TFDebertaVaModel,
           TFDebertaVaForMaskedLM,
           TFDebertaVaForQuestionAnswering,
           TFDebertaVaForSequenceClassification,
           TFDebertaVaForTokenClassification,
       )
       if is_tf_available()
       else ()
   )
   _UpperCamelCase       		=   (
       {
           """feature-extraction""": TFDebertaVaModel,
           """fill-mask""": TFDebertaVaForMaskedLM,
           """question-answering""": TFDebertaVaForQuestionAnswering,
           """text-classification""": TFDebertaVaForSequenceClassification,
           """token-classification""": TFDebertaVaForTokenClassification,
           """zero-shot""": TFDebertaVaForSequenceClassification,
       }
       if is_tf_available()
       else {}
   )

   _UpperCamelCase       		=   False
   _UpperCamelCase       		=   False


   def 					snake_case				( self					):
       A       :       Tuple							=						TFDebertaVaModelTester(self					)
       A       :       Optional[int]							=						ConfigTester(self    ,   config_class=_UpperCAmelCase    ,   hidden_size=37					)


   def 					snake_case				( self					):
       self.config_tester.run_common_tests()


   def 					snake_case				( self					):
       A       :       Any							=						self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*_UpperCAmelCase					)


   def 					snake_case				( self					):
       A       :       str							=						self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_masked_lm(*_UpperCAmelCase					)


   def 					snake_case				( self					):
       A       :       List[Any]							=						self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_question_answering(*_UpperCAmelCase					)


   def 					snake_case				( self					):
       A       :       Optional[Any]							=						self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_sequence_classification(*_UpperCAmelCase					)


   def 					snake_case				( self					):
       A       :       int							=						self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_token_classification(*_UpperCAmelCase					)


   @slow
   def 					snake_case				( self					):
       A       :       List[str]							=						TFDebertaVaModel.from_pretrained('''kamalkraj/deberta-v2-xlarge'''					)
       self.assertIsNotNone(_UpperCAmelCase					)







@require_tf
class   _lowercase						(							unittest.TestCase				):


   @unittest.skip(reason='''Model not available yet'''					)
   def 					snake_case				( self					):
       pass


   @slow
   def 					snake_case				( self					):
       A       :       Union[str, Any]							=						TFDebertaVaModel.from_pretrained('''kamalkraj/deberta-v2-xlarge'''					)
       A       :       int							=						tf.constant([[0, 31_414, 232, 328, 740, 1_140, 12_695, 69, 46_078, 1_588, 2]]					)
       A       :       Dict							=						tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]					)
       A       :       int							=						model(_UpperCAmelCase    ,   attention_mask=_UpperCAmelCase					)[0]

       A       :       Any							=						tf.constant(
           [[[0.2356, 0.1948, 0.0369], [-0.1063, 0.3586, -0.5152], [-0.6399, -0.0259, -0.2525]]]					)
       tf.debugging.assert_near(output[:, 1:4, 1:4]    ,   _UpperCAmelCase    ,   atol=1E-4					)







'''simple docstring'''






snake_case_     =	[
    9_99,
    8_00,
    7_99,
    6_00,
    5_99,
    5_00,
    4_00,
    3_99,
    3_77,
    3_55,
    3_33,
    3_11,
    2_88,
    2_66,
    2_44,
    2_22,
    2_00,
    1_99,
    1_77,
    1_55,
    1_33,
    1_11,
    88,
    66,
    44,
    22,
    0,
]

snake_case_     =	[
    9_99,
    9_76,
    9_52,
    9_28,
    9_05,
    8_82,
    8_58,
    8_57,
    8_10,
    7_62,
    7_15,
    7_14,
    5_72,
    4_29,
    4_28,
    2_86,
    2_85,
    2_38,
    1_90,
    1_43,
    1_42,
    1_18,
    95,
    71,
    47,
    24,
    0,
]

snake_case_     =	[
    9_99,
    9_88,
    9_77,
    9_66,
    9_55,
    9_44,
    9_33,
    9_22,
    9_11,
    9_00,
    8_99,
    8_79,
    8_59,
    8_40,
    8_20,
    8_00,
    7_99,
    7_66,
    7_33,
    7_00,
    6_99,
    6_50,
    6_00,
    5_99,
    5_00,
    4_99,
    4_00,
    3_99,
    3_50,
    3_00,
    2_99,
    2_66,
    2_33,
    2_00,
    1_99,
    1_79,
    1_59,
    1_40,
    1_20,
    1_00,
    99,
    88,
    77,
    66,
    55,
    44,
    33,
    22,
    11,
    0,
]

snake_case_     =	[
    9_99,
    9_95,
    9_92,
    9_89,
    9_85,
    9_81,
    9_78,
    9_75,
    9_71,
    9_67,
    9_64,
    9_61,
    9_57,
    9_56,
    9_51,
    9_47,
    9_42,
    9_37,
    9_33,
    9_28,
    9_23,
    9_19,
    9_14,
    9_13,
    9_08,
    9_03,
    8_97,
    8_92,
    8_87,
    8_81,
    8_76,
    8_71,
    8_70,
    8_64,
    8_58,
    8_52,
    8_46,
    8_40,
    8_34,
    8_28,
    8_27,
    8_20,
    8_13,
    8_06,
    7_99,
    7_92,
    7_85,
    7_84,
    7_77,
    7_70,
    7_63,
    7_56,
    7_49,
    7_42,
    7_41,
    7_33,
    7_24,
    7_16,
    7_07,
    6_99,
    6_98,
    6_88,
    6_77,
    6_66,
    6_56,
    6_55,
    6_45,
    6_34,
    6_23,
    6_13,
    6_12,
    5_98,
    5_84,
    5_70,
    5_69,
    5_55,
    5_41,
    5_27,
    5_26,
    5_05,
    4_84,
    4_83,
    4_62,
    4_40,
    4_39,
    3_96,
    3_95,
    3_52,
    3_51,
    3_08,
    3_07,
    2_64,
    2_63,
    2_20,
    2_19,
    1_76,
    1_32,
    88,
    44,
    0,
]

snake_case_     =	[
    9_99,
    9_97,
    9_95,
    9_92,
    9_90,
    9_88,
    9_86,
    9_84,
    9_81,
    9_79,
    9_77,
    9_75,
    9_72,
    9_70,
    9_68,
    9_66,
    9_64,
    9_61,
    9_59,
    9_57,
    9_56,
    9_54,
    9_51,
    9_49,
    9_46,
    9_44,
    9_41,
    9_39,
    9_36,
    9_34,
    9_31,
    9_29,
    9_26,
    9_24,
    9_21,
    9_19,
    9_16,
    9_14,
    9_13,
    9_10,
    9_07,
    9_05,
    9_02,
    8_99,
    8_96,
    8_93,
    8_91,
    8_88,
    8_85,
    8_82,
    8_79,
    8_77,
    8_74,
    8_71,
    8_70,
    8_67,
    8_64,
    8_61,
    8_58,
    8_55,
    8_52,
    8_49,
    8_46,
    8_43,
    8_40,
    8_37,
    8_34,
    8_31,
    8_28,
    8_27,
    8_24,
    8_21,
    8_17,
    8_14,
    8_11,
    8_08,
    8_04,
    8_01,
    7_98,
    7_95,
    7_91,
    7_88,
    7_85,
    7_84,
    7_80,
    7_77,
    7_74,
    7_70,
    7_66,
    7_63,
    7_60,
    7_56,
    7_52,
    7_49,
    7_46,
    7_42,
    7_41,
    7_37,
    7_33,
    7_30,
    7_26,
    7_22,
    7_18,
    7_14,
    7_10,
    7_07,
    7_03,
    6_99,
    6_98,
    6_94,
    6_90,
    6_85,
    6_81,
    6_77,
    6_73,
    6_69,
    6_64,
    6_60,
    6_56,
    6_55,
    6_50,
    6_46,
    6_41,
    6_36,
    6_32,
    6_27,
    6_22,
    6_18,
    6_13,
    6_12,
    6_07,
    6_02,
    5_96,
    5_91,
    5_86,
    5_80,
    5_75,
    5_70,
    5_69,
    5_63,
    5_57,
    5_51,
    5_45,
    5_39,
    5_33,
    5_27,
    5_26,
    5_19,
    5_12,
    5_05,
    4_98,
    4_91,
    4_84,
    4_83,
    4_74,
    4_66,
    4_57,
    4_49,
    4_40,
    4_39,
    4_28,
    4_18,
    4_07,
    3_96,
    3_95,
    3_81,
    3_66,
    3_52,
    3_51,
    3_30,
    3_08,
    3_07,
    2_86,
    2_64,
    2_63,
    2_42,
    2_20,
    2_19,
    1_76,
    1_75,
    1_32,
    1_31,
    88,
    44,
    0,
]

snake_case_     =	[
    9_99,
    9_91,
    9_82,
    9_74,
    9_66,
    9_58,
    9_50,
    9_41,
    9_33,
    9_25,
    9_16,
    9_08,
    9_00,
    8_99,
    8_74,
    8_50,
    8_25,
    8_00,
    7_99,
    7_00,
    6_00,
    5_00,
    4_00,
    3_00,
    2_00,
    1_00,
    0,
]

snake_case_     =	[
    9_99,
    9_92,
    9_85,
    9_78,
    9_71,
    9_64,
    9_57,
    9_49,
    9_42,
    9_35,
    9_28,
    9_21,
    9_14,
    9_07,
    9_00,
    8_99,
    8_79,
    8_59,
    8_40,
    8_20,
    8_00,
    7_99,
    7_66,
    7_33,
    7_00,
    6_99,
    6_50,
    6_00,
    5_99,
    5_00,
    4_99,
    4_00,
    3_99,
    3_00,
    2_99,
    2_00,
    1_99,
    1_00,
    99,
    0,
]

snake_case_     =	[
    9_99,
    9_96,
    9_92,
    9_89,
    9_85,
    9_82,
    9_79,
    9_75,
    9_72,
    9_68,
    9_65,
    9_61,
    9_58,
    9_55,
    9_51,
    9_48,
    9_44,
    9_41,
    9_38,
    9_34,
    9_31,
    9_27,
    9_24,
    9_20,
    9_17,
    9_14,
    9_10,
    9_07,
    9_03,
    9_00,
    8_99,
    8_91,
    8_84,
    8_76,
    8_69,
    8_61,
    8_53,
    8_46,
    8_38,
    8_30,
    8_23,
    8_15,
    8_08,
    8_00,
    7_99,
    7_88,
    7_77,
    7_66,
    7_55,
    7_44,
    7_33,
    7_22,
    7_11,
    7_00,
    6_99,
    6_88,
    6_77,
    6_66,
    6_55,
    6_44,
    6_33,
    6_22,
    6_11,
    6_00,
    5_99,
    5_85,
    5_71,
    5_57,
    5_42,
    5_28,
    5_14,
    5_00,
    4_99,
    4_85,
    4_71,
    4_57,
    4_42,
    4_28,
    4_14,
    4_00,
    3_99,
    3_79,
    3_59,
    3_40,
    3_20,
    3_00,
    2_99,
    2_79,
    2_59,
    2_40,
    2_20,
    2_00,
    1_99,
    1_66,
    1_33,
    1_00,
    99,
    66,
    33,
    0,
]
