





'''simple docstring'''






import unittest

from transformers import DebertaConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch

					from transformers import (
					    DebertaForMaskedLM,
					    DebertaForQuestionAnswering,
					    DebertaForSequenceClassification,
					    DebertaForTokenClassification,
					    DebertaModel,
					)
					from transformers.models.deberta.modeling_deberta import DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST
class 		lowerCamelCase	(   _A							):



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



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

			lowerCAmelCase  :     Any       						= None
			if self.use_input_mask:
					lowerCAmelCase  :     Optional[Any]       						= ids_tensor([self.batch_size, self.seq_length]		,   vocab_size=2						)

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

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

			lowerCAmelCase  :     Optional[Any]       						= self.get_config()

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



	def 	_lowerCamelCase     ( self						):
			return DebertaConfig(
			    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		,   initializer_range=self.initializer_range		,   relative_attention=self.relative_attention		,   position_biased_input=self.position_biased_input		,   pos_att_type=self.pos_att_type		,   )



	def 	_lowerCamelCase     ( self						):
			lowerCAmelCase  :     Tuple       						= self.get_config()
			lowerCAmelCase  :     Tuple       						= 300
			return config



	def 	_lowerCamelCase     ( self		,   a_						):
			self.parent.assertListEqual(list(result.loss.size()						)		,   []						)



	def 	_lowerCamelCase     ( self		,   a_		,   a_		,   a_		,   a_		,   a_		,   a_		,   a_						):
			lowerCAmelCase  :     Optional[Any]       						= DebertaModel(config=lowerCamelCase_						)
			model.to(lowerCamelCase_						)
			model.eval()
			lowerCAmelCase  :     List[Any]       						= model(lowerCamelCase_		,   attention_mask=lowerCamelCase_		,   token_type_ids=lowerCamelCase_						)[0]
			lowerCAmelCase  :     Tuple       						= model(lowerCamelCase_		,   token_type_ids=lowerCamelCase_						)[0]
			lowerCAmelCase  :     int       						= model(lowerCamelCase_						)[0]

			self.parent.assertListEqual(list(sequence_output.size()						)		,   [self.batch_size, self.seq_length, self.hidden_size]						)



	def 	_lowerCamelCase     ( self		,   a_		,   a_		,   a_		,   a_		,   a_		,   a_		,   a_						):
			lowerCAmelCase  :     Union[str, Any]       						= DebertaForMaskedLM(config=lowerCamelCase_						)
			model.to(lowerCamelCase_						)
			model.eval()
			lowerCAmelCase  :     str       						= model(lowerCamelCase_		,   attention_mask=lowerCamelCase_		,   token_type_ids=lowerCamelCase_		,   labels=lowerCamelCase_						)

			self.parent.assertEqual(result.logits.shape		,   (self.batch_size, self.seq_length, self.vocab_size)						)



	def 	_lowerCamelCase     ( self		,   a_		,   a_		,   a_		,   a_		,   a_		,   a_		,   a_						):
			lowerCAmelCase  :     Tuple       						= self.num_labels
			lowerCAmelCase  :     Optional[Any]       						= DebertaForSequenceClassification(lowerCamelCase_						)
			model.to(lowerCamelCase_						)
			model.eval()
			lowerCAmelCase  :     Optional[Any]       						= model(lowerCamelCase_		,   attention_mask=lowerCamelCase_		,   token_type_ids=lowerCamelCase_		,   labels=lowerCamelCase_						)
			self.parent.assertListEqual(list(result.logits.size()						)		,   [self.batch_size, self.num_labels]						)
			self.check_loss_output(lowerCamelCase_						)



	def 	_lowerCamelCase     ( self		,   a_		,   a_		,   a_		,   a_		,   a_		,   a_		,   a_						):
			lowerCAmelCase  :     Any       						= self.num_labels
			lowerCAmelCase  :     Optional[int]       						= DebertaForTokenClassification(config=lowerCamelCase_						)
			model.to(lowerCamelCase_						)
			model.eval()
			lowerCAmelCase  :     Tuple       						= model(lowerCamelCase_		,   attention_mask=lowerCamelCase_		,   token_type_ids=lowerCamelCase_		,   labels=lowerCamelCase_						)
			self.parent.assertEqual(result.logits.shape		,   (self.batch_size, self.seq_length, self.num_labels)						)



	def 	_lowerCamelCase     ( self		,   a_		,   a_		,   a_		,   a_		,   a_		,   a_		,   a_						):
			lowerCAmelCase  :     Optional[int]       						= DebertaForQuestionAnswering(config=lowerCamelCase_						)
			model.to(lowerCamelCase_						)
			model.eval()
			lowerCAmelCase  :     str       						= model(
			    lowerCamelCase_		,   attention_mask=lowerCamelCase_		,   token_type_ids=lowerCamelCase_		,   start_positions=lowerCamelCase_		,   end_positions=lowerCamelCase_		,   )
			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 	_lowerCamelCase     ( self						):
			lowerCAmelCase  :     str       						= self.prepare_config_and_inputs()
			(
			    lowerCAmelCase   
			)  :     List[str]       						= config_and_inputs
			lowerCAmelCase  :     Optional[int]       						= {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
			return config, inputs_dict






@require_torch
class 		lowerCamelCase	(   _A   , _A   , unittest.TestCase							):
	snake_case_   = (
	    (
	        DebertaModel,
	        DebertaForMaskedLM,
	        DebertaForSequenceClassification,
	        DebertaForTokenClassification,
	        DebertaForQuestionAnswering,
	    )
	    if is_torch_available()
	    else ()
	)
	snake_case_   = (
	    {
	        '''feature-extraction''': DebertaModel,
	        '''fill-mask''': DebertaForMaskedLM,
	        '''question-answering''': DebertaForQuestionAnswering,
	        '''text-classification''': DebertaForSequenceClassification,
	        '''token-classification''': DebertaForTokenClassification,
	        '''zero-shot''': DebertaForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)

	snake_case_   = True
	snake_case_   = False
	snake_case_   = False
	snake_case_   = False
	snake_case_   = False



	def 	_lowerCamelCase     ( self						):
			lowerCAmelCase  :     Tuple       						= DebertaModelTester(self						)
			lowerCAmelCase  :     Any       						= ConfigTester(self		,   config_class=lowerCamelCase_		,   hidden_size=37						)



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



	def 	_lowerCamelCase     ( self						):
			lowerCAmelCase  :     str       						= self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_deberta_model(*lowerCamelCase_						)



	def 	_lowerCamelCase     ( self						):
			lowerCAmelCase  :     Any       						= self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_deberta_for_sequence_classification(*lowerCamelCase_						)



	def 	_lowerCamelCase     ( self						):
			lowerCAmelCase  :     List[Any]       						= self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_deberta_for_masked_lm(*lowerCamelCase_						)



	def 	_lowerCamelCase     ( self						):
			lowerCAmelCase  :     Union[str, Any]       						= self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_deberta_for_question_answering(*lowerCamelCase_						)



	def 	_lowerCamelCase     ( self						):
			lowerCAmelCase  :     Optional[int]       						= self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_deberta_for_token_classification(*lowerCamelCase_						)





	@slow
	def 	_lowerCamelCase     ( self						):



			for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
					lowerCAmelCase  :     Optional[Any]       						= DebertaModel.from_pretrained(lowerCamelCase_						)
					self.assertIsNotNone(lowerCamelCase_						)






@require_torch
@require_sentencepiece
@require_tokenizers
class 		lowerCamelCase	(   unittest.TestCase							):



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





	@slow
	def 	_lowerCamelCase     ( self						):
			lowerCAmelCase  :     str       						= DebertaModel.from_pretrained("microsoft/deberta-base"						)

			lowerCAmelCase  :     int       						= torch.tensor([[0, 31_414, 232, 328, 740, 1_140, 12_695, 69, 46_078, 1_588, 2]]						)
			lowerCAmelCase  :     List[str]       						= torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]						)
			with torch.no_grad():
					lowerCAmelCase  :     Optional[int]       						= model(lowerCamelCase_		,   attention_mask=lowerCamelCase_						)[0]
			# compare the actual values for a slice.
			lowerCAmelCase  :     List[str]       						= torch.tensor(
			    [[[-0.5986, -0.8055, -0.8462], [1.4484, -0.9348, -0.8059], [0.3123, 0.0032, -1.4131]]]						)
			self.assertTrue(torch.allclose(output[:, 1:4, 1:4]		,   lowerCamelCase_		,   atol=1e-4						)		,   F'''{output[:, 1:4, 1:4]}'''						)




'''simple docstring'''

def __UpperCamelCase( _A       :					float	,      _A       :					list[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__				:					str 					=	sum(
       cash_flow / ((1 + discount_rate) ** i) for i, cash_flow in enumerate(_A     )     )
   return round(_A	,      ndigits=2     )


if __name__ == "__main__":
  import doctest

  doctest.testmod()




