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



	"""simple docstring"""




	def __init__(	self  :      List[Any]	,							SCREAMING_SNAKE_CASE_  :      int	,							SCREAMING_SNAKE_CASE_  :      List[str]=1_3	,							SCREAMING_SNAKE_CASE_  :      Union[str, Any]=7	,							SCREAMING_SNAKE_CASE_  :      Tuple=True	,							SCREAMING_SNAKE_CASE_  :      Union[str, Any]=True	,							SCREAMING_SNAKE_CASE_  :      Any=True	,							SCREAMING_SNAKE_CASE_  :      int=True	,							SCREAMING_SNAKE_CASE_  :      List[str]=9_9	,							SCREAMING_SNAKE_CASE_  :      int=3_2	,							SCREAMING_SNAKE_CASE_  :      Optional[int]=2	,							SCREAMING_SNAKE_CASE_  :      Optional[Any]=4	,							SCREAMING_SNAKE_CASE_  :      Dict=3_7	,							SCREAMING_SNAKE_CASE_  :      str="gelu"	,							SCREAMING_SNAKE_CASE_  :      Optional[Any]=0.1	,							SCREAMING_SNAKE_CASE_  :      Union[str, Any]=0.1	,							SCREAMING_SNAKE_CASE_  :      Dict=5_1_2	,							SCREAMING_SNAKE_CASE_  :      Dict=1_6	,							SCREAMING_SNAKE_CASE_  :      Any=2	,							SCREAMING_SNAKE_CASE_  :      List[Any]=0.02	,							SCREAMING_SNAKE_CASE_  :      str=3	,							SCREAMING_SNAKE_CASE_  :      List[str]=4	,							SCREAMING_SNAKE_CASE_  :      List[str]=None	,							)	->					Tuple:
						lowercase_					  = parent
						lowercase_					  = 1_3
						lowercase_					  = 7
						lowercase_					  = True
						lowercase_					  = True
						lowercase_					  = True
						lowercase_					  = True
						lowercase_					  = 9_9
						lowercase_					  = 3_2
						lowercase_					  = 2
						lowercase_					  = 4
						lowercase_					  = 3_7
						lowercase_					  = "gelu"
						lowercase_					  = 0.1
						lowercase_					  = 0.1
						lowercase_					  = 5_1_2
						lowercase_					  = 1_6
						lowercase_					  = False
						lowercase_					  = -1
						lowercase_					  = True
						lowercase_					  = 2
						lowercase_					  = 0.02
						lowercase_					  = 3
						lowercase_					  = 4
						lowercase_					  = None
	def 						_lowercase  (	self  :      Any	)	->					List[str]:
						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=SCREAMING_SNAKE_CASE_	,							)

						return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
	def 						_lowercase  (	self  :      Optional[Any]	,							SCREAMING_SNAKE_CASE_  :      Optional[int]	,							SCREAMING_SNAKE_CASE_  :      List[Any]	,							SCREAMING_SNAKE_CASE_  :      Dict	,							SCREAMING_SNAKE_CASE_  :      Optional[Any]	,							SCREAMING_SNAKE_CASE_  :      Union[str, Any]	,							SCREAMING_SNAKE_CASE_  :      int	,							SCREAMING_SNAKE_CASE_  :      Tuple	)	->					str:
						lowercase_					  = TFDebertaModel(config=SCREAMING_SNAKE_CASE_	)
						lowercase_					  = {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

						lowercase_					  = [input_ids, input_mask]
						lowercase_					  = model(SCREAMING_SNAKE_CASE_	)

						lowercase_					  = model(SCREAMING_SNAKE_CASE_	)

						self.parent.assertEqual(result.last_hidden_state.shape	,							(self.batch_size, self.seq_length, self.hidden_size)	)
	def 						_lowercase  (	self  :      Any	,							SCREAMING_SNAKE_CASE_  :      List[str]	,							SCREAMING_SNAKE_CASE_  :      List[str]	,							SCREAMING_SNAKE_CASE_  :      List[str]	,							SCREAMING_SNAKE_CASE_  :      List[Any]	,							SCREAMING_SNAKE_CASE_  :      Optional[Any]	,							SCREAMING_SNAKE_CASE_  :      Union[str, Any]	,							SCREAMING_SNAKE_CASE_  :      int	)	->					List[str]:
						lowercase_					  = TFDebertaForMaskedLM(config=SCREAMING_SNAKE_CASE_	)
						lowercase_					  = {
						    "input_ids": input_ids,
						    "attention_mask": input_mask,
						    "token_type_ids": token_type_ids,
						}
						lowercase_					  = model(SCREAMING_SNAKE_CASE_	)
						self.parent.assertEqual(result.logits.shape	,							(self.batch_size, self.seq_length, self.vocab_size)	)
	def 						_lowercase  (	self  :      str	,							SCREAMING_SNAKE_CASE_  :      Tuple	,							SCREAMING_SNAKE_CASE_  :      List[Any]	,							SCREAMING_SNAKE_CASE_  :      Any	,							SCREAMING_SNAKE_CASE_  :      List[Any]	,							SCREAMING_SNAKE_CASE_  :      Any	,							SCREAMING_SNAKE_CASE_  :      Dict	,							SCREAMING_SNAKE_CASE_  :      Union[str, Any]	)	->					List[str]:
						lowercase_					  = self.num_labels
						lowercase_					  = TFDebertaForSequenceClassification(config=SCREAMING_SNAKE_CASE_	)
						lowercase_					  = {
						    "input_ids": input_ids,
						    "attention_mask": input_mask,
						    "token_type_ids": token_type_ids,
						}

						lowercase_					  = model(SCREAMING_SNAKE_CASE_	)
						self.parent.assertEqual(result.logits.shape	,							(self.batch_size, self.num_labels)	)
	def 						_lowercase  (	self  :      int	,							SCREAMING_SNAKE_CASE_  :      Tuple	,							SCREAMING_SNAKE_CASE_  :      str	,							SCREAMING_SNAKE_CASE_  :      List[str]	,							SCREAMING_SNAKE_CASE_  :      str	,							SCREAMING_SNAKE_CASE_  :      Any	,							SCREAMING_SNAKE_CASE_  :      List[str]	,							SCREAMING_SNAKE_CASE_  :      Dict	)	->					List[Any]:
						lowercase_					  = self.num_labels
						lowercase_					  = TFDebertaForTokenClassification(config=SCREAMING_SNAKE_CASE_	)
						lowercase_					  = {
						    "input_ids": input_ids,
						    "attention_mask": input_mask,
						    "token_type_ids": token_type_ids,
						}
						lowercase_					  = model(SCREAMING_SNAKE_CASE_	)
						self.parent.assertEqual(result.logits.shape	,							(self.batch_size, self.seq_length, self.num_labels)	)
	def 						_lowercase  (	self  :      int	,							SCREAMING_SNAKE_CASE_  :      int	,							SCREAMING_SNAKE_CASE_  :      List[str]	,							SCREAMING_SNAKE_CASE_  :      Dict	,							SCREAMING_SNAKE_CASE_  :      int	,							SCREAMING_SNAKE_CASE_  :      List[str]	,							SCREAMING_SNAKE_CASE_  :      str	,							SCREAMING_SNAKE_CASE_  :      Optional[int]	)	->					Union[str, Any]:
						lowercase_					  = TFDebertaForQuestionAnswering(config=SCREAMING_SNAKE_CASE_	)
						lowercase_					  = {
						    "input_ids": input_ids,
						    "attention_mask": input_mask,
						    "token_type_ids": token_type_ids,
						}

						lowercase_					  = 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 						_lowercase  (	self  :      Dict	)	->					str:
						lowercase_					  = self.prepare_config_and_inputs()
						(
						    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 			lowercase__(    snake_case__			,						snake_case__			,						unittest.TestCase							):



	"""simple docstring"""




	a      :str   					=     (
	    (
	        TFDebertaModel,
	        TFDebertaForMaskedLM,
	        TFDebertaForQuestionAnswering,
	        TFDebertaForSequenceClassification,
	        TFDebertaForTokenClassification,
	    )
	    if is_tf_available()
	    else ()
	)
	a      :Optional[Any]   					=     (
	    {
	        "feature-extraction": TFDebertaModel,
	        "fill-mask": TFDebertaForMaskedLM,
	        "question-answering": TFDebertaForQuestionAnswering,
	        "text-classification": TFDebertaForSequenceClassification,
	        "token-classification": TFDebertaForTokenClassification,
	        "zero-shot": TFDebertaForSequenceClassification,
	    }
	    if is_tf_available()
	    else {}
	)

	a      :List[str]   					=     False
	a      :Tuple   					=     False
	def 						_lowercase  (	self  :      List[str]	)	->					Optional[int]:
						lowercase_					  = TFDebertaModelTester(self	)
						lowercase_					  = ConfigTester(self	,							config_class=SCREAMING_SNAKE_CASE_	,							hidden_size=3_7	)
	def 						_lowercase  (	self  :      Optional[Any]	)	->					Optional[Any]:
						self.config_tester.run_common_tests()
	def 						_lowercase  (	self  :      Dict	)	->					Tuple:
						lowercase_					  = self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE_	)
	def 						_lowercase  (	self  :      Any	)	->					int:
						lowercase_					  = self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_lm(*SCREAMING_SNAKE_CASE_	)
	def 						_lowercase  (	self  :      Dict	)	->					Optional[int]:
						lowercase_					  = self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*SCREAMING_SNAKE_CASE_	)
	def 						_lowercase  (	self  :      Any	)	->					List[str]:
						lowercase_					  = self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*SCREAMING_SNAKE_CASE_	)
	def 						_lowercase  (	self  :      Any	)	->					Any:
						lowercase_					  = self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_token_classification(*SCREAMING_SNAKE_CASE_	)




	@slow
	def 						_lowercase  (	self  :      Dict	)	->					Tuple:
						lowercase_					  = TFDebertaModel.from_pretrained('''kamalkraj/deberta-base'''	)
						self.assertIsNotNone(SCREAMING_SNAKE_CASE_	)

@require_tf
class 			lowercase__(    unittest.TestCase							):



	"""simple docstring"""




	@unittest.skip(reason='''Model not available yet'''	)
	def 						_lowercase  (	self  :      Union[str, Any]	)	->					int:
						pass




	@slow
	def 						_lowercase  (	self  :      int	)	->					Optional[int]:
						lowercase_					  = TFDebertaModel.from_pretrained('''kamalkraj/deberta-base'''	)
						lowercase_					  = tf.constant([[0, 3_1_4_1_4, 2_3_2, 3_2_8, 7_4_0, 1_1_4_0, 1_2_6_9_5, 6_9, 4_6_0_7_8, 1_5_8_8, 2]]	)
						lowercase_					  = tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]	)
						lowercase_					  = model(SCREAMING_SNAKE_CASE_	,							attention_mask=SCREAMING_SNAKE_CASE_	)[0]

						lowercase_					  = tf.constant(
						    [
						        [
						            [-0.59_85_58_96, -0.80_55_25_66, -0.8_46_21_35],
						            [1.4_48_40_25, -0.93_48_37_94, -0.80_59_30_85],
						            [0.3_12_27_41, 0.00_31_60_59, -1.4_13_13_77],
						        ]
						    ]	)
						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, is_vision_available


__a        = {
    'configuration_donut_swin': ['DONUT_SWIN_PRETRAINED_CONFIG_ARCHIVE_MAP', 'DonutSwinConfig'],
    'processing_donut': ['DonutProcessor'],
}

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						__a        = [
						    'DONUT_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST',
						    'DonutSwinModel',
						    'DonutSwinPreTrainedModel',
						]

try:
						if not is_vision_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						__a        = ['DonutFeatureExtractor']
						__a        = ['DonutImageProcessor']


if TYPE_CHECKING:
						from .configuration_donut_swin import DONUT_SWIN_PRETRAINED_CONFIG_ARCHIVE_MAP, DonutSwinConfig
						from .processing_donut import DonutProcessor

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_donut_swin import (
												    DONUT_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST,
												    DonutSwinModel,
												    DonutSwinPreTrainedModel,
												)

						try:
												if not is_vision_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .feature_extraction_donut import DonutFeatureExtractor
												from .image_processing_donut import DonutImageProcessor

else:
						import sys

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




