
"""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						:Optional[int]  ,							lowerCamelCase_						:Union[str, Any]  ,							lowerCamelCase_						:Tuple=13  ,							lowerCamelCase_						:List[Any]=7  ,							lowerCamelCase_						:List[str]=True  ,							lowerCamelCase_						:Any=True  ,							lowerCamelCase_						:Any=True  ,							lowerCamelCase_						:Union[str, Any]=True  ,							lowerCamelCase_						:Union[str, Any]=99  ,							lowerCamelCase_						:str=32  ,							lowerCamelCase_						:Dict=2  ,							lowerCamelCase_						:Union[str, Any]=4  ,							lowerCamelCase_						:Tuple=37  ,							lowerCamelCase_						:Union[str, Any]="gelu"  ,							lowerCamelCase_						:Union[str, Any]=0.1  ,							lowerCamelCase_						:Optional[Any]=0.1  ,							lowerCamelCase_						:Dict=512  ,							lowerCamelCase_						:Optional[Any]=16  ,							lowerCamelCase_						:Optional[int]=2  ,							lowerCamelCase_						:Any=0.02  ,							lowerCamelCase_						:Any=3  ,							lowerCamelCase_						:Tuple=4  ,							lowerCamelCase_						:List[Any]=None  ,							):





										"""simple docstring"""

										lowerCamelCase__			:  Optional[int]  =parent
										lowerCamelCase__			:  Tuple  =13
										lowerCamelCase__			:  Any  =7
										lowerCamelCase__			:  List[Any]  =True
										lowerCamelCase__			:  Tuple  =True
										lowerCamelCase__			:  List[Any]  =True
										lowerCamelCase__			:  List[str]  =True
										lowerCamelCase__			:  List[Any]  =99
										lowerCamelCase__			:  Optional[int]  =32
										lowerCamelCase__			:  Optional[int]  =2
										lowerCamelCase__			:  Any  =4
										lowerCamelCase__			:  Union[str, Any]  =37
										lowerCamelCase__			:  List[Any]  ='gelu'
										lowerCamelCase__			:  Union[str, Any]  =0.1
										lowerCamelCase__			:  Tuple  =0.1
										lowerCamelCase__			:  str  =512
										lowerCamelCase__			:  Optional[Any]  =16
										lowerCamelCase__			:  int  =False
										lowerCamelCase__			:  Dict  =-1
										lowerCamelCase__			:  Dict  =True
										lowerCamelCase__			:  Optional[Any]  =2
										lowerCamelCase__			:  Optional[Any]  =0.02
										lowerCamelCase__			:  int  =3
										lowerCamelCase__			:  str  =4
										lowerCamelCase__			:  str  =None





							def    UpperCAmelCase__							(						self						:Tuple ):





										"""simple docstring"""

										lowerCamelCase__			:  Optional[Any]  =ids_tensor([self.batch_size, self.seq_length]  ,							self.vocab_size )

										lowerCamelCase__			:  Dict  =None
										if self.use_input_mask:
													lowerCamelCase__			:  List[Any]  =random_attention_mask([self.batch_size, self.seq_length] )

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

										lowerCamelCase__			:  List[Any]  =None
										lowerCamelCase__			:  int  =None
										lowerCamelCase__			:  Optional[int]  =None
										if self.use_labels:
													lowerCamelCase__			:  Optional[Any]  =ids_tensor([self.batch_size]  ,							self.type_sequence_label_size )
													lowerCamelCase__			:  Any  =ids_tensor([self.batch_size, self.seq_length]  ,							self.num_labels )

										lowerCamelCase__			:  Optional[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=lowerCamelCase_  ,							)

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





							def    UpperCAmelCase__							(						self						:List[str]  ,							lowerCamelCase_						:List[str]  ,							lowerCamelCase_						:List[Any]  ,							lowerCamelCase_						:Tuple  ,							lowerCamelCase_						:Union[str, Any]  ,							lowerCamelCase_						:Union[str, Any]  ,							lowerCamelCase_						:List[str]  ,							lowerCamelCase_						:str ):





										"""simple docstring"""

										lowerCamelCase__			:  Tuple  =TFDebertaModel(config=lowerCamelCase_ )
										lowerCamelCase__			:  Optional[Any]  ={'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}

										lowerCamelCase__			:  List[str]  =[input_ids, input_mask]
										lowerCamelCase__			:  str  =model(lowerCamelCase_ )

										lowerCamelCase__			:  int  =model(lowerCamelCase_ )

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





							def    UpperCAmelCase__							(						self						:Any  ,							lowerCamelCase_						:Tuple  ,							lowerCamelCase_						:Optional[Any]  ,							lowerCamelCase_						:str  ,							lowerCamelCase_						:int  ,							lowerCamelCase_						:List[str]  ,							lowerCamelCase_						:Optional[int]  ,							lowerCamelCase_						:Optional[Any] ):





										"""simple docstring"""

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





							def    UpperCAmelCase__							(						self						:List[str]  ,							lowerCamelCase_						:Tuple  ,							lowerCamelCase_						:List[str]  ,							lowerCamelCase_						:Any  ,							lowerCamelCase_						:Any  ,							lowerCamelCase_						:List[str]  ,							lowerCamelCase_						:Tuple  ,							lowerCamelCase_						:Optional[int] ):





										"""simple docstring"""

										lowerCamelCase__			:  Union[str, Any]  =self.num_labels
										lowerCamelCase__			:  List[str]  =TFDebertaForSequenceClassification(config=lowerCamelCase_ )
										lowerCamelCase__			:  Dict  ={
										    'input_ids': input_ids,
										    'attention_mask': input_mask,
										    'token_type_ids': token_type_ids,
										}

										lowerCamelCase__			:  Optional[Any]  =model(lowerCamelCase_ )
										self.parent.assertEqual(result.logits.shape  ,							(self.batch_size, self.num_labels) )





							def    UpperCAmelCase__							(						self						:List[str]  ,							lowerCamelCase_						:int  ,							lowerCamelCase_						:Dict  ,							lowerCamelCase_						:Optional[int]  ,							lowerCamelCase_						:str  ,							lowerCamelCase_						:List[Any]  ,							lowerCamelCase_						:Union[str, Any]  ,							lowerCamelCase_						:Optional[Any] ):





										"""simple docstring"""

										lowerCamelCase__			:  List[str]  =self.num_labels
										lowerCamelCase__			:  Optional[int]  =TFDebertaForTokenClassification(config=lowerCamelCase_ )
										lowerCamelCase__			:  Tuple  ={
										    'input_ids': input_ids,
										    'attention_mask': input_mask,
										    'token_type_ids': token_type_ids,
										}
										lowerCamelCase__			:  int  =model(lowerCamelCase_ )
										self.parent.assertEqual(result.logits.shape  ,							(self.batch_size, self.seq_length, self.num_labels) )





							def    UpperCAmelCase__							(						self						:List[str]  ,							lowerCamelCase_						:List[str]  ,							lowerCamelCase_						:Dict  ,							lowerCamelCase_						:Any  ,							lowerCamelCase_						:int  ,							lowerCamelCase_						:List[str]  ,							lowerCamelCase_						:Dict  ,							lowerCamelCase_						:Tuple ):





										"""simple docstring"""

										lowerCamelCase__			:  Dict  =TFDebertaForQuestionAnswering(config=lowerCamelCase_ )
										lowerCamelCase__			:  Optional[int]  ={
										    'input_ids': input_ids,
										    'attention_mask': input_mask,
										    'token_type_ids': token_type_ids,
										}

										lowerCamelCase__			:  Optional[int]  =model(lowerCamelCase_ )
										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						:int ):





										"""simple docstring"""

										lowerCamelCase__			:  Tuple  =self.prepare_config_and_inputs()
										(
										    lowerCamelCase__       
										)			:  Dict  =config_and_inputs
										lowerCamelCase__			:  int  ={'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
										return config, inputs_dict






@require_tf
class 					A_			(  A__   ,      A__   ,      unittest.TestCase     ):
							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    UpperCAmelCase__							(						self						:Union[str, Any] ):





										"""simple docstring"""

										lowerCamelCase__			:  Union[str, Any]  =TFDebertaModelTester(self )
										lowerCamelCase__			:  Any  =ConfigTester(self  ,							config_class=lowerCamelCase_  ,							hidden_size=37 )





							def    UpperCAmelCase__							(						self						:Union[str, Any] ):





										"""simple docstring"""

										self.config_tester.run_common_tests()





							def    UpperCAmelCase__							(						self						:Optional[Any] ):





										"""simple docstring"""

										lowerCamelCase__			:  Tuple  =self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*lowerCamelCase_ )





							def    UpperCAmelCase__							(						self						:Optional[int] ):





										"""simple docstring"""

										lowerCamelCase__			:  Dict  =self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_masked_lm(*lowerCamelCase_ )





							def    UpperCAmelCase__							(						self						:Any ):





										"""simple docstring"""

										lowerCamelCase__			:  Dict  =self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_question_answering(*lowerCamelCase_ )





							def    UpperCAmelCase__							(						self						:Tuple ):





										"""simple docstring"""

										lowerCamelCase__			:  List[Any]  =self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_sequence_classification(*lowerCamelCase_ )





							def    UpperCAmelCase__							(						self						:Union[str, Any] ):





										"""simple docstring"""

										lowerCamelCase__			:  Dict  =self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_token_classification(*lowerCamelCase_ )





							@slow
							def    UpperCAmelCase__							(						self						:int ):





										"""simple docstring"""

										lowerCamelCase__			:  Optional[int]  =TFDebertaModel.from_pretrained('kamalkraj/deberta-base' )
										self.assertIsNotNone(lowerCamelCase_ )






@require_tf
class 					A_			(  unittest.TestCase     ):





							@unittest.skip(reason='Model not available yet' )
							def    UpperCAmelCase__							(						self						:List[Any] ):





										"""simple docstring"""

										pass





							@slow
							def    UpperCAmelCase__							(						self						:int ):





										"""simple docstring"""

										lowerCamelCase__			:  Tuple  =TFDebertaModel.from_pretrained('kamalkraj/deberta-base' )
										lowerCamelCase__			:  List[str]  =tf.constant([[0, 31_414, 232, 328, 740, 1_140, 12_695, 69, 46_078, 1_588, 2]] )
										lowerCamelCase__			:  Optional[Any]  =tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]] )
										lowerCamelCase__			:  Any  =model(lowerCamelCase_  ,							attention_mask=lowerCamelCase_ )[0]

										lowerCamelCase__			:  List[str]  =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]  ,							lowerCamelCase_  ,							atol=1e-4 )

"""simple docstring"""


from typing import TYPE_CHECKING

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


lowerCAmelCase			=		{
    """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:
							lowerCAmelCase			=		[
							    """DONUT_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST""",
							    """DonutSwinModel""",
							    """DonutSwinPreTrainedModel""",
							]

try:
							if not is_vision_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							lowerCAmelCase			=		["""DonutFeatureExtractor"""]
							lowerCAmelCase			=		["""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

							lowerCAmelCase			=		_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)