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







   def __init__( self       ,							__UpperCAmelCase       ,							__UpperCAmelCase=13       ,							__UpperCAmelCase=7       ,							__UpperCAmelCase=True       ,							__UpperCAmelCase=True       ,							__UpperCAmelCase=True       ,							__UpperCAmelCase=True       ,							__UpperCAmelCase=99       ,							__UpperCAmelCase=32       ,							__UpperCAmelCase=2       ,							__UpperCAmelCase=4       ,							__UpperCAmelCase=37       ,							__UpperCAmelCase="gelu"       ,							__UpperCAmelCase=0.1       ,							__UpperCAmelCase=0.1       ,							__UpperCAmelCase=5_12       ,							__UpperCAmelCase=16       ,							__UpperCAmelCase=2       ,							__UpperCAmelCase=0.02       ,							__UpperCAmelCase=3       ,							__UpperCAmelCase=4       ,							__UpperCAmelCase=None       ,							)   ->List[str]:
      a_						   =     parent
      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_						   =     5_12
      a_						   =     16
      a_						   =     False
      a_						   =     -1
      a_						   =     True
      a_						   =     2
      a_						   =     0.02
      a_						   =     3
      a_						   =     4
      a_						   =     None







   def    UpperCAmelCase__	( self)   ->Dict:
      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_						   =     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=__UpperCAmelCase       ,							)

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







   def    UpperCAmelCase__	( self       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							__UpperCAmelCase)   ->Any:
      a_						   =     TFDebertaModel(config=__UpperCAmelCase)
      a_						   =     {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

      a_						   =     [input_ids, input_mask]
      a_						   =     model(__UpperCAmelCase)

      a_						   =     model(__UpperCAmelCase)

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







   def    UpperCAmelCase__	( self       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							__UpperCAmelCase)   ->Optional[int]:
      a_						   =     TFDebertaForMaskedLM(config=__UpperCAmelCase)
      a_						   =     {
          "input_ids": input_ids,
          "attention_mask": input_mask,
          "token_type_ids": token_type_ids,
      }
      a_						   =     model(__UpperCAmelCase)
      self.parent.assertEqual(result.logits.shape       ,							(self.batch_size, self.seq_length, self.vocab_size))







   def    UpperCAmelCase__	( self       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							__UpperCAmelCase)   ->List[Any]:
      a_						   =     self.num_labels
      a_						   =     TFDebertaForSequenceClassification(config=__UpperCAmelCase)
      a_						   =     {
          "input_ids": input_ids,
          "attention_mask": input_mask,
          "token_type_ids": token_type_ids,
      }

      a_						   =     model(__UpperCAmelCase)
      self.parent.assertEqual(result.logits.shape       ,							(self.batch_size, self.num_labels))







   def    UpperCAmelCase__	( self       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							__UpperCAmelCase)   ->Optional[Any]:
      a_						   =     self.num_labels
      a_						   =     TFDebertaForTokenClassification(config=__UpperCAmelCase)
      a_						   =     {
          "input_ids": input_ids,
          "attention_mask": input_mask,
          "token_type_ids": token_type_ids,
      }
      a_						   =     model(__UpperCAmelCase)
      self.parent.assertEqual(result.logits.shape       ,							(self.batch_size, self.seq_length, self.num_labels))







   def    UpperCAmelCase__	( self       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							__UpperCAmelCase)   ->str:
      a_						   =     TFDebertaForQuestionAnswering(config=__UpperCAmelCase)
      a_						   =     {
          "input_ids": input_ids,
          "attention_mask": input_mask,
          "token_type_ids": token_type_ids,
      }

      a_						   =     model(__UpperCAmelCase)
      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)   ->Dict:
      a_						   =     self.prepare_config_and_inputs()
      (
          (
          a_
      )   ,			(
          a_
      )   ,			(
          a_
      )   ,			(
          a_
      )   ,			(
          a_
      )   ,			(
          a_
      )   ,			(
          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 							snake_case       (     SCREAMING_SNAKE_CASE_							,       SCREAMING_SNAKE_CASE_							,       unittest.TestCase		):
   a_					:		Optional[int]     					=     (
       (
           TFDebertaModel,
           TFDebertaForMaskedLM,
           TFDebertaForQuestionAnswering,
           TFDebertaForSequenceClassification,
           TFDebertaForTokenClassification,
       )
       if is_tf_available()
       else ()
   )
   a_					:		Tuple     					=     (
       {
           """feature-extraction""": TFDebertaModel,
           """fill-mask""": TFDebertaForMaskedLM,
           """question-answering""": TFDebertaForQuestionAnswering,
           """text-classification""": TFDebertaForSequenceClassification,
           """token-classification""": TFDebertaForTokenClassification,
           """zero-shot""": TFDebertaForSequenceClassification,
       }
       if is_tf_available()
       else {}
   )

   a_					:		Dict     					=     False
   a_					:		Dict     					=     False







   def    UpperCAmelCase__	( self)   ->str:
      a_						   =     TFDebertaModelTester(self)
      a_						   =     ConfigTester(self       ,							config_class=__UpperCAmelCase       ,							hidden_size=37)







   def    UpperCAmelCase__	( self)   ->Optional[Any]:
      self.config_tester.run_common_tests()







   def    UpperCAmelCase__	( self)   ->Optional[Any]:
      a_						   =     self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*__UpperCAmelCase)







   def    UpperCAmelCase__	( self)   ->str:
      a_						   =     self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_masked_lm(*__UpperCAmelCase)







   def    UpperCAmelCase__	( self)   ->Optional[int]:
      a_						   =     self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_question_answering(*__UpperCAmelCase)







   def    UpperCAmelCase__	( self)   ->Union[str, Any]:
      a_						   =     self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_sequence_classification(*__UpperCAmelCase)







   def    UpperCAmelCase__	( self)   ->Tuple:
      a_						   =     self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_token_classification(*__UpperCAmelCase)







   @slow
   def    UpperCAmelCase__	( self)   ->Optional[Any]:
      a_						   =     TFDebertaModel.from_pretrained("kamalkraj/deberta-base")
      self.assertIsNotNone(__UpperCAmelCase)






@require_tf
class 							snake_case       (     unittest.TestCase		):







   @unittest.skip(reason="Model not available yet")
   def    UpperCAmelCase__	( self)   ->int:
      pass







   @slow
   def    UpperCAmelCase__	( self)   ->int:
      a_						   =     TFDebertaModel.from_pretrained("kamalkraj/deberta-base")
      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(__UpperCAmelCase       ,							attention_mask=__UpperCAmelCase)[0]

      a_						   =     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]       ,							__UpperCAmelCase       ,							atol=1E-4)

"""simple docstring"""






import copy

from transformers.configuration_utils import PretrainedConfig
from transformers.utils import logging


UpperCamelCase_						   =   logging.get_logger(__name__)





class 							snake_case       (     SCREAMING_SNAKE_CASE_		):
   a_					:		Tuple     					=     """hybrid-clip"""
   a_					:		Optional[Any]     					=     True







   def __init__( self       ,							__UpperCAmelCase=5_12       ,							**__UpperCAmelCase)   ->Dict:
      super().__init__(**__UpperCAmelCase)

      if "text_config" not in kwargs:
         raise ValueError("`text_config` can not be `None`.")

      if "vision_config" not in kwargs:
         raise ValueError("`vision_config` can not be `None`.")

      a_						   =     kwargs.pop("text_config")
      a_						   =     kwargs.pop("vision_config")

      a_						   =     text_config.pop("model_type")
      a_						   =     vision_config.pop("model_type")

      from transformers import AutoConfig

      a_						   =     AutoConfig.for_model(__UpperCAmelCase       ,							**__UpperCAmelCase)

      if vision_model_type == "clip":
         a_						   =     AutoConfig.for_model(__UpperCAmelCase       ,							**__UpperCAmelCase).vision_config
      elif vision_model_type == "clip_vision_model":
         from transformers import CLIPVisionConfig

         a_						   =     CLIPVisionConfig(**__UpperCAmelCase)
      else:
         a_						   =     AutoConfig.for_model(__UpperCAmelCase       ,							**__UpperCAmelCase)

      a_						   =     projection_dim
      a_						   =     1.0







   @classmethod
   def    UpperCAmelCase__	( cls       ,							__UpperCAmelCase       ,							__UpperCAmelCase       ,							**__UpperCAmelCase)   ->Optional[int]:
      return cls(text_config=text_config.to_dict()       ,							vision_config=vision_config.to_dict()       ,							**__UpperCAmelCase)







   def    UpperCAmelCase__	( self)   ->str:
      a_						   =     copy.deepcopy(self.__dict__)
      a_						   =     self.text_config.to_dict()
      a_						   =     self.vision_config.to_dict()
      a_						   =     self.__class__.model_type
      return output