
"""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							,						__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=5_12							,						__a=16							,						__a=2							,						__a=0.02							,						__a=False							,						__a=True							,						__a="None"							,						__a=3							,						__a=4							,						__a=None							,						)			->			Dict:






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



		def 		UpperCAmelCase				(   self)			->			str:






							'''simple docstring'''
							_UpperCamelCase									=    ids_tensor([self.batch_size, self.seq_length]							,						self.vocab_size)

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

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

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

							_UpperCamelCase									=    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=__a							,						)

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



		def 		UpperCAmelCase				(   self							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a)			->			Tuple:






							'''simple docstring'''
							_UpperCamelCase									=    TFDebertaVaModel(config=__a)
							_UpperCamelCase									=    {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

							_UpperCamelCase									=    [input_ids, input_mask]
							_UpperCamelCase									=    model(__a)

							_UpperCamelCase									=    model(__a)

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



		def 		UpperCAmelCase				(   self							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a)			->			Optional[Any]:






							'''simple docstring'''
							_UpperCamelCase									=    TFDebertaVaForMaskedLM(config=__a)
							_UpperCamelCase									=    {
							    '''input_ids''': input_ids,
							    '''attention_mask''': input_mask,
							    '''token_type_ids''': token_type_ids,
							}
							_UpperCamelCase									=    model(__a)
							self.parent.assertEqual(result.logits.shape							,						(self.batch_size, self.seq_length, self.vocab_size))



		def 		UpperCAmelCase				(   self							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a)			->			Optional[int]:






							'''simple docstring'''
							_UpperCamelCase									=    self.num_labels
							_UpperCamelCase									=    TFDebertaVaForSequenceClassification(config=__a)
							_UpperCamelCase									=    {
							    '''input_ids''': input_ids,
							    '''attention_mask''': input_mask,
							    '''token_type_ids''': token_type_ids,
							}

							_UpperCamelCase									=    model(__a)
							self.parent.assertEqual(result.logits.shape							,						(self.batch_size, self.num_labels))



		def 		UpperCAmelCase				(   self							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a)			->			Optional[Any]:






							'''simple docstring'''
							_UpperCamelCase									=    self.num_labels
							_UpperCamelCase									=    TFDebertaVaForTokenClassification(config=__a)
							_UpperCamelCase									=    {
							    '''input_ids''': input_ids,
							    '''attention_mask''': input_mask,
							    '''token_type_ids''': token_type_ids,
							}
							_UpperCamelCase									=    model(__a)
							self.parent.assertEqual(result.logits.shape							,						(self.batch_size, self.seq_length, self.num_labels))



		def 		UpperCAmelCase				(   self							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a							,						__a)			->			List[str]:






							'''simple docstring'''
							_UpperCamelCase									=    TFDebertaVaForQuestionAnswering(config=__a)
							_UpperCamelCase									=    {
							    '''input_ids''': input_ids,
							    '''attention_mask''': input_mask,
							    '''token_type_ids''': token_type_ids,
							}

							_UpperCamelCase									=    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 		UpperCAmelCase				(   self)			->			Any:






							'''simple docstring'''
							_UpperCamelCase									=    self.prepare_config_and_inputs()
							(
							    (
							    _UpperCamelCase
							)					,    (
							    _UpperCamelCase
							)					,    (
							    _UpperCamelCase
							)					,    (
							    _UpperCamelCase
							)					,    (
							    _UpperCamelCase
							)					,    (
							    _UpperCamelCase
							)					,    (
							    _UpperCamelCase
							)					,    
							)									=    config_and_inputs
							_UpperCamelCase									=    {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
							return config, inputs_dict






@require_tf
class        _UpperCAmelCase(       lowerCamelCase ,	lowerCamelCase ,	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 		UpperCAmelCase				(   self)			->			Optional[int]:






							'''simple docstring'''
							_UpperCamelCase									=    TFDebertaVaModelTester(self)
							_UpperCamelCase									=    ConfigTester(self							,						config_class=__a							,						hidden_size=37)



		def 		UpperCAmelCase				(   self)			->			int:






							'''simple docstring'''
							self.config_tester.run_common_tests()



		def 		UpperCAmelCase				(   self)			->			int:






							'''simple docstring'''
							_UpperCamelCase									=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*__a)



		def 		UpperCAmelCase				(   self)			->			Optional[Any]:






							'''simple docstring'''
							_UpperCamelCase									=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_lm(*__a)



		def 		UpperCAmelCase				(   self)			->			Tuple:






							'''simple docstring'''
							_UpperCamelCase									=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_question_answering(*__a)



		def 		UpperCAmelCase				(   self)			->			List[str]:






							'''simple docstring'''
							_UpperCamelCase									=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_sequence_classification(*__a)



		def 		UpperCAmelCase				(   self)			->			List[Any]:






							'''simple docstring'''
							_UpperCamelCase									=    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_token_classification(*__a)




		@slow
		def 		UpperCAmelCase				(   self)			->			List[str]:






							'''simple docstring'''
							_UpperCamelCase									=    TFDebertaVaModel.from_pretrained('''kamalkraj/deberta-v2-xlarge''')
							self.assertIsNotNone(__a)






@require_tf
class        _UpperCAmelCase(       unittest.TestCase      ):



		@unittest.skip(reason='''Model not available yet''')
		def 		UpperCAmelCase				(   self)			->			List[str]:






							'''simple docstring'''
							pass




		@slow
		def 		UpperCAmelCase				(   self)			->			str:






							'''simple docstring'''
							_UpperCamelCase									=    TFDebertaVaModel.from_pretrained('''kamalkraj/deberta-v2-xlarge''')
							_UpperCamelCase									=    tf.constant([[0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]])
							_UpperCamelCase									=    tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
							_UpperCamelCase									=    model(__a							,						attention_mask=__a)[0]

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








"""simple docstring"""





import warnings

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






class        _UpperCAmelCase(       lowerCamelCase      ):
		lowercase__         = ['image_processor', 'tokenizer']
		lowercase__         = 'ViTImageProcessor'
		lowercase__         = ('CLIPTokenizer', 'CLIPTokenizerFast')



		def __init__(   self							,						__a=None							,						__a=None							,						**__a)			->			Union[str, Any]:






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

							_UpperCamelCase									=    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__(__a							,						__a)



		def __call__(   self							,						__a=None							,						__a=None							,						__a=None							,						__a=None							,						**__a)			->			Tuple:






							'''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:
												_UpperCamelCase									=    self.tokenizer(__a							,						return_tensors=__a							,						**__a)

							if visual_prompt is not None:
												_UpperCamelCase									=    self.image_processor(__a							,						return_tensors=__a							,						**__a)

							if images is not None:
												_UpperCamelCase									=    self.image_processor(__a							,						return_tensors=__a							,						**__a)

							if visual_prompt is not None and images is not None:
												_UpperCamelCase									=    {
												    '''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:
												_UpperCamelCase									=    image_features.pixel_values
												return encoding
							elif text is not None:
												return encoding
							elif visual_prompt is not None:
												_UpperCamelCase									=    {
												    '''conditional_pixel_values''': prompt_features.pixel_values,
												}
												return encoding
							else:
												return BatchEncoding(data=dict(**__a)							,						tensor_type=__a)



		def 		UpperCAmelCase				(   self							,						*__a							,						**__a)			->			Any:






							'''simple docstring'''
							return self.tokenizer.batch_decode(*__a							,						**__a)



		def 		UpperCAmelCase				(   self							,						*__a							,						**__a)			->			List[str]:






							'''simple docstring'''
							return self.tokenizer.decode(*__a							,						**__a)



		@property
		def 		UpperCAmelCase				(   self)			->			List[str]:






							'''simple docstring'''
							warnings.warn(
							    '''`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.'''							,						__a							,						)
							return self.image_processor_class




		@property
		def 		UpperCAmelCase				(   self)			->			List[str]:






							'''simple docstring'''
							warnings.warn(
							    '''`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.'''							,						__a							,						)
							return self.image_processor






