


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 					lowerCAmelCase_ :




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






         """simple docstring"""






         a__ :List[str]						  =    parent
         a__ :Tuple						  =    batch_size
         a__ :Any						  =    seq_length
         a__ :List[Any]						  =    is_training
         a__ :str						  =    use_input_mask
         a__ :int						  =    use_token_type_ids
         a__ :Dict						  =    use_labels
         a__ :Optional[int]						  =    vocab_size
         a__ :Any						  =    hidden_size
         a__ :str						  =    num_hidden_layers
         a__ :List[Any]						  =    num_attention_heads
         a__ :List[str]						  =    intermediate_size
         a__ :Tuple						  =    hidden_act
         a__ :int						  =    hidden_dropout_prob
         a__ :Optional[int]						  =    attention_probs_dropout_prob
         a__ :Optional[Any]						  =    max_position_embeddings
         a__ :Dict						  =    type_vocab_size
         a__ :str						  =    type_sequence_label_size
         a__ :Optional[Any]						  =    initializer_range
         a__ :List[str]						  =    num_labels
         a__ :Optional[Any]						  =    num_choices
         a__ :Dict						  =    relative_attention
         a__ :Any						  =    position_biased_input
         a__ :int						  =    pos_att_type
         a__ :Optional[Any]						  =    scope




      def  _snake_case					(	self						:   Tuple						)      ->Optional[Any]:






         """simple docstring"""






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

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

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

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

         a__ :Tuple						  =    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=__A   ,     )

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




      def  _snake_case					(	self						:   str   ,     __A						:   Any   ,     __A						:   str   ,     __A						:   Tuple   ,     __A						:   Tuple   ,     __A						:   Union[str, Any]   ,     __A						:   Optional[int]   ,     __A						:   List[str]						)      ->Any:






         """simple docstring"""






         a__ :Optional[int]						  =    TFDebertaVaModel(config=__A						)
         a__ :List[Any]						  =    {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

         a__ :List[Any]						  =    [input_ids, input_mask]
         a__ :Optional[Any]						  =    model(__A						)

         a__ :str						  =    model(__A						)

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




      def  _snake_case					(	self						:   Any   ,     __A						:   str   ,     __A						:   Union[str, Any]   ,     __A						:   Optional[Any]   ,     __A						:   Optional[int]   ,     __A						:   Optional[Any]   ,     __A						:   Any   ,     __A						:   Dict						)      ->Union[str, Any]:






         """simple docstring"""






         a__ :int						  =    TFDebertaVaForMaskedLM(config=__A						)
         a__ :Union[str, Any]						  =    {
             "input_ids": input_ids,
             "attention_mask": input_mask,
             "token_type_ids": token_type_ids,
         }
         a__ :Dict						  =    model(__A						)
         self.parent.assertEqual(result.logits.shape   ,     (self.batch_size, self.seq_length, self.vocab_size)						)




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






         """simple docstring"""






         a__ :Tuple						  =    self.num_labels
         a__ :Union[str, Any]						  =    TFDebertaVaForSequenceClassification(config=__A						)
         a__ :Optional[int]						  =    {
             "input_ids": input_ids,
             "attention_mask": input_mask,
             "token_type_ids": token_type_ids,
         }

         a__ :int						  =    model(__A						)
         self.parent.assertEqual(result.logits.shape   ,     (self.batch_size, self.num_labels)						)




      def  _snake_case					(	self						:   Union[str, Any]   ,     __A						:   Union[str, Any]   ,     __A						:   List[str]   ,     __A						:   Optional[Any]   ,     __A						:   Union[str, Any]   ,     __A						:   Optional[int]   ,     __A						:   List[Any]   ,     __A						:   int						)      ->int:






         """simple docstring"""






         a__ :Optional[Any]						  =    self.num_labels
         a__ :Optional[int]						  =    TFDebertaVaForTokenClassification(config=__A						)
         a__ :Optional[Any]						  =    {
             "input_ids": input_ids,
             "attention_mask": input_mask,
             "token_type_ids": token_type_ids,
         }
         a__ :Dict						  =    model(__A						)
         self.parent.assertEqual(result.logits.shape   ,     (self.batch_size, self.seq_length, self.num_labels)						)




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






         """simple docstring"""






         a__ :Tuple						  =    TFDebertaVaForQuestionAnswering(config=__A						)
         a__ :Tuple						  =    {
             "input_ids": input_ids,
             "attention_mask": input_mask,
             "token_type_ids": token_type_ids,
         }

         a__ :Dict						  =    model(__A						)
         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						:   Union[str, Any]						)      ->int:






         """simple docstring"""






         a__ :str						  =    self.prepare_config_and_inputs()
         (
             a__  
         ) :int						  =    config_and_inputs
         a__ :List[Any]						  =    {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
         return config, inputs_dict






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

      lowerCamelCase_         =     False
      lowerCamelCase_         =     False




      def  _snake_case					(	self						:   Optional[Any]						)      ->Any:






         """simple docstring"""






         a__ :Dict						  =    TFDebertaVaModelTester(self						)
         a__ :Dict						  =    ConfigTester(self   ,     config_class=__A   ,     hidden_size=37						)




      def  _snake_case					(	self						:   List[str]						)      ->int:






         """simple docstring"""






         self.config_tester.run_common_tests()




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






         """simple docstring"""






         a__ :List[Any]						  =    self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*__A						)




      def  _snake_case					(	self						:   List[str]						)      ->Optional[int]:






         """simple docstring"""






         a__ :str						  =    self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_masked_lm(*__A						)




      def  _snake_case					(	self						:   Dict						)      ->List[Any]:






         """simple docstring"""






         a__ :Any						  =    self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_question_answering(*__A						)




      def  _snake_case					(	self						:   List[str]						)      ->List[str]:






         """simple docstring"""






         a__ :List[Any]						  =    self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_sequence_classification(*__A						)




      def  _snake_case					(	self						:   Dict						)      ->Union[str, Any]:






         """simple docstring"""






         a__ :List[str]						  =    self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_token_classification(*__A						)






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






         """simple docstring"""






         a__ :Dict						  =    TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"						)
         self.assertIsNotNone(__A						)






@require_tf
class 					lowerCAmelCase_ (       unittest.TestCase):




      @unittest.skip(reason="Model not available yet"						)
      def  _snake_case					(	self						:   Dict						)      ->int:






         """simple docstring"""






         pass






      @slow
      def  _snake_case					(	self						:   Union[str, Any]						)      ->List[Any]:






         """simple docstring"""






         a__ :Union[str, Any]						  =    TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"						)
         a__ :Optional[Any]						  =    tf.constant([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]						)
         a__ :Tuple						  =    tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]						)
         a__ :Dict						  =    model(__A   ,     attention_mask=__A						)[0]

         a__ :Any						  =    tf.constant(
             [[[0.2_356, 0.1_948, 0.0_369], [-0.1_063, 0.3_586, -0.5_152], [-0.6_399, -0.0_259, -0.2_525]]]						)
         tf.debugging.assert_near(output[:, 1:4, 1:4]   ,     __A   ,     atol=1E-4						)






def 				lowerCamelCase__	(      a	:   int	,  a	:   int				)    ->	Any:





			"""simple docstring"""
			# "extended trapezoidal rule"
			# int(f) = dx/2 * (f1 + 2f2 + ... + fn)
			a__ :Optional[int]						  =    (boundary[1] - boundary[0]) / steps
			a__ :str						  =    boundary[0]
			a__ :Optional[int]						  =    boundary[1]
			a__ :str						  =    make_points(a	,  a	,  a				)
			a__ :Any						  =    0.0
			y += (h / 2.0) * f(a				)
			for i in x_i:
						# print(i)
						y += h * f(a				)
			y += (h / 2.0) * f(a				)
			return y


def 				lowerCamelCase__	(      a	:   Any	,  a	:   str	,  a	:   Dict				)    ->	int:





			"""simple docstring"""
			a__ :Union[str, Any]						  =    a + h
			while x < (b - h):
						yield x
						a__ :str						  =    x + h


def 				lowerCamelCase__	(      a	:   Optional[int]				)    ->	List[Any]:  # enter your function here





			"""simple docstring"""
			a__ :Tuple						  =    (x - 0) * (x - 0)
			return y


def 				lowerCamelCase__	(      )    ->	List[str]:





			"""simple docstring"""
			a__ :Optional[Any]						  =    0.0  # Lower bound of integration
			a__ :Optional[Any]						  =    1.0  # Upper bound of integration
			a__ :List[str]						  =    1_0.0  # define number of steps or resolution
			a__ :int						  =    [a, b]  # define boundary of integration
			a__ :str						  =    method_a(a	,  a				)
			print(F'''y = {y}'''				)


if __name__ == "__main__":
		main()


