






"""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[int]    ,						A     :						List[str]    ,						A     :						Optional[Any]=13    ,						A     :						Dict=7    ,						A     :						Optional[int]=True    ,						A     :						Tuple=True    ,						A     :						Optional[Any]=True    ,						A     :						Any=True    ,						A     :						str=99    ,						A     :						Dict=32    ,						A     :						List[str]=2    ,						A     :						Tuple=4    ,						A     :						Any=37    ,						A     :						Tuple="gelu"    ,						A     :						Any=0.1    ,						A     :						int=0.1    ,						A     :						Optional[int]=5_12    ,						A     :						Optional[int]=16    ,						A     :						List[Any]=2    ,						A     :						Union[str, Any]=0.02    ,						A     :						int=False    ,						A     :						int=True    ,						A     :						Dict="None"    ,						A     :						Dict=3    ,						A     :						List[Any]=4    ,						A     :						int=None    ,						)  ->  Optional[int]:
							lowercase_ : Tuple							       =   parent
							lowercase_ : Dict							       =   batch_size
							lowercase_ : Union[str, Any]							       =   seq_length
							lowercase_ : Dict							       =   is_training
							lowercase_ : Any							       =   use_input_mask
							lowercase_ : Dict							       =   use_token_type_ids
							lowercase_ : Dict							       =   use_labels
							lowercase_ : List[Any]							       =   vocab_size
							lowercase_ : Any							       =   hidden_size
							lowercase_ : Tuple							       =   num_hidden_layers
							lowercase_ : List[Any]							       =   num_attention_heads
							lowercase_ : Union[str, Any]							       =   intermediate_size
							lowercase_ : str							       =   hidden_act
							lowercase_ : List[Any]							       =   hidden_dropout_prob
							lowercase_ : Union[str, Any]							       =   attention_probs_dropout_prob
							lowercase_ : Union[str, Any]							       =   max_position_embeddings
							lowercase_ : Optional[Any]							       =   type_vocab_size
							lowercase_ : Any							       =   type_sequence_label_size
							lowercase_ : int							       =   initializer_range
							lowercase_ : Any							       =   num_labels
							lowercase_ : int							       =   num_choices
							lowercase_ : List[str]							       =   relative_attention
							lowercase_ : str							       =   position_biased_input
							lowercase_ : str							       =   pos_att_type
							lowercase_ : int							       =   scope




					def   A  (				self     :						Dict   )  ->  List[str]:
							lowercase_ : List[Any]							       =   ids_tensor([self.batch_size, self.seq_length]    ,						self.vocab_size   )

							lowercase_ : Any							       =   None
							if self.use_input_mask:
									lowercase_ : Tuple							       =   random_attention_mask([self.batch_size, self.seq_length]   )

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

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

							lowercase_ : Union[str, Any]							       =   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   A  (				self     :						Tuple    ,						A     :						Tuple    ,						A     :						Dict    ,						A     :						Dict    ,						A     :						List[Any]    ,						A     :						str    ,						A     :						List[Any]    ,						A     :						List[Any]   )  ->  List[Any]:
							lowercase_ : List[str]							       =   TFDebertaVaModel(config=A   )
							lowercase_ : Optional[int]							       =   {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

							lowercase_ : List[str]							       =   [input_ids, input_mask]
							lowercase_ : List[Any]							       =   model(A   )

							lowercase_ : str							       =   model(A   )

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




					def   A  (				self     :						int    ,						A     :						Tuple    ,						A     :						Any    ,						A     :						Any    ,						A     :						int    ,						A     :						Dict    ,						A     :						List[str]    ,						A     :						int   )  ->  List[Any]:
							lowercase_ : str							       =   TFDebertaVaForMaskedLM(config=A   )
							lowercase_ : int							       =   {
							    '''input_ids''': input_ids,
							    '''attention_mask''': input_mask,
							    '''token_type_ids''': token_type_ids,
							}
							lowercase_ : Tuple							       =   model(A   )
							self.parent.assertEqual(result.logits.shape    ,						(self.batch_size, self.seq_length, self.vocab_size)   )




					def   A  (				self     :						Union[str, Any]    ,						A     :						Any    ,						A     :						Optional[Any]    ,						A     :						Optional[int]    ,						A     :						Tuple    ,						A     :						str    ,						A     :						Tuple    ,						A     :						Optional[Any]   )  ->  Union[str, Any]:
							lowercase_ : Dict							       =   self.num_labels
							lowercase_ : Tuple							       =   TFDebertaVaForSequenceClassification(config=A   )
							lowercase_ : Union[str, Any]							       =   {
							    '''input_ids''': input_ids,
							    '''attention_mask''': input_mask,
							    '''token_type_ids''': token_type_ids,
							}

							lowercase_ : Optional[int]							       =   model(A   )
							self.parent.assertEqual(result.logits.shape    ,						(self.batch_size, self.num_labels)   )




					def   A  (				self     :						Tuple    ,						A     :						Any    ,						A     :						Any    ,						A     :						Tuple    ,						A     :						Optional[int]    ,						A     :						List[str]    ,						A     :						Optional[Any]    ,						A     :						List[Any]   )  ->  Optional[int]:
							lowercase_ : Any							       =   self.num_labels
							lowercase_ : Optional[int]							       =   TFDebertaVaForTokenClassification(config=A   )
							lowercase_ : List[Any]							       =   {
							    '''input_ids''': input_ids,
							    '''attention_mask''': input_mask,
							    '''token_type_ids''': token_type_ids,
							}
							lowercase_ : str							       =   model(A   )
							self.parent.assertEqual(result.logits.shape    ,						(self.batch_size, self.seq_length, self.num_labels)   )




					def   A  (				self     :						Optional[Any]    ,						A     :						Any    ,						A     :						Any    ,						A     :						List[Any]    ,						A     :						Any    ,						A     :						Dict    ,						A     :						List[Any]    ,						A     :						Union[str, Any]   )  ->  List[str]:
							lowercase_ : Any							       =   TFDebertaVaForQuestionAnswering(config=A   )
							lowercase_ : List[str]							       =   {
							    '''input_ids''': input_ids,
							    '''attention_mask''': input_mask,
							    '''token_type_ids''': token_type_ids,
							}

							lowercase_ : 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   A  (				self     :						List[Any]   )  ->  int:
							lowercase_ : List[Any]							       =   self.prepare_config_and_inputs()
							(
							    (
							    lowercase_
							)       ,					(
							    lowercase_
							)       ,					(
							    lowercase_
							)       ,					(
							    lowercase_
							)       ,					(
							    lowercase_
							)       ,					(
							    lowercase_
							)       ,					(
							    lowercase_
							)       ,					
							) : List[str]							       =   config_and_inputs
							lowercase_ : Tuple							       =   {'''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							):
					SCREAMING_SNAKE_CASE_		:				List[Any]							    =   (
					    (
					        TFDebertaVaModel,
					        TFDebertaVaForMaskedLM,
					        TFDebertaVaForQuestionAnswering,
					        TFDebertaVaForSequenceClassification,
					        TFDebertaVaForTokenClassification,
					    )
					    if is_tf_available()
					    else ()
					)
					SCREAMING_SNAKE_CASE_		:				int							    =   (
					    {
					        "feature-extraction": TFDebertaVaModel,
					        "fill-mask": TFDebertaVaForMaskedLM,
					        "question-answering": TFDebertaVaForQuestionAnswering,
					        "text-classification": TFDebertaVaForSequenceClassification,
					        "token-classification": TFDebertaVaForTokenClassification,
					        "zero-shot": TFDebertaVaForSequenceClassification,
					    }
					    if is_tf_available()
					    else {}
					)

					SCREAMING_SNAKE_CASE_		:				Optional[Any]							    =   False
					SCREAMING_SNAKE_CASE_		:				Tuple							    =   False




					def   A  (				self     :						Union[str, Any]   )  ->  Optional[int]:
							lowercase_ : Any							       =   TFDebertaVaModelTester(self   )
							lowercase_ : Dict							       =   ConfigTester(self    ,						config_class=A    ,						hidden_size=37   )




					def   A  (				self     :						List[Any]   )  ->  Union[str, Any]:
							self.config_tester.run_common_tests()




					def   A  (				self     :						int   )  ->  Dict:
							lowercase_ : Optional[int]							       =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*A   )




					def   A  (				self     :						Optional[int]   )  ->  str:
							lowercase_ : List[str]							       =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_lm(*A   )




					def   A  (				self     :						Optional[Any]   )  ->  Any:
							lowercase_ : List[str]							       =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_question_answering(*A   )




					def   A  (				self     :						Optional[Any]   )  ->  List[Any]:
							lowercase_ : str							       =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_sequence_classification(*A   )




					def   A  (				self     :						Tuple   )  ->  Optional[Any]:
							lowercase_ : str							       =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_token_classification(*A   )






					@slow
					def   A  (				self     :						Tuple   )  ->  List[Any]:
							lowercase_ : Any							       =   TFDebertaVaModel.from_pretrained('''kamalkraj/deberta-v2-xlarge'''   )
							self.assertIsNotNone(A   )





@require_tf
class 					_UpperCAmelCase       ( unittest.TestCase							):




					@unittest.skip(reason='''Model not available yet'''   )
					def   A  (				self     :						Dict   )  ->  Dict:
							pass






					@slow
					def   A  (				self     :						List[str]   )  ->  Union[str, Any]:
							lowercase_ : List[str]							       =   TFDebertaVaModel.from_pretrained('''kamalkraj/deberta-v2-xlarge'''   )
							lowercase_ : Tuple							       =   tf.constant([[0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]]   )
							lowercase_ : Dict							       =   tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]   )
							lowercase_ : Union[str, Any]							       =   model(A    ,						attention_mask=A   )[0]

							lowercase_ : int							       =   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"""



from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


__A		:       List[Any]  				=		{
    '''configuration_mega''': ['''MEGA_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''MegaConfig''', '''MegaOnnxConfig'''],
}

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						__A		:       List[str]  				=		[
						    '''MEGA_PRETRAINED_MODEL_ARCHIVE_LIST''',
						    '''MegaForCausalLM''',
						    '''MegaForMaskedLM''',
						    '''MegaForMultipleChoice''',
						    '''MegaForQuestionAnswering''',
						    '''MegaForSequenceClassification''',
						    '''MegaForTokenClassification''',
						    '''MegaModel''',
						    '''MegaPreTrainedModel''',
						]

if TYPE_CHECKING:
						from .configuration_mega import MEGA_PRETRAINED_CONFIG_ARCHIVE_MAP, MegaConfig, MegaOnnxConfig

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_mega import (
												    MEGA_PRETRAINED_MODEL_ARCHIVE_LIST,
												    MegaForCausalLM,
												    MegaForMaskedLM,
												    MegaForMultipleChoice,
												    MegaForQuestionAnswering,
												    MegaForSequenceClassification,
												    MegaForTokenClassification,
												    MegaModel,
												    MegaPreTrainedModel,
												)

else:
						import sys

						__A		:       Any  				=		_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)



