

'''simple docstring'''







from __future__ import annotations

import unittest

from transformers import DebertaConfig, 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 (
							    TFDebertaForMaskedLM,
							    TFDebertaForQuestionAnswering,
							    TFDebertaForSequenceClassification,
							    TFDebertaForTokenClassification,
							    TFDebertaModel,
							)
class 					__a   :

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

							"""simple docstring"""



							_lowercase							=     parent
							_lowercase							=     13
							_lowercase							=     7
							_lowercase							=     True
							_lowercase							=     True
							_lowercase							=     True
							_lowercase							=     True
							_lowercase							=     99
							_lowercase							=     32
							_lowercase							=     2
							_lowercase							=     4
							_lowercase							=     37
							_lowercase							=     """gelu"""
							_lowercase							=     0.1
							_lowercase							=     0.1
							_lowercase							=     5_12
							_lowercase							=     16
							_lowercase							=     False
							_lowercase							=     -1
							_lowercase							=     True
							_lowercase							=     2
							_lowercase							=     0.02
							_lowercase							=     3
							_lowercase							=     4
							_lowercase							=     None

						def 	_UpperCAmelCase							(		self	:						Dict)						->List[str]:

							"""simple docstring"""



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

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

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

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

							_lowercase							=     DebertaConfig(
							    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    ,			max_relative_positions=self.max_relative_positions    ,			position_biased_input=self.position_biased_input    ,			initializer_range=self.initializer_range    ,			return_dict=lowercase__    ,			)

							return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels

						def 	_UpperCAmelCase							(		self	:						Tuple    ,			lowercase__	:						int    ,			lowercase__	:						Any    ,			lowercase__	:						Any    ,			lowercase__	:						Any    ,			lowercase__	:						Union[str, Any]    ,			lowercase__	:						int    ,			lowercase__	:						Dict)						->Union[str, Any]:

							"""simple docstring"""



							_lowercase							=     TFDebertaModel(config=lowercase__)
							_lowercase							=     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}

							_lowercase							=     [input_ids, input_mask]
							_lowercase							=     model(lowercase__)

							_lowercase							=     model(lowercase__)

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

						def 	_UpperCAmelCase							(		self	:						Optional[Any]    ,			lowercase__	:						Dict    ,			lowercase__	:						Dict    ,			lowercase__	:						Dict    ,			lowercase__	:						List[Any]    ,			lowercase__	:						Tuple    ,			lowercase__	:						List[str]    ,			lowercase__	:						List[Any])						->Optional[Any]:

							"""simple docstring"""



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

						def 	_UpperCAmelCase							(		self	:						Optional[int]    ,			lowercase__	:						List[str]    ,			lowercase__	:						int    ,			lowercase__	:						List[Any]    ,			lowercase__	:						Union[str, Any]    ,			lowercase__	:						List[Any]    ,			lowercase__	:						Dict    ,			lowercase__	:						int)						->Union[str, Any]:

							"""simple docstring"""



							_lowercase							=     self.num_labels
							_lowercase							=     TFDebertaForSequenceClassification(config=lowercase__)
							_lowercase							=     {
							    """input_ids""": input_ids,
							    """attention_mask""": input_mask,
							    """token_type_ids""": token_type_ids,
							}

							_lowercase							=     model(lowercase__)
							self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.num_labels))

						def 	_UpperCAmelCase							(		self	:						str    ,			lowercase__	:						Any    ,			lowercase__	:						List[str]    ,			lowercase__	:						Any    ,			lowercase__	:						List[str]    ,			lowercase__	:						int    ,			lowercase__	:						Any    ,			lowercase__	:						Optional[int])						->int:

							"""simple docstring"""



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

						def 	_UpperCAmelCase							(		self	:						List[str]    ,			lowercase__	:						str    ,			lowercase__	:						Dict    ,			lowercase__	:						List[Any]    ,			lowercase__	:						Optional[int]    ,			lowercase__	:						Any    ,			lowercase__	:						int    ,			lowercase__	:						List[Any])						->Tuple:

							"""simple docstring"""



							_lowercase							=     TFDebertaForQuestionAnswering(config=lowercase__)
							_lowercase							=     {
							    """input_ids""": input_ids,
							    """attention_mask""": input_mask,
							    """token_type_ids""": token_type_ids,
							}

							_lowercase							=     model(lowercase__)
							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	:						str)						->Any:

							"""simple docstring"""



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






@require_tf
class 					__a   (		_snake_case							,_snake_case							,unittest.TestCase  ):
						__SCREAMING_SNAKE_CASE     :					int  =      (
						    (
						        TFDebertaModel,
						        TFDebertaForMaskedLM,
						        TFDebertaForQuestionAnswering,
						        TFDebertaForSequenceClassification,
						        TFDebertaForTokenClassification,
						    )
						    if is_tf_available()
						    else ()
						)
						__SCREAMING_SNAKE_CASE     :					Tuple  =      (
						    {
						        'feature-extraction': TFDebertaModel,
						        'fill-mask': TFDebertaForMaskedLM,
						        'question-answering': TFDebertaForQuestionAnswering,
						        'text-classification': TFDebertaForSequenceClassification,
						        'token-classification': TFDebertaForTokenClassification,
						        'zero-shot': TFDebertaForSequenceClassification,
						    }
						    if is_tf_available()
						    else {}
						)

						__SCREAMING_SNAKE_CASE     :					Optional[Any]  =      False
						__SCREAMING_SNAKE_CASE     :					str  =      False

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

							"""simple docstring"""



							_lowercase							=     TFDebertaModelTester(self)
							_lowercase							=     ConfigTester(self    ,			config_class=lowercase__    ,			hidden_size=37)

						def 	_UpperCAmelCase							(		self	:						str)						->Any:

							"""simple docstring"""



							self.config_tester.run_common_tests()

						def 	_UpperCAmelCase							(		self	:						Tuple)						->int:

							"""simple docstring"""



							_lowercase							=     self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*lowercase__)

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

							"""simple docstring"""



							_lowercase							=     self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_lm(*lowercase__)

						def 	_UpperCAmelCase							(		self	:						Dict)						->Tuple:

							"""simple docstring"""



							_lowercase							=     self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_question_answering(*lowercase__)

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

							"""simple docstring"""



							_lowercase							=     self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_sequence_classification(*lowercase__)

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

							"""simple docstring"""



							_lowercase							=     self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_token_classification(*lowercase__)


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

							"""simple docstring"""



							_lowercase							=     TFDebertaModel.from_pretrained("""kamalkraj/deberta-base""")
							self.assertIsNotNone(lowercase__)






@require_tf
class 					__a   (		unittest.TestCase  ):

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

							"""simple docstring"""



							pass


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

							"""simple docstring"""



							_lowercase							=     TFDebertaModel.from_pretrained("""kamalkraj/deberta-base""")
							_lowercase							=     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							=     tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
							_lowercase							=     model(lowercase__    ,			attention_mask=lowercase__)[0]

							_lowercase							=     tf.constant(
							    [
							        [
							            [-0.59855896, -0.80552566, -0.8462135],
							            [1.4484025, -0.93483794, -0.80593085],
							            [0.3122741, 0.00316059, -1.4131377],
							        ]
							    ])
							tf.debugging.assert_near(output[:, 1:4, 1:4]    ,			lowercase__    ,			atol=1e-4)






"""simple docstring"""




import safs
class SCREAMING_SNAKE_CASE       (      safs.SaFileSystem					):






	'''simple docstring'''




