





'''simple docstring'''

import unittest

from transformers import DebertaVaConfig, 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 (
        DebertaVaForMaskedLM,
        DebertaVaForMultipleChoice,
        DebertaVaForQuestionAnswering,
        DebertaVaForSequenceClassification,
        DebertaVaForTokenClassification,
        DebertaVaModel,
    )
    from transformers.models.deberta_va.modeling_deberta_va import DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST







class __a			( _snake_case      ):





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

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							parent
      __SCREAMING_SNAKE_CASE   				=							batch_size
      __SCREAMING_SNAKE_CASE   				=							seq_length
      __SCREAMING_SNAKE_CASE   				=							is_training
      __SCREAMING_SNAKE_CASE   				=							use_input_mask
      __SCREAMING_SNAKE_CASE   				=							use_token_type_ids
      __SCREAMING_SNAKE_CASE   				=							use_labels
      __SCREAMING_SNAKE_CASE   				=							vocab_size
      __SCREAMING_SNAKE_CASE   				=							hidden_size
      __SCREAMING_SNAKE_CASE   				=							num_hidden_layers
      __SCREAMING_SNAKE_CASE   				=							num_attention_heads
      __SCREAMING_SNAKE_CASE   				=							intermediate_size
      __SCREAMING_SNAKE_CASE   				=							hidden_act
      __SCREAMING_SNAKE_CASE   				=							hidden_dropout_prob
      __SCREAMING_SNAKE_CASE   				=							attention_probs_dropout_prob
      __SCREAMING_SNAKE_CASE   				=							max_position_embeddings
      __SCREAMING_SNAKE_CASE   				=							type_vocab_size
      __SCREAMING_SNAKE_CASE   				=							type_sequence_label_size
      __SCREAMING_SNAKE_CASE   				=							initializer_range
      __SCREAMING_SNAKE_CASE   				=							num_labels
      __SCREAMING_SNAKE_CASE   				=							num_choices
      __SCREAMING_SNAKE_CASE   				=							relative_attention
      __SCREAMING_SNAKE_CASE   				=							position_biased_input
      __SCREAMING_SNAKE_CASE   				=							pos_att_type
      __SCREAMING_SNAKE_CASE   				=							scope





   def   UpperCAmelCase__  (       self					:      Dict     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							ids_tensor([self.batch_size, self.seq_length]					,self.vocab_size     )

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

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

      __SCREAMING_SNAKE_CASE   				=							None
      __SCREAMING_SNAKE_CASE   				=							None
      __SCREAMING_SNAKE_CASE   				=							None
      if self.use_labels:
         __SCREAMING_SNAKE_CASE   				=							ids_tensor([self.batch_size]					,self.type_sequence_label_size     )
         __SCREAMING_SNAKE_CASE   				=							ids_tensor([self.batch_size, self.seq_length]					,self.num_labels     )
         __SCREAMING_SNAKE_CASE   				=							ids_tensor([self.batch_size]					,self.num_choices     )

      __SCREAMING_SNAKE_CASE   				=							self.get_config()

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





   def   UpperCAmelCase__  (       self					:      Tuple     ):

      '''simple docstring'''

      return 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					,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   UpperCAmelCase__  (       self					:      Tuple					,lowerCamelCase					:      Tuple     ):

      '''simple docstring'''

      self.parent.assertListEqual(list(result.loss.size()     )					,[]     )





   def   UpperCAmelCase__  (       self					:      Dict					,lowerCamelCase					:      int					,lowerCamelCase					:      List[str]					,lowerCamelCase					:      Optional[Any]					,lowerCamelCase					:      Optional[int]					,lowerCamelCase					:      str					,lowerCamelCase					:      List[Any]					,lowerCamelCase					:      int     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							DebertaVaModel(config=lowerCamelCase     )
      model.to(lowerCamelCase     )
      model.eval()
      __SCREAMING_SNAKE_CASE   				=							model(lowerCamelCase					,attention_mask=lowerCamelCase					,token_type_ids=lowerCamelCase     )[0]
      __SCREAMING_SNAKE_CASE   				=							model(lowerCamelCase					,token_type_ids=lowerCamelCase     )[0]
      __SCREAMING_SNAKE_CASE   				=							model(lowerCamelCase     )[0]

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





   def   UpperCAmelCase__  (       self					:      Optional[Any]					,lowerCamelCase					:      Dict					,lowerCamelCase					:      int					,lowerCamelCase					:      List[str]					,lowerCamelCase					:      Union[str, Any]					,lowerCamelCase					:      List[str]					,lowerCamelCase					:      Union[str, Any]					,lowerCamelCase					:      Dict     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							DebertaVaForMaskedLM(config=lowerCamelCase     )
      model.to(lowerCamelCase     )
      model.eval()
      __SCREAMING_SNAKE_CASE   				=							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   UpperCAmelCase__  (       self					:      str					,lowerCamelCase					:      Dict					,lowerCamelCase					:      Optional[int]					,lowerCamelCase					:      Any					,lowerCamelCase					:      str					,lowerCamelCase					:      str					,lowerCamelCase					:      Dict					,lowerCamelCase					:      List[Any]     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							self.num_labels
      __SCREAMING_SNAKE_CASE   				=							DebertaVaForSequenceClassification(lowerCamelCase     )
      model.to(lowerCamelCase     )
      model.eval()
      __SCREAMING_SNAKE_CASE   				=							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   UpperCAmelCase__  (       self					:      Union[str, Any]					,lowerCamelCase					:      Dict					,lowerCamelCase					:      List[Any]					,lowerCamelCase					:      int					,lowerCamelCase					:      Dict					,lowerCamelCase					:      List[Any]					,lowerCamelCase					:      Optional[int]					,lowerCamelCase					:      Union[str, Any]     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							self.num_labels
      __SCREAMING_SNAKE_CASE   				=							DebertaVaForTokenClassification(config=lowerCamelCase     )
      model.to(lowerCamelCase     )
      model.eval()
      __SCREAMING_SNAKE_CASE   				=							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   UpperCAmelCase__  (       self					:      Union[str, Any]					,lowerCamelCase					:      List[str]					,lowerCamelCase					:      Any					,lowerCamelCase					:      Union[str, Any]					,lowerCamelCase					:      Optional[Any]					,lowerCamelCase					:      Any					,lowerCamelCase					:      Optional[int]					,lowerCamelCase					:      Tuple     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							DebertaVaForQuestionAnswering(config=lowerCamelCase     )
      model.to(lowerCamelCase     )
      model.eval()
      __SCREAMING_SNAKE_CASE   				=							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   UpperCAmelCase__  (       self					:      Dict					,lowerCamelCase					:      int					,lowerCamelCase					:      Tuple					,lowerCamelCase					:      List[str]					,lowerCamelCase					:      int					,lowerCamelCase					:      Optional[Any]					,lowerCamelCase					:      Optional[int]					,lowerCamelCase					:      int     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							DebertaVaForMultipleChoice(config=lowerCamelCase     )
      model.to(lowerCamelCase     )
      model.eval()
      __SCREAMING_SNAKE_CASE   				=							input_ids.unsqueeze(1     ).expand(-1					,self.num_choices					,-1     ).contiguous()
      __SCREAMING_SNAKE_CASE   				=							token_type_ids.unsqueeze(1     ).expand(-1					,self.num_choices					,-1     ).contiguous()
      __SCREAMING_SNAKE_CASE   				=							input_mask.unsqueeze(1     ).expand(-1					,self.num_choices					,-1     ).contiguous()
      __SCREAMING_SNAKE_CASE   				=							model(
          lowerCamelCase					,attention_mask=lowerCamelCase					,token_type_ids=lowerCamelCase					,labels=lowerCamelCase					,)
      self.parent.assertEqual(result.logits.shape					,(self.batch_size, self.num_choices)     )





   def   UpperCAmelCase__  (       self					:      Optional[int]     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							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
      )				,  
      )   				=							config_and_inputs
      __SCREAMING_SNAKE_CASE   				=							{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
      return config, inputs_dict







@require_torch
class __a			( _snake_case, _snake_case, unittest.TestCase      ):
   __UpperCamelCase :			str						   =						(
       (
           DebertaVaModel,
           DebertaVaForMaskedLM,
           DebertaVaForSequenceClassification,
           DebertaVaForTokenClassification,
           DebertaVaForQuestionAnswering,
           DebertaVaForMultipleChoice,
       )
       if is_torch_available()
       else ()
   )
   __UpperCamelCase :			Dict						   =						(
       {
           'feature-extraction': DebertaVaModel,
           'fill-mask': DebertaVaForMaskedLM,
           'question-answering': DebertaVaForQuestionAnswering,
           'text-classification': DebertaVaForSequenceClassification,
           'token-classification': DebertaVaForTokenClassification,
           'zero-shot': DebertaVaForSequenceClassification,
       }
       if is_torch_available()
       else {}
   )

   __UpperCamelCase :			Any						   =						True
   __UpperCamelCase :			List[str]						   =						False
   __UpperCamelCase :			Optional[Any]						   =						False
   __UpperCamelCase :			List[str]						   =						False
   __UpperCamelCase :			Tuple						   =						False





   def   UpperCAmelCase__  (       self					:      List[Any]     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							DebertaVaModelTester(self     )
      __SCREAMING_SNAKE_CASE   				=							ConfigTester(self					,config_class=lowerCamelCase					,hidden_size=37     )





   def   UpperCAmelCase__  (       self					:      List[Any]     ):

      '''simple docstring'''

      self.config_tester.run_common_tests()





   def   UpperCAmelCase__  (       self					:      List[str]     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_deberta_model(*lowerCamelCase     )





   def   UpperCAmelCase__  (       self					:      Optional[Any]     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_deberta_for_sequence_classification(*lowerCamelCase     )





   def   UpperCAmelCase__  (       self					:      Optional[Any]     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_deberta_for_masked_lm(*lowerCamelCase     )





   def   UpperCAmelCase__  (       self					:      List[Any]     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_deberta_for_question_answering(*lowerCamelCase     )





   def   UpperCAmelCase__  (       self					:      List[str]     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_deberta_for_token_classification(*lowerCamelCase     )





   def   UpperCAmelCase__  (       self					:      Optional[Any]     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_deberta_for_multiple_choice(*lowerCamelCase     )





   @slow
   def   UpperCAmelCase__  (       self					:      List[Any]     ):

      '''simple docstring'''

      for model_name in DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
         __SCREAMING_SNAKE_CASE   				=							DebertaVaModel.from_pretrained(lowerCamelCase     )
         self.assertIsNotNone(lowerCamelCase     )







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





   @unittest.skip(reason="""Model not available yet"""     )
   def   UpperCAmelCase__  (       self					:      Optional[int]     ):

      '''simple docstring'''

      pass





   @slow
   def   UpperCAmelCase__  (       self					:      Tuple     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							DebertaVaModel.from_pretrained("""microsoft/deberta-v2-xlarge"""     )

      __SCREAMING_SNAKE_CASE   				=							torch.tensor([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]]     )
      __SCREAMING_SNAKE_CASE   				=							torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]     )
      with torch.no_grad():
         __SCREAMING_SNAKE_CASE   				=							model(lowerCamelCase					,attention_mask=lowerCamelCase     )[0]
      # compare the actual values for a slice.
      __SCREAMING_SNAKE_CASE   				=							torch.tensor(
          [[[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]]]     )
      self.assertTrue(torch.allclose(output[:, 1:4, 1:4]					,lowerCamelCase					,atol=1E-4     )					,f"""{output[:, 1:4, 1:4]}"""     )









'''simple docstring'''
from __future__ import annotations

from math import pi, sqrt


def      a (     __a					,   __a  )    ->      tuple:



					'''simple docstring'''






					if inductance <= 0:
										raise ValueError('''Inductance cannot be 0 or negative'''  )

					elif capacitance <= 0:
										raise ValueError('''Capacitance cannot be 0 or negative'''  )

					else:
										return (
										    "Resonant frequency",
										    float(1 / (2 * pi * (sqrt(inductance * capacitance  )))  ),
										)


if __name__ == "__main__":
		import doctest

		doctest.testmod()