



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       __lowerCAmelCase   :



			def __init__(						self       :  str			,		A       :  str			,		A       :  Dict=13			,		A       :  int=7			,		A       :  Tuple=True			,		A       :  Union[str, Any]=True			,		A       :  Any=True			,		A       :  Dict=True			,		A       :  Dict=99			,		A       :  Tuple=32			,		A       :  Any=2			,		A       :  Any=4			,		A       :  Any=37			,		A       :  Optional[Any]="gelu"			,		A       :  List[Any]=0.1			,		A       :  Tuple=0.1			,		A       :  Optional[Any]=5_12			,		A       :  Tuple=16			,		A       :  int=2			,		A       :  List[str]=0.0_2			,		A       :  int=False			,		A       :  List[Any]=True			,		A       :  Optional[Any]="None"			,		A       :  Union[str, Any]=3			,		A       :  List[str]=4			,		A       :  List[Any]=None			,		)       ->   int:



								"""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    _lowerCamelCase	(						self       :  Any)       ->   Union[str, Any]:



								"""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    _lowerCamelCase	(						self       :  Union[str, Any]			,		A       :  Optional[int]			,		A       :  Tuple			,		A       :  int			,		A       :  Any			,		A       :  List[str]			,		A       :  List[str]			,		A       :  int)       ->   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    _lowerCamelCase	(						self       :  str			,		A       :  Tuple			,		A       :  Tuple			,		A       :  Optional[int]			,		A       :  List[str]			,		A       :  Any			,		A       :  List[str]			,		A       :  List[str])       ->   Optional[int]:



								"""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    _lowerCamelCase	(						self       :  List[Any]			,		A       :  Tuple			,		A       :  Tuple			,		A       :  Optional[int]			,		A       :  Optional[int]			,		A       :  List[Any]			,		A       :  Any			,		A       :  Optional[int])       ->   Union[str, Any]:



								"""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    _lowerCamelCase	(						self       :  Union[str, Any]			,		A       :  List[Any]			,		A       :  List[Any]			,		A       :  List[str]			,		A       :  Optional[Any]			,		A       :  int			,		A       :  Any			,		A       :  int)       ->   Union[str, 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    _lowerCamelCase	(						self       :  List[Any]			,		A       :  List[Any]			,		A       :  List[str]			,		A       :  Dict			,		A       :  Dict			,		A       :  Any			,		A       :  Tuple			,		A       :  List[Any])       ->   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    _lowerCamelCase	(						self       :  Union[str, Any])       ->   List[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       __lowerCAmelCase   (      A    ,						A    ,						unittest.TestCase						):
			UpperCamelCase        =					(
			    (
			        TFDebertaVaModel,
			        TFDebertaVaForMaskedLM,
			        TFDebertaVaForQuestionAnswering,
			        TFDebertaVaForSequenceClassification,
			        TFDebertaVaForTokenClassification,
			    )
			    if is_tf_available()
			    else ()
			)
			UpperCamelCase        =					(
			    {
			        '''feature-extraction''': TFDebertaVaModel,
			        '''fill-mask''': TFDebertaVaForMaskedLM,
			        '''question-answering''': TFDebertaVaForQuestionAnswering,
			        '''text-classification''': TFDebertaVaForSequenceClassification,
			        '''token-classification''': TFDebertaVaForTokenClassification,
			        '''zero-shot''': TFDebertaVaForSequenceClassification,
			    }
			    if is_tf_available()
			    else {}
			)

			UpperCamelCase        =					False
			UpperCamelCase        =					False



			def    _lowerCamelCase	(						self       :  int)       ->   Optional[int]:



								"""simple docstring"""






								_UpperCAmelCase			=       TFDebertaVaModelTester(self)
								_UpperCAmelCase			=       ConfigTester(self			,		config_class=A			,		hidden_size=37)



			def    _lowerCamelCase	(						self       :  Optional[int])       ->   List[str]:



								"""simple docstring"""






								self.config_tester.run_common_tests()



			def    _lowerCamelCase	(						self       :  Tuple)       ->   Optional[int]:



								"""simple docstring"""






								_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*A)



			def    _lowerCamelCase	(						self       :  Tuple)       ->   Optional[Any]:



								"""simple docstring"""






								_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_masked_lm(*A)



			def    _lowerCamelCase	(						self       :  Tuple)       ->   str:



								"""simple docstring"""






								_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_question_answering(*A)



			def    _lowerCamelCase	(						self       :  int)       ->   List[Any]:



								"""simple docstring"""






								_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_sequence_classification(*A)



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



								"""simple docstring"""






								_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_token_classification(*A)



			@slow
			def    _lowerCamelCase	(						self       :  List[Any])       ->   Union[str, Any]:



								"""simple docstring"""






								_UpperCAmelCase			=       TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge')
								self.assertIsNotNone(A)







@require_tf
class       __lowerCAmelCase   (      unittest.TestCase						):



			@unittest.skip(reason='Model not available yet')
			def    _lowerCamelCase	(						self       :  Optional[int])       ->   Dict:



								"""simple docstring"""






								pass



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



								"""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.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)





from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


UpperCAmelCase__       =	logging.get_logger(__name__)

UpperCAmelCase__       =	{
    "facebook/xmod-base": "https://huggingface.co/facebook/xmod-base/resolve/main/config.json",
    "facebook/xmod-large-prenorm": "https://huggingface.co/facebook/xmod-large-prenorm/resolve/main/config.json",
    "facebook/xmod-base-13-125k": "https://huggingface.co/facebook/xmod-base-13-125k/resolve/main/config.json",
    "facebook/xmod-base-30-125k": "https://huggingface.co/facebook/xmod-base-30-125k/resolve/main/config.json",
    "facebook/xmod-base-30-195k": "https://huggingface.co/facebook/xmod-base-30-195k/resolve/main/config.json",
    "facebook/xmod-base-60-125k": "https://huggingface.co/facebook/xmod-base-60-125k/resolve/main/config.json",
    "facebook/xmod-base-60-265k": "https://huggingface.co/facebook/xmod-base-60-265k/resolve/main/config.json",
    "facebook/xmod-base-75-125k": "https://huggingface.co/facebook/xmod-base-75-125k/resolve/main/config.json",
    "facebook/xmod-base-75-269k": "https://huggingface.co/facebook/xmod-base-75-269k/resolve/main/config.json",
}







class       __lowerCAmelCase   (      A						):
			UpperCamelCase        =					'''xmod'''



			def __init__(						self       :  Optional[int]			,		A       :  int=3_05_22			,		A       :  Tuple=7_68			,		A       :  Optional[Any]=12			,		A       :  Tuple=12			,		A       :  str=30_72			,		A       :  List[str]="gelu"			,		A       :  Any=0.1			,		A       :  int=0.1			,		A       :  Dict=5_12			,		A       :  Optional[Any]=2			,		A       :  Optional[Any]=0.0_2			,		A       :  List[Any]=1E-12			,		A       :  int=1			,		A       :  Tuple=0			,		A       :  Optional[Any]=2			,		A       :  int="absolute"			,		A       :  Union[str, Any]=True			,		A       :  List[Any]=None			,		A       :  Optional[Any]=False			,		A       :  List[str]=2			,		A       :  int=False			,		A       :  str=True			,		A       :  Optional[Any]=True			,		A       :  Tuple=("en_XX",)			,		A       :  Optional[int]=None			,		**A       :  List[str]			,		)       ->   Dict:



						"""simple docstring"""






						super().__init__(pad_token_id=A			,		bos_token_id=A			,		eos_token_id=A			,		**A)

						_UpperCAmelCase			=       vocab_size
						_UpperCAmelCase			=       hidden_size
						_UpperCAmelCase			=       num_hidden_layers
						_UpperCAmelCase			=       num_attention_heads
						_UpperCAmelCase			=       hidden_act
						_UpperCAmelCase			=       intermediate_size
						_UpperCAmelCase			=       hidden_dropout_prob
						_UpperCAmelCase			=       attention_probs_dropout_prob
						_UpperCAmelCase			=       max_position_embeddings
						_UpperCAmelCase			=       type_vocab_size
						_UpperCAmelCase			=       initializer_range
						_UpperCAmelCase			=       layer_norm_eps
						_UpperCAmelCase			=       position_embedding_type
						_UpperCAmelCase			=       use_cache
						_UpperCAmelCase			=       classifier_dropout
						_UpperCAmelCase			=       pre_norm
						_UpperCAmelCase			=       adapter_reduction_factor
						_UpperCAmelCase			=       adapter_layer_norm
						_UpperCAmelCase			=       adapter_reuse_layer_norm
						_UpperCAmelCase			=       ln_before_adapter
						_UpperCAmelCase			=       list(A)
						_UpperCAmelCase			=       default_language







class       __lowerCAmelCase   (      A						):



			@property
			def    _lowerCamelCase	(						self       :  Optional[Any])       ->   Mapping[str, Mapping[int, str]]:



						"""simple docstring"""






						if self.task == "multiple-choice":
									_UpperCAmelCase			=       {0: 'batch', 1: 'choice', 2: 'sequence'}
						else:
									_UpperCAmelCase			=       {0: 'batch', 1: 'sequence'}
						return OrderedDict(
						    [
						        ('input_ids', dynamic_axis),
						        ('attention_mask', dynamic_axis),
						    ])
