





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     :Dict				,					__A     :Optional[Any]				,					__A     :Dict=13				,					__A     :int=7				,					__A     :List[str]=True				,					__A     :Optional[int]=True				,					__A     :Union[str, Any]=True				,					__A     :Optional[Any]=True				,					__A     :List[Any]=99				,					__A     :Any=32				,					__A     :Union[str, Any]=2				,					__A     :Optional[int]=4				,					__A     :int=37				,					__A     :Any="gelu"				,					__A     :int=0.1				,					__A     :Dict=0.1				,					__A     :Any=512				,					__A     :List[Any]=16				,					__A     :Tuple=2				,					__A     :List[Any]=0.0_2				,					__A     :List[Any]=False				,					__A     :int=True				,					__A     :Union[str, Any]="None"				,					__A     :Optional[Any]=3				,					__A     :Dict=4				,					__A     :Any=None				,					) -> List[str]:



									"""simple docstring"""



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


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



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   ids_tensor([self.batch_size, self.seq_length]				,					self.vocab_size		)

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

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

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

									SCREAMING_SNAKE_CASE__								=   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   _snake_case	(				self     :List[str]				,					__A     :Optional[Any]				,					__A     :Tuple				,					__A     :Optional[Any]				,					__A     :str				,					__A     :str				,					__A     :Optional[Any]				,					__A     :Dict		) -> Union[str, Any]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   TFDebertaVaModel(config=_A		)
									SCREAMING_SNAKE_CASE__								=   {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}

									SCREAMING_SNAKE_CASE__								=   [input_ids, input_mask]
									SCREAMING_SNAKE_CASE__								=   model(_A		)

									SCREAMING_SNAKE_CASE__								=   model(_A		)

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


							def   _snake_case	(				self     :Optional[Any]				,					__A     :int				,					__A     :List[str]				,					__A     :str				,					__A     :Tuple				,					__A     :List[Any]				,					__A     :Dict				,					__A     :Union[str, Any]		) -> int:



									"""simple docstring"""



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


							def   _snake_case	(				self     :int				,					__A     :str				,					__A     :str				,					__A     :Union[str, Any]				,					__A     :int				,					__A     :Optional[Any]				,					__A     :str				,					__A     :Dict		) -> Any:



									"""simple docstring"""



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

									SCREAMING_SNAKE_CASE__								=   model(_A		)
									self.parent.assertEqual(result.logits.shape				,					(self.batch_size, self.num_labels)		)


							def   _snake_case	(				self     :List[Any]				,					__A     :List[str]				,					__A     :Tuple				,					__A     :int				,					__A     :int				,					__A     :Tuple				,					__A     :Tuple				,					__A     :int		) -> Optional[Any]:



									"""simple docstring"""



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


							def   _snake_case	(				self     :Dict				,					__A     :Any				,					__A     :Union[str, Any]				,					__A     :List[str]				,					__A     :Dict				,					__A     :Tuple				,					__A     :Any				,					__A     :Union[str, Any]		) -> Any:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   TFDebertaVaForQuestionAnswering(config=_A		)
									SCREAMING_SNAKE_CASE__								=   {
									    """input_ids""": input_ids,
									    """attention_mask""": input_mask,
									    """token_type_ids""": token_type_ids,
									}

									SCREAMING_SNAKE_CASE__								=   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   _snake_case	(				self     :Union[str, Any]		) -> Optional[int]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   self.prepare_config_and_inputs()
									(
									    (
									    SCREAMING_SNAKE_CASE__    
									)						,    (
									    SCREAMING_SNAKE_CASE__    
									)						,    (
									    SCREAMING_SNAKE_CASE__    
									)						,    (
									    SCREAMING_SNAKE_CASE__    
									)						,    (
									    SCREAMING_SNAKE_CASE__    
									)						,    (
									    SCREAMING_SNAKE_CASE__    
									)						,    (
									    SCREAMING_SNAKE_CASE__    
									)						,        
									)								=   config_and_inputs
									SCREAMING_SNAKE_CASE__								=   {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
									return config, inputs_dict




@require_tf
class 	UpperCamelCase_							(  __lowercase					,	__lowercase					,	unittest.TestCase     ):
							lowerCamelCase_							     =       (
							    (
							        TFDebertaVaModel,
							        TFDebertaVaForMaskedLM,
							        TFDebertaVaForQuestionAnswering,
							        TFDebertaVaForSequenceClassification,
							        TFDebertaVaForTokenClassification,
							    )
							    if is_tf_available()
							    else ()
							)
							lowerCamelCase_							     =       (
							    {
							        "feature-extraction": TFDebertaVaModel,
							        "fill-mask": TFDebertaVaForMaskedLM,
							        "question-answering": TFDebertaVaForQuestionAnswering,
							        "text-classification": TFDebertaVaForSequenceClassification,
							        "token-classification": TFDebertaVaForTokenClassification,
							        "zero-shot": TFDebertaVaForSequenceClassification,
							    }
							    if is_tf_available()
							    else {}
							)

							lowerCamelCase_							     =       False
							lowerCamelCase_							     =       False


							def   _snake_case	(				self     :Tuple		) -> List[str]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   TFDebertaVaModelTester(self		)
									SCREAMING_SNAKE_CASE__								=   ConfigTester(self				,					config_class=_A				,					hidden_size=37		)


							def   _snake_case	(				self     :Dict		) -> Optional[Any]:



									"""simple docstring"""



									self.config_tester.run_common_tests()


							def   _snake_case	(				self     :Optional[Any]		) -> str:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*_A		)


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



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_masked_lm(*_A		)


							def   _snake_case	(				self     :Dict		) -> str:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_question_answering(*_A		)


							def   _snake_case	(				self     :Tuple		) -> Any:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_sequence_classification(*_A		)


							def   _snake_case	(				self     :Optional[Any]		) -> str:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_token_classification(*_A		)


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



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   TFDebertaVaModel.from_pretrained("""kamalkraj/deberta-v2-xlarge"""		)
									self.assertIsNotNone(_A		)




@require_tf
class 	UpperCamelCase_							(  unittest.TestCase     ):


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



									"""simple docstring"""



									pass


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



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   TFDebertaVaModel.from_pretrained("""kamalkraj/deberta-v2-xlarge"""		)
									SCREAMING_SNAKE_CASE__								=   tf.constant([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]]		)
									SCREAMING_SNAKE_CASE__								=   tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
									SCREAMING_SNAKE_CASE__								=   model(_A				,					attention_mask=_A		)[0]

									SCREAMING_SNAKE_CASE__								=   tf.constant(
									    [[[0.2_3_5_6, 0.1_9_4_8, 0.0_3_6_9], [-0.1_0_6_3, 0.3_5_8_6, -0.5_1_5_2], [-0.6_3_9_9, -0.0_2_5_9, -0.2_5_2_5]]]		)
									tf.debugging.assert_near(output[:, 1:4, 1:4]				,					_A				,					atol=1E-4		)
import inspect
import warnings
from typing import Any, Dict, Optional, Union

from packaging import version
def 					_snake_case	(  *__snake_case  ,     __snake_case = None  ,     __snake_case=True  ,     __snake_case=2						):
					from .. import __version__

					_UpperCamelCase			     =     take_from
					_UpperCamelCase			     =     ()
					if not isinstance(args[0]  ,     __snake_case						):
										_UpperCamelCase			     =     (args,)

					for attribute, version_name, message in args:
										if version.parse(version.parse(__snake_case						).base_version						) >= version.parse(__snake_case						):
															raise ValueError(
															    f"""The deprecation tuple {(attribute, version_name, message)} should be removed since diffusers'"""
															    f""" version {__version__} is >= {version_name}"""						)

										_UpperCamelCase			     =     None
										if isinstance(__snake_case  ,     __snake_case						) and attribute in deprecated_kwargs:
															values += (deprecated_kwargs.pop(__snake_case						),)
															_UpperCamelCase			     =     f"""The `{attribute}` argument is deprecated and will be removed in version {version_name}."""
										elif hasattr(__snake_case  ,     __snake_case						):
															values += (getattr(__snake_case  ,     __snake_case						),)
															_UpperCamelCase			     =     f"""The `{attribute}` attribute is deprecated and will be removed in version {version_name}."""
										elif deprecated_kwargs is None:
															_UpperCamelCase			     =     f"""`{attribute}` is deprecated and will be removed in version {version_name}."""

										if warning is not None:
															_UpperCamelCase			     =     warning + ''' ''' if standard_warn else ''''''
															warnings.warn(warning + message  ,     __snake_case  ,     stacklevel=__snake_case						)

					if isinstance(__snake_case  ,     __snake_case						) and len(__snake_case						) > 0:
										_UpperCamelCase			     =     inspect.getouterframes(inspect.currentframe()						)[1]
										_UpperCamelCase			     =     call_frame.filename
										_UpperCamelCase			     =     call_frame.lineno
										_UpperCamelCase			     =     call_frame.function
										_UpperCamelCase     ,    _UpperCamelCase			     =     next(iter(deprecated_kwargs.items()						)						)
										raise TypeError(f"""{function} in {filename} line {line_number-1} got an unexpected keyword argument `{key}`"""						)

					if len(__snake_case						) == 0:
										return
					elif len(__snake_case						) == 1:
										return values[0]
					return values
