


'''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  __magic_name__							(		lowercase__    ):






       def __init__(      self  ,							snake_case  ,							snake_case=1_3  ,							snake_case=7  ,							snake_case=True  ,							snake_case=True  ,							snake_case=True  ,							snake_case=True  ,							snake_case=9_9  ,							snake_case=3_2  ,							snake_case=5  ,							snake_case=4  ,							snake_case=3_7  ,							snake_case="gelu"  ,							snake_case=0.1  ,							snake_case=0.1  ,							snake_case=5_1_2  ,							snake_case=1_6  ,							snake_case=2  ,							snake_case=0.02  ,							snake_case=False  ,							snake_case=True  ,							snake_case="None"  ,							snake_case=3  ,							snake_case=4  ,							snake_case=None  ,							)						->  Tuple:




          '''simple docstring'''
          _UpperCAmelCase       :       int							   =parent
          _UpperCAmelCase       :       str							   =batch_size
          _UpperCAmelCase       :       Dict							   =seq_length
          _UpperCAmelCase       :       Optional[int]							   =is_training
          _UpperCAmelCase       :       Union[str, Any]							   =use_input_mask
          _UpperCAmelCase       :       Optional[int]							   =use_token_type_ids
          _UpperCAmelCase       :       Tuple							   =use_labels
          _UpperCAmelCase       :       Optional[int]							   =vocab_size
          _UpperCAmelCase       :       str							   =hidden_size
          _UpperCAmelCase       :       Dict							   =num_hidden_layers
          _UpperCAmelCase       :       Dict							   =num_attention_heads
          _UpperCAmelCase       :       List[Any]							   =intermediate_size
          _UpperCAmelCase       :       int							   =hidden_act
          _UpperCAmelCase       :       Dict							   =hidden_dropout_prob
          _UpperCAmelCase       :       str							   =attention_probs_dropout_prob
          _UpperCAmelCase       :       List[str]							   =max_position_embeddings
          _UpperCAmelCase       :       str							   =type_vocab_size
          _UpperCAmelCase       :       Any							   =type_sequence_label_size
          _UpperCAmelCase       :       Union[str, Any]							   =initializer_range
          _UpperCAmelCase       :       Union[str, Any]							   =num_labels
          _UpperCAmelCase       :       List[str]							   =num_choices
          _UpperCAmelCase       :       Optional[Any]							   =relative_attention
          _UpperCAmelCase       :       Dict							   =position_biased_input
          _UpperCAmelCase       :       Optional[int]							   =pos_att_type
          _UpperCAmelCase       :       List[Any]							   =scope






       def       lowerCAmelCase		(      self)						->  int:




          '''simple docstring'''
          _UpperCAmelCase       :       Tuple							   =ids_tensor([self.batch_size, self.seq_length]  ,							self.vocab_size)

          _UpperCAmelCase       :       int							   =None
          if self.use_input_mask:
             _UpperCAmelCase       :       Union[str, Any]							   =ids_tensor([self.batch_size, self.seq_length]  ,							vocab_size=2)

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

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

          _UpperCAmelCase       :       List[str]							   =self.get_config()

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






       def       lowerCAmelCase		(      self)						->  Tuple:




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




          '''simple docstring'''
          _UpperCAmelCase       :       Union[str, Any]							   =self.get_config()
          _UpperCAmelCase       :       Optional[int]							   =3_0_0
          return config






       def       lowerCAmelCase		(      self  ,							snake_case)						->  int:




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






       def       lowerCAmelCase		(      self  ,							snake_case  ,							snake_case  ,							snake_case  ,							snake_case  ,							snake_case  ,							snake_case  ,							snake_case)						->  List[Any]:




          '''simple docstring'''
          _UpperCAmelCase       :       List[str]							   =DebertaModel(config=_a)
          model.to(_a)
          model.eval()
          _UpperCAmelCase       :       Tuple							   =model(_a  ,							attention_mask=_a  ,							token_type_ids=_a)[0]
          _UpperCAmelCase       :       Optional[int]							   =model(_a  ,							token_type_ids=_a)[0]
          _UpperCAmelCase       :       Tuple							   =model(_a)[0]

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






       def       lowerCAmelCase		(      self  ,							snake_case  ,							snake_case  ,							snake_case  ,							snake_case  ,							snake_case  ,							snake_case  ,							snake_case)						->  Optional[Any]:




          '''simple docstring'''
          _UpperCAmelCase       :       Any							   =DebertaForMaskedLM(config=_a)
          model.to(_a)
          model.eval()
          _UpperCAmelCase       :       str							   =model(_a  ,							attention_mask=_a  ,							token_type_ids=_a  ,							labels=_a)

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






       def       lowerCAmelCase		(      self  ,							snake_case  ,							snake_case  ,							snake_case  ,							snake_case  ,							snake_case  ,							snake_case  ,							snake_case)						->  List[Any]:




          '''simple docstring'''
          _UpperCAmelCase       :       List[Any]							   =self.num_labels
          _UpperCAmelCase       :       List[str]							   =DebertaForSequenceClassification(_a)
          model.to(_a)
          model.eval()
          _UpperCAmelCase       :       str							   =model(_a  ,							attention_mask=_a  ,							token_type_ids=_a  ,							labels=_a)
          self.parent.assertListEqual(list(result.logits.size())  ,							[self.batch_size, self.num_labels])
          self.check_loss_output(_a)






       def       lowerCAmelCase		(      self  ,							snake_case  ,							snake_case  ,							snake_case  ,							snake_case  ,							snake_case  ,							snake_case  ,							snake_case)						->  int:




          '''simple docstring'''
          _UpperCAmelCase       :       Tuple							   =self.num_labels
          _UpperCAmelCase       :       List[str]							   =DebertaForTokenClassification(config=_a)
          model.to(_a)
          model.eval()
          _UpperCAmelCase       :       List[str]							   =model(_a  ,							attention_mask=_a  ,							token_type_ids=_a  ,							labels=_a)
          self.parent.assertEqual(result.logits.shape  ,							(self.batch_size, self.seq_length, self.num_labels))






       def       lowerCAmelCase		(      self  ,							snake_case  ,							snake_case  ,							snake_case  ,							snake_case  ,							snake_case  ,							snake_case  ,							snake_case)						->  Union[str, Any]:




          '''simple docstring'''
          _UpperCAmelCase       :       Dict							   =DebertaForQuestionAnswering(config=_a)
          model.to(_a)
          model.eval()
          _UpperCAmelCase       :       int							   =model(
              _a  ,							attention_mask=_a  ,							token_type_ids=_a  ,							start_positions=_a  ,							end_positions=_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       lowerCAmelCase		(      self)						->  List[Any]:




          '''simple docstring'''
          _UpperCAmelCase       :       Any							   =self.prepare_config_and_inputs()
          (
              _UpperCAmelCase  
          )       :       str							   =config_and_inputs
          _UpperCAmelCase       :       List[Any]							   ={'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
          return config, inputs_dict






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

       UpperCAmelCase										=True
       UpperCAmelCase										=False
       UpperCAmelCase										=False
       UpperCAmelCase										=False
       UpperCAmelCase										=False






       def       lowerCAmelCase		(      self)						->  Tuple:




          '''simple docstring'''
          _UpperCAmelCase       :       Any							   =DebertaModelTester(self)
          _UpperCAmelCase       :       Any							   =ConfigTester(self  ,							config_class=_a  ,							hidden_size=3_7)






       def       lowerCAmelCase		(      self)						->  str:




          '''simple docstring'''
          self.config_tester.run_common_tests()






       def       lowerCAmelCase		(      self)						->  str:




          '''simple docstring'''
          _UpperCAmelCase       :       Dict							   =self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_deberta_model(*_a)






       def       lowerCAmelCase		(      self)						->  Tuple:




          '''simple docstring'''
          _UpperCAmelCase       :       str							   =self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_deberta_for_sequence_classification(*_a)






       def       lowerCAmelCase		(      self)						->  Dict:




          '''simple docstring'''
          _UpperCAmelCase       :       Tuple							   =self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_deberta_for_masked_lm(*_a)






       def       lowerCAmelCase		(      self)						->  str:




          '''simple docstring'''
          _UpperCAmelCase       :       List[Any]							   =self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_deberta_for_question_answering(*_a)






       def       lowerCAmelCase		(      self)						->  List[str]:




          '''simple docstring'''
          _UpperCAmelCase       :       Tuple							   =self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_deberta_for_token_classification(*_a)






       @slow
       def       lowerCAmelCase		(      self)						->  Dict:




          '''simple docstring'''






          for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             _UpperCAmelCase       :       Dict							   =DebertaModel.from_pretrained(_a)
             self.assertIsNotNone(_a)






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






       @unittest.skip(reason='Model not available yet')
       def       lowerCAmelCase		(      self)						->  Union[str, Any]:




          '''simple docstring'''
          pass






       @slow
       def       lowerCAmelCase		(      self)						->  int:




          '''simple docstring'''
          _UpperCAmelCase       :       Optional[Any]							   =DebertaModel.from_pretrained('microsoft/deberta-base')

          _UpperCAmelCase       :       Optional[int]							   =torch.tensor([[0, 3_1_4_1_4, 2_3_2, 3_2_8, 7_4_0, 1_1_4_0, 1_2_6_9_5, 6_9, 4_6_0_7_8, 1_5_8_8, 2]])
          _UpperCAmelCase       :       Optional[Any]							   =torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
          with torch.no_grad():
             _UpperCAmelCase       :       Dict							   =model(_a  ,							attention_mask=_a)[0]
          # compare the actual values for a slice.
          _UpperCAmelCase       :       int							   =torch.tensor(
              [[[-0.59_86, -0.80_55, -0.84_62], [1.44_84, -0.93_48, -0.80_59], [0.31_23, 0.00_32, -1.41_31]]])
          self.assertTrue(torch.allclose(output[:, 1:4, 1:4]  ,							_a  ,							atol=1E-4)  ,							f"{output[:, 1:4, 1:4]}")





'''simple docstring'''






from string import ascii_uppercase

lowercase							={str(ord(c) - 55): c for c in ascii_uppercase}





def lowerCamelCase__      (						__lowerCamelCase	:							int	,   __lowerCamelCase	:							int							):







   '''simple docstring'''




   if isinstance(__lowerCamelCase	,   __lowerCamelCase							):
      raise TypeError('int() can\'t convert non-string with explicit base'							)
   if num < 0:
      raise ValueError('parameter must be positive int'							)
   if isinstance(__lowerCamelCase	,   __lowerCamelCase							):
      raise TypeError('\'str\' object cannot be interpreted as an integer'							)
   if isinstance(__lowerCamelCase	,   __lowerCamelCase							):
      raise TypeError('\'float\' object cannot be interpreted as an integer'							)
   if base in (0, 1):
      raise ValueError('base must be >= 2'							)
   if base > 3_6:
      raise ValueError('base must be <= 36'							)
   _UpperCAmelCase       :       Union[str, Any]							   =''
   _UpperCAmelCase       :       Optional[int]							   =0
   _UpperCAmelCase       :       str							   =0
   while div != 1:
      _UpperCAmelCase   ,	_UpperCAmelCase       :       int							   =divmod(__lowerCamelCase	,   __lowerCamelCase							)
      if base >= 1_1 and 9 < mod < 3_6:
         _UpperCAmelCase       :       str							   =ALPHABET_VALUES[str(__lowerCamelCase							)]
      else:
         _UpperCAmelCase       :       Any							   =str(__lowerCamelCase							)
      new_value += actual_value
      _UpperCAmelCase       :       Union[str, Any]							   =num // base
      _UpperCAmelCase       :       Dict							   =div
      if div == 0:
         return str(new_value[::-1]							)
      elif div == 1:
         new_value += str(__lowerCamelCase							)
         return str(new_value[::-1]							)

   return new_value[::-1]


if __name__ == "__main__":
 import doctest

 doctest.testmod()

 for base in range(2, 37):
  for num in range(1000):
   assert int(decimal_to_any(num, base), base) == num, (
       num,
       base,
       decimal_to_any(num, base),
       int(decimal_to_any(num, base), base),
   )

