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   lowerCamelCase					:
  """simple docstring"""







  def __init__(							self :       int  ,     __magic_name__ :       Optional[int]  ,     __magic_name__ :       Union[str, Any]=13  ,     __magic_name__ :       Tuple=7  ,     __magic_name__ :       Tuple=True  ,     __magic_name__ :       List[Any]=True  ,     __magic_name__ :       Optional[Any]=True  ,     __magic_name__ :       str=True  ,     __magic_name__ :       List[Any]=99  ,     __magic_name__ :       Optional[Any]=32  ,     __magic_name__ :       List[Any]=2  ,     __magic_name__ :       Optional[Any]=4  ,     __magic_name__ :       Optional[Any]=37  ,     __magic_name__ :       List[Any]="gelu"  ,     __magic_name__ :       Optional[int]=0.1  ,     __magic_name__ :       Optional[Any]=0.1  ,     __magic_name__ :       Union[str, Any]=512  ,     __magic_name__ :       List[str]=16  ,     __magic_name__ :       Optional[int]=2  ,     __magic_name__ :       List[Any]=0.02  ,     __magic_name__ :       Optional[Any]=False  ,     __magic_name__ :       List[str]=True  ,     __magic_name__ :       int="None"  ,     __magic_name__ :       int=3  ,     __magic_name__ :       Optional[Any]=4  ,     __magic_name__ :       int=None  ,     )  ->	Dict:
        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    __A     (							self :       Dict   )  ->	int:
        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_          =  random_attention_mask([self.batch_size, self.seq_length]   )

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

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







  def    __A     (							self :       Tuple  ,     __magic_name__ :       str  ,     __magic_name__ :       int  ,     __magic_name__ :       Dict  ,     __magic_name__ :       List[Any]  ,     __magic_name__ :       Optional[Any]  ,     __magic_name__ :       Dict  ,     __magic_name__ :       Optional[Any]   )  ->	Optional[Any]:
        SCREAMING_SNAKE_CASE_          =  TFDebertaVaModel(config=__magic_name__   )
        SCREAMING_SNAKE_CASE_          =  {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

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

        SCREAMING_SNAKE_CASE_          =  model(__magic_name__   )

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







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







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

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







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







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

        SCREAMING_SNAKE_CASE_          =  model(__magic_name__   )
        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    __A     (							self :       Dict   )  ->	int:
        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_tf
class   lowerCamelCase					(SCREAMING_SNAKE_CASE__  ,      SCREAMING_SNAKE_CASE__  ,      unittest.TestCase					):
  """simple docstring"""







  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    __A     (							self :       Dict   )  ->	List[str]:
        SCREAMING_SNAKE_CASE_          =  TFDebertaVaModelTester(self   )
        SCREAMING_SNAKE_CASE_          =  ConfigTester(self  ,     config_class=__magic_name__  ,     hidden_size=37   )







  def    __A     (							self :       Any   )  ->	Tuple:
        self.config_tester.run_common_tests()







  def    __A     (							self :       Dict   )  ->	Optional[Any]:
        SCREAMING_SNAKE_CASE_          =  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*__magic_name__   )







  def    __A     (							self :       int   )  ->	Union[str, Any]:
        SCREAMING_SNAKE_CASE_          =  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_masked_lm(*__magic_name__   )







  def    __A     (							self :       Dict   )  ->	Optional[Any]:
        SCREAMING_SNAKE_CASE_          =  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_question_answering(*__magic_name__   )







  def    __A     (							self :       Tuple   )  ->	Any:
        SCREAMING_SNAKE_CASE_          =  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_sequence_classification(*__magic_name__   )







  def    __A     (							self :       List[Any]   )  ->	int:
        SCREAMING_SNAKE_CASE_          =  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_token_classification(*__magic_name__   )







  @slow
  def    __A     (							self :       Optional[Any]   )  ->	Dict:
        SCREAMING_SNAKE_CASE_          =  TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"   )
        self.assertIsNotNone(__magic_name__   )



@require_tf
class   lowerCamelCase					(unittest.TestCase					):
  """simple docstring"""







  @unittest.skip(reason="Model not available yet"   )
  def    __A     (							self :       int   )  ->	Union[str, Any]:
        pass







  @slow
  def    __A     (							self :       List[str]   )  ->	List[str]:
        SCREAMING_SNAKE_CASE_          =  TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"   )
        SCREAMING_SNAKE_CASE_          =  tf.constant([[0, 31_414, 232, 328, 740, 1_140, 12_695, 69, 46_078, 1_588, 2]]   )
        SCREAMING_SNAKE_CASE_          =  tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]   )
        SCREAMING_SNAKE_CASE_          =  model(__magic_name__  ,     attention_mask=__magic_name__   )[0]

        SCREAMING_SNAKE_CASE_          =  tf.constant(
            [[[0.2356, 0.1948, 0.0369], [-0.1063, 0.3586, -0.5152], [-0.6399, -0.0259, -0.2525]]]   )
        tf.debugging.assert_near(output[:, 1:4, 1:4]  ,     __magic_name__  ,     atol=1e-4   )



from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


A     :  str					     =       {
    "configuration_rembert": ["REMBERT_PRETRAINED_CONFIG_ARCHIVE_MAP", "RemBertConfig", "RemBertOnnxConfig"]
}

try:
      if not is_sentencepiece_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      A     :  Tuple					     =       ["RemBertTokenizer"]

try:
      if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      A     :  Tuple					     =       ["RemBertTokenizerFast"]

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      A     :  Tuple					     =       [
          "REMBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
          "RemBertForCausalLM",
          "RemBertForMaskedLM",
          "RemBertForMultipleChoice",
          "RemBertForQuestionAnswering",
          "RemBertForSequenceClassification",
          "RemBertForTokenClassification",
          "RemBertLayer",
          "RemBertModel",
          "RemBertPreTrainedModel",
          "load_tf_weights_in_rembert",
      ]


try:
      if not is_tf_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      A     :  List[str]					     =       [
          "TF_REMBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
          "TFRemBertForCausalLM",
          "TFRemBertForMaskedLM",
          "TFRemBertForMultipleChoice",
          "TFRemBertForQuestionAnswering",
          "TFRemBertForSequenceClassification",
          "TFRemBertForTokenClassification",
          "TFRemBertLayer",
          "TFRemBertModel",
          "TFRemBertPreTrainedModel",
      ]


if TYPE_CHECKING:
      from .configuration_rembert import REMBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, RemBertConfig, RemBertOnnxConfig

      try:
            if not is_sentencepiece_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .tokenization_rembert import RemBertTokenizer

      try:
            if not is_tokenizers_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .tokenization_rembert_fast import RemBertTokenizerFast

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_rembert import (
                REMBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
                RemBertForCausalLM,
                RemBertForMaskedLM,
                RemBertForMultipleChoice,
                RemBertForQuestionAnswering,
                RemBertForSequenceClassification,
                RemBertForTokenClassification,
                RemBertLayer,
                RemBertModel,
                RemBertPreTrainedModel,
                load_tf_weights_in_rembert,
            )

      try:
            if not is_tf_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_tf_rembert import (
                TF_REMBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
                TFRemBertForCausalLM,
                TFRemBertForMaskedLM,
                TFRemBertForMultipleChoice,
                TFRemBertForQuestionAnswering,
                TFRemBertForSequenceClassification,
                TFRemBertForTokenClassification,
                TFRemBertLayer,
                TFRemBertModel,
                TFRemBertPreTrainedModel,
            )


else:
      import sys

      A     :  Tuple					     =       _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)


