






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							:





		'''simple docstring'''



		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 ,    ):
						SCREAMING_SNAKE_CASE_   :	Any													=   parent
						SCREAMING_SNAKE_CASE_   :	List[str]													=   batch_size
						SCREAMING_SNAKE_CASE_   :	str													=   seq_length
						SCREAMING_SNAKE_CASE_   :	Tuple													=   is_training
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   use_input_mask
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   use_token_type_ids
						SCREAMING_SNAKE_CASE_   :	Tuple													=   use_labels
						SCREAMING_SNAKE_CASE_   :	int													=   vocab_size
						SCREAMING_SNAKE_CASE_   :	Tuple													=   hidden_size
						SCREAMING_SNAKE_CASE_   :	List[str]													=   num_hidden_layers
						SCREAMING_SNAKE_CASE_   :	Dict													=   num_attention_heads
						SCREAMING_SNAKE_CASE_   :	Dict													=   intermediate_size
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   hidden_act
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   hidden_dropout_prob
						SCREAMING_SNAKE_CASE_   :	Tuple													=   attention_probs_dropout_prob
						SCREAMING_SNAKE_CASE_   :	Dict													=   max_position_embeddings
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   type_vocab_size
						SCREAMING_SNAKE_CASE_   :	List[str]													=   type_sequence_label_size
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   initializer_range
						SCREAMING_SNAKE_CASE_   :	Dict													=   num_labels
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   num_choices
						SCREAMING_SNAKE_CASE_   :	int													=   relative_attention
						SCREAMING_SNAKE_CASE_   :	Tuple													=   position_biased_input
						SCREAMING_SNAKE_CASE_   :	List[str]													=   pos_att_type
						SCREAMING_SNAKE_CASE_   :	str													=   scope


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   ids_tensor([self.batch_size, self.seq_length] ,    self.vocab_size       )

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

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

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

						SCREAMING_SNAKE_CASE_   :	str													=   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__       ):
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   TFDebertaVaModel(config=UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}

						SCREAMING_SNAKE_CASE_   :	str													=   [input_ids, input_mask]
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   model(UpperCamelCase__       )

						SCREAMING_SNAKE_CASE_   :	str													=   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__       ):
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   TFDebertaVaForMaskedLM(config=UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	Tuple													=   {
						    'input_ids': input_ids,
						    'attention_mask': input_mask,
						    'token_type_ids': token_type_ids,
						}
						SCREAMING_SNAKE_CASE_   :	Optional[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__       ):
						SCREAMING_SNAKE_CASE_   :	Any													=   self.num_labels
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   TFDebertaVaForSequenceClassification(config=UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	str													=   {
						    'input_ids': input_ids,
						    'attention_mask': input_mask,
						    'token_type_ids': token_type_ids,
						}

						SCREAMING_SNAKE_CASE_   :	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__       ):
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   self.num_labels
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   TFDebertaVaForTokenClassification(config=UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	int													=   {
						    'input_ids': input_ids,
						    'attention_mask': input_mask,
						    'token_type_ids': token_type_ids,
						}
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   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__       ):
						SCREAMING_SNAKE_CASE_   :	List[str]													=   TFDebertaVaForQuestionAnswering(config=UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	Dict													=   {
						    'input_ids': input_ids,
						    'attention_mask': input_mask,
						    'token_type_ids': token_type_ids,
						}

						SCREAMING_SNAKE_CASE_   :	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       ):
						SCREAMING_SNAKE_CASE_   :	Dict													=   self.prepare_config_and_inputs()
						(
						    (
						    SCREAMING_SNAKE_CASE_
						)							,       (
						    SCREAMING_SNAKE_CASE_
						)							,       (
						    SCREAMING_SNAKE_CASE_
						)							,       (
						    SCREAMING_SNAKE_CASE_
						)							,       (
						    SCREAMING_SNAKE_CASE_
						)							,       (
						    SCREAMING_SNAKE_CASE_
						)							,       (
						    SCREAMING_SNAKE_CASE_
						)							,       
						)   :	Tuple													=   config_and_inputs
						SCREAMING_SNAKE_CASE_   :	int													=   {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
						return config, inputs_dict






@require_tf
class 							__a							(  __A ,	__A ,	unittest.TestCase						):





		'''simple docstring'''



		UpperCAmelCase__      :				Optional[int]				    =						(
		    (
		        TFDebertaVaModel,
		        TFDebertaVaForMaskedLM,
		        TFDebertaVaForQuestionAnswering,
		        TFDebertaVaForSequenceClassification,
		        TFDebertaVaForTokenClassification,
		    )
		    if is_tf_available()
		    else ()
		)
		UpperCAmelCase__      :				Optional[Any]				    =						(
		    {
		        """feature-extraction""": TFDebertaVaModel,
		        """fill-mask""": TFDebertaVaForMaskedLM,
		        """question-answering""": TFDebertaVaForQuestionAnswering,
		        """text-classification""": TFDebertaVaForSequenceClassification,
		        """token-classification""": TFDebertaVaForTokenClassification,
		        """zero-shot""": TFDebertaVaForSequenceClassification,
		    }
		    if is_tf_available()
		    else {}
		)

		UpperCAmelCase__      :				Optional[int]				    =						False
		UpperCAmelCase__      :				str				    =						False


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Dict													=   TFDebertaVaModelTester(self       )
						SCREAMING_SNAKE_CASE_   :	List[str]													=   ConfigTester(self ,    config_class=UpperCamelCase__ ,    hidden_size=37       )


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


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Tuple													=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*UpperCamelCase__       )


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_lm(*UpperCamelCase__       )


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	str													=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*UpperCamelCase__       )


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	int													=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*UpperCamelCase__       )


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_token_classification(*UpperCamelCase__       )






		@slow
		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Tuple													=   TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'       )
						self.assertIsNotNone(UpperCamelCase__       )






@require_tf
class 							__a							(  unittest.TestCase						):





		'''simple docstring'''



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






		@slow
		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	int													=   TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'       )
						SCREAMING_SNAKE_CASE_   :	int													=   tf.constant([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]       )
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]       )
						SCREAMING_SNAKE_CASE_   :	List[str]													=   model(UpperCamelCase__ ,    attention_mask=UpperCamelCase__       )[0]

						SCREAMING_SNAKE_CASE_   :	List[str]													=   tf.constant(
						    [[[0.23_56, 0.19_48, 0.03_69], [-0.10_63, 0.35_86, -0.51_52], [-0.63_99, -0.02_59, -0.25_25]]]       )
						tf.debugging.assert_near(output[:, 1:4, 1:4] ,    UpperCamelCase__ ,    atol=1E-4       )







import math



def 					_lowerCamelCase(			lowerCAmelCase__				:		float    ,    lowerCAmelCase__				:		float      ):





				'''simple docstring'''







				return math.pow(lowerCAmelCase__    ,    2      ) - a



def 					_lowerCamelCase(			lowerCAmelCase__				:		float      ):





				'''simple docstring'''







				return 2 * x



def 					_lowerCamelCase(			lowerCAmelCase__				:		float      ):





				'''simple docstring'''







				SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   2.0

				while start <= a:
								SCREAMING_SNAKE_CASE_   :	str													=   math.pow(lowerCAmelCase__    ,    2      )

				return start



def 					_lowerCamelCase(			lowerCAmelCase__				:		float    ,    lowerCAmelCase__				:		int = 9999    ,    lowerCAmelCase__				:		float = 0.00_000_000_000_001      ):





				'''simple docstring'''







				if a < 0:
								raise ValueError('math domain error'      )

				SCREAMING_SNAKE_CASE_   :	Optional[int]													=   get_initial_point(lowerCAmelCase__      )

				for _ in range(lowerCAmelCase__      ):
								SCREAMING_SNAKE_CASE_   :	Tuple													=   value
								SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   value - fx(lowerCAmelCase__    ,    lowerCAmelCase__      ) / fx_derivative(lowerCAmelCase__      )
								if abs(prev_value - value      ) < tolerance:
												return value

				return value


if __name__ == "__main__":
				from doctest import testmod

				testmod()