


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







    """simple docstring"""



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

    def __lowercase       (       self   :  Optional[Any]		)       ->  Union[str, Any]:
      lowerCAmelCase_      :				Dict      =       ids_tensor([self.batch_size, self.seq_length]   ,						self.vocab_size		)

      lowerCAmelCase_      :				str      =       None
      if self.use_input_mask:
        lowerCAmelCase_      :				Dict      =       random_attention_mask([self.batch_size, self.seq_length]		)

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

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

      lowerCAmelCase_      :				Dict      =       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=lowerCamelCase   ,						)

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

    def __lowercase       (       self   :  Optional[int]   ,						lowerCamelCase   :  List[Any]   ,						lowerCamelCase   :  Any   ,						lowerCamelCase   :  List[Any]   ,						lowerCamelCase   :  Dict   ,						lowerCamelCase   :  Optional[int]   ,						lowerCamelCase   :  Dict   ,						lowerCamelCase   :  str		)       ->  Optional[Any]:
      lowerCAmelCase_      :				Any      =       TFDebertaVaModel(config=lowerCamelCase		)
      lowerCAmelCase_      :				Dict      =       {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}

      lowerCAmelCase_      :				str      =       [input_ids, input_mask]
      lowerCAmelCase_      :				Dict      =       model(lowerCamelCase		)

      lowerCAmelCase_      :				str      =       model(lowerCamelCase		)

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

    def __lowercase       (       self   :  Optional[Any]   ,						lowerCamelCase   :  List[str]   ,						lowerCamelCase   :  List[str]   ,						lowerCamelCase   :  str   ,						lowerCamelCase   :  Tuple   ,						lowerCamelCase   :  List[str]   ,						lowerCamelCase   :  List[str]   ,						lowerCamelCase   :  Optional[int]		)       ->  List[str]:
      lowerCAmelCase_      :				List[Any]      =       TFDebertaVaForMaskedLM(config=lowerCamelCase		)
      lowerCAmelCase_      :				Tuple      =       {
          """input_ids""": input_ids,
          """attention_mask""": input_mask,
          """token_type_ids""": token_type_ids,
      }
      lowerCAmelCase_      :				Tuple      =       model(lowerCamelCase		)
      self.parent.assertEqual(result.logits.shape   ,						(self.batch_size, self.seq_length, self.vocab_size)		)

    def __lowercase       (       self   :  int   ,						lowerCamelCase   :  Tuple   ,						lowerCamelCase   :  int   ,						lowerCamelCase   :  int   ,						lowerCamelCase   :  List[str]   ,						lowerCamelCase   :  int   ,						lowerCamelCase   :  List[str]   ,						lowerCamelCase   :  Any		)       ->  List[str]:
      lowerCAmelCase_      :				str      =       self.num_labels
      lowerCAmelCase_      :				Dict      =       TFDebertaVaForSequenceClassification(config=lowerCamelCase		)
      lowerCAmelCase_      :				Optional[int]      =       {
          """input_ids""": input_ids,
          """attention_mask""": input_mask,
          """token_type_ids""": token_type_ids,
      }

      lowerCAmelCase_      :				Dict      =       model(lowerCamelCase		)
      self.parent.assertEqual(result.logits.shape   ,						(self.batch_size, self.num_labels)		)

    def __lowercase       (       self   :  int   ,						lowerCamelCase   :  Dict   ,						lowerCamelCase   :  Union[str, Any]   ,						lowerCamelCase   :  Union[str, Any]   ,						lowerCamelCase   :  Union[str, Any]   ,						lowerCamelCase   :  Optional[Any]   ,						lowerCamelCase   :  List[Any]   ,						lowerCamelCase   :  str		)       ->  Optional[int]:
      lowerCAmelCase_      :				List[str]      =       self.num_labels
      lowerCAmelCase_      :				List[str]      =       TFDebertaVaForTokenClassification(config=lowerCamelCase		)
      lowerCAmelCase_      :				Union[str, Any]      =       {
          """input_ids""": input_ids,
          """attention_mask""": input_mask,
          """token_type_ids""": token_type_ids,
      }
      lowerCAmelCase_      :				List[str]      =       model(lowerCamelCase		)
      self.parent.assertEqual(result.logits.shape   ,						(self.batch_size, self.seq_length, self.num_labels)		)

    def __lowercase       (       self   :  List[str]   ,						lowerCamelCase   :  Union[str, Any]   ,						lowerCamelCase   :  Optional[int]   ,						lowerCamelCase   :  Optional[int]   ,						lowerCamelCase   :  List[str]   ,						lowerCamelCase   :  List[Any]   ,						lowerCamelCase   :  str   ,						lowerCamelCase   :  Union[str, Any]		)       ->  Optional[int]:
      lowerCAmelCase_      :				int      =       TFDebertaVaForQuestionAnswering(config=lowerCamelCase		)
      lowerCAmelCase_      :				int      =       {
          """input_ids""": input_ids,
          """attention_mask""": input_mask,
          """token_type_ids""": token_type_ids,
      }

      lowerCAmelCase_      :				Union[str, Any]      =       model(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 __lowercase       (       self   :  str		)       ->  Optional[int]:
      lowerCAmelCase_      :				Tuple      =       self.prepare_config_and_inputs()
      (
          (
          lowerCAmelCase_
      ),							(
          lowerCAmelCase_
      ),							(
          lowerCAmelCase_
      ),							(
          lowerCAmelCase_
      ),							(
          lowerCAmelCase_
      ),							(
          lowerCAmelCase_
      ),							(
          lowerCAmelCase_
      ),							
      )      :				Dict      =       config_and_inputs
      lowerCAmelCase_      :				str      =       {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
      return config, inputs_dict







@require_tf
class        __snake_case	(       _SCREAMING_SNAKE_CASE     ,_SCREAMING_SNAKE_CASE     ,unittest.TestCase):







    """simple docstring"""



    lowercase       			= (
        (
            TFDebertaVaModel,
            TFDebertaVaForMaskedLM,
            TFDebertaVaForQuestionAnswering,
            TFDebertaVaForSequenceClassification,
            TFDebertaVaForTokenClassification,
        )
        if is_tf_available()
        else ()
    )
    lowercase       			= (
        {
            'feature-extraction': TFDebertaVaModel,
            'fill-mask': TFDebertaVaForMaskedLM,
            'question-answering': TFDebertaVaForQuestionAnswering,
            'text-classification': TFDebertaVaForSequenceClassification,
            'token-classification': TFDebertaVaForTokenClassification,
            'zero-shot': TFDebertaVaForSequenceClassification,
        }
        if is_tf_available()
        else {}
    )

    lowercase       			= False
    lowercase       			= False

    def __lowercase       (       self   :  Dict		)       ->  Optional[Any]:
      lowerCAmelCase_      :				Tuple      =       TFDebertaVaModelTester(self		)
      lowerCAmelCase_      :				Any      =       ConfigTester(self   ,						config_class=lowerCamelCase   ,						hidden_size=37		)

    def __lowercase       (       self   :  List[str]		)       ->  Optional[Any]:
      self.config_tester.run_common_tests()

    def __lowercase       (       self   :  List[Any]		)       ->  List[str]:
      lowerCAmelCase_      :				Any      =       self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*lowerCamelCase		)

    def __lowercase       (       self   :  str		)       ->  Dict:
      lowerCAmelCase_      :				List[Any]      =       self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_masked_lm(*lowerCamelCase		)

    def __lowercase       (       self   :  str		)       ->  Optional[Any]:
      lowerCAmelCase_      :				List[Any]      =       self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_question_answering(*lowerCamelCase		)

    def __lowercase       (       self   :  Optional[int]		)       ->  Union[str, Any]:
      lowerCAmelCase_      :				List[Any]      =       self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_sequence_classification(*lowerCamelCase		)

    def __lowercase       (       self   :  Tuple		)       ->  Tuple:
      lowerCAmelCase_      :				str      =       self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_token_classification(*lowerCamelCase		)





    @slow
    def __lowercase       (       self   :  Optional[Any]		)       ->  Optional[int]:
      lowerCAmelCase_      :				List[str]      =       TFDebertaVaModel.from_pretrained("""kamalkraj/deberta-v2-xlarge"""		)
      self.assertIsNotNone(lowerCamelCase		)







@require_tf
class        __snake_case	(       unittest.TestCase):







    """simple docstring"""



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





    @slow
    def __lowercase       (       self   :  List[str]		)       ->  Optional[int]:
      lowerCAmelCase_      :				str      =       TFDebertaVaModel.from_pretrained("""kamalkraj/deberta-v2-xlarge"""		)
      lowerCAmelCase_      :				Union[str, Any]      =       tf.constant([[0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]]		)
      lowerCAmelCase_      :				int      =       tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
      lowerCAmelCase_      :				Tuple      =       model(lowerCamelCase   ,						attention_mask=lowerCamelCase		)[0]

      lowerCAmelCase_      :				str      =       tf.constant(
          [[[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]]]		)
      tf.debugging.assert_near(output[:, 1:4, 1:4]   ,						lowerCamelCase   ,						atol=1E-4		)







'''simple docstring'''






from ..utils import DummyObject, requires_backends






class        __snake_case	(       metaclass=_SCREAMING_SNAKE_CASE):







    """simple docstring"""



    lowercase       			= ['note_seq']

    def __init__(       self   :  Tuple   ,						*lowerCamelCase   :  Optional[int]   ,						**lowerCamelCase   :  Tuple		)       ->  Any:
      requires_backends(self   ,						["""note_seq"""]		)

    @classmethod
    def __lowercase       (       cls   :  Optional[Any]   ,						*lowerCamelCase   :  List[Any]   ,						**lowerCamelCase   :  Dict		)       ->  List[Any]:
      requires_backends(cls   ,						["""note_seq"""]		)





    @classmethod
    def __lowercase       (       cls   :  Union[str, Any]   ,						*lowerCamelCase   :  Union[str, Any]   ,						**lowerCamelCase   :  List[Any]		)       ->  Optional[int]:
      requires_backends(cls   ,						["""note_seq"""]		)



