



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






				"""simple docstring"""

				def __init__(				self						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__=13						,	SCREAMING_SNAKE_CASE__=7						,	SCREAMING_SNAKE_CASE__=True						,	SCREAMING_SNAKE_CASE__=True						,	SCREAMING_SNAKE_CASE__=True						,	SCREAMING_SNAKE_CASE__=True						,	SCREAMING_SNAKE_CASE__=99						,	SCREAMING_SNAKE_CASE__=32						,	SCREAMING_SNAKE_CASE__=2						,	SCREAMING_SNAKE_CASE__=4						,	SCREAMING_SNAKE_CASE__=37						,	SCREAMING_SNAKE_CASE__="gelu"						,	SCREAMING_SNAKE_CASE__=0.1						,	SCREAMING_SNAKE_CASE__=0.1						,	SCREAMING_SNAKE_CASE__=5_12						,	SCREAMING_SNAKE_CASE__=16						,	SCREAMING_SNAKE_CASE__=2						,	SCREAMING_SNAKE_CASE__=0.02						,	SCREAMING_SNAKE_CASE__=3						,	SCREAMING_SNAKE_CASE__=4						,	SCREAMING_SNAKE_CASE__=None						,	):






					"""simple docstring"""

					_snake_case					:							Dict					     =   parent
					_snake_case					:							int					     =   13
					_snake_case					:							Union[str, Any]					     =   7
					_snake_case					:							List[str]					     =   True
					_snake_case					:							Any					     =   True
					_snake_case					:							Optional[Any]					     =   True
					_snake_case					:							str					     =   True
					_snake_case					:							List[Any]					     =   99
					_snake_case					:							int					     =   32
					_snake_case					:							List[str]					     =   2
					_snake_case					:							Union[str, Any]					     =   4
					_snake_case					:							Any					     =   37
					_snake_case					:							Union[str, Any]					     =   """gelu"""
					_snake_case					:							Dict					     =   0.1
					_snake_case					:							Any					     =   0.1
					_snake_case					:							Dict					     =   5_12
					_snake_case					:							Any					     =   16
					_snake_case					:							List[Any]					     =   False
					_snake_case					:							Any					     =   -1
					_snake_case					:							str					     =   True
					_snake_case					:							Union[str, Any]					     =   2
					_snake_case					:							Union[str, Any]					     =   0.02
					_snake_case					:							str					     =   3
					_snake_case					:							Dict					     =   4
					_snake_case					:							List[str]					     =   None







				def 		__lowerCamelCase(				self      ):






					"""simple docstring"""

					_snake_case					:							List[Any]					     =   ids_tensor([self.batch_size, self.seq_length]						,	self.vocab_size      )

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

					_snake_case					:							Optional[Any]					     =   None
					if self.use_token_type_ids:
						_snake_case					:							Dict					     =   ids_tensor([self.batch_size, self.seq_length]						,	self.type_vocab_size      )

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

					_snake_case					:							Any					     =   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=SCREAMING_SNAKE_CASE__						,	)

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







				def 		__lowerCamelCase(				self						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__      ):






					"""simple docstring"""

					_snake_case					:							Dict					     =   TFDebertaModel(config=SCREAMING_SNAKE_CASE__      )
					_snake_case					:							Dict					     =   {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}

					_snake_case					:							Optional[Any]					     =   [input_ids, input_mask]
					_snake_case					:							Optional[int]					     =   model(SCREAMING_SNAKE_CASE__      )

					_snake_case					:							Optional[Any]					     =   model(SCREAMING_SNAKE_CASE__      )

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







				def 		__lowerCamelCase(				self						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__      ):






					"""simple docstring"""

					_snake_case					:							Union[str, Any]					     =   TFDebertaForMaskedLM(config=SCREAMING_SNAKE_CASE__      )
					_snake_case					:							List[str]					     =   {
					    """input_ids""": input_ids,
					    """attention_mask""": input_mask,
					    """token_type_ids""": token_type_ids,
					}
					_snake_case					:							str					     =   model(SCREAMING_SNAKE_CASE__      )
					self.parent.assertEqual(result.logits.shape						,	(self.batch_size, self.seq_length, self.vocab_size)      )







				def 		__lowerCamelCase(				self						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__      ):






					"""simple docstring"""

					_snake_case					:							str					     =   self.num_labels
					_snake_case					:							List[str]					     =   TFDebertaForSequenceClassification(config=SCREAMING_SNAKE_CASE__      )
					_snake_case					:							int					     =   {
					    """input_ids""": input_ids,
					    """attention_mask""": input_mask,
					    """token_type_ids""": token_type_ids,
					}

					_snake_case					:							Tuple					     =   model(SCREAMING_SNAKE_CASE__      )
					self.parent.assertEqual(result.logits.shape						,	(self.batch_size, self.num_labels)      )







				def 		__lowerCamelCase(				self						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__      ):






					"""simple docstring"""

					_snake_case					:							int					     =   self.num_labels
					_snake_case					:							Optional[int]					     =   TFDebertaForTokenClassification(config=SCREAMING_SNAKE_CASE__      )
					_snake_case					:							str					     =   {
					    """input_ids""": input_ids,
					    """attention_mask""": input_mask,
					    """token_type_ids""": token_type_ids,
					}
					_snake_case					:							Optional[int]					     =   model(SCREAMING_SNAKE_CASE__      )
					self.parent.assertEqual(result.logits.shape						,	(self.batch_size, self.seq_length, self.num_labels)      )







				def 		__lowerCamelCase(				self						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__      ):






					"""simple docstring"""

					_snake_case					:							Union[str, Any]					     =   TFDebertaForQuestionAnswering(config=SCREAMING_SNAKE_CASE__      )
					_snake_case					:							List[Any]					     =   {
					    """input_ids""": input_ids,
					    """attention_mask""": input_mask,
					    """token_type_ids""": token_type_ids,
					}

					_snake_case					:							Dict					     =   model(SCREAMING_SNAKE_CASE__      )
					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      ):






					"""simple docstring"""

					_snake_case					:							Union[str, Any]					     =   self.prepare_config_and_inputs()
					(
					    (
					    _snake_case
					)     , (
					    _snake_case
					)     , (
					    _snake_case
					)     , (
					    _snake_case
					)     , (
					    _snake_case
					)     , (
					    _snake_case
					)     , (
					    _snake_case
					)     , 
					)					:							Optional[int]					     =   config_and_inputs
					_snake_case					:							Dict					     =   {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
					return config, inputs_dict





@require_tf
class 		__SCREAMING_SNAKE_CASE      (				lowercase__					,			lowercase__					,			unittest.TestCase      ):






				"""simple docstring"""

				SCREAMING_SNAKE_CASE_ 				=  (
				    (
				        TFDebertaModel,
				        TFDebertaForMaskedLM,
				        TFDebertaForQuestionAnswering,
				        TFDebertaForSequenceClassification,
				        TFDebertaForTokenClassification,
				    )
				    if is_tf_available()
				    else ()
				)
				SCREAMING_SNAKE_CASE_ 				=  (
				    {
				        '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_ 				=  False
				SCREAMING_SNAKE_CASE_ 				=  False







				def 		__lowerCamelCase(				self      ):






					"""simple docstring"""

					_snake_case					:							Any					     =   TFDebertaModelTester(self      )
					_snake_case					:							Optional[Any]					     =   ConfigTester(self						,	config_class=SCREAMING_SNAKE_CASE__						,	hidden_size=37      )







				def 		__lowerCamelCase(				self      ):






					"""simple docstring"""

					self.config_tester.run_common_tests()







				def 		__lowerCamelCase(				self      ):






					"""simple docstring"""

					_snake_case					:							str					     =   self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE__      )







				def 		__lowerCamelCase(				self      ):






					"""simple docstring"""

					_snake_case					:							Dict					     =   self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_masked_lm(*SCREAMING_SNAKE_CASE__      )







				def 		__lowerCamelCase(				self      ):






					"""simple docstring"""

					_snake_case					:							Optional[int]					     =   self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_question_answering(*SCREAMING_SNAKE_CASE__      )







				def 		__lowerCamelCase(				self      ):






					"""simple docstring"""

					_snake_case					:							Union[str, Any]					     =   self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_sequence_classification(*SCREAMING_SNAKE_CASE__      )







				def 		__lowerCamelCase(				self      ):






					"""simple docstring"""

					_snake_case					:							Any					     =   self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_token_classification(*SCREAMING_SNAKE_CASE__      )







				@slow
				def 		__lowerCamelCase(				self      ):






					"""simple docstring"""

					_snake_case					:							Union[str, Any]					     =   TFDebertaModel.from_pretrained("""kamalkraj/deberta-base"""      )
					self.assertIsNotNone(SCREAMING_SNAKE_CASE__      )





@require_tf
class 		__SCREAMING_SNAKE_CASE      (				unittest.TestCase      ):






				"""simple docstring"""

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






					"""simple docstring"""

					pass







				@slow
				def 		__lowerCamelCase(				self      ):






					"""simple docstring"""

					_snake_case					:							List[Any]					     =   TFDebertaModel.from_pretrained("""kamalkraj/deberta-base"""      )
					_snake_case					:							Any					     =   tf.constant([[0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]]      )
					_snake_case					:							Union[str, Any]					     =   tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]      )
					_snake_case					:							str					     =   model(SCREAMING_SNAKE_CASE__						,	attention_mask=SCREAMING_SNAKE_CASE__      )[0]

					_snake_case					:							Union[str, Any]					     =   tf.constant(
					    [
					        [
					            [-0.5985_5896, -0.8055_2566, -0.846_2135],
					            [1.448_4025, -0.9348_3794, -0.8059_3085],
					            [0.312_2741, 0.0031_6059, -1.413_1377],
					        ]
					    ]      )
					tf.debugging.assert_near(output[:, 1:4, 1:4]						,	SCREAMING_SNAKE_CASE__						,	atol=1e-4      )










from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


UpperCAmelCase_			      =  {'''configuration_qdqbert''': ['''QDQBERT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''QDQBertConfig''']}

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						UpperCAmelCase_			      =  [
						    '''QDQBERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
						    '''QDQBertForMaskedLM''',
						    '''QDQBertForMultipleChoice''',
						    '''QDQBertForNextSentencePrediction''',
						    '''QDQBertForQuestionAnswering''',
						    '''QDQBertForSequenceClassification''',
						    '''QDQBertForTokenClassification''',
						    '''QDQBertLayer''',
						    '''QDQBertLMHeadModel''',
						    '''QDQBertModel''',
						    '''QDQBertPreTrainedModel''',
						    '''load_tf_weights_in_qdqbert''',
						]


if TYPE_CHECKING:
						from .configuration_qdqbert import QDQBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, QDQBertConfig

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_qdqbert import (
												    QDQBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
												    QDQBertForMaskedLM,
												    QDQBertForMultipleChoice,
												    QDQBertForNextSentencePrediction,
												    QDQBertForQuestionAnswering,
												    QDQBertForSequenceClassification,
												    QDQBertForTokenClassification,
												    QDQBertLayer,
												    QDQBertLMHeadModel,
												    QDQBertModel,
												    QDQBertPreTrainedModel,
												    load_tf_weights_in_qdqbert,
												)


else:
						import sys

						UpperCAmelCase_			      =  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)





