





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







					'''simple docstring'''

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






						'''simple docstring'''







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





					def 							SCREAMING_SNAKE_CASE				(    self     :	Optional[int]		):






						'''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_		    =  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 							SCREAMING_SNAKE_CASE				(    self     :	Dict			,       __lowercase     :	Tuple			,       __lowercase     :	Any			,       __lowercase     :	Dict			,       __lowercase     :	int			,       __lowercase     :	int			,       __lowercase     :	Optional[int]			,       __lowercase     :	Union[str, Any]		):






						'''simple docstring'''







						UpperCAmelCase_		    =  TFDebertaModel(config=__lowercase		)
						UpperCAmelCase_		    =  {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}

						UpperCAmelCase_		    =  [input_ids, input_mask]
						UpperCAmelCase_		    =  model(__lowercase		)

						UpperCAmelCase_		    =  model(__lowercase		)

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





					def 							SCREAMING_SNAKE_CASE				(    self     :	Optional[int]			,       __lowercase     :	List[str]			,       __lowercase     :	Tuple			,       __lowercase     :	Dict			,       __lowercase     :	Dict			,       __lowercase     :	int			,       __lowercase     :	Union[str, Any]			,       __lowercase     :	List[Any]		):






						'''simple docstring'''







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





					def 							SCREAMING_SNAKE_CASE				(    self     :	Optional[int]			,       __lowercase     :	Optional[int]			,       __lowercase     :	Optional[int]			,       __lowercase     :	Tuple			,       __lowercase     :	Dict			,       __lowercase     :	int			,       __lowercase     :	Tuple			,       __lowercase     :	Dict		):






						'''simple docstring'''







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

						UpperCAmelCase_		    =  model(__lowercase		)
						self.parent.assertEqual(result.logits.shape			,       (self.batch_size, self.num_labels)		)





					def 							SCREAMING_SNAKE_CASE				(    self     :	Tuple			,       __lowercase     :	Tuple			,       __lowercase     :	Optional[Any]			,       __lowercase     :	Tuple			,       __lowercase     :	Dict			,       __lowercase     :	Tuple			,       __lowercase     :	str			,       __lowercase     :	List[Any]		):






						'''simple docstring'''







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





					def 							SCREAMING_SNAKE_CASE				(    self     :	Dict			,       __lowercase     :	str			,       __lowercase     :	Dict			,       __lowercase     :	Tuple			,       __lowercase     :	Union[str, Any]			,       __lowercase     :	str			,       __lowercase     :	Any			,       __lowercase     :	str		):






						'''simple docstring'''







						UpperCAmelCase_		    =  TFDebertaForQuestionAnswering(config=__lowercase		)
						UpperCAmelCase_		    =  {
						    """input_ids""": input_ids,
						    """attention_mask""": input_mask,
						    """token_type_ids""": token_type_ids,
						}

						UpperCAmelCase_		    =  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 							SCREAMING_SNAKE_CASE				(    self     :	Optional[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 	_UpperCamelCase	(							A_    ,							A_    ,							unittest.TestCase	):







					'''simple docstring'''

					lowerCamelCase  :  Dict           =							(
					    (
					        TFDebertaModel,
					        TFDebertaForMaskedLM,
					        TFDebertaForQuestionAnswering,
					        TFDebertaForSequenceClassification,
					        TFDebertaForTokenClassification,
					    )
					    if is_tf_available()
					    else ()
					)
					lowerCamelCase  :  List[str]           =							(
					    {
					        'feature-extraction': TFDebertaModel,
					        'fill-mask': TFDebertaForMaskedLM,
					        'question-answering': TFDebertaForQuestionAnswering,
					        'text-classification': TFDebertaForSequenceClassification,
					        'token-classification': TFDebertaForTokenClassification,
					        'zero-shot': TFDebertaForSequenceClassification,
					    }
					    if is_tf_available()
					    else {}
					)

					lowerCamelCase  :  List[Any]           =							False
					lowerCamelCase  :  Any           =							False





					def 							SCREAMING_SNAKE_CASE				(    self     :	str		):






						'''simple docstring'''







						UpperCAmelCase_		    =  TFDebertaModelTester(self		)
						UpperCAmelCase_		    =  ConfigTester(self			,       config_class=__lowercase			,       hidden_size=37		)





					def 							SCREAMING_SNAKE_CASE				(    self     :	Optional[int]		):






						'''simple docstring'''







						self.config_tester.run_common_tests()





					def 							SCREAMING_SNAKE_CASE				(    self     :	Optional[Any]		):






						'''simple docstring'''







						UpperCAmelCase_		    =  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*__lowercase		)





					def 							SCREAMING_SNAKE_CASE				(    self     :	List[Any]		):






						'''simple docstring'''







						UpperCAmelCase_		    =  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_lm(*__lowercase		)





					def 							SCREAMING_SNAKE_CASE				(    self     :	str		):






						'''simple docstring'''







						UpperCAmelCase_		    =  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*__lowercase		)





					def 							SCREAMING_SNAKE_CASE				(    self     :	Optional[int]		):






						'''simple docstring'''







						UpperCAmelCase_		    =  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*__lowercase		)





					def 							SCREAMING_SNAKE_CASE				(    self     :	Optional[Any]		):






						'''simple docstring'''







						UpperCAmelCase_		    =  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_token_classification(*__lowercase		)





					@slow
					def 							SCREAMING_SNAKE_CASE				(    self     :	Optional[Any]		):






						'''simple docstring'''







						UpperCAmelCase_		    =  TFDebertaModel.from_pretrained("""kamalkraj/deberta-base"""		)
						self.assertIsNotNone(__lowercase		)







@require_tf
class 	_UpperCamelCase	(							unittest.TestCase	):







					'''simple docstring'''

					@unittest.skip(reason="""Model not available yet"""		)
					def 							SCREAMING_SNAKE_CASE				(    self     :	List[str]		):






						'''simple docstring'''







						pass





					@slow
					def 							SCREAMING_SNAKE_CASE				(    self     :	Optional[int]		):






						'''simple docstring'''







						UpperCAmelCase_		    =  TFDebertaModel.from_pretrained("""kamalkraj/deberta-base"""		)
						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(__lowercase			,       attention_mask=__lowercase		)[0]

						UpperCAmelCase_		    =  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		)









from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


UpperCamelCase__ :			Any       	=			{
    """configuration_splinter""": ["""SPLINTER_PRETRAINED_CONFIG_ARCHIVE_MAP""", """SplinterConfig"""],
    """tokenization_splinter""": ["""SplinterTokenizer"""],
}

try:
				if not is_tokenizers_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				UpperCamelCase__ :			Any       	=			["""SplinterTokenizerFast"""]

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				UpperCamelCase__ :			Union[str, Any]       	=			[
				    """SPLINTER_PRETRAINED_MODEL_ARCHIVE_LIST""",
				    """SplinterForQuestionAnswering""",
				    """SplinterForPreTraining""",
				    """SplinterLayer""",
				    """SplinterModel""",
				    """SplinterPreTrainedModel""",
				]


if TYPE_CHECKING:
				from .configuration_splinter import SPLINTER_PRETRAINED_CONFIG_ARCHIVE_MAP, SplinterConfig
				from .tokenization_splinter import SplinterTokenizer

				try:
								if not is_tokenizers_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .tokenization_splinter_fast import SplinterTokenizerFast

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_splinter import (
								    SPLINTER_PRETRAINED_MODEL_ARCHIVE_LIST,
								    SplinterForPreTraining,
								    SplinterForQuestionAnswering,
								    SplinterLayer,
								    SplinterModel,
								    SplinterPreTrainedModel,
								)


else:
				import sys

				UpperCamelCase__ :			List[str]       	=			_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)


