




'''simple docstring'''







from __future__ import annotations

import unittest

from transformers import DebertaConfig, 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 (
          TFDebertaForMaskedLM,
          TFDebertaForQuestionAnswering,
          TFDebertaForSequenceClassification,
          TFDebertaForTokenClassification,
          TFDebertaModel,
      )







class 				_a   :





     '''simple docstring'''



     def __init__(							self       ,__a       ,__a=13       ,__a=7       ,__a=True       ,__a=True       ,__a=True       ,__a=True       ,__a=99       ,__a=32       ,__a=2       ,__a=4       ,__a=37       ,__a="gelu"       ,__a=0.1       ,__a=0.1       ,__a=512       ,__a=16       ,__a=2       ,__a=0.02       ,__a=3       ,__a=4       ,__a=None       ,)			->							Union[str, Any]:
          snake_case :			List[str]					   = parent
          snake_case :			Dict					   = 13
          snake_case :			List[str]					   = 7
          snake_case :			Dict					   = True
          snake_case :			Optional[int]					   = True
          snake_case :			Union[str, Any]					   = True
          snake_case :			Union[str, Any]					   = True
          snake_case :			int					   = 99
          snake_case :			Union[str, Any]					   = 32
          snake_case :			Dict					   = 2
          snake_case :			Optional[Any]					   = 4
          snake_case :			int					   = 37
          snake_case :			List[Any]					   = """gelu"""
          snake_case :			List[Any]					   = 0.1
          snake_case :			Optional[Any]					   = 0.1
          snake_case :			Any					   = 512
          snake_case :			List[str]					   = 16
          snake_case :			Union[str, Any]					   = False
          snake_case :			List[Any]					   = -1
          snake_case :			Any					   = True
          snake_case :			str					   = 2
          snake_case :			Union[str, Any]					   = 0.02
          snake_case :			Optional[int]					   = 3
          snake_case :			List[Any]					   = 4
          snake_case :			Optional[Any]					   = None







     def  snake_case_			(							self       )			->							str:
          snake_case :			int					   = ids_tensor([self.batch_size, self.seq_length]       ,self.vocab_size       )

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

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

          snake_case :			Optional[Any]					   = None
          snake_case :			Dict					   = None
          snake_case :			Dict					   = None
          if self.use_labels:
               snake_case :			Any					   = ids_tensor([self.batch_size]       ,self.type_sequence_label_size       )
               snake_case :			Dict					   = ids_tensor([self.batch_size, self.seq_length]       ,self.num_labels       )

          snake_case :			List[Any]					   = DebertaConfig(
              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       ,max_relative_positions=self.max_relative_positions       ,position_biased_input=self.position_biased_input       ,initializer_range=self.initializer_range       ,return_dict=__a       ,)

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







     def  snake_case_			(							self       ,__a       ,__a       ,__a       ,__a       ,__a       ,__a       ,__a       )			->							List[Any]:
          snake_case :			Tuple					   = TFDebertaModel(config=__a       )
          snake_case :			int					   = {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}

          snake_case :			str					   = [input_ids, input_mask]
          snake_case :			Optional[Any]					   = model(__a       )

          snake_case :			Any					   = model(__a       )

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







     def  snake_case_			(							self       ,__a       ,__a       ,__a       ,__a       ,__a       ,__a       ,__a       )			->							Tuple:
          snake_case :			List[str]					   = TFDebertaForMaskedLM(config=__a       )
          snake_case :			int					   = {
              """input_ids""": input_ids,
              """attention_mask""": input_mask,
              """token_type_ids""": token_type_ids,
          }
          snake_case :			List[Any]					   = model(__a       )
          self.parent.assertEqual(result.logits.shape       ,(self.batch_size, self.seq_length, self.vocab_size)       )







     def  snake_case_			(							self       ,__a       ,__a       ,__a       ,__a       ,__a       ,__a       ,__a       )			->							Dict:
          snake_case :			Dict					   = self.num_labels
          snake_case :			int					   = TFDebertaForSequenceClassification(config=__a       )
          snake_case :			Union[str, Any]					   = {
              """input_ids""": input_ids,
              """attention_mask""": input_mask,
              """token_type_ids""": token_type_ids,
          }

          snake_case :			List[Any]					   = model(__a       )
          self.parent.assertEqual(result.logits.shape       ,(self.batch_size, self.num_labels)       )







     def  snake_case_			(							self       ,__a       ,__a       ,__a       ,__a       ,__a       ,__a       ,__a       )			->							Union[str, Any]:
          snake_case :			int					   = self.num_labels
          snake_case :			Optional[Any]					   = TFDebertaForTokenClassification(config=__a       )
          snake_case :			int					   = {
              """input_ids""": input_ids,
              """attention_mask""": input_mask,
              """token_type_ids""": token_type_ids,
          }
          snake_case :			str					   = model(__a       )
          self.parent.assertEqual(result.logits.shape       ,(self.batch_size, self.seq_length, self.num_labels)       )







     def  snake_case_			(							self       ,__a       ,__a       ,__a       ,__a       ,__a       ,__a       ,__a       )			->							Union[str, Any]:
          snake_case :			str					   = TFDebertaForQuestionAnswering(config=__a       )
          snake_case :			List[str]					   = {
              """input_ids""": input_ids,
              """attention_mask""": input_mask,
              """token_type_ids""": token_type_ids,
          }

          snake_case :			int					   = model(__a       )
          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  snake_case_			(							self       )			->							Tuple:
          snake_case :			List[Any]					   = self.prepare_config_and_inputs()
          (
              (
              snake_case
          )   ,		(
              snake_case
          )   ,		(
              snake_case
          )   ,		(
              snake_case
          )   ,		(
              snake_case
          )   ,		(
              snake_case
          )   ,		(
              snake_case
          )   ,		
          ) :			List[Any]					   = config_and_inputs
          snake_case :			Optional[Any]					   = {"""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  ):





     '''simple docstring'''



     lowerCAmelCase_     :    Optional[int]									=				(
         (
             TFDebertaModel,
             TFDebertaForMaskedLM,
             TFDebertaForQuestionAnswering,
             TFDebertaForSequenceClassification,
             TFDebertaForTokenClassification,
         )
         if is_tf_available()
         else ()
     )
     lowerCAmelCase_     :    List[Any]									=				(
         {
             """feature-extraction""": TFDebertaModel,
             """fill-mask""": TFDebertaForMaskedLM,
             """question-answering""": TFDebertaForQuestionAnswering,
             """text-classification""": TFDebertaForSequenceClassification,
             """token-classification""": TFDebertaForTokenClassification,
             """zero-shot""": TFDebertaForSequenceClassification,
         }
         if is_tf_available()
         else {}
     )

     lowerCAmelCase_     :    str									=				False
     lowerCAmelCase_     :    Tuple									=				False







     def  snake_case_			(							self       )			->							Union[str, Any]:
          snake_case :			int					   = TFDebertaModelTester(self       )
          snake_case :			int					   = ConfigTester(self       ,config_class=__a       ,hidden_size=37       )







     def  snake_case_			(							self       )			->							int:
          self.config_tester.run_common_tests()







     def  snake_case_			(							self       )			->							Tuple:
          snake_case :			Dict					   = self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*__a       )







     def  snake_case_			(							self       )			->							str:
          snake_case :			str					   = self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_masked_lm(*__a       )







     def  snake_case_			(							self       )			->							int:
          snake_case :			Union[str, Any]					   = self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_question_answering(*__a       )







     def  snake_case_			(							self       )			->							Any:
          snake_case :			Dict					   = self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_sequence_classification(*__a       )







     def  snake_case_			(							self       )			->							Tuple:
          snake_case :			Optional[Any]					   = self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_token_classification(*__a       )







     @slow
     def  snake_case_			(							self       )			->							str:
          snake_case :			Tuple					   = TFDebertaModel.from_pretrained("""kamalkraj/deberta-base"""       )
          self.assertIsNotNone(__a       )







@require_tf
class 				_a   (unittest.TestCase  ):





     '''simple docstring'''



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







     @slow
     def  snake_case_			(							self       )			->							int:
          snake_case :			Dict					   = TFDebertaModel.from_pretrained("""kamalkraj/deberta-base"""       )
          snake_case :			int					   = tf.constant([[0, 31_414, 232, 328, 740, 1_140, 12_695, 69, 46_078, 1_588, 2]]       )
          snake_case :			Optional[int]					   = tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]       )
          snake_case :			Optional[Any]					   = model(__a       ,attention_mask=__a       )[0]

          snake_case :			Tuple					   = tf.constant(
              [
                  [
                      [-0.59_855_896, -0.80_552_566, -0.8_462_135],
                      [1.4_484_025, -0.93_483_794, -0.80_593_085],
                      [0.3_122_741, 0.00_316_059, -1.4_131_377],
                  ]
              ]       )
          tf.debugging.assert_near(output[:, 1:4, 1:4]       ,__a       ,atol=1E-4       )









'''simple docstring'''







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowercase			:      Any			=					{"""configuration_visual_bert""": ["""VISUAL_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """VisualBertConfig"""]}

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      lowercase			:      Optional[int]			=					[
          """VISUAL_BERT_PRETRAINED_MODEL_ARCHIVE_LIST""",
          """VisualBertForMultipleChoice""",
          """VisualBertForPreTraining""",
          """VisualBertForQuestionAnswering""",
          """VisualBertForRegionToPhraseAlignment""",
          """VisualBertForVisualReasoning""",
          """VisualBertLayer""",
          """VisualBertModel""",
          """VisualBertPreTrainedModel""",
      ]


if TYPE_CHECKING:
      from .configuration_visual_bert import VISUAL_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP, VisualBertConfig

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_visual_bert import (
                VISUAL_BERT_PRETRAINED_MODEL_ARCHIVE_LIST,
                VisualBertForMultipleChoice,
                VisualBertForPreTraining,
                VisualBertForQuestionAnswering,
                VisualBertForRegionToPhraseAlignment,
                VisualBertForVisualReasoning,
                VisualBertLayer,
                VisualBertModel,
                VisualBertPreTrainedModel,
            )


else:
      import sys

      lowercase			:      List[Any]			=					_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)



