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






       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_=5_12				,     UpperCamelCase_=16				,     UpperCamelCase_=2				,     UpperCamelCase_=0.0_2				,     UpperCamelCase_=False				,     UpperCamelCase_=True				,     UpperCamelCase_="None"				,     UpperCamelCase_=3				,     UpperCamelCase_=4				,     UpperCamelCase_=None				,     ):
              __UpperCAmelCase  :				int       				=		parent
              __UpperCAmelCase  :				Any       				=		batch_size
              __UpperCAmelCase  :				List[str]       				=		seq_length
              __UpperCAmelCase  :				Dict       				=		is_training
              __UpperCAmelCase  :				Optional[Any]       				=		use_input_mask
              __UpperCAmelCase  :				Optional[Any]       				=		use_token_type_ids
              __UpperCAmelCase  :				str       				=		use_labels
              __UpperCAmelCase  :				List[str]       				=		vocab_size
              __UpperCAmelCase  :				str       				=		hidden_size
              __UpperCAmelCase  :				List[str]       				=		num_hidden_layers
              __UpperCAmelCase  :				str       				=		num_attention_heads
              __UpperCAmelCase  :				Dict       				=		intermediate_size
              __UpperCAmelCase  :				Union[str, Any]       				=		hidden_act
              __UpperCAmelCase  :				str       				=		hidden_dropout_prob
              __UpperCAmelCase  :				Union[str, Any]       				=		attention_probs_dropout_prob
              __UpperCAmelCase  :				Union[str, Any]       				=		max_position_embeddings
              __UpperCAmelCase  :				List[str]       				=		type_vocab_size
              __UpperCAmelCase  :				List[Any]       				=		type_sequence_label_size
              __UpperCAmelCase  :				Optional[Any]       				=		initializer_range
              __UpperCAmelCase  :				int       				=		num_labels
              __UpperCAmelCase  :				Optional[Any]       				=		num_choices
              __UpperCAmelCase  :				Any       				=		relative_attention
              __UpperCAmelCase  :				str       				=		position_biased_input
              __UpperCAmelCase  :				Any       				=		pos_att_type
              __UpperCAmelCase  :				List[Any]       				=		scope






       def 			_snake_case						(      self      ):
              __UpperCAmelCase  :				Optional[Any]       				=		ids_tensor([self.batch_size, self.seq_length]				,     self.vocab_size      )

              __UpperCAmelCase  :				List[Any]       				=		None
              if self.use_input_mask:
                     __UpperCAmelCase  :				Union[str, Any]       				=		random_attention_mask([self.batch_size, self.seq_length]      )

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

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

              __UpperCAmelCase  :				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_      ):
              __UpperCAmelCase  :				List[Any]       				=		TFDebertaVaModel(config=UpperCamelCase_      )
              __UpperCAmelCase  :				Dict       				=		{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

              __UpperCAmelCase  :				int       				=		[input_ids, input_mask]
              __UpperCAmelCase  :				Any       				=		model(UpperCamelCase_      )

              __UpperCAmelCase  :				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_      ):
              __UpperCAmelCase  :				Union[str, Any]       				=		TFDebertaVaForMaskedLM(config=UpperCamelCase_      )
              __UpperCAmelCase  :				Optional[int]       				=		{
                  "input_ids": input_ids,
                  "attention_mask": input_mask,
                  "token_type_ids": token_type_ids,
              }
              __UpperCAmelCase  :				Any       				=		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_      ):
              __UpperCAmelCase  :				List[Any]       				=		self.num_labels
              __UpperCAmelCase  :				Any       				=		TFDebertaVaForSequenceClassification(config=UpperCamelCase_      )
              __UpperCAmelCase  :				List[str]       				=		{
                  "input_ids": input_ids,
                  "attention_mask": input_mask,
                  "token_type_ids": token_type_ids,
              }

              __UpperCAmelCase  :				Optional[Any]       				=		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_      ):
              __UpperCAmelCase  :				Union[str, Any]       				=		self.num_labels
              __UpperCAmelCase  :				str       				=		TFDebertaVaForTokenClassification(config=UpperCamelCase_      )
              __UpperCAmelCase  :				List[str]       				=		{
                  "input_ids": input_ids,
                  "attention_mask": input_mask,
                  "token_type_ids": token_type_ids,
              }
              __UpperCAmelCase  :				Dict       				=		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_      ):
              __UpperCAmelCase  :				Union[str, Any]       				=		TFDebertaVaForQuestionAnswering(config=UpperCamelCase_      )
              __UpperCAmelCase  :				Tuple       				=		{
                  "input_ids": input_ids,
                  "attention_mask": input_mask,
                  "token_type_ids": token_type_ids,
              }

              __UpperCAmelCase  :				Union[str, Any]       				=		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      ):
              __UpperCAmelCase  :				Tuple       				=		self.prepare_config_and_inputs()
              (
                  __UpperCAmelCase 
              )  :				int       				=		config_and_inputs
              __UpperCAmelCase  :				int       				=		{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
              return config, inputs_dict






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

       snake_case       :List[Any]				    =					False
       snake_case       :Optional[int]				    =					False






       def 			_snake_case						(      self      ):
              __UpperCAmelCase  :				List[Any]       				=		TFDebertaVaModelTester(self      )
              __UpperCAmelCase  :				Any       				=		ConfigTester(self				,     config_class=UpperCamelCase_				,     hidden_size=37      )






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






       def 			_snake_case						(      self      ):
              __UpperCAmelCase  :				int       				=		self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_model(*UpperCamelCase_      )






       def 			_snake_case						(      self      ):
              __UpperCAmelCase  :				Dict       				=		self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_masked_lm(*UpperCamelCase_      )






       def 			_snake_case						(      self      ):
              __UpperCAmelCase  :				Optional[int]       				=		self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_question_answering(*UpperCamelCase_      )






       def 			_snake_case						(      self      ):
              __UpperCAmelCase  :				Optional[int]       				=		self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_sequence_classification(*UpperCamelCase_      )






       def 			_snake_case						(      self      ):
              __UpperCAmelCase  :				Optional[Any]       				=		self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_for_token_classification(*UpperCamelCase_      )







       @slow
       def 			_snake_case						(      self      ):
              __UpperCAmelCase  :				Union[str, Any]       				=		TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"      )
              self.assertIsNotNone(UpperCamelCase_      )






@require_tf
class 		__A       (unittest.TestCase   ):






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







       @slow
       def 			_snake_case						(      self      ):
              __UpperCAmelCase  :				Any       				=		TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"      )
              __UpperCAmelCase  :				Optional[Any]       				=		tf.constant([[0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]]      )
              __UpperCAmelCase  :				Dict       				=		tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]      )
              __UpperCAmelCase  :				List[str]       				=		model(UpperCamelCase_				,     attention_mask=UpperCamelCase_      )[0]

              __UpperCAmelCase  :				Any       				=		tf.constant(
                  [[[0.2_3_5_6, 0.1_9_4_8, 0.0_3_6_9], [-0.1_0_6_3, 0.3_5_8_6, -0.5_1_5_2], [-0.6_3_9_9, -0.0_2_5_9, -0.2_5_2_5]]]      )
              tf.debugging.assert_near(output[:, 1:4, 1:4]				,     UpperCamelCase_				,     atol=1E-4      )







'''simple docstring'''




def _lowercase	(      lowerCamelCase__							,    lowerCamelCase__						)					->       float:





       """simple docstring"""


       if discount_rate < 0:
              raise ValueError("Discount rate cannot be negative"						)
       if not cash_flows:
              raise ValueError("Cash flows list cannot be empty"						)
       __UpperCAmelCase  :				Tuple       				=		sum(
           cash_flow / ((1 + discount_rate) ** i) for i, cash_flow in enumerate(lowerCamelCase__						)						)
       return round(lowerCamelCase__							,    ndigits=2						)


if __name__ == "__main__":
   import doctest

   doctest.testmod()






