



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 ,       __lowercase ,       __lowercase=1_3 ,       __lowercase=7 ,       __lowercase=True ,       __lowercase=True ,       __lowercase=True ,       __lowercase=True ,       __lowercase=9_9 ,       __lowercase=3_2 ,       __lowercase=2 ,       __lowercase=4 ,       __lowercase=3_7 ,       __lowercase="gelu" ,       __lowercase=0.1 ,       __lowercase=0.1 ,       __lowercase=5_1_2 ,       __lowercase=1_6 ,       __lowercase=2 ,       __lowercase=0.0_2 ,       __lowercase=False ,       __lowercase=True ,       __lowercase="None" ,       __lowercase=3 ,       __lowercase=4 ,       __lowercase=None ,       ) ->				List[Any]:
									"""simple docstring"""




									a__       :						Tuple							=  parent
									a__       :						Optional[int]							=  batch_size
									a__       :						Union[str, Any]							=  seq_length
									a__       :						Union[str, Any]							=  is_training
									a__       :						List[Any]							=  use_input_mask
									a__       :						str							=  use_token_type_ids
									a__       :						Optional[int]							=  use_labels
									a__       :						List[str]							=  vocab_size
									a__       :						Optional[Any]							=  hidden_size
									a__       :						Dict							=  num_hidden_layers
									a__       :						Tuple							=  num_attention_heads
									a__       :						Tuple							=  intermediate_size
									a__       :						int							=  hidden_act
									a__       :						Any							=  hidden_dropout_prob
									a__       :						List[Any]							=  attention_probs_dropout_prob
									a__       :						List[str]							=  max_position_embeddings
									a__       :						List[Any]							=  type_vocab_size
									a__       :						List[Any]							=  type_sequence_label_size
									a__       :						Tuple							=  initializer_range
									a__       :						Optional[int]							=  num_labels
									a__       :						str							=  num_choices
									a__       :						Union[str, Any]							=  relative_attention
									a__       :						Dict							=  position_biased_input
									a__       :						List[str]							=  pos_att_type
									a__       :						Any							=  scope

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Union[str, Any]:
									"""simple docstring"""




									a__       :						Union[str, Any]							=  ids_tensor([self.batch_size, self.seq_length] ,       self.vocab_size  )

									a__       :						List[str]							=  None
									if self.use_input_mask:
												a__       :						int							=  random_attention_mask([self.batch_size, self.seq_length]  )

									a__       :						List[str]							=  None
									if self.use_token_type_ids:
												a__       :						Dict							=  ids_tensor([self.batch_size, self.seq_length] ,       self.type_vocab_size  )

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

									a__       :						Tuple							=  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=__lowercase ,       )

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

						def 							SCREAMING_SNAKE_CASE__(       self ,       __lowercase ,       __lowercase ,       __lowercase ,       __lowercase ,       __lowercase ,       __lowercase ,       __lowercase  ) ->				List[str]:
									"""simple docstring"""




									a__       :						Tuple							=  TFDebertaVaModel(config=__lowercase  )
									a__       :						List[str]							=  {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}

									a__       :						Optional[int]							=  [input_ids, input_mask]
									a__       :						Dict							=  model(__lowercase  )

									a__       :						List[str]							=  model(__lowercase  )

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

						def 							SCREAMING_SNAKE_CASE__(       self ,       __lowercase ,       __lowercase ,       __lowercase ,       __lowercase ,       __lowercase ,       __lowercase ,       __lowercase  ) ->				Dict:
									"""simple docstring"""




									a__       :						int							=  TFDebertaVaForMaskedLM(config=__lowercase  )
									a__       :						Dict							=  {
									    """input_ids""": input_ids,
									    """attention_mask""": input_mask,
									    """token_type_ids""": token_type_ids,
									}
									a__       :						Optional[Any]							=  model(__lowercase  )
									self.parent.assertEqual(result.logits.shape ,       (self.batch_size, self.seq_length, self.vocab_size)  )

						def 							SCREAMING_SNAKE_CASE__(       self ,       __lowercase ,       __lowercase ,       __lowercase ,       __lowercase ,       __lowercase ,       __lowercase ,       __lowercase  ) ->				Optional[int]:
									"""simple docstring"""




									a__       :						Optional[Any]							=  self.num_labels
									a__       :						Dict							=  TFDebertaVaForSequenceClassification(config=__lowercase  )
									a__       :						Optional[Any]							=  {
									    """input_ids""": input_ids,
									    """attention_mask""": input_mask,
									    """token_type_ids""": token_type_ids,
									}

									a__       :						List[str]							=  model(__lowercase  )
									self.parent.assertEqual(result.logits.shape ,       (self.batch_size, self.num_labels)  )

						def 							SCREAMING_SNAKE_CASE__(       self ,       __lowercase ,       __lowercase ,       __lowercase ,       __lowercase ,       __lowercase ,       __lowercase ,       __lowercase  ) ->				List[str]:
									"""simple docstring"""




									a__       :						Tuple							=  self.num_labels
									a__       :						Union[str, Any]							=  TFDebertaVaForTokenClassification(config=__lowercase  )
									a__       :						Optional[Any]							=  {
									    """input_ids""": input_ids,
									    """attention_mask""": input_mask,
									    """token_type_ids""": token_type_ids,
									}
									a__       :						Union[str, Any]							=  model(__lowercase  )
									self.parent.assertEqual(result.logits.shape ,       (self.batch_size, self.seq_length, self.num_labels)  )

						def 							SCREAMING_SNAKE_CASE__(       self ,       __lowercase ,       __lowercase ,       __lowercase ,       __lowercase ,       __lowercase ,       __lowercase ,       __lowercase  ) ->				Dict:
									"""simple docstring"""




									a__       :						Any							=  TFDebertaVaForQuestionAnswering(config=__lowercase  )
									a__       :						Dict							=  {
									    """input_ids""": input_ids,
									    """attention_mask""": input_mask,
									    """token_type_ids""": token_type_ids,
									}

									a__       :						List[str]							=  model(__lowercase  )
									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  ) ->				int:
									"""simple docstring"""




									a__       :						List[str]							=  self.prepare_config_and_inputs()
									(
									    (
									    a__
									)	,						(
									    a__
									)	,						(
									    a__
									)	,						(
									    a__
									)	,						(
									    a__
									)	,						(
									    a__
									)	,						(
									    a__
									)	,						
									)       :						List[str]							=  config_and_inputs
									a__       :						int							=  {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
									return config, inputs_dict




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







						"""simple docstring"""




						__lowerCAmelCase					:Optional[Any]      =					(
						    (
						        TFDebertaVaModel,
						        TFDebertaVaForMaskedLM,
						        TFDebertaVaForQuestionAnswering,
						        TFDebertaVaForSequenceClassification,
						        TFDebertaVaForTokenClassification,
						    )
						    if is_tf_available()
						    else ()
						)
						__lowerCAmelCase					:Dict      =					(
						    {
						        "feature-extraction": TFDebertaVaModel,
						        "fill-mask": TFDebertaVaForMaskedLM,
						        "question-answering": TFDebertaVaForQuestionAnswering,
						        "text-classification": TFDebertaVaForSequenceClassification,
						        "token-classification": TFDebertaVaForTokenClassification,
						        "zero-shot": TFDebertaVaForSequenceClassification,
						    }
						    if is_tf_available()
						    else {}
						)

						__lowerCAmelCase					:Tuple      =					False
						__lowerCAmelCase					:Union[str, Any]      =					False

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Tuple:
									"""simple docstring"""




									a__       :						Dict							=  TFDebertaVaModelTester(self  )
									a__       :						Dict							=  ConfigTester(self ,       config_class=__lowercase ,       hidden_size=3_7  )

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Union[str, Any]:
									"""simple docstring"""




									self.config_tester.run_common_tests()

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				List[str]:
									"""simple docstring"""




									a__       :						List[str]							=  self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*__lowercase  )

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Any:
									"""simple docstring"""




									a__       :						List[str]							=  self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_masked_lm(*__lowercase  )

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Any:
									"""simple docstring"""




									a__       :						Any							=  self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_question_answering(*__lowercase  )

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				List[Any]:
									"""simple docstring"""




									a__       :						Optional[int]							=  self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_sequence_classification(*__lowercase  )

						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				List[str]:
									"""simple docstring"""




									a__       :						Any							=  self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_token_classification(*__lowercase  )

						@slow
						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				str:
									"""simple docstring"""




									a__       :						Union[str, Any]							=  TFDebertaVaModel.from_pretrained("""kamalkraj/deberta-v2-xlarge"""  )
									self.assertIsNotNone(__lowercase  )




@require_tf
class        snake_case__    (unittest.TestCase		):







						"""simple docstring"""




						@unittest.skip(reason="""Model not available yet"""  )
						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				List[Any]:
									"""simple docstring"""




									pass

						@slow
						def 							SCREAMING_SNAKE_CASE__(       self  ) ->				Optional[Any]:
									"""simple docstring"""




									a__       :						Dict							=  TFDebertaVaModel.from_pretrained("""kamalkraj/deberta-v2-xlarge"""  )
									a__       :						List[str]							=  tf.constant([[0, 3_1_4_1_4, 2_3_2, 3_2_8, 7_4_0, 1_1_4_0, 1_2_6_9_5, 6_9, 4_6_0_7_8, 1_5_8_8, 2]]  )
									a__       :						List[str]							=  tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]  )
									a__       :						List[Any]							=  model(__lowercase ,       attention_mask=__lowercase  )[0]

									a__       :						List[Any]							=  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] ,       __lowercase ,       atol=1E-4  )









def      lowerCAmelCase_					(  _lowercase    :       int)							->	int:







			"""simple docstring"""

			if not isinstance(_lowercase						,       _lowercase):
						raise TypeError("""only integers accepted as input""")
			else:
						a__       :						Any							=  str(abs(_lowercase))
						a__       :						str							=  [list(_lowercase) for char in range(len(_lowercase))]
						for index in range(len(_lowercase)):
									num_transpositions[index].pop(_lowercase)
						return max(
						    int("""""".join(list(_lowercase))) for transposition in num_transpositions)


if __name__ == "__main__":
		__import__("doctest").testmod()




