





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



				def 					UpperCAmelCase_		(			self     ):
									__A	:						int       =				ids_tensor([self.batch_size, self.seq_length]     ,					self.vocab_size     )

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

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

									__A	:						Dict       =				None
									__A	:						Optional[int]       =				None
									__A	:						Optional[Any]       =				None
									if self.use_labels:
														__A	:						List[str]       =				ids_tensor([self.batch_size]     ,					self.type_sequence_label_size     )
														__A	:						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 					UpperCAmelCase_		(			self     ,					_A     ,					_A     ,					_A     ,					_A     ,					_A     ,					_A     ,					_A     ):
									__A	:						List[Any]       =				TFDebertaVaModel(config=_A     )
									__A	:						str       =				{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}

									__A	:						Optional[int]       =				[input_ids, input_mask]
									__A	:						Dict       =				model(_A     )

									__A	:						int       =				model(_A     )

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



				def 					UpperCAmelCase_		(			self     ,					_A     ,					_A     ,					_A     ,					_A     ,					_A     ,					_A     ,					_A     ):
									__A	:						int       =				TFDebertaVaForMaskedLM(config=_A     )
									__A	:						str       =				{
									    '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 					UpperCAmelCase_		(			self     ,					_A     ,					_A     ,					_A     ,					_A     ,					_A     ,					_A     ,					_A     ):
									__A	:						Any       =				self.num_labels
									__A	:						str       =				TFDebertaVaForSequenceClassification(config=_A     )
									__A	:						Optional[int]       =				{
									    'input_ids': input_ids,
									    'attention_mask': input_mask,
									    'token_type_ids': token_type_ids,
									}

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



				def 					UpperCAmelCase_		(			self     ,					_A     ,					_A     ,					_A     ,					_A     ,					_A     ,					_A     ,					_A     ):
									__A	:						str       =				self.num_labels
									__A	:						Tuple       =				TFDebertaVaForTokenClassification(config=_A     )
									__A	:						Dict       =				{
									    '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.seq_length, self.num_labels)     )



				def 					UpperCAmelCase_		(			self     ,					_A     ,					_A     ,					_A     ,					_A     ,					_A     ,					_A     ,					_A     ):
									__A	:						Optional[Any]       =				TFDebertaVaForQuestionAnswering(config=_A     )
									__A	:						Tuple       =				{
									    'input_ids': input_ids,
									    'attention_mask': input_mask,
									    'token_type_ids': token_type_ids,
									}

									__A	:						Optional[Any]       =				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 					UpperCAmelCase_		(			self     ):
									__A	:						Optional[Any]       =				self.prepare_config_and_inputs()
									(
									    (
									    __A
									)    ,				(
									    __A
									)    ,				(
									    __A
									)    ,				(
									    __A
									)    ,				(
									    __A
									)    ,				(
									    __A
									)    ,				(
									    __A
									)    ,				
									)	:						Optional[int]       =				config_and_inputs
									__A	:						str       =				{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
									return config, inputs_dict





@require_tf
class 						_A(					snake_case__				, snake_case__				, unittest.TestCase   ):


				"""simple docstring"""


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

				UpperCamelCase    :  List[Any]					    =	False
				UpperCamelCase    :  List[Any]					    =	False



				def 					UpperCAmelCase_		(			self     ):
									__A	:						Tuple       =				TFDebertaVaModelTester(self     )
									__A	:						int       =				ConfigTester(self     ,					config_class=_A     ,					hidden_size=37     )



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



				def 					UpperCAmelCase_		(			self     ):
									__A	:						List[str]       =				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*_A     )



				def 					UpperCAmelCase_		(			self     ):
									__A	:						Any       =				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_masked_lm(*_A     )



				def 					UpperCAmelCase_		(			self     ):
									__A	:						str       =				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_question_answering(*_A     )



				def 					UpperCAmelCase_		(			self     ):
									__A	:						int       =				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_sequence_classification(*_A     )



				def 					UpperCAmelCase_		(			self     ):
									__A	:						List[Any]       =				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_token_classification(*_A     )





				@slow
				def 					UpperCAmelCase_		(			self     ):
									__A	:						Dict       =				TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'     )
									self.assertIsNotNone(_A     )





@require_tf
class 						_A(					unittest.TestCase   ):


				"""simple docstring"""


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





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

									__A	:						List[str]       =				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]     ,					_A     ,					atol=1e-4     )











from __future__ import annotations







def  _SCREAMING_SNAKE_CASE				(   a					,						a					,						a  )      ->      float:
					if days_between_payments <= 0:
										raise ValueError('days_between_payments must be > 0'  )
					if daily_interest_rate < 0:
										raise ValueError('daily_interest_rate must be >= 0'  )
					if principal <= 0:
										raise ValueError('principal must be > 0'  )
					return principal * daily_interest_rate * days_between_payments







def  _SCREAMING_SNAKE_CASE				(   a					,						a					,						a					,						)      ->      float:
					if number_of_compounding_periods <= 0:
										raise ValueError('number_of_compounding_periods must be > 0'  )
					if nominal_annual_interest_rate_percentage < 0:
										raise ValueError('nominal_annual_interest_rate_percentage must be >= 0'  )
					if principal <= 0:
										raise ValueError('principal must be > 0'  )

					return principal * (
					    (1 + nominal_annual_interest_rate_percentage) ** number_of_compounding_periods
					    - 1
					)







def  _SCREAMING_SNAKE_CASE				(   a					,						a					,						a					,						)      ->      float:
					if number_of_years <= 0:
										raise ValueError('number_of_years must be > 0'  )
					if nominal_annual_percentage_rate < 0:
										raise ValueError('nominal_annual_percentage_rate must be >= 0'  )
					if principal <= 0:
										raise ValueError('principal must be > 0'  )

					return compound_interest(
					    a					,						nominal_annual_percentage_rate / 3_65					,						number_of_years * 3_65  )


if __name__ == "__main__":
				import doctest

				doctest.testmod()




