




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




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




     '''simple docstring'''

     A__	=    parent
     A__	=    batch_size
     A__	=    seq_length
     A__	=    is_training
     A__	=    use_input_mask
     A__	=    use_token_type_ids
     A__	=    use_labels
     A__	=    vocab_size
     A__	=    hidden_size
     A__	=    num_hidden_layers
     A__	=    num_attention_heads
     A__	=    intermediate_size
     A__	=    hidden_act
     A__	=    hidden_dropout_prob
     A__	=    attention_probs_dropout_prob
     A__	=    max_position_embeddings
     A__	=    type_vocab_size
     A__	=    type_sequence_label_size
     A__	=    initializer_range
     A__	=    num_labels
     A__	=    num_choices
     A__	=    relative_attention
     A__	=    position_biased_input
     A__	=    pos_att_type
     A__	=    scope




    def 							__magic_name__							(   self						:	List[str]				)				->							List[Any]:




     '''simple docstring'''

     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__	=    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=snake_case_     ,			)

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




    def 							__magic_name__							(   self						:	Dict     ,			snake_case_						:	Any     ,			snake_case_						:	Tuple     ,			snake_case_						:	Union[str, Any]     ,			snake_case_						:	Optional[Any]     ,			snake_case_						:	Tuple     ,			snake_case_						:	List[Any]     ,			snake_case_						:	Any				)				->							List[Any]:




     '''simple docstring'''

     A__	=    TFDebertaVaModel(config=snake_case_				)
     A__	=    {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

     A__	=    [input_ids, input_mask]
     A__	=    model(snake_case_				)

     A__	=    model(snake_case_				)

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




    def 							__magic_name__							(   self						:	Any     ,			snake_case_						:	Union[str, Any]     ,			snake_case_						:	Any     ,			snake_case_						:	Tuple     ,			snake_case_						:	Any     ,			snake_case_						:	Any     ,			snake_case_						:	List[Any]     ,			snake_case_						:	Any				)				->							Optional[Any]:




     '''simple docstring'''

     A__	=    TFDebertaVaForMaskedLM(config=snake_case_				)
     A__	=    {
         "input_ids": input_ids,
         "attention_mask": input_mask,
         "token_type_ids": token_type_ids,
     }
     A__	=    model(snake_case_				)
     self.parent.assertEqual(result.logits.shape     ,			(self.batch_size, self.seq_length, self.vocab_size)				)




    def 							__magic_name__							(   self						:	int     ,			snake_case_						:	List[str]     ,			snake_case_						:	Any     ,			snake_case_						:	List[Any]     ,			snake_case_						:	Any     ,			snake_case_						:	Union[str, Any]     ,			snake_case_						:	Union[str, Any]     ,			snake_case_						:	Tuple				)				->							List[str]:




     '''simple docstring'''

     A__	=    self.num_labels
     A__	=    TFDebertaVaForSequenceClassification(config=snake_case_				)
     A__	=    {
         "input_ids": input_ids,
         "attention_mask": input_mask,
         "token_type_ids": token_type_ids,
     }

     A__	=    model(snake_case_				)
     self.parent.assertEqual(result.logits.shape     ,			(self.batch_size, self.num_labels)				)




    def 							__magic_name__							(   self						:	str     ,			snake_case_						:	str     ,			snake_case_						:	List[str]     ,			snake_case_						:	Optional[int]     ,			snake_case_						:	str     ,			snake_case_						:	Any     ,			snake_case_						:	List[str]     ,			snake_case_						:	str				)				->							Optional[Any]:




     '''simple docstring'''

     A__	=    self.num_labels
     A__	=    TFDebertaVaForTokenClassification(config=snake_case_				)
     A__	=    {
         "input_ids": input_ids,
         "attention_mask": input_mask,
         "token_type_ids": token_type_ids,
     }
     A__	=    model(snake_case_				)
     self.parent.assertEqual(result.logits.shape     ,			(self.batch_size, self.seq_length, self.num_labels)				)




    def 							__magic_name__							(   self						:	Dict     ,			snake_case_						:	Union[str, Any]     ,			snake_case_						:	int     ,			snake_case_						:	Tuple     ,			snake_case_						:	str     ,			snake_case_						:	int     ,			snake_case_						:	List[str]     ,			snake_case_						:	Tuple				)				->							str:




     '''simple docstring'''

     A__	=    TFDebertaVaForQuestionAnswering(config=snake_case_				)
     A__	=    {
         "input_ids": input_ids,
         "attention_mask": input_mask,
         "token_type_ids": token_type_ids,
     }

     A__	=    model(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 							__magic_name__							(   self						:	Optional[int]				)				->							int:




     '''simple docstring'''

     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      UpperCAmelCase_  (						A_,       A_,       unittest.TestCase							):
    lowercase__						 =				(
        (
            TFDebertaVaModel,
            TFDebertaVaForMaskedLM,
            TFDebertaVaForQuestionAnswering,
            TFDebertaVaForSequenceClassification,
            TFDebertaVaForTokenClassification,
        )
        if is_tf_available()
        else ()
    )
    lowercase__						 =				(
        {
            '''feature-extraction''': TFDebertaVaModel,
            '''fill-mask''': TFDebertaVaForMaskedLM,
            '''question-answering''': TFDebertaVaForQuestionAnswering,
            '''text-classification''': TFDebertaVaForSequenceClassification,
            '''token-classification''': TFDebertaVaForTokenClassification,
            '''zero-shot''': TFDebertaVaForSequenceClassification,
        }
        if is_tf_available()
        else {}
    )

    lowercase__						 =				False
    lowercase__						 =				False




    def 							__magic_name__							(   self						:	List[Any]				)				->							Dict:




     '''simple docstring'''

     A__	=    TFDebertaVaModelTester(self				)
     A__	=    ConfigTester(self     ,			config_class=snake_case_     ,			hidden_size=37				)




    def 							__magic_name__							(   self						:	str				)				->							Tuple:




     '''simple docstring'''

     self.config_tester.run_common_tests()




    def 							__magic_name__							(   self						:	Union[str, Any]				)				->							List[Any]:




     '''simple docstring'''

     A__	=    self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_model(*snake_case_				)




    def 							__magic_name__							(   self						:	List[Any]				)				->							str:




     '''simple docstring'''

     A__	=    self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_masked_lm(*snake_case_				)




    def 							__magic_name__							(   self						:	Optional[int]				)				->							Dict:




     '''simple docstring'''

     A__	=    self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_question_answering(*snake_case_				)




    def 							__magic_name__							(   self						:	Any				)				->							Tuple:




     '''simple docstring'''

     A__	=    self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_sequence_classification(*snake_case_				)




    def 							__magic_name__							(   self						:	Any				)				->							str:




     '''simple docstring'''

     A__	=    self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_token_classification(*snake_case_				)




    @slow
    def 							__magic_name__							(   self						:	str				)				->							Dict:




     '''simple docstring'''

     A__	=    TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"				)
     self.assertIsNotNone(snake_case_				)






@require_tf
class      UpperCAmelCase_  (						unittest.TestCase							):




    @unittest.skip(reason="Model not available yet"				)
    def 							__magic_name__							(   self						:	Union[str, Any]				)				->							Optional[Any]:




     '''simple docstring'''

     pass




    @slow
    def 							__magic_name__							(   self						:	int				)				->							int:




     '''simple docstring'''

     A__	=    TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"				)
     A__	=    tf.constant([[0, 31_414, 232, 328, 740, 1_140, 12_695, 69, 46_078, 1_588, 2]]				)
     A__	=    tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]				)
     A__	=    model(snake_case_     ,			attention_mask=snake_case_				)[0]

     A__	=    tf.constant(
         [[[0.2356, 0.1948, 0.0369], [-0.1063, 0.3586, -0.5152], [-0.6399, -0.0259, -0.2525]]]				)
     tf.debugging.assert_near(output[:, 1:4, 1:4]     ,			snake_case_     ,			atol=1e-4				)











"""simple docstring"""



import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding




class      UpperCAmelCase_  (						A_							):
    lowercase__						 =				['''image_processor''', '''tokenizer''']
    lowercase__						 =				'''ViTImageProcessor'''
    lowercase__						 =				('''CLIPTokenizer''', '''CLIPTokenizerFast''')




    def __init__(   self						:	Optional[Any]     ,			snake_case_						:	Union[str, Any]=None     ,			snake_case_						:	Dict=None     ,			**snake_case_						:	Optional[Any]				)				->							List[str]:




     '''simple docstring'''

     A__	=    None
     if "feature_extractor" in kwargs:
      warnings.warn(
          "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"
          " instead."     ,			snake_case_     ,			)
      A__	=    kwargs.pop("feature_extractor"				)

     A__	=    image_processor if image_processor is not None else feature_extractor
     if image_processor is None:
      raise ValueError("You need to specify an `image_processor`."				)
     if tokenizer is None:
      raise ValueError("You need to specify a `tokenizer`."				)

     super().__init__(snake_case_     ,			snake_case_				)




    def __call__(   self						:	int     ,			snake_case_						:	Union[str, Any]=None     ,			snake_case_						:	int=None     ,			snake_case_						:	Dict=None     ,			snake_case_						:	int=None     ,			**snake_case_						:	List[str]				)				->							Union[str, Any]:




     '''simple docstring'''

     if text is None and visual_prompt is None and images is None:
      raise ValueError("You have to specify either text, visual prompt or images."				)

     if text is not None and visual_prompt is not None:
      raise ValueError("You have to specify exactly one type of prompt. Either text or visual prompt."				)

     if text is not None:
      A__	=    self.tokenizer(snake_case_     ,			return_tensors=snake_case_     ,			**snake_case_				)

     if visual_prompt is not None:
      A__	=    self.image_processor(snake_case_     ,			return_tensors=snake_case_     ,			**snake_case_				)

     if images is not None:
      A__	=    self.image_processor(snake_case_     ,			return_tensors=snake_case_     ,			**snake_case_				)

     if visual_prompt is not None and images is not None:
      A__	=    {
          "pixel_values": image_features.pixel_values,
          "conditional_pixel_values": prompt_features.pixel_values,
      }
      return encoding
     elif text is not None and images is not None:
      A__	=    image_features.pixel_values
      return encoding
     elif text is not None:
      return encoding
     elif visual_prompt is not None:
      A__	=    {
          "conditional_pixel_values": prompt_features.pixel_values,
      }
      return encoding
     else:
      return BatchEncoding(data=dict(**snake_case_				)     ,			tensor_type=snake_case_				)




    def 							__magic_name__							(   self						:	Tuple     ,			*snake_case_						:	List[str]     ,			**snake_case_						:	Optional[int]				)				->							str:




     '''simple docstring'''

     return self.tokenizer.batch_decode(*snake_case_     ,			**snake_case_				)




    def 							__magic_name__							(   self						:	Optional[Any]     ,			*snake_case_						:	Any     ,			**snake_case_						:	List[Any]				)				->							List[str]:




     '''simple docstring'''

     return self.tokenizer.decode(*snake_case_     ,			**snake_case_				)




    @property
    def 							__magic_name__							(   self						:	int				)				->							Optional[int]:




     '''simple docstring'''

     warnings.warn(
         "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."     ,			snake_case_     ,			)
     return self.image_processor_class




    @property
    def 							__magic_name__							(   self						:	int				)				->							int:




     '''simple docstring'''

     warnings.warn(
         "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."     ,			snake_case_     ,			)
     return self.image_processor





