

"""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 		_A       :





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





      def 					_lowerCamelCase  (  self		)   ->					str:
         lowerCamelCase__						=			ids_tensor([self.batch_size, self.seq_length]    ,						self.vocab_size		)

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

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

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

         lowerCamelCase__						=			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=SCREAMING_SNAKE_CASE__    ,						)

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





      def 					_lowerCamelCase  (  self    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__		)   ->					Optional[int]:
         lowerCamelCase__						=			TFDebertaVaModel(config=SCREAMING_SNAKE_CASE__		)
         lowerCamelCase__						=			{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

         lowerCamelCase__						=			[input_ids, input_mask]
         lowerCamelCase__						=			model(SCREAMING_SNAKE_CASE__		)

         lowerCamelCase__						=			model(SCREAMING_SNAKE_CASE__		)

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





      def 					_lowerCamelCase  (  self    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__		)   ->					Tuple:
         lowerCamelCase__						=			TFDebertaVaForMaskedLM(config=SCREAMING_SNAKE_CASE__		)
         lowerCamelCase__						=			{
             "input_ids": input_ids,
             "attention_mask": input_mask,
             "token_type_ids": token_type_ids,
         }
         lowerCamelCase__						=			model(SCREAMING_SNAKE_CASE__		)
         self.parent.assertEqual(result.logits.shape    ,						(self.batch_size, self.seq_length, self.vocab_size)		)





      def 					_lowerCamelCase  (  self    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__		)   ->					Optional[Any]:
         lowerCamelCase__						=			self.num_labels
         lowerCamelCase__						=			TFDebertaVaForSequenceClassification(config=SCREAMING_SNAKE_CASE__		)
         lowerCamelCase__						=			{
             "input_ids": input_ids,
             "attention_mask": input_mask,
             "token_type_ids": token_type_ids,
         }

         lowerCamelCase__						=			model(SCREAMING_SNAKE_CASE__		)
         self.parent.assertEqual(result.logits.shape    ,						(self.batch_size, self.num_labels)		)





      def 					_lowerCamelCase  (  self    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__		)   ->					Any:
         lowerCamelCase__						=			self.num_labels
         lowerCamelCase__						=			TFDebertaVaForTokenClassification(config=SCREAMING_SNAKE_CASE__		)
         lowerCamelCase__						=			{
             "input_ids": input_ids,
             "attention_mask": input_mask,
             "token_type_ids": token_type_ids,
         }
         lowerCamelCase__						=			model(SCREAMING_SNAKE_CASE__		)
         self.parent.assertEqual(result.logits.shape    ,						(self.batch_size, self.seq_length, self.num_labels)		)





      def 					_lowerCamelCase  (  self    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__    ,						SCREAMING_SNAKE_CASE__		)   ->					Tuple:
         lowerCamelCase__						=			TFDebertaVaForQuestionAnswering(config=SCREAMING_SNAKE_CASE__		)
         lowerCamelCase__						=			{
             "input_ids": input_ids,
             "attention_mask": input_mask,
             "token_type_ids": token_type_ids,
         }

         lowerCamelCase__						=			model(SCREAMING_SNAKE_CASE__		)
         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 					_lowerCamelCase  (  self		)   ->					str:
         lowerCamelCase__						=			self.prepare_config_and_inputs()
         (
             (
             lowerCamelCase__
         )					,       (
             lowerCamelCase__
         )					,       (
             lowerCamelCase__
         )					,       (
             lowerCamelCase__
         )					,       (
             lowerCamelCase__
         )					,       (
             lowerCamelCase__
         )					,       (
             lowerCamelCase__
         )					,       
         )						=			config_and_inputs
         lowerCamelCase__						=			{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
         return config, inputs_dict






@require_tf
class 		_A       (			__a				,       __a				,       unittest.TestCase					):
      __a								=	(
          (
              TFDebertaVaModel,
              TFDebertaVaForMaskedLM,
              TFDebertaVaForQuestionAnswering,
              TFDebertaVaForSequenceClassification,
              TFDebertaVaForTokenClassification,
          )
          if is_tf_available()
          else ()
      )
      __a								=	(
          {
              'feature-extraction': TFDebertaVaModel,
              'fill-mask': TFDebertaVaForMaskedLM,
              'question-answering': TFDebertaVaForQuestionAnswering,
              'text-classification': TFDebertaVaForSequenceClassification,
              'token-classification': TFDebertaVaForTokenClassification,
              'zero-shot': TFDebertaVaForSequenceClassification,
          }
          if is_tf_available()
          else {}
      )

      __a								=	False
      __a								=	False





      def 					_lowerCamelCase  (  self		)   ->					Tuple:
         lowerCamelCase__						=			TFDebertaVaModelTester(self		)
         lowerCamelCase__						=			ConfigTester(self    ,						config_class=SCREAMING_SNAKE_CASE__    ,						hidden_size=37		)





      def 					_lowerCamelCase  (  self		)   ->					List[str]:
         self.config_tester.run_common_tests()





      def 					_lowerCamelCase  (  self		)   ->					Tuple:
         lowerCamelCase__						=			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE__		)





      def 					_lowerCamelCase  (  self		)   ->					Optional[int]:
         lowerCamelCase__						=			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_masked_lm(*SCREAMING_SNAKE_CASE__		)





      def 					_lowerCamelCase  (  self		)   ->					List[str]:
         lowerCamelCase__						=			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_question_answering(*SCREAMING_SNAKE_CASE__		)





      def 					_lowerCamelCase  (  self		)   ->					Tuple:
         lowerCamelCase__						=			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_sequence_classification(*SCREAMING_SNAKE_CASE__		)





      def 					_lowerCamelCase  (  self		)   ->					Optional[int]:
         lowerCamelCase__						=			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_token_classification(*SCREAMING_SNAKE_CASE__		)





      @slow
      def 					_lowerCamelCase  (  self		)   ->					Tuple:
         lowerCamelCase__						=			TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"		)
         self.assertIsNotNone(SCREAMING_SNAKE_CASE__		)






@require_tf
class 		_A       (			unittest.TestCase					):





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





      @slow
      def 					_lowerCamelCase  (  self		)   ->					int:
         lowerCamelCase__						=			TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"		)
         lowerCamelCase__						=			tf.constant([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]		)
         lowerCamelCase__						=			tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
         lowerCamelCase__						=			model(SCREAMING_SNAKE_CASE__    ,						attention_mask=SCREAMING_SNAKE_CASE__		)[0]

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







"""simple docstring"""




def 	UpperCAmelCase__   (				A__   )      ->      str:




   """simple docstring"""
   return " ".join(input_str.split()[::-1]   )


if __name__ == "__main__":
     import doctest

     doctest.testmod()




