
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		,     _snake_case		,     _snake_case=13		,     _snake_case=7		,     _snake_case=True		,     _snake_case=True		,     _snake_case=True		,     _snake_case=True		,     _snake_case=99		,     _snake_case=32		,     _snake_case=2		,     _snake_case=4		,     _snake_case=37		,     _snake_case="gelu"		,     _snake_case=0.1		,     _snake_case=0.1		,     _snake_case=512		,     _snake_case=16		,     _snake_case=2		,     _snake_case=0.02		,     _snake_case=False		,     _snake_case=True		,     _snake_case="None"		,     _snake_case=3		,     _snake_case=4		,     _snake_case=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 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Optional[int]:


								'''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 				SCREAMING_SNAKE_CASE_		(     self		,     _snake_case		,     _snake_case		,     _snake_case		,     _snake_case		,     _snake_case		,     _snake_case		,     _snake_case				)    ->      List[str]:


								'''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 				SCREAMING_SNAKE_CASE_		(     self		,     _snake_case		,     _snake_case		,     _snake_case		,     _snake_case		,     _snake_case		,     _snake_case		,     _snake_case				)    ->      int:


								'''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 				SCREAMING_SNAKE_CASE_		(     self		,     _snake_case		,     _snake_case		,     _snake_case		,     _snake_case		,     _snake_case		,     _snake_case		,     _snake_case				)    ->      Optional[int]:


								'''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 				SCREAMING_SNAKE_CASE_		(     self		,     _snake_case		,     _snake_case		,     _snake_case		,     _snake_case		,     _snake_case		,     _snake_case		,     _snake_case				)    ->      str:


								'''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 				SCREAMING_SNAKE_CASE_		(     self		,     _snake_case		,     _snake_case		,     _snake_case		,     _snake_case		,     _snake_case		,     _snake_case		,     _snake_case				)    ->      Tuple:


								'''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 				SCREAMING_SNAKE_CASE_		(     self				)    ->      List[str]:


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

				snake_case_						   =    False
				snake_case_						   =    False




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Dict:


								'''simple docstring'''




								__a										=    TFDebertaVaModelTester(self				)
								__a										=    ConfigTester(self		,     config_class=_snake_case		,     hidden_size=37				)




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Any:


								'''simple docstring'''




								self.config_tester.run_common_tests()




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


								'''simple docstring'''




								__a										=    self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*_snake_case				)




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Tuple:


								'''simple docstring'''




								__a										=    self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_masked_lm(*_snake_case				)




				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      str:


								'''simple docstring'''




								__a										=    self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_question_answering(*_snake_case				)




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


								'''simple docstring'''




								__a										=    self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_sequence_classification(*_snake_case				)




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


								'''simple docstring'''




								__a										=    self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_token_classification(*_snake_case				)




				@slow
				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      List[Any]:


								'''simple docstring'''




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







@require_tf
class 			__A( unittest.TestCase			):




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


								'''simple docstring'''




								pass




				@slow
				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      List[Any]:


								'''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				)







from typing import List, Optional, Union

from ...image_utils import ImageInput
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType
class       _UpperCAmelCase					(       A__	):

				"""simple docstring"""




				lowercase__											=       ["""image_processor""", """tokenizer"""]
				lowercase__											=       """BlipImageProcessor"""
				lowercase__											=       ("""BertTokenizer""", """BertTokenizerFast""")




				def __init__(     self						:    Dict,  lowerCamelCase						:    Dict,  lowerCamelCase						:    str  ):

								'''simple docstring'''
								lowercase__    =			False
								super().__init__(lowerCamelCase,  lowerCamelCase  )
								lowercase__    =			self.image_processor




				def __call__(     self						:    int,  lowerCamelCase						:    ImageInput = None,  lowerCamelCase						:    Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None,  lowerCamelCase						:    bool = True,  lowerCamelCase						:    Union[bool, str, PaddingStrategy] = False,  lowerCamelCase						:    Union[bool, str, TruncationStrategy] = None,  lowerCamelCase						:    Optional[int] = None,  lowerCamelCase						:    int = 0,  lowerCamelCase						:    Optional[int] = None,  lowerCamelCase						:    Optional[bool] = None,  lowerCamelCase						:    bool = False,  lowerCamelCase						:    bool = False,  lowerCamelCase						:    bool = False,  lowerCamelCase						:    bool = False,  lowerCamelCase						:    bool = False,  lowerCamelCase						:    bool = True,  lowerCamelCase						:    Optional[Union[str, TensorType]] = None,  **lowerCamelCase						:    Any,  ):

								'''simple docstring'''
								if images is None and text is None:
												raise ValueError('''You have to specify either images or text.'''  )

								# Get only text
								if images is None:
												lowercase__    =			self.tokenizer
												lowercase__    =			self.tokenizer(
												    text=lowerCamelCase,  add_special_tokens=lowerCamelCase,  padding=lowerCamelCase,  truncation=lowerCamelCase,  max_length=lowerCamelCase,  stride=lowerCamelCase,  pad_to_multiple_of=lowerCamelCase,  return_attention_mask=lowerCamelCase,  return_overflowing_tokens=lowerCamelCase,  return_special_tokens_mask=lowerCamelCase,  return_offsets_mapping=lowerCamelCase,  return_token_type_ids=lowerCamelCase,  return_length=lowerCamelCase,  verbose=lowerCamelCase,  return_tensors=lowerCamelCase,  **lowerCamelCase,  )
												return text_encoding

								# add pixel_values
								lowercase__    =			self.image_processor(lowerCamelCase,  return_tensors=lowerCamelCase  )

								if text is not None:
												lowercase__    =			self.tokenizer(
												    text=lowerCamelCase,  add_special_tokens=lowerCamelCase,  padding=lowerCamelCase,  truncation=lowerCamelCase,  max_length=lowerCamelCase,  stride=lowerCamelCase,  pad_to_multiple_of=lowerCamelCase,  return_attention_mask=lowerCamelCase,  return_overflowing_tokens=lowerCamelCase,  return_special_tokens_mask=lowerCamelCase,  return_offsets_mapping=lowerCamelCase,  return_token_type_ids=lowerCamelCase,  return_length=lowerCamelCase,  verbose=lowerCamelCase,  return_tensors=lowerCamelCase,  **lowerCamelCase,  )
								else:
												lowercase__    =			None

								if text_encoding is not None:
												encoding_image_processor.update(lowerCamelCase  )

								return encoding_image_processor




				def 				lowercase__   (     self						:    Tuple,  *lowerCamelCase						:    Union[str, Any],  **lowerCamelCase						:    Optional[int]  ):

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




				def 				lowercase__   (     self						:    List[str],  *lowerCamelCase						:    int,  **lowerCamelCase						:    List[str]  ):

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




				@property
				def 				lowercase__   (     self						:    List[str]  ):

								'''simple docstring'''
								lowercase__    =			self.tokenizer.model_input_names
								lowercase__    =			self.image_processor.model_input_names
								return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names  )  )




