
"""simple docstring"""



from __future__ import annotations

import unittest

from transformers import DebertaVaConfig, 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 (
						    TFDebertaVaForMaskedLM,
						    TFDebertaVaForQuestionAnswering,
						    TFDebertaVaForSequenceClassification,
						    TFDebertaVaForTokenClassification,
						    TFDebertaVaModel,
						)







class        lowercase__      :


			def __init__(				self					:  Union[str, Any]       ,	snake_case__					:  List[Any]       ,	snake_case__					:  List[str]=13       ,	snake_case__					:  int=7       ,	snake_case__					:  int=True       ,	snake_case__					:  str=True       ,	snake_case__					:  Any=True       ,	snake_case__					:  Union[str, Any]=True       ,	snake_case__					:  Union[str, Any]=99       ,	snake_case__					:  List[Any]=32       ,	snake_case__					:  int=2       ,	snake_case__					:  Optional[int]=4       ,	snake_case__					:  int=37       ,	snake_case__					:  List[str]="gelu"       ,	snake_case__					:  Tuple=0.1       ,	snake_case__					:  Optional[Any]=0.1       ,	snake_case__					:  Union[str, Any]=512       ,	snake_case__					:  str=16       ,	snake_case__					:  int=2       ,	snake_case__					:  str=0.02       ,	snake_case__					:  List[Any]=False       ,	snake_case__					:  List[str]=True       ,	snake_case__					:  List[str]="None"       ,	snake_case__					:  Optional[int]=3       ,	snake_case__					:  Tuple=4       ,	snake_case__					:  Tuple=None       ,	):
										lowerCamelCase_	:							Dict									=parent
										lowerCamelCase_	:							str									=batch_size
										lowerCamelCase_	:							Any									=seq_length
										lowerCamelCase_	:							Dict									=is_training
										lowerCamelCase_	:							Dict									=use_input_mask
										lowerCamelCase_	:							Dict									=use_token_type_ids
										lowerCamelCase_	:							Tuple									=use_labels
										lowerCamelCase_	:							Tuple									=vocab_size
										lowerCamelCase_	:							Union[str, Any]									=hidden_size
										lowerCamelCase_	:							Optional[Any]									=num_hidden_layers
										lowerCamelCase_	:							List[Any]									=num_attention_heads
										lowerCamelCase_	:							int									=intermediate_size
										lowerCamelCase_	:							Union[str, Any]									=hidden_act
										lowerCamelCase_	:							Optional[int]									=hidden_dropout_prob
										lowerCamelCase_	:							str									=attention_probs_dropout_prob
										lowerCamelCase_	:							List[str]									=max_position_embeddings
										lowerCamelCase_	:							Optional[int]									=type_vocab_size
										lowerCamelCase_	:							List[str]									=type_sequence_label_size
										lowerCamelCase_	:							Union[str, Any]									=initializer_range
										lowerCamelCase_	:							Optional[int]									=num_labels
										lowerCamelCase_	:							int									=num_choices
										lowerCamelCase_	:							Any									=relative_attention
										lowerCamelCase_	:							Any									=position_biased_input
										lowerCamelCase_	:							Any									=pos_att_type
										lowerCamelCase_	:							List[Any]									=scope


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

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

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

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

										lowerCamelCase_	:							int									=DebertaVaConfig(
										    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       ,	position_biased_input=self.position_biased_input       ,	initializer_range=self.initializer_range       ,	return_dict=_snake_case       ,	)

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


			def      UpperCAmelCase__						(				self					:  Optional[int]       ,	snake_case__					:  str       ,	snake_case__					:  Optional[Any]       ,	snake_case__					:  str       ,	snake_case__					:  Any       ,	snake_case__					:  Tuple       ,	snake_case__					:  List[str]       ,	snake_case__					:  str ):
										lowerCamelCase_	:							Optional[Any]									=TFDebertaVaModel(config=_snake_case )
										lowerCamelCase_	:							Dict									={"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

										lowerCamelCase_	:							Any									=[input_ids, input_mask]
										lowerCamelCase_	:							Dict									=model(_snake_case )

										lowerCamelCase_	:							Union[str, Any]									=model(_snake_case )

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


			def      UpperCAmelCase__						(				self					:  Union[str, Any]       ,	snake_case__					:  Union[str, Any]       ,	snake_case__					:  List[Any]       ,	snake_case__					:  Tuple       ,	snake_case__					:  Dict       ,	snake_case__					:  int       ,	snake_case__					:  Dict       ,	snake_case__					:  str ):
										lowerCamelCase_	:							Any									=TFDebertaVaForMaskedLM(config=_snake_case )
										lowerCamelCase_	:							str									={
										    "input_ids": input_ids,
										    "attention_mask": input_mask,
										    "token_type_ids": token_type_ids,
										}
										lowerCamelCase_	:							str									=model(_snake_case )
										self.parent.assertEqual(result.logits.shape       ,	(self.batch_size, self.seq_length, self.vocab_size) )


			def      UpperCAmelCase__						(				self					:  int       ,	snake_case__					:  Dict       ,	snake_case__					:  Dict       ,	snake_case__					:  str       ,	snake_case__					:  List[Any]       ,	snake_case__					:  int       ,	snake_case__					:  Tuple       ,	snake_case__					:  Tuple ):
										lowerCamelCase_	:							Union[str, Any]									=self.num_labels
										lowerCamelCase_	:							str									=TFDebertaVaForSequenceClassification(config=_snake_case )
										lowerCamelCase_	:							str									={
										    "input_ids": input_ids,
										    "attention_mask": input_mask,
										    "token_type_ids": token_type_ids,
										}

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


			def      UpperCAmelCase__						(				self					:  Dict       ,	snake_case__					:  List[str]       ,	snake_case__					:  List[str]       ,	snake_case__					:  Any       ,	snake_case__					:  List[str]       ,	snake_case__					:  List[Any]       ,	snake_case__					:  List[Any]       ,	snake_case__					:  Optional[int] ):
										lowerCamelCase_	:							Optional[int]									=self.num_labels
										lowerCamelCase_	:							Dict									=TFDebertaVaForTokenClassification(config=_snake_case )
										lowerCamelCase_	:							Union[str, Any]									={
										    "input_ids": input_ids,
										    "attention_mask": input_mask,
										    "token_type_ids": token_type_ids,
										}
										lowerCamelCase_	:							Tuple									=model(_snake_case )
										self.parent.assertEqual(result.logits.shape       ,	(self.batch_size, self.seq_length, self.num_labels) )


			def      UpperCAmelCase__						(				self					:  Union[str, Any]       ,	snake_case__					:  List[Any]       ,	snake_case__					:  List[Any]       ,	snake_case__					:  str       ,	snake_case__					:  List[str]       ,	snake_case__					:  Optional[int]       ,	snake_case__					:  List[str]       ,	snake_case__					:  str ):
										lowerCamelCase_	:							int									=TFDebertaVaForQuestionAnswering(config=_snake_case )
										lowerCamelCase_	:							List[Any]									={
										    "input_ids": input_ids,
										    "attention_mask": input_mask,
										    "token_type_ids": token_type_ids,
										}

										lowerCamelCase_	:							Dict									=model(_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      UpperCAmelCase__						(				self					:  Any ):
										lowerCamelCase_	:							Dict									=self.prepare_config_and_inputs()
										(
										    (
										    lowerCamelCase_					
										)							,						(
										    lowerCamelCase_					
										)							,						(
										    lowerCamelCase_					
										)							,						(
										    lowerCamelCase_					
										)							,						(
										    lowerCamelCase_					
										)							,						(
										    lowerCamelCase_					
										)							,						(
										    lowerCamelCase_					
										)							,											
										)	:							List[str]									=config_and_inputs
										lowerCamelCase_	:							Dict									={"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       ):
			_UpperCAmelCase		:List[Any]             =			(
			    (
			        TFDebertaVaModel,
			        TFDebertaVaForMaskedLM,
			        TFDebertaVaForQuestionAnswering,
			        TFDebertaVaForSequenceClassification,
			        TFDebertaVaForTokenClassification,
			    )
			    if is_tf_available()
			    else ()
			)
			_UpperCAmelCase		:int             =			(
			    {
			        "feature-extraction": TFDebertaVaModel,
			        "fill-mask": TFDebertaVaForMaskedLM,
			        "question-answering": TFDebertaVaForQuestionAnswering,
			        "text-classification": TFDebertaVaForSequenceClassification,
			        "token-classification": TFDebertaVaForTokenClassification,
			        "zero-shot": TFDebertaVaForSequenceClassification,
			    }
			    if is_tf_available()
			    else {}
			)

			_UpperCAmelCase		:Union[str, Any]             =			False
			_UpperCAmelCase		:List[Any]             =			False


			def      UpperCAmelCase__						(				self					:  Optional[Any] ):
										lowerCamelCase_	:							Optional[Any]									=TFDebertaVaModelTester(self )
										lowerCamelCase_	:							List[str]									=ConfigTester(self       ,	config_class=_snake_case       ,	hidden_size=37 )


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


			def      UpperCAmelCase__						(				self					:  Optional[Any] ):
										lowerCamelCase_	:							Optional[int]									=self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*_snake_case )


			def      UpperCAmelCase__						(				self					:  Dict ):
										lowerCamelCase_	:							Optional[int]									=self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_masked_lm(*_snake_case )


			def      UpperCAmelCase__						(				self					:  Optional[int] ):
										lowerCamelCase_	:							Tuple									=self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_question_answering(*_snake_case )


			def      UpperCAmelCase__						(				self					:  Optional[int] ):
										lowerCamelCase_	:							Tuple									=self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_sequence_classification(*_snake_case )


			def      UpperCAmelCase__						(				self					:  Union[str, Any] ):
										lowerCamelCase_	:							int									=self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_token_classification(*_snake_case )


			@slow
			def      UpperCAmelCase__						(				self					:  Optional[int] ):
										lowerCamelCase_	:							int									=TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge" )
										self.assertIsNotNone(_snake_case )







@require_tf
class        lowercase__      (							unittest.TestCase       ):


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


			@slow
			def      UpperCAmelCase__						(				self					:  List[Any] ):
										lowerCamelCase_	:							int									=TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge" )
										lowerCamelCase_	:							List[str]									=tf.constant([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]] )
										lowerCamelCase_	:							List[str]									=tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]] )
										lowerCamelCase_	:							Optional[Any]									=model(_snake_case       ,	attention_mask=_snake_case )[0]

										lowerCamelCase_	:							Tuple									=tf.constant(
										    [[[0.2_356, 0.1_948, 0.0_369], [-0.1_063, 0.3_586, -0.5_152], [-0.6_399, -0.0_259, -0.2_525]]] )
										tf.debugging.assert_near(output[:, 1:4, 1:4]       ,	_snake_case       ,	atol=1E-4 )











"""simple docstring"""



def 			_snake_case    (					lowerCamelCase__     :   Optional[Any]  )    ->     Optional[int]:
							if not head:
														return True
							# split the list to two parts
							lowerCamelCase_							,						lowerCamelCase_	:							Union[str, Any]									=head.next, head
							while fast and fast.next:
														lowerCamelCase_	:							Optional[Any]									=fast.next.next
														lowerCamelCase_	:							str									=slow.next
							lowerCamelCase_	:							Tuple									=slow.next
							lowerCamelCase_	:							Any									=None  # Don't forget here! But forget still works!
							# reverse the second part
							lowerCamelCase_	:							List[str]									=None
							while second:
														lowerCamelCase_	:							Any									=second.next
														lowerCamelCase_	:							Union[str, Any]									=node
														lowerCamelCase_	:							Union[str, Any]									=second
														lowerCamelCase_	:							Optional[Any]									=nxt
							# compare two parts
							# second part has the same or one less node
							while node:
														if node.val != head.val:
																					return False
														lowerCamelCase_	:							List[str]									=node.next
														lowerCamelCase_	:							Optional[Any]									=head.next
							return True

def 			_snake_case    (					lowerCamelCase__     :   str  )    ->     Optional[int]:
							if not head or not head.next:
														return True

							# 1. Get the midpoint (slow)
							lowerCamelCase_	:							List[str]									=head
							while fast and fast.next:
														lowerCamelCase_							,						lowerCamelCase_	:							Union[str, Any]									=fast.next.next, slow.next

							# 2. Push the second half into the stack
							lowerCamelCase_	:							List[Any]									=[slow.val]
							while slow.next:
														lowerCamelCase_	:							List[Any]									=slow.next
														stack.append(slow.val  )

							# 3. Comparison
							while stack:
														if stack.pop() != cur.val:
																					return False
														lowerCamelCase_	:							Union[str, Any]									=cur.next

							return True

def 			_snake_case    (					lowerCamelCase__     :   Dict  )    ->     Optional[Any]:
							if not head or not head.next:
														return True
							lowerCamelCase_	:							Union[str, Any]									={}
							lowerCamelCase_	:							List[Any]									=0
							while head:
														if head.val in d:
																					d[head.val].append(lowerCamelCase__  )
														else:
																					lowerCamelCase_	:							List[str]									=[pos]
														lowerCamelCase_	:							Optional[int]									=head.next
														pos += 1
							lowerCamelCase_	:							Union[str, Any]									=pos - 1
							lowerCamelCase_	:							Optional[int]									=0
							for v in d.values():
														if len(lowerCamelCase__  ) % 2 != 0:
																					middle += 1
														else:
																					lowerCamelCase_	:							Optional[Any]									=0
																					for i in range(0    ,						len(lowerCamelCase__  )  ):
																												if v[i] + v[len(lowerCamelCase__  ) - 1 - step] != checksum:
																																			return False
																												step += 1
														if middle > 1:
																					return False
							return True



