


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

						"""simple docstring"""






						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.0_2 ,  lowerCAmelCase							:      Union[str, Any]=False ,  lowerCAmelCase							:      Union[str, Any]=True ,  lowerCAmelCase							:      Any="None" ,  lowerCAmelCase							:      Dict=3 ,  lowerCAmelCase							:      Optional[int]=4 ,  lowerCAmelCase							:      int=None ,  ):
													A_			    =		parent
													A_			    =		batch_size
													A_			    =		seq_length
													A_			    =		is_training
													A_			    =		use_input_mask
													A_			    =		use_token_type_ids
													A_			    =		use_labels
													A_			    =		vocab_size
													A_			    =		hidden_size
													A_			    =		num_hidden_layers
													A_			    =		num_attention_heads
													A_			    =		intermediate_size
													A_			    =		hidden_act
													A_			    =		hidden_dropout_prob
													A_			    =		attention_probs_dropout_prob
													A_			    =		max_position_embeddings
													A_			    =		type_vocab_size
													A_			    =		type_sequence_label_size
													A_			    =		initializer_range
													A_			    =		num_labels
													A_			    =		num_choices
													A_			    =		relative_attention
													A_			    =		position_biased_input
													A_			    =		pos_att_type
													A_			    =		scope






						def 				_UpperCAmelCase       (  self							:      Any	):
													A_			    =		ids_tensor([self.batch_size, self.seq_length] ,  self.vocab_size	)

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

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

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

													A_			    =		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 				_UpperCAmelCase       (  self							:      List[Any] ,  lowerCAmelCase							:      Dict ,  lowerCAmelCase							:      Optional[Any] ,  lowerCAmelCase							:      str ,  lowerCAmelCase							:      Dict ,  lowerCAmelCase							:      List[str] ,  lowerCAmelCase							:      Optional[Any] ,  lowerCAmelCase							:      Optional[Any]	):
													A_			    =		TFDebertaVaModel(config=lowerCAmelCase	)
													A_			    =		{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}

													A_			    =		[input_ids, input_mask]
													A_			    =		model(lowerCAmelCase	)

													A_			    =		model(lowerCAmelCase	)

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






						def 				_UpperCAmelCase       (  self							:      Optional[int] ,  lowerCAmelCase							:      Union[str, Any] ,  lowerCAmelCase							:      str ,  lowerCAmelCase							:      Dict ,  lowerCAmelCase							:      str ,  lowerCAmelCase							:      List[Any] ,  lowerCAmelCase							:      int ,  lowerCAmelCase							:      Dict	):
													A_			    =		TFDebertaVaForMaskedLM(config=lowerCAmelCase	)
													A_			    =		{
													    'input_ids': input_ids,
													    'attention_mask': input_mask,
													    'token_type_ids': token_type_ids,
													}
													A_			    =		model(lowerCAmelCase	)
													self.parent.assertEqual(result.logits.shape ,  (self.batch_size, self.seq_length, self.vocab_size)	)






						def 				_UpperCAmelCase       (  self							:      Any ,  lowerCAmelCase							:      Union[str, Any] ,  lowerCAmelCase							:      Any ,  lowerCAmelCase							:      Any ,  lowerCAmelCase							:      int ,  lowerCAmelCase							:      Optional[int] ,  lowerCAmelCase							:      str ,  lowerCAmelCase							:      List[Any]	):
													A_			    =		self.num_labels
													A_			    =		TFDebertaVaForSequenceClassification(config=lowerCAmelCase	)
													A_			    =		{
													    'input_ids': input_ids,
													    'attention_mask': input_mask,
													    'token_type_ids': token_type_ids,
													}

													A_			    =		model(lowerCAmelCase	)
													self.parent.assertEqual(result.logits.shape ,  (self.batch_size, self.num_labels)	)






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






						def 				_UpperCAmelCase       (  self							:      Union[str, Any] ,  lowerCAmelCase							:      Optional[Any] ,  lowerCAmelCase							:      str ,  lowerCAmelCase							:      List[str] ,  lowerCAmelCase							:      Union[str, Any] ,  lowerCAmelCase							:      List[Any] ,  lowerCAmelCase							:      Optional[Any] ,  lowerCAmelCase							:      Any	):
													A_			    =		TFDebertaVaForQuestionAnswering(config=lowerCAmelCase	)
													A_			    =		{
													    'input_ids': input_ids,
													    'attention_mask': input_mask,
													    'token_type_ids': token_type_ids,
													}

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






@require_tf
class 					__lowerCAmelCase   (   snake_case__				,			snake_case__				,			unittest.TestCase						):

						"""simple docstring"""






						_UpperCAmelCase		:       int   						=(
						    (
						        TFDebertaVaModel,
						        TFDebertaVaForMaskedLM,
						        TFDebertaVaForQuestionAnswering,
						        TFDebertaVaForSequenceClassification,
						        TFDebertaVaForTokenClassification,
						    )
						    if is_tf_available()
						    else ()
						)
						_UpperCAmelCase		:       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 {}
						)

						_UpperCAmelCase		:       Optional[int]   						=False
						_UpperCAmelCase		:       Optional[int]   						=False






						def 				_UpperCAmelCase       (  self							:      List[Any]	):
													A_			    =		TFDebertaVaModelTester(self	)
													A_			    =		ConfigTester(self ,  config_class=lowerCAmelCase ,  hidden_size=37	)






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






						def 				_UpperCAmelCase       (  self							:      Union[str, Any]	):
													A_			    =		self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_model(*lowerCAmelCase	)






						def 				_UpperCAmelCase       (  self							:      int	):
													A_			    =		self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_masked_lm(*lowerCAmelCase	)






						def 				_UpperCAmelCase       (  self							:      int	):
													A_			    =		self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_question_answering(*lowerCAmelCase	)






						def 				_UpperCAmelCase       (  self							:      Optional[Any]	):
													A_			    =		self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_sequence_classification(*lowerCAmelCase	)






						def 				_UpperCAmelCase       (  self							:      List[Any]	):
													A_			    =		self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_token_classification(*lowerCAmelCase	)






						@slow
						def 				_UpperCAmelCase       (  self							:      Optional[Any]	):
													A_			    =		TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"	)
													self.assertIsNotNone(lowerCAmelCase	)






@require_tf
class 					__lowerCAmelCase   (   unittest.TestCase						):

						"""simple docstring"""






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






						@slow
						def 				_UpperCAmelCase       (  self							:      str	):
													A_			    =		TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"	)
													A_			    =		tf.constant([[0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]]	)
													A_			    =		tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]	)
													A_			    =		model(lowerCAmelCase ,  attention_mask=lowerCAmelCase	)[0]

													A_			    =		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] ,  lowerCAmelCase ,  atol=1e-4	)












import os
import sys

_lowercase		:  List[str]			       =os.path.join(os.path.dirname(__file__), """src""")
sys.path.append(SRC_DIR)


from transformers import (
    AutoConfig,
    AutoModel,
    AutoModelForCausalLM,
    AutoModelForMaskedLM,
    AutoModelForQuestionAnswering,
    AutoModelForSequenceClassification,
    AutoTokenizer,
    add_start_docstrings,
)


_lowercase		:  Optional[int]			       =[
    """torch""",
    """numpy""",
    """tokenizers""",
    """filelock""",
    """requests""",
    """tqdm""",
    """regex""",
    """sentencepiece""",
    """sacremoses""",
    """importlib_metadata""",
    """huggingface_hub""",
]


@add_start_docstrings(AutoConfig.__doc__						)
def 		_SCREAMING_SNAKE_CASE     ( *lowerCAmelCase__							,**lowerCAmelCase__						):
		return AutoConfig.from_pretrained(*lowerCAmelCase__							,**lowerCAmelCase__						)


@add_start_docstrings(AutoTokenizer.__doc__						)
def 		_SCREAMING_SNAKE_CASE     ( *lowerCAmelCase__							,**lowerCAmelCase__						):
		return AutoTokenizer.from_pretrained(*lowerCAmelCase__							,**lowerCAmelCase__						)


@add_start_docstrings(AutoModel.__doc__						)
def 		_SCREAMING_SNAKE_CASE     ( *lowerCAmelCase__							,**lowerCAmelCase__						):
		return AutoModel.from_pretrained(*lowerCAmelCase__							,**lowerCAmelCase__						)


@add_start_docstrings(AutoModelForCausalLM.__doc__						)
def 		_SCREAMING_SNAKE_CASE     ( *lowerCAmelCase__							,**lowerCAmelCase__						):
		return AutoModelForCausalLM.from_pretrained(*lowerCAmelCase__							,**lowerCAmelCase__						)


@add_start_docstrings(AutoModelForMaskedLM.__doc__						)
def 		_SCREAMING_SNAKE_CASE     ( *lowerCAmelCase__							,**lowerCAmelCase__						):
		return AutoModelForMaskedLM.from_pretrained(*lowerCAmelCase__							,**lowerCAmelCase__						)


@add_start_docstrings(AutoModelForSequenceClassification.__doc__						)
def 		_SCREAMING_SNAKE_CASE     ( *lowerCAmelCase__							,**lowerCAmelCase__						):
		return AutoModelForSequenceClassification.from_pretrained(*lowerCAmelCase__							,**lowerCAmelCase__						)





@add_start_docstrings(AutoModelForQuestionAnswering.__doc__						)
def 		_SCREAMING_SNAKE_CASE     ( *lowerCAmelCase__							,**lowerCAmelCase__						):
		return AutoModelForQuestionAnswering.from_pretrained(*lowerCAmelCase__							,**lowerCAmelCase__						)
