






'''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    _snake_case   :

					"""simple docstring"""





					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   , )      ->	Tuple:
										a_									=   parent
										a_									=   13
										a_									=   7
										a_									=   True
										a_									=   True
										a_									=   True
										a_									=   True
										a_									=   99
										a_									=   32
										a_									=   2
										a_									=   4
										a_									=   37
										a_									=   'gelu'
										a_									=   0.1
										a_									=   0.1
										a_									=   512
										a_									=   16
										a_									=   False
										a_									=   -1
										a_									=   True
										a_									=   2
										a_									=   0.0_2
										a_									=   3
										a_									=   4
										a_									=   None




					def  __SCREAMING_SNAKE_CASE (     self     )      ->	str:
										a_									=   ids_tensor([self.batch_size, self.seq_length]   , self.vocab_size     )

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

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

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

										a_									=   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  __SCREAMING_SNAKE_CASE (     self   , UpperCAmelCase__   , UpperCAmelCase__   , UpperCAmelCase__   , UpperCAmelCase__   , UpperCAmelCase__   , UpperCAmelCase__   , UpperCAmelCase__     )      ->	Optional[Any]:
										a_									=   TFDebertaModel(config=UpperCAmelCase__     )
										a_									=   {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}

										a_									=   [input_ids, input_mask]
										a_									=   model(UpperCAmelCase__     )

										a_									=   model(UpperCAmelCase__     )

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




					def  __SCREAMING_SNAKE_CASE (     self   , UpperCAmelCase__   , UpperCAmelCase__   , UpperCAmelCase__   , UpperCAmelCase__   , UpperCAmelCase__   , UpperCAmelCase__   , UpperCAmelCase__     )      ->	str:
										a_									=   TFDebertaForMaskedLM(config=UpperCAmelCase__     )
										a_									=   {
										    'input_ids': input_ids,
										    'attention_mask': input_mask,
										    'token_type_ids': token_type_ids,
										}
										a_									=   model(UpperCAmelCase__     )
										self.parent.assertEqual(result.logits.shape   , (self.batch_size, self.seq_length, self.vocab_size)     )




					def  __SCREAMING_SNAKE_CASE (     self   , UpperCAmelCase__   , UpperCAmelCase__   , UpperCAmelCase__   , UpperCAmelCase__   , UpperCAmelCase__   , UpperCAmelCase__   , UpperCAmelCase__     )      ->	Union[str, Any]:
										a_									=   self.num_labels
										a_									=   TFDebertaForSequenceClassification(config=UpperCAmelCase__     )
										a_									=   {
										    'input_ids': input_ids,
										    'attention_mask': input_mask,
										    'token_type_ids': token_type_ids,
										}

										a_									=   model(UpperCAmelCase__     )
										self.parent.assertEqual(result.logits.shape   , (self.batch_size, self.num_labels)     )




					def  __SCREAMING_SNAKE_CASE (     self   , UpperCAmelCase__   , UpperCAmelCase__   , UpperCAmelCase__   , UpperCAmelCase__   , UpperCAmelCase__   , UpperCAmelCase__   , UpperCAmelCase__     )      ->	Optional[int]:
										a_									=   self.num_labels
										a_									=   TFDebertaForTokenClassification(config=UpperCAmelCase__     )
										a_									=   {
										    'input_ids': input_ids,
										    'attention_mask': input_mask,
										    'token_type_ids': token_type_ids,
										}
										a_									=   model(UpperCAmelCase__     )
										self.parent.assertEqual(result.logits.shape   , (self.batch_size, self.seq_length, self.num_labels)     )




					def  __SCREAMING_SNAKE_CASE (     self   , UpperCAmelCase__   , UpperCAmelCase__   , UpperCAmelCase__   , UpperCAmelCase__   , UpperCAmelCase__   , UpperCAmelCase__   , UpperCAmelCase__     )      ->	Union[str, Any]:
										a_									=   TFDebertaForQuestionAnswering(config=UpperCAmelCase__     )
										a_									=   {
										    'input_ids': input_ids,
										    'attention_mask': input_mask,
										    'token_type_ids': token_type_ids,
										}

										a_									=   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  __SCREAMING_SNAKE_CASE (     self     )      ->	List[Any]:
										a_									=   self.prepare_config_and_inputs()
										(
										    (
										    a_					
										)							,					(
										    a_					
										)							,					(
										    a_					
										)							,					(
										    a_					
										)							,					(
										    a_					
										)							,					(
										    a_					
										)							,					(
										    a_					
										)							,										
										)									=   config_and_inputs
										a_									=   {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
										return config, inputs_dict



@require_tf
class    _snake_case   (				snake_case     ,					snake_case     ,					unittest.TestCase					):

					"""simple docstring"""





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

					_UpperCamelCase		 =      False
					_UpperCamelCase		 =      False




					def  __SCREAMING_SNAKE_CASE (     self     )      ->	Any:
										a_									=   TFDebertaModelTester(self     )
										a_									=   ConfigTester(self   , config_class=UpperCAmelCase__   , hidden_size=37     )




					def  __SCREAMING_SNAKE_CASE (     self     )      ->	int:
										self.config_tester.run_common_tests()




					def  __SCREAMING_SNAKE_CASE (     self     )      ->	Optional[int]:
										a_									=   self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*UpperCAmelCase__     )




					def  __SCREAMING_SNAKE_CASE (     self     )      ->	Tuple:
										a_									=   self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_masked_lm(*UpperCAmelCase__     )




					def  __SCREAMING_SNAKE_CASE (     self     )      ->	Dict:
										a_									=   self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_question_answering(*UpperCAmelCase__     )




					def  __SCREAMING_SNAKE_CASE (     self     )      ->	Optional[int]:
										a_									=   self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_sequence_classification(*UpperCAmelCase__     )




					def  __SCREAMING_SNAKE_CASE (     self     )      ->	int:
										a_									=   self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_token_classification(*UpperCAmelCase__     )




					@slow
					def  __SCREAMING_SNAKE_CASE (     self     )      ->	str:
										a_									=   TFDebertaModel.from_pretrained('kamalkraj/deberta-base'     )
										self.assertIsNotNone(UpperCAmelCase__     )



@require_tf
class    _snake_case   (				unittest.TestCase					):

					"""simple docstring"""





					@unittest.skip(reason='Model not available yet'     )
					def  __SCREAMING_SNAKE_CASE (     self     )      ->	Dict:
										pass




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

										a_									=   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'''
class    _snake_case   :

					"""simple docstring"""





					def __init__(     self   , UpperCAmelCase__     )      ->	None:
										a_									=   data
										a_									=   42
										a_									=   42



def 							a	(   _UpperCAmelCase )				->				None:






					"""simple docstring"""







					a_									=   0
					a_									=   x

def 							a	(   _UpperCAmelCase					,  _UpperCAmelCase )				->				None:






					"""simple docstring"""







					a_							,					a_									=   find_set(_UpperCAmelCase ), find_set(_UpperCAmelCase )
					if x == y:
										return

					elif x.rank > y.rank:
										a_									=   x
					else:
										a_									=   y
										if x.rank == y.rank:
															y.rank += 1

def 							a	(   _UpperCAmelCase )				->				Node:






					"""simple docstring"""







					if x != x.parent:
										a_									=   find_set(x.parent )
					return x.parent

def 							a	(   _UpperCAmelCase )				->				set:






					"""simple docstring"""







					a_									=   ({0, 1, 2}, {3, 4, 5})
					for s in sets:
										if node.data in s:
															return s
					a_									=   F'''{node.data} is not in {sets}'''
					raise ValueError(_UpperCAmelCase )

def 							a	(   )				->				None:






					"""simple docstring"""







					a_									=   [Node(_UpperCAmelCase ) for i in range(6 )]
					for v in vertex:
										make_set(_UpperCAmelCase )

					union_set(vertex[0]					,  vertex[1] )
					union_set(vertex[1]					,  vertex[2] )
					union_set(vertex[3]					,  vertex[4] )
					union_set(vertex[3]					,  vertex[5] )

					for nodea in vertex:
										for nodea in vertex:
															if find_python_set(_UpperCAmelCase ).isdisjoint(find_python_set(_UpperCAmelCase ) ):
																				assert find_set(_UpperCAmelCase ) != find_set(_UpperCAmelCase )
															else:
																				assert find_set(_UpperCAmelCase ) == find_set(_UpperCAmelCase )


if __name__ == "__main__":
						test_disjoint_set()

