

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						,					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_=False						,					A_=True						,					A_="None"						,					A_=3						,					A_=4						,					A_=None						,					):







										'''simple docstring'''


										_UpperCAmelCase       :		Tuple 		=    parent
										_UpperCAmelCase       :		List[Any] 		=    batch_size
										_UpperCAmelCase       :		Union[str, Any] 		=    seq_length
										_UpperCAmelCase       :		Dict 		=    is_training
										_UpperCAmelCase       :		Any 		=    use_input_mask
										_UpperCAmelCase       :		int 		=    use_token_type_ids
										_UpperCAmelCase       :		Tuple 		=    use_labels
										_UpperCAmelCase       :		str 		=    vocab_size
										_UpperCAmelCase       :		Optional[Any] 		=    hidden_size
										_UpperCAmelCase       :		Any 		=    num_hidden_layers
										_UpperCAmelCase       :		Tuple 		=    num_attention_heads
										_UpperCAmelCase       :		List[str] 		=    intermediate_size
										_UpperCAmelCase       :		Optional[int] 		=    hidden_act
										_UpperCAmelCase       :		Tuple 		=    hidden_dropout_prob
										_UpperCAmelCase       :		int 		=    attention_probs_dropout_prob
										_UpperCAmelCase       :		Union[str, Any] 		=    max_position_embeddings
										_UpperCAmelCase       :		str 		=    type_vocab_size
										_UpperCAmelCase       :		Union[str, Any] 		=    type_sequence_label_size
										_UpperCAmelCase       :		List[Any] 		=    initializer_range
										_UpperCAmelCase       :		List[str] 		=    num_labels
										_UpperCAmelCase       :		List[Any] 		=    num_choices
										_UpperCAmelCase       :		Any 		=    relative_attention
										_UpperCAmelCase       :		Tuple 		=    position_biased_input
										_UpperCAmelCase       :		Dict 		=    pos_att_type
										_UpperCAmelCase       :		str 		=    scope


						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										_UpperCAmelCase       :		Optional[Any] 		=    ids_tensor([self.batch_size, self.seq_length]						,					self.vocab_size	)

										_UpperCAmelCase       :		List[Any] 		=    None
										if self.use_input_mask:
														_UpperCAmelCase       :		Optional[int] 		=    random_attention_mask([self.batch_size, self.seq_length]	)

										_UpperCAmelCase       :		Union[str, Any] 		=    None
										if self.use_token_type_ids:
														_UpperCAmelCase       :		str 		=    ids_tensor([self.batch_size, self.seq_length]						,					self.type_vocab_size	)

										_UpperCAmelCase       :		List[str] 		=    None
										_UpperCAmelCase       :		List[str] 		=    None
										_UpperCAmelCase       :		Any 		=    None
										if self.use_labels:
														_UpperCAmelCase       :		int 		=    ids_tensor([self.batch_size]						,					self.type_sequence_label_size	)
														_UpperCAmelCase       :		str 		=    ids_tensor([self.batch_size, self.seq_length]						,					self.num_labels	)

										_UpperCAmelCase       :		str 		=    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_	):







										'''simple docstring'''


										_UpperCAmelCase       :		Dict 		=    TFDebertaVaModel(config=A_	)
										_UpperCAmelCase       :		Any 		=    {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

										_UpperCAmelCase       :		Dict 		=    [input_ids, input_mask]
										_UpperCAmelCase       :		str 		=    model(A_	)

										_UpperCAmelCase       :		str 		=    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_	):







										'''simple docstring'''


										_UpperCAmelCase       :		Optional[int] 		=    TFDebertaVaForMaskedLM(config=A_	)
										_UpperCAmelCase       :		List[str] 		=    {
										    '''input_ids''': input_ids,
										    '''attention_mask''': input_mask,
										    '''token_type_ids''': token_type_ids,
										}
										_UpperCAmelCase       :		Optional[Any] 		=    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_	):







										'''simple docstring'''


										_UpperCAmelCase       :		str 		=    self.num_labels
										_UpperCAmelCase       :		Tuple 		=    TFDebertaVaForSequenceClassification(config=A_	)
										_UpperCAmelCase       :		List[str] 		=    {
										    '''input_ids''': input_ids,
										    '''attention_mask''': input_mask,
										    '''token_type_ids''': token_type_ids,
										}

										_UpperCAmelCase       :		Union[str, Any] 		=    model(A_	)
										self.parent.assertEqual(result.logits.shape						,					(self.batch_size, self.num_labels)	)


						def        _UpperCAmelCase				(       self						,					A_						,					A_						,					A_						,					A_						,					A_						,					A_						,					A_	):







										'''simple docstring'''


										_UpperCAmelCase       :		Any 		=    self.num_labels
										_UpperCAmelCase       :		Any 		=    TFDebertaVaForTokenClassification(config=A_	)
										_UpperCAmelCase       :		Union[str, Any] 		=    {
										    '''input_ids''': input_ids,
										    '''attention_mask''': input_mask,
										    '''token_type_ids''': token_type_ids,
										}
										_UpperCAmelCase       :		Dict 		=    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_	):







										'''simple docstring'''


										_UpperCAmelCase       :		Any 		=    TFDebertaVaForQuestionAnswering(config=A_	)
										_UpperCAmelCase       :		Optional[Any] 		=    {
										    '''input_ids''': input_ids,
										    '''attention_mask''': input_mask,
										    '''token_type_ids''': token_type_ids,
										}

										_UpperCAmelCase       :		Optional[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        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										_UpperCAmelCase       :		List[Any] 		=    self.prepare_config_and_inputs()
										(
										    _UpperCAmelCase	
										)       :		Any 		=    config_and_inputs
										_UpperCAmelCase       :		List[Any] 		=    {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
										return config, inputs_dict







@require_tf
class 				a  (	UpperCamelCase_							, UpperCamelCase_							, 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	):







										'''simple docstring'''


										_UpperCAmelCase       :		List[str] 		=    TFDebertaVaModelTester(self	)
										_UpperCAmelCase       :		str 		=    ConfigTester(self						,					config_class=A_						,					hidden_size=37	)


						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										self.config_tester.run_common_tests()


						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										_UpperCAmelCase       :		Dict 		=    self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*A_	)


						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										_UpperCAmelCase       :		str 		=    self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_masked_lm(*A_	)


						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										_UpperCAmelCase       :		Any 		=    self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_question_answering(*A_	)


						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										_UpperCAmelCase       :		Tuple 		=    self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_sequence_classification(*A_	)


						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										_UpperCAmelCase       :		Optional[Any] 		=    self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_token_classification(*A_	)





						@slow
						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										_UpperCAmelCase       :		Optional[Any] 		=    TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"	)
										self.assertIsNotNone(A_	)







@require_tf
class 				a  (	unittest.TestCase				):


						@unittest.skip(reason="Model not available yet"	)
						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										pass





						@slow
						def        _UpperCAmelCase				(       self	):







										'''simple docstring'''


										_UpperCAmelCase       :		Any 		=    TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"	)
										_UpperCAmelCase       :		Optional[int] 		=    tf.constant([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]	)
										_UpperCAmelCase       :		List[Any] 		=    tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]	)
										_UpperCAmelCase       :		Dict 		=    model(A_						,					attention_mask=A_	)[0]

										_UpperCAmelCase       :		Any 		=    tf.constant(
										    [[[0.23_56, 0.19_48, 0.03_69], [-0.10_63, 0.35_86, -0.51_52], [-0.63_99, -0.02_59, -0.25_25]]]	)
										tf.debugging.assert_near(output[:, 1:4, 1:4]						,					A_						,					atol=1e-4	)





import warnings

from ...utils import logging
from .image_processing_perceiver import PerceiverImageProcessor


SCREAMING_SNAKE_CASE_        =      logging.get_logger(__name__)

class 				a  (	UpperCAmelCase				):


						def __init__(       self						,					*A_						,					**A_	):







										'''simple docstring'''


										warnings.warn(
										    "The class PerceiverFeatureExtractor is deprecated and will be removed in version 5 of Transformers."
										    " Please use PerceiverImageProcessor instead."						,					A_						,					)
										super().__init__(*A_						,					**A_	)


