





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



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



					def   __a     (		self     :     Any						):
							lowerCamelCase_	:     Optional[int] 						=      ids_tensor([self.batch_size, self.seq_length]       ,      self.vocab_size						)

							lowerCamelCase_	:     Optional[Any] 						=      None
							if self.use_input_mask:
									lowerCamelCase_	:     Optional[Any] 						=      random_attention_mask([self.batch_size, self.seq_length]						)

							lowerCamelCase_	:     int 						=      None
							if self.use_token_type_ids:
									lowerCamelCase_	:     List[Any] 						=      ids_tensor([self.batch_size, self.seq_length]       ,      self.type_vocab_size						)

							lowerCamelCase_	:     Union[str, Any] 						=      None
							lowerCamelCase_	:     str 						=      None
							lowerCamelCase_	:     List[Any] 						=      None
							if self.use_labels:
									lowerCamelCase_	:     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_	:     str 						=      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   __a     (		self     :     List[Any]       ,      lowerCamelCase     :     Dict       ,      lowerCamelCase     :     Optional[Any]       ,      lowerCamelCase     :     str       ,      lowerCamelCase     :     Dict       ,      lowerCamelCase     :     List[str]       ,      lowerCamelCase     :     Optional[Any]       ,      lowerCamelCase     :     Optional[Any]						):
							lowerCamelCase_	:     Union[str, Any] 						=      TFDebertaVaModel(config=lowerCamelCase						)
							lowerCamelCase_	:     Any 						=      {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}

							lowerCamelCase_	:     str 						=      [input_ids, input_mask]
							lowerCamelCase_	:     List[str] 						=      model(lowerCamelCase						)

							lowerCamelCase_	:     List[Any] 						=      model(lowerCamelCase						)

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



					def   __a     (		self     :     Optional[int]       ,      lowerCamelCase     :     Union[str, Any]       ,      lowerCamelCase     :     str       ,      lowerCamelCase     :     Dict       ,      lowerCamelCase     :     str       ,      lowerCamelCase     :     List[Any]       ,      lowerCamelCase     :     int       ,      lowerCamelCase     :     Dict						):
							lowerCamelCase_	:     Dict 						=      TFDebertaVaForMaskedLM(config=lowerCamelCase						)
							lowerCamelCase_	:     str 						=      {
							    '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.vocab_size)						)



					def   __a     (		self     :     Any       ,      lowerCamelCase     :     Union[str, Any]       ,      lowerCamelCase     :     Any       ,      lowerCamelCase     :     Any       ,      lowerCamelCase     :     int       ,      lowerCamelCase     :     Optional[int]       ,      lowerCamelCase     :     str       ,      lowerCamelCase     :     List[Any]						):
							lowerCamelCase_	:     Optional[Any] 						=      self.num_labels
							lowerCamelCase_	:     Any 						=      TFDebertaVaForSequenceClassification(config=lowerCamelCase						)
							lowerCamelCase_	:     Tuple 						=      {
							    'input_ids': input_ids,
							    'attention_mask': input_mask,
							    'token_type_ids': token_type_ids,
							}

							lowerCamelCase_	:     Union[str, Any] 						=      model(lowerCamelCase						)
							self.parent.assertEqual(result.logits.shape       ,      (self.batch_size, self.num_labels)						)



					def   __a     (		self     :     List[str]       ,      lowerCamelCase     :     int       ,      lowerCamelCase     :     int       ,      lowerCamelCase     :     List[str]       ,      lowerCamelCase     :     Union[str, Any]       ,      lowerCamelCase     :     Optional[Any]       ,      lowerCamelCase     :     Optional[Any]       ,      lowerCamelCase     :     Optional[Any]						):
							lowerCamelCase_	:     Tuple 						=      self.num_labels
							lowerCamelCase_	:     int 						=      TFDebertaVaForTokenClassification(config=lowerCamelCase						)
							lowerCamelCase_	:     List[str] 						=      {
							    'input_ids': input_ids,
							    'attention_mask': input_mask,
							    'token_type_ids': token_type_ids,
							}
							lowerCamelCase_	:     Optional[int] 						=      model(lowerCamelCase						)
							self.parent.assertEqual(result.logits.shape       ,      (self.batch_size, self.seq_length, self.num_labels)						)



					def   __a     (		self     :     Union[str, Any]       ,      lowerCamelCase     :     Optional[Any]       ,      lowerCamelCase     :     str       ,      lowerCamelCase     :     List[str]       ,      lowerCamelCase     :     Union[str, Any]       ,      lowerCamelCase     :     List[Any]       ,      lowerCamelCase     :     Optional[Any]       ,      lowerCamelCase     :     Any						):
							lowerCamelCase_	:     Tuple 						=      TFDebertaVaForQuestionAnswering(config=lowerCamelCase						)
							lowerCamelCase_	:     int 						=      {
							    'input_ids': input_ids,
							    'attention_mask': input_mask,
							    'token_type_ids': token_type_ids,
							}

							lowerCamelCase_	:     int 						=      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   __a     (		self     :     List[str]						):
							lowerCamelCase_	:     List[Any] 						=      self.prepare_config_and_inputs()
							(
							    (
							    lowerCamelCase_
							)						,      (
							    lowerCamelCase_
							)						,      (
							    lowerCamelCase_
							)						,      (
							    lowerCamelCase_
							)						,      (
							    lowerCamelCase_
							)						,      (
							    lowerCamelCase_
							)						,      (
							    lowerCamelCase_
							)						,      
							)	:     Optional[Any] 						=      config_and_inputs
							lowerCamelCase_	:     List[Any] 						=      {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
							return config, inputs_dict






@require_tf
class 						UpperCamelCase_  (  snake_case__  ,     snake_case__  ,     unittest.TestCase							):
					_a      :						int						    =					(
					    (
					        TFDebertaVaModel,
					        TFDebertaVaForMaskedLM,
					        TFDebertaVaForQuestionAnswering,
					        TFDebertaVaForSequenceClassification,
					        TFDebertaVaForTokenClassification,
					    )
					    if is_tf_available()
					    else ()
					)
					_a      :						Optional[int]						    =					(
					    {
					        'feature-extraction': TFDebertaVaModel,
					        'fill-mask': TFDebertaVaForMaskedLM,
					        'question-answering': TFDebertaVaForQuestionAnswering,
					        'text-classification': TFDebertaVaForSequenceClassification,
					        'token-classification': TFDebertaVaForTokenClassification,
					        'zero-shot': TFDebertaVaForSequenceClassification,
					    }
					    if is_tf_available()
					    else {}
					)

					_a      :						Optional[int]						    =					False
					_a      :						Optional[int]						    =					False



					def   __a     (		self     :     List[Any]						):
							lowerCamelCase_	:     Any 						=      TFDebertaVaModelTester(self						)
							lowerCamelCase_	:     Optional[int] 						=      ConfigTester(self       ,      config_class=lowerCamelCase       ,      hidden_size=37						)



					def   __a     (		self     :     Optional[int]						):
							self.config_tester.run_common_tests()



					def   __a     (		self     :     Union[str, Any]						):
							lowerCamelCase_	:     Any 						=      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*lowerCamelCase						)



					def   __a     (		self     :     int						):
							lowerCamelCase_	:     Dict 						=      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_lm(*lowerCamelCase						)



					def   __a     (		self     :     int						):
							lowerCamelCase_	:     str 						=      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_question_answering(*lowerCamelCase						)



					def   __a     (		self     :     Optional[Any]						):
							lowerCamelCase_	:     str 						=      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_sequence_classification(*lowerCamelCase						)



					def   __a     (		self     :     List[Any]						):
							lowerCamelCase_	:     Tuple 						=      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_token_classification(*lowerCamelCase						)





					@slow
					def   __a     (		self     :     Optional[Any]						):
							lowerCamelCase_	:     Any 						=      TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'						)
							self.assertIsNotNone(lowerCamelCase						)






@require_tf
class 						UpperCamelCase_  (  unittest.TestCase							):



					@unittest.skip(reason='Model not available yet'						)
					def   __a     (		self     :     List[Any]						):
							pass





					@slow
					def   __a     (		self     :     str						):
							lowerCamelCase_	:     Tuple 						=      TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'						)
							lowerCamelCase_	:     List[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_	:     List[str] 						=      tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]						)
							lowerCamelCase_	:     List[Any] 						=      model(lowerCamelCase       ,      attention_mask=lowerCamelCase						)[0]

							lowerCamelCase_	:     Any 						=      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						)







from collections import OrderedDict
from typing import TYPE_CHECKING, Any, Mapping, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


if TYPE_CHECKING:
		from ... import FeatureExtractionMixin, PreTrainedTokenizerBase, TensorType


_lowercase		:  Tuple			       =logging.get_logger(__name__)

_lowercase		:  Any			       ={
    """microsoft/deberta-v2-xlarge""": """https://huggingface.co/microsoft/deberta-v2-xlarge/resolve/main/config.json""",
    """microsoft/deberta-v2-xxlarge""": """https://huggingface.co/microsoft/deberta-v2-xxlarge/resolve/main/config.json""",
    """microsoft/deberta-v2-xlarge-mnli""": (
        """https://huggingface.co/microsoft/deberta-v2-xlarge-mnli/resolve/main/config.json"""
    ),
    """microsoft/deberta-v2-xxlarge-mnli""": (
        """https://huggingface.co/microsoft/deberta-v2-xxlarge-mnli/resolve/main/config.json"""
    ),
}






class 						UpperCamelCase_  (  snake_case__							):
					_a      :						int						    =					'deberta-v2'



					def __init__(		self     :     Any       ,      lowerCamelCase     :     Dict=12_81_00       ,      lowerCamelCase     :     List[Any]=15_36       ,      lowerCamelCase     :     Union[str, Any]=24       ,      lowerCamelCase     :     Union[str, Any]=24       ,      lowerCamelCase     :     Optional[int]=61_44       ,      lowerCamelCase     :     Any="gelu"       ,      lowerCamelCase     :     int=0.1       ,      lowerCamelCase     :     str=0.1       ,      lowerCamelCase     :     Optional[int]=5_12       ,      lowerCamelCase     :     str=0       ,      lowerCamelCase     :     Union[str, Any]=0.02       ,      lowerCamelCase     :     List[str]=1E-7       ,      lowerCamelCase     :     Dict=False       ,      lowerCamelCase     :     List[Any]=-1       ,      lowerCamelCase     :     Union[str, Any]=0       ,      lowerCamelCase     :     Optional[int]=True       ,      lowerCamelCase     :     Optional[int]=None       ,      lowerCamelCase     :     Tuple=0       ,      lowerCamelCase     :     Tuple="gelu"       ,      **lowerCamelCase     :     Optional[int]       ,      ):
							super().__init__(**lowerCamelCase						)

							lowerCamelCase_	:     Any 						=      hidden_size
							lowerCamelCase_	:     Dict 						=      num_hidden_layers
							lowerCamelCase_	:     Optional[int] 						=      num_attention_heads
							lowerCamelCase_	:     Optional[int] 						=      intermediate_size
							lowerCamelCase_	:     str 						=      hidden_act
							lowerCamelCase_	:     int 						=      hidden_dropout_prob
							lowerCamelCase_	:     Tuple 						=      attention_probs_dropout_prob
							lowerCamelCase_	:     Union[str, Any] 						=      max_position_embeddings
							lowerCamelCase_	:     Union[str, Any] 						=      type_vocab_size
							lowerCamelCase_	:     List[Any] 						=      initializer_range
							lowerCamelCase_	:     Optional[Any] 						=      relative_attention
							lowerCamelCase_	:     List[Any] 						=      max_relative_positions
							lowerCamelCase_	:     Optional[int] 						=      pad_token_id
							lowerCamelCase_	:     int 						=      position_biased_input

							# Backwards compatibility
							if type(lowerCamelCase						) == str:
									lowerCamelCase_	:     Dict 						=      [x.strip() for x in pos_att_type.lower().split('|'						)]

							lowerCamelCase_	:     Optional[Any] 						=      pos_att_type
							lowerCamelCase_	:     List[Any] 						=      vocab_size
							lowerCamelCase_	:     Any 						=      layer_norm_eps

							lowerCamelCase_	:     int 						=      kwargs.get('pooler_hidden_size'       ,      lowerCamelCase						)
							lowerCamelCase_	:     Dict 						=      pooler_dropout
							lowerCamelCase_	:     Tuple 						=      pooler_hidden_act






class 						UpperCamelCase_  (  snake_case__							):



					@property
					def   __a     (		self     :     Optional[int]						):
							if self.task == "multiple-choice":
									lowerCamelCase_	:     Optional[Any] 						=      {0: 'batch', 1: 'choice', 2: 'sequence'}
							else:
									lowerCamelCase_	:     Any 						=      {0: 'batch', 1: 'sequence'}
							if self._config.type_vocab_size > 0:
									return OrderedDict(
									    [('input_ids', dynamic_axis), ('attention_mask', dynamic_axis), ('token_type_ids', dynamic_axis)]						)
							else:
									return OrderedDict([('input_ids', dynamic_axis), ('attention_mask', dynamic_axis)]						)



					@property
					def   __a     (		self     :     List[Any]						):
							return 12





					def   __a     (		self     :     Tuple       ,      lowerCamelCase     :     Union["PreTrainedTokenizerBase", "FeatureExtractionMixin"]       ,      lowerCamelCase     :     int = -1       ,      lowerCamelCase     :     int = -1       ,      lowerCamelCase     :     int = -1       ,      lowerCamelCase     :     bool = False       ,      lowerCamelCase     :     Optional["TensorType"] = None       ,      lowerCamelCase     :     int = 3       ,      lowerCamelCase     :     int = 40       ,      lowerCamelCase     :     int = 40       ,      lowerCamelCase     :     "PreTrainedTokenizerBase" = None       ,      ):
							lowerCamelCase_	:     Union[str, Any] 						=      super().generate_dummy_inputs(preprocessor=lowerCamelCase       ,      framework=lowerCamelCase						)
							if self._config.type_vocab_size == 0 and "token_type_ids" in dummy_inputs:
									del dummy_inputs["token_type_ids"]
							return dummy_inputs
