

"""simple docstring"""






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        _lowercase					:







     def __init__(      self ,						UpperCamelCase_ ,						UpperCamelCase_=13 ,						UpperCamelCase_=7 ,						UpperCamelCase_=True ,						UpperCamelCase_=True ,						UpperCamelCase_=True ,						UpperCamelCase_=True ,						UpperCamelCase_=99 ,						UpperCamelCase_=32 ,						UpperCamelCase_=2 ,						UpperCamelCase_=4 ,						UpperCamelCase_=37 ,						UpperCamelCase_="gelu" ,						UpperCamelCase_=0.1 ,						UpperCamelCase_=0.1 ,						UpperCamelCase_=512 ,						UpperCamelCase_=16 ,						UpperCamelCase_=2 ,						UpperCamelCase_=0.0_2 ,						UpperCamelCase_=False ,						UpperCamelCase_=True ,						UpperCamelCase_="None" ,						UpperCamelCase_=3 ,						UpperCamelCase_=4 ,						UpperCamelCase_=None ,						):
      __magic_name__     =      parent
      __magic_name__     =      batch_size
      __magic_name__     =      seq_length
      __magic_name__     =      is_training
      __magic_name__     =      use_input_mask
      __magic_name__     =      use_token_type_ids
      __magic_name__     =      use_labels
      __magic_name__     =      vocab_size
      __magic_name__     =      hidden_size
      __magic_name__     =      num_hidden_layers
      __magic_name__     =      num_attention_heads
      __magic_name__     =      intermediate_size
      __magic_name__     =      hidden_act
      __magic_name__     =      hidden_dropout_prob
      __magic_name__     =      attention_probs_dropout_prob
      __magic_name__     =      max_position_embeddings
      __magic_name__     =      type_vocab_size
      __magic_name__     =      type_sequence_label_size
      __magic_name__     =      initializer_range
      __magic_name__     =      num_labels
      __magic_name__     =      num_choices
      __magic_name__     =      relative_attention
      __magic_name__     =      position_biased_input
      __magic_name__     =      pos_att_type
      __magic_name__     =      scope







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      ids_tensor([self.batch_size, self.seq_length] ,						self.vocab_size       )

      __magic_name__     =      None
      if self.use_input_mask:
       __magic_name__     =      random_attention_mask([self.batch_size, self.seq_length]       )

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

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

      __magic_name__     =      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=_lowercase ,						)

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







     def 	lowerCAmelCase__    (      self ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_       ):
      __magic_name__     =      TFDebertaVaModel(config=_lowercase       )
      __magic_name__     =      {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}

      __magic_name__     =      [input_ids, input_mask]
      __magic_name__     =      model(_lowercase       )

      __magic_name__     =      model(_lowercase       )

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







     def 	lowerCAmelCase__    (      self ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_       ):
      __magic_name__     =      TFDebertaVaForMaskedLM(config=_lowercase       )
      __magic_name__     =      {
          """input_ids""": input_ids,
          """attention_mask""": input_mask,
          """token_type_ids""": token_type_ids,
      }
      __magic_name__     =      model(_lowercase       )
      self.parent.assertEqual(result.logits.shape ,						(self.batch_size, self.seq_length, self.vocab_size)       )







     def 	lowerCAmelCase__    (      self ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_       ):
      __magic_name__     =      self.num_labels
      __magic_name__     =      TFDebertaVaForSequenceClassification(config=_lowercase       )
      __magic_name__     =      {
          """input_ids""": input_ids,
          """attention_mask""": input_mask,
          """token_type_ids""": token_type_ids,
      }

      __magic_name__     =      model(_lowercase       )
      self.parent.assertEqual(result.logits.shape ,						(self.batch_size, self.num_labels)       )







     def 	lowerCAmelCase__    (      self ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_       ):
      __magic_name__     =      self.num_labels
      __magic_name__     =      TFDebertaVaForTokenClassification(config=_lowercase       )
      __magic_name__     =      {
          """input_ids""": input_ids,
          """attention_mask""": input_mask,
          """token_type_ids""": token_type_ids,
      }
      __magic_name__     =      model(_lowercase       )
      self.parent.assertEqual(result.logits.shape ,						(self.batch_size, self.seq_length, self.num_labels)       )







     def 	lowerCAmelCase__    (      self ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_       ):
      __magic_name__     =      TFDebertaVaForQuestionAnswering(config=_lowercase       )
      __magic_name__     =      {
          """input_ids""": input_ids,
          """attention_mask""": input_mask,
          """token_type_ids""": token_type_ids,
      }

      __magic_name__     =      model(_lowercase       )
      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       ):
      __magic_name__     =      self.prepare_config_and_inputs()
      (
          __magic_name__		
      )     =      config_and_inputs
      __magic_name__     =      {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
      return config, inputs_dict


@require_tf
class        _lowercase					(     SCREAMING_SNAKE_CASE__   , SCREAMING_SNAKE_CASE__   , unittest.TestCase     ):
     _lowerCamelCase     =       (
         (
             TFDebertaVaModel,
             TFDebertaVaForMaskedLM,
             TFDebertaVaForQuestionAnswering,
             TFDebertaVaForSequenceClassification,
             TFDebertaVaForTokenClassification,
         )
         if is_tf_available()
         else ()
     )
     _lowerCamelCase     =       (
         {
             '''feature-extraction''': TFDebertaVaModel,
             '''fill-mask''': TFDebertaVaForMaskedLM,
             '''question-answering''': TFDebertaVaForQuestionAnswering,
             '''text-classification''': TFDebertaVaForSequenceClassification,
             '''token-classification''': TFDebertaVaForTokenClassification,
             '''zero-shot''': TFDebertaVaForSequenceClassification,
         }
         if is_tf_available()
         else {}
     )

     _lowerCamelCase     =       False
     _lowerCamelCase     =       False







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      TFDebertaVaModelTester(self       )
      __magic_name__     =      ConfigTester(self ,						config_class=_lowercase ,						hidden_size=37       )







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







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*_lowercase       )







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_masked_lm(*_lowercase       )







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_question_answering(*_lowercase       )







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_sequence_classification(*_lowercase       )







     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_token_classification(*_lowercase       )







     @slow
     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      TFDebertaVaModel.from_pretrained('''kamalkraj/deberta-v2-xlarge'''       )
      self.assertIsNotNone(_lowercase       )


@require_tf
class        _lowercase					(     unittest.TestCase     ):







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







     @slow
     def 	lowerCAmelCase__    (      self       ):
      __magic_name__     =      TFDebertaVaModel.from_pretrained('''kamalkraj/deberta-v2-xlarge'''       )
      __magic_name__     =      tf.constant([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]]       )
      __magic_name__     =      tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]       )
      __magic_name__     =      model(_lowercase ,						attention_mask=_lowercase       )[0]

      __magic_name__     =      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] ,						_lowercase ,						atol=1E-4       )





"""simple docstring"""






class        _lowercase					:







     def __init__(      self ,						UpperCamelCase_       ):
      __magic_name__     =      size
      __magic_name__     =      [0] * size
      __magic_name__     =      [0] * size







     @staticmethod
     def 	lowerCAmelCase__    (      UpperCamelCase_       ):
      return index | (index + 1)







     @staticmethod
     def 	lowerCAmelCase__    (      UpperCamelCase_       ):
      return (index & (index + 1)) - 1







     def 	lowerCAmelCase__    (      self ,						UpperCamelCase_ ,						UpperCamelCase_       ):
      __magic_name__     =      value
      while index < self.size:
       __magic_name__     =      self.get_prev(UpperCamelCase_       ) + 1
       if current_left_border == index:
        __magic_name__     =      value
       else:
        __magic_name__     =      max(UpperCamelCase_ ,						UpperCamelCase_ ,						UpperCamelCase_       )
       __magic_name__     =      self.get_next(UpperCamelCase_       )







     def 	lowerCAmelCase__    (      self ,						UpperCamelCase_ ,						UpperCamelCase_       ):
      right -= 1  # Because of right is exclusive
      __magic_name__     =      0
      while left <= right:
       __magic_name__     =      self.get_prev(UpperCamelCase_       )
       if left <= current_left:
        __magic_name__     =      max(UpperCamelCase_ ,						self.tree[right]       )
        __magic_name__     =      current_left
       else:
        __magic_name__     =      max(UpperCamelCase_ ,						self.arr[right]       )
        right -= 1
      return result


if __name__ == "__main__":
 import doctest

 doctest.testmod()

