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







						'''simple docstring'''



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





						def        SCREAMING_SNAKE_CASE(			self							:str     )  ->Optional[int]:
										lowercase         =      ids_tensor([self.batch_size, self.seq_length]		,    self.vocab_size     )

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

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

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

										lowercase         =      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        SCREAMING_SNAKE_CASE(			self							:str		,    lowerCAmelCase__							:Union[str, Any]		,    lowerCAmelCase__							:Optional[Any]		,    lowerCAmelCase__							:int		,    lowerCAmelCase__							:str		,    lowerCAmelCase__							:Dict		,    lowerCAmelCase__							:Dict		,    lowerCAmelCase__							:str     )  ->List[str]:
										lowercase         =      TFDebertaVaModel(config=lowerCAmelCase__     )
										lowercase         =      {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

										lowercase         =      [input_ids, input_mask]
										lowercase         =      model(lowerCAmelCase__     )

										lowercase         =      model(lowerCAmelCase__     )

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





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





						def        SCREAMING_SNAKE_CASE(			self							:List[Any]		,    lowerCAmelCase__							:List[Any]		,    lowerCAmelCase__							:Optional[int]		,    lowerCAmelCase__							:Optional[Any]		,    lowerCAmelCase__							:List[Any]		,    lowerCAmelCase__							:List[Any]		,    lowerCAmelCase__							:Dict		,    lowerCAmelCase__							:List[Any]     )  ->List[Any]:
										lowercase         =      self.num_labels
										lowercase         =      TFDebertaVaForSequenceClassification(config=lowerCAmelCase__     )
										lowercase         =      {
										    "input_ids": input_ids,
										    "attention_mask": input_mask,
										    "token_type_ids": token_type_ids,
										}

										lowercase         =      model(lowerCAmelCase__     )
										self.parent.assertEqual(result.logits.shape		,    (self.batch_size, self.num_labels)     )





						def        SCREAMING_SNAKE_CASE(			self							:List[str]		,    lowerCAmelCase__							:List[Any]		,    lowerCAmelCase__							:Optional[Any]		,    lowerCAmelCase__							:List[str]		,    lowerCAmelCase__							:Tuple		,    lowerCAmelCase__							:List[str]		,    lowerCAmelCase__							:List[str]		,    lowerCAmelCase__							:str     )  ->Union[str, Any]:
										lowercase         =      self.num_labels
										lowercase         =      TFDebertaVaForTokenClassification(config=lowerCAmelCase__     )
										lowercase         =      {
										    "input_ids": input_ids,
										    "attention_mask": input_mask,
										    "token_type_ids": token_type_ids,
										}
										lowercase         =      model(lowerCAmelCase__     )
										self.parent.assertEqual(result.logits.shape		,    (self.batch_size, self.seq_length, self.num_labels)     )





						def        SCREAMING_SNAKE_CASE(			self							:Union[str, Any]		,    lowerCAmelCase__							:Tuple		,    lowerCAmelCase__							:Union[str, Any]		,    lowerCAmelCase__							:List[Any]		,    lowerCAmelCase__							:List[str]		,    lowerCAmelCase__							:Dict		,    lowerCAmelCase__							:Union[str, Any]		,    lowerCAmelCase__							:int     )  ->List[str]:
										lowercase         =      TFDebertaVaForQuestionAnswering(config=lowerCAmelCase__     )
										lowercase         =      {
										    "input_ids": input_ids,
										    "attention_mask": input_mask,
										    "token_type_ids": token_type_ids,
										}

										lowercase         =      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        SCREAMING_SNAKE_CASE(			self							:Any     )  ->int:
										lowercase         =      self.prepare_config_and_inputs()
										(
										    (
										    lowercase	
										)     ,	(
										    lowercase	
										)     ,	(
										    lowercase	
										)     ,	(
										    lowercase	
										)     ,	(
										    lowercase	
										)     ,	(
										    lowercase	
										)     ,	(
										    lowercase	
										)     ,		
										)         =      config_and_inputs
										lowercase         =      {"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		):







						'''simple docstring'''



						UpperCamelCase      :  Any				   =					(
						    (
						        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[Any]				   =					False
						UpperCamelCase      :  List[str]				   =					False





						def        SCREAMING_SNAKE_CASE(			self							:List[Any]     )  ->str:
										lowercase         =      TFDebertaVaModelTester(self     )
										lowercase         =      ConfigTester(self		,    config_class=lowerCAmelCase__		,    hidden_size=37     )





						def        SCREAMING_SNAKE_CASE(			self							:List[str]     )  ->Union[str, Any]:
										self.config_tester.run_common_tests()





						def        SCREAMING_SNAKE_CASE(			self							:Union[str, Any]     )  ->Dict:
										lowercase         =      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*lowerCAmelCase__     )





						def        SCREAMING_SNAKE_CASE(			self							:Union[str, Any]     )  ->Dict:
										lowercase         =      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_masked_lm(*lowerCAmelCase__     )





						def        SCREAMING_SNAKE_CASE(			self							:Tuple     )  ->Dict:
										lowercase         =      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_question_answering(*lowerCAmelCase__     )





						def        SCREAMING_SNAKE_CASE(			self							:List[Any]     )  ->Dict:
										lowercase         =      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_sequence_classification(*lowerCAmelCase__     )





						def        SCREAMING_SNAKE_CASE(			self							:Any     )  ->Union[str, Any]:
										lowercase         =      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_token_classification(*lowerCAmelCase__     )





						@slow
						def        SCREAMING_SNAKE_CASE(			self							:Optional[Any]     )  ->Optional[int]:
										lowercase         =      TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"     )
										self.assertIsNotNone(lowerCAmelCase__     )





@require_tf
class   UpperCamelCase_      (      unittest.TestCase		):







						'''simple docstring'''



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





						@slow
						def        SCREAMING_SNAKE_CASE(			self							:Union[str, Any]     )  ->Any:
										lowercase         =      TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"     )
										lowercase         =      tf.constant([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]     )
										lowercase         =      tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]     )
										lowercase         =      model(lowerCAmelCase__		,    attention_mask=lowerCAmelCase__     )[0]

										lowercase         =      tf.constant(
										    [[[0.23_56, 0.19_48, 0.03_69], [-0.10_63, 0.35_86, -0.51_52], [-0.63_99, -0.02_59, -0.25_25]]]     )
										tf.debugging.assert_near(output[:, 1:4, 1:4]		,    lowerCAmelCase__		,    atol=1E-4     )




"""simple docstring"""



from diffusers.utils.testing_utils import require_onnxruntime







@require_onnxruntime
class    __a						:
				pass