





'''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				:			int				,lowerCamelCase				:			List[str]				,lowerCamelCase				:			Optional[int]=13				,lowerCamelCase				:			Optional[Any]=7				,lowerCamelCase				:			List[Any]=True				,lowerCamelCase				:			int=True				,lowerCamelCase				:			Dict=True				,lowerCamelCase				:			Optional[int]=True				,lowerCamelCase				:			Optional[int]=99				,lowerCamelCase				:			Tuple=32				,lowerCamelCase				:			List[str]=5				,lowerCamelCase				:			int=4				,lowerCamelCase				:			Optional[Any]=37				,lowerCamelCase				:			List[Any]="gelu"				,lowerCamelCase				:			Any=0.1				,lowerCamelCase				:			int=0.1				,lowerCamelCase				:			Optional[Any]=512				,lowerCamelCase				:			Optional[int]=16				,lowerCamelCase				:			str=2				,lowerCamelCase				:			Union[str, Any]=0.02				,lowerCamelCase				:			int=False				,lowerCamelCase				:			Dict=True				,lowerCamelCase				:			Any="None"				,lowerCamelCase				:			Optional[int]=3				,lowerCamelCase				:			List[str]=4				,lowerCamelCase				:			Union[str, Any]=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				:			Optional[int]    ):

      '''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				:			List[Any]				,lowerCamelCase				:			List[str]    ):

      '''simple docstring'''

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





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

      '''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				:			Union[str, Any]				,lowerCamelCase				:			Any				,lowerCamelCase				:			List[Any]				,lowerCamelCase				:			List[Any]				,lowerCamelCase				:			Any				,lowerCamelCase				:			List[str]				,lowerCamelCase				:			Any				,lowerCamelCase				:			Optional[Any]    ):

      '''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				:			List[Any]				,lowerCamelCase				:			Optional[int]				,lowerCamelCase				:			List[Any]				,lowerCamelCase				:			Any				,lowerCamelCase				:			Optional[int]				,lowerCamelCase				:			int				,lowerCamelCase				:			Optional[Any]				,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				:			Any				,lowerCamelCase				:			Dict				,lowerCamelCase				:			Optional[int]				,lowerCamelCase				:			List[Any]				,lowerCamelCase				:			Tuple				,lowerCamelCase				:			Dict				,lowerCamelCase				:			List[Any]				,lowerCamelCase				:			Optional[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				:			int				,lowerCamelCase				:			Optional[int]				,lowerCamelCase				:			Tuple				,lowerCamelCase				:			Optional[int]				,lowerCamelCase				:			Optional[int]				,lowerCamelCase				:			Dict				,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				:			Union[str, Any]				,lowerCamelCase				:			int				,lowerCamelCase				:			Dict				,lowerCamelCase				:			Optional[Any]				,lowerCamelCase				:			int				,lowerCamelCase				:			int				,lowerCamelCase				:			Dict				,lowerCamelCase				:			str    ):

      '''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				:			List[str]    ):

      '''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   : Any	      =	(
       (
           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   : Optional[Any]	      =	True
   __UpperCamelCase   : str	      =	False
   __UpperCamelCase   : Dict	      =	False
   __UpperCamelCase   : int	      =	False
   __UpperCamelCase   : Union[str, Any]	      =	False





   def      UpperCAmelCase__     (					self				:			Optional[int]    ):

      '''simple docstring'''

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





   def      UpperCAmelCase__     (					self				:			Dict    ):

      '''simple docstring'''

      self.config_tester.run_common_tests()





   def      UpperCAmelCase__     (					self				:			List[Any]    ):

      '''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				:			List[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				:			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				:			int    ):

      '''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				:			List[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				:			Tuple    ):

      '''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				:			Dict    ):

      '''simple docstring'''

      pass





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

      '''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

import bisect

def 						__magic_name__       (							__UpperCAmelCase							,	__UpperCAmelCase							,	__UpperCAmelCase = 0							,	__UpperCAmelCase = -1      )						->					int:

   '''simple docstring'''







   if hi < 0:
      __SCREAMING_SNAKE_CASE      							=       len(__UpperCAmelCase      )

   while lo < hi:
      __SCREAMING_SNAKE_CASE      							=       lo + (hi - lo) // 2
      if sorted_collection[mid] < item:
         __SCREAMING_SNAKE_CASE      							=       mid + 1
      else:
         __SCREAMING_SNAKE_CASE      							=       mid

   return lo

def 						__magic_name__       (							__UpperCAmelCase							,	__UpperCAmelCase							,	__UpperCAmelCase = 0							,	__UpperCAmelCase = -1      )						->					int:

   '''simple docstring'''







   if hi < 0:
      __SCREAMING_SNAKE_CASE      							=       len(__UpperCAmelCase      )

   while lo < hi:
      __SCREAMING_SNAKE_CASE      							=       lo + (hi - lo) // 2
      if sorted_collection[mid] <= item:
         __SCREAMING_SNAKE_CASE      							=       mid + 1
      else:
         __SCREAMING_SNAKE_CASE      							=       mid

   return lo

def 						__magic_name__       (							__UpperCAmelCase							,	__UpperCAmelCase							,	__UpperCAmelCase = 0							,	__UpperCAmelCase = -1      )						->					None:

   '''simple docstring'''







   sorted_collection.insert(bisect_left(__UpperCAmelCase							,	__UpperCAmelCase							,	__UpperCAmelCase							,	__UpperCAmelCase      )							,	__UpperCAmelCase      )

def 						__magic_name__       (							__UpperCAmelCase							,	__UpperCAmelCase							,	__UpperCAmelCase = 0							,	__UpperCAmelCase = -1      )						->					None:

   '''simple docstring'''







   sorted_collection.insert(bisect_right(__UpperCAmelCase							,	__UpperCAmelCase							,	__UpperCAmelCase							,	__UpperCAmelCase      )							,	__UpperCAmelCase      )

def 						__magic_name__       (							__UpperCAmelCase							,	__UpperCAmelCase      )						->					int | None:

   '''simple docstring'''







   __SCREAMING_SNAKE_CASE      							=       0
   __SCREAMING_SNAKE_CASE      							=       len(__UpperCAmelCase      ) - 1

   while left <= right:
      __SCREAMING_SNAKE_CASE      							=       left + (right - left) // 2
      __SCREAMING_SNAKE_CASE      							=       sorted_collection[midpoint]
      if current_item == item:
         return midpoint
      elif item < current_item:
         __SCREAMING_SNAKE_CASE      							=       midpoint - 1
      else:
         __SCREAMING_SNAKE_CASE      							=       midpoint + 1
   return None

def 						__magic_name__       (							__UpperCAmelCase							,	__UpperCAmelCase      )						->					int | None:

   '''simple docstring'''







   __SCREAMING_SNAKE_CASE      							=       bisect.bisect_left(__UpperCAmelCase							,	__UpperCAmelCase      )
   if index != len(__UpperCAmelCase      ) and sorted_collection[index] == item:
      return index
   return None

def 						__magic_name__       (							__UpperCAmelCase							,	__UpperCAmelCase							,	__UpperCAmelCase							,	__UpperCAmelCase      )						->					int | None:

   '''simple docstring'''







   if right < left:
      return None

   __SCREAMING_SNAKE_CASE      							=       left + (right - left) // 2

   if sorted_collection[midpoint] == item:
      return midpoint
   elif sorted_collection[midpoint] > item:
      return binary_search_by_recursion(__UpperCAmelCase							,	__UpperCAmelCase							,	__UpperCAmelCase							,	midpoint - 1      )
   else:
      return binary_search_by_recursion(__UpperCAmelCase							,	__UpperCAmelCase							,	midpoint + 1							,	__UpperCAmelCase      )


if __name__ == "__main__":
    a        =						input("Enter numbers separated by comma:\n").strip()
    a        =						sorted(int(item) for item in user_input.split(","))
    a        =						int(input("Enter a single number to be found in the list:\n"))
    a        =						binary_search(collection, target)
    if result is None:
        print(F'''{target} was not found in {collection}.''')
    else:
        print(F'''{target} was found at position {result} in {collection}.''')





