
"""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    __lowerCamelCase     :




				def __init__(							self       ,	UpperCAmelCase       ,	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=512       ,	UpperCAmelCase=16       ,	UpperCAmelCase=2       ,	UpperCAmelCase=0.0_2       ,	UpperCAmelCase=3       ,	UpperCAmelCase=4       ,	UpperCAmelCase=None       ,	):
							lowerCamelCase_ 		=     parent
							lowerCamelCase_ 		=     13
							lowerCamelCase_ 		=     7
							lowerCamelCase_ 		=     True
							lowerCamelCase_ 		=     True
							lowerCamelCase_ 		=     True
							lowerCamelCase_ 		=     True
							lowerCamelCase_ 		=     99
							lowerCamelCase_ 		=     32
							lowerCamelCase_ 		=     2
							lowerCamelCase_ 		=     4
							lowerCamelCase_ 		=     37
							lowerCamelCase_ 		=     '''gelu'''
							lowerCamelCase_ 		=     0.1
							lowerCamelCase_ 		=     0.1
							lowerCamelCase_ 		=     512
							lowerCamelCase_ 		=     16
							lowerCamelCase_ 		=     False
							lowerCamelCase_ 		=     -1
							lowerCamelCase_ 		=     True
							lowerCamelCase_ 		=     2
							lowerCamelCase_ 		=     0.0_2
							lowerCamelCase_ 		=     3
							lowerCamelCase_ 		=     4
							lowerCamelCase_ 		=     None




				def 					UpperCAmelCase__	(							self      ):
							lowerCamelCase_ 		=     ids_tensor([self.batch_size, self.seq_length]       ,	self.vocab_size      )

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

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

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

							lowerCamelCase_ 		=     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=UpperCAmelCase       ,	)

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




				def 					UpperCAmelCase__	(							self       ,	UpperCAmelCase       ,	UpperCAmelCase       ,	UpperCAmelCase       ,	UpperCAmelCase       ,	UpperCAmelCase       ,	UpperCAmelCase       ,	UpperCAmelCase      ):
							lowerCamelCase_ 		=     TFDebertaModel(config=UpperCAmelCase      )
							lowerCamelCase_ 		=     {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

							lowerCamelCase_ 		=     [input_ids, input_mask]
							lowerCamelCase_ 		=     model(UpperCAmelCase      )

							lowerCamelCase_ 		=     model(UpperCAmelCase      )

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




				def 					UpperCAmelCase__	(							self       ,	UpperCAmelCase       ,	UpperCAmelCase       ,	UpperCAmelCase       ,	UpperCAmelCase       ,	UpperCAmelCase       ,	UpperCAmelCase       ,	UpperCAmelCase      ):
							lowerCamelCase_ 		=     TFDebertaForMaskedLM(config=UpperCAmelCase      )
							lowerCamelCase_ 		=     {
							    '''input_ids''': input_ids,
							    '''attention_mask''': input_mask,
							    '''token_type_ids''': token_type_ids,
							}
							lowerCamelCase_ 		=     model(UpperCAmelCase      )
							self.parent.assertEqual(result.logits.shape       ,	(self.batch_size, self.seq_length, self.vocab_size)      )




				def 					UpperCAmelCase__	(							self       ,	UpperCAmelCase       ,	UpperCAmelCase       ,	UpperCAmelCase       ,	UpperCAmelCase       ,	UpperCAmelCase       ,	UpperCAmelCase       ,	UpperCAmelCase      ):
							lowerCamelCase_ 		=     self.num_labels
							lowerCamelCase_ 		=     TFDebertaForSequenceClassification(config=UpperCAmelCase      )
							lowerCamelCase_ 		=     {
							    '''input_ids''': input_ids,
							    '''attention_mask''': input_mask,
							    '''token_type_ids''': token_type_ids,
							}

							lowerCamelCase_ 		=     model(UpperCAmelCase      )
							self.parent.assertEqual(result.logits.shape       ,	(self.batch_size, self.num_labels)      )




				def 					UpperCAmelCase__	(							self       ,	UpperCAmelCase       ,	UpperCAmelCase       ,	UpperCAmelCase       ,	UpperCAmelCase       ,	UpperCAmelCase       ,	UpperCAmelCase       ,	UpperCAmelCase      ):
							lowerCamelCase_ 		=     self.num_labels
							lowerCamelCase_ 		=     TFDebertaForTokenClassification(config=UpperCAmelCase      )
							lowerCamelCase_ 		=     {
							    '''input_ids''': input_ids,
							    '''attention_mask''': input_mask,
							    '''token_type_ids''': token_type_ids,
							}
							lowerCamelCase_ 		=     model(UpperCAmelCase      )
							self.parent.assertEqual(result.logits.shape       ,	(self.batch_size, self.seq_length, self.num_labels)      )




				def 					UpperCAmelCase__	(							self       ,	UpperCAmelCase       ,	UpperCAmelCase       ,	UpperCAmelCase       ,	UpperCAmelCase       ,	UpperCAmelCase       ,	UpperCAmelCase       ,	UpperCAmelCase      ):
							lowerCamelCase_ 		=     TFDebertaForQuestionAnswering(config=UpperCAmelCase      )
							lowerCamelCase_ 		=     {
							    '''input_ids''': input_ids,
							    '''attention_mask''': input_mask,
							    '''token_type_ids''': token_type_ids,
							}

							lowerCamelCase_ 		=     model(UpperCAmelCase      )
							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      ):
							lowerCamelCase_ 		=     self.prepare_config_and_inputs()
							(
							    (
							    lowerCamelCase_ 
							)		,   (
							    lowerCamelCase_ 
							)		,   (
							    lowerCamelCase_ 
							)		,   (
							    lowerCamelCase_ 
							)		,   (
							    lowerCamelCase_ 
							)		,   (
							    lowerCamelCase_ 
							)		,   (
							    lowerCamelCase_ 
							)		,    
							) 		=     config_and_inputs
							lowerCamelCase_ 		=     {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
							return config, inputs_dict




@require_tf
class    __lowerCamelCase     (   snake_case_	,  snake_case_	,  unittest.TestCase ):
				a__:			Dict									=						(
				    (
				        TFDebertaModel,
				        TFDebertaForMaskedLM,
				        TFDebertaForQuestionAnswering,
				        TFDebertaForSequenceClassification,
				        TFDebertaForTokenClassification,
				    )
				    if is_tf_available()
				    else ()
				)
				a__:			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__:			Optional[int]									=						False
				a__:			Optional[Any]									=						False




				def 					UpperCAmelCase__	(							self      ):
							lowerCamelCase_ 		=     TFDebertaModelTester(self      )
							lowerCamelCase_ 		=     ConfigTester(self       ,	config_class=UpperCAmelCase       ,	hidden_size=37      )




				def 					UpperCAmelCase__	(							self      ):
							self.config_tester.run_common_tests()




				def 					UpperCAmelCase__	(							self      ):
							lowerCamelCase_ 		=     self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*UpperCAmelCase      )




				def 					UpperCAmelCase__	(							self      ):
							lowerCamelCase_ 		=     self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_lm(*UpperCAmelCase      )




				def 					UpperCAmelCase__	(							self      ):
							lowerCamelCase_ 		=     self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_question_answering(*UpperCAmelCase      )




				def 					UpperCAmelCase__	(							self      ):
							lowerCamelCase_ 		=     self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_sequence_classification(*UpperCAmelCase      )




				def 					UpperCAmelCase__	(							self      ):
							lowerCamelCase_ 		=     self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_token_classification(*UpperCAmelCase      )





				@slow
				def 					UpperCAmelCase__	(							self      ):
							lowerCamelCase_ 		=     TFDebertaModel.from_pretrained('''kamalkraj/deberta-base'''      )
							self.assertIsNotNone(UpperCAmelCase      )




@require_tf
class    __lowerCamelCase     (   unittest.TestCase ):




				@unittest.skip(reason='''Model not available yet'''      )
				def 					UpperCAmelCase__	(							self      ):
							pass





				@slow
				def 					UpperCAmelCase__	(							self      ):
							lowerCamelCase_ 		=     TFDebertaModel.from_pretrained('''kamalkraj/deberta-base'''      )
							lowerCamelCase_ 		=     tf.constant([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]]      )
							lowerCamelCase_ 		=     tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]      )
							lowerCamelCase_ 		=     model(UpperCAmelCase       ,	attention_mask=UpperCAmelCase      )[0]

							lowerCamelCase_ 		=     tf.constant(
							    [
							        [
							            [-0.5_9_8_5_5_8_9_6, -0.8_0_5_5_2_5_6_6, -0.8_4_6_2_1_3_5],
							            [1.4_4_8_4_0_2_5, -0.9_3_4_8_3_7_9_4, -0.8_0_5_9_3_0_8_5],
							            [0.3_1_2_2_7_4_1, 0.0_0_3_1_6_0_5_9, -1.4_1_3_1_3_7_7],
							        ]
							    ]      )
							tf.debugging.assert_near(output[:, 1:4, 1:4]       ,	UpperCAmelCase       ,	atol=1e-4      )





"""simple docstring"""


from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


A_						       =				logging.get_logger(__name__)

A_						       =				{
    """MBZUAI/swiftformer-xs""": """https://huggingface.co/MBZUAI/swiftformer-xs/resolve/main/config.json""",
}




class    __lowerCamelCase     (   lowerCAmelCase ):
				a__:			Any									=						'swiftformer'




				def __init__(							self       ,	UpperCAmelCase=3       ,	UpperCAmelCase=[3, 3, 6, 4]       ,	UpperCAmelCase=[48, 56, 112, 220]       ,	UpperCAmelCase=4       ,	UpperCAmelCase=[True, True, True, True]       ,	UpperCAmelCase="gelu"       ,	UpperCAmelCase=3       ,	UpperCAmelCase=2       ,	UpperCAmelCase=1       ,	UpperCAmelCase=0.0       ,	UpperCAmelCase=True       ,	UpperCAmelCase=1e-5       ,	UpperCAmelCase=1e-5       ,	**UpperCAmelCase       ,	):
							super().__init__(**UpperCAmelCase      )
							lowerCamelCase_ 		=     num_channels
							lowerCamelCase_ 		=     depths
							lowerCamelCase_ 		=     embed_dims
							lowerCamelCase_ 		=     mlp_ratio
							lowerCamelCase_ 		=     downsamples
							lowerCamelCase_ 		=     hidden_act
							lowerCamelCase_ 		=     down_patch_size
							lowerCamelCase_ 		=     down_stride
							lowerCamelCase_ 		=     down_pad
							lowerCamelCase_ 		=     drop_path_rate
							lowerCamelCase_ 		=     use_layer_scale
							lowerCamelCase_ 		=     layer_scale_init_value
							lowerCamelCase_ 		=     batch_norm_eps




class    __lowerCamelCase     (   lowerCAmelCase ):
				a__:			str									=						version.parse('1.11' )




				@property
				def 					UpperCAmelCase__	(							self      ):
							return OrderedDict(
							    [
							        ('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''}),
							    ]      )





				@property
				def 					UpperCAmelCase__	(							self      ):
							return 1e-4



