



'''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			,							__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.02			,							__UpperCAmelCase=3			,							__UpperCAmelCase=4			,							__UpperCAmelCase=None			,							)							->  Any:

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





		def 				__A							(  self					)							->  List[Any]:

					'''simple docstring'''
					__UpperCAmelCase :   List[Any]    					=  ids_tensor([self.batch_size, self.seq_length]			,							self.vocab_size					)

					__UpperCAmelCase :   str    					=  None
					if self.use_input_mask:
								__UpperCAmelCase :   int    					=  random_attention_mask([self.batch_size, self.seq_length]					)

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

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

					__UpperCAmelCase :   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=__UpperCAmelCase			,							)

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





		def 				__A							(  self			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase					)							->  Tuple:

					'''simple docstring'''
					__UpperCAmelCase :   List[Any]    					=  TFDebertaModel(config=__UpperCAmelCase					)
					__UpperCAmelCase :   Optional[Any]    					=  {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}

					__UpperCAmelCase :   List[str]    					=  [input_ids, input_mask]
					__UpperCAmelCase :   Union[str, Any]    					=  model(__UpperCAmelCase					)

					__UpperCAmelCase :   str    					=  model(__UpperCAmelCase					)

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





		def 				__A							(  self			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase					)							->  Union[str, Any]:

					'''simple docstring'''
					__UpperCAmelCase :   Dict    					=  TFDebertaForMaskedLM(config=__UpperCAmelCase					)
					__UpperCAmelCase :   Dict    					=  {
					    """input_ids""": input_ids,
					    """attention_mask""": input_mask,
					    """token_type_ids""": token_type_ids,
					}
					__UpperCAmelCase :   Tuple    					=  model(__UpperCAmelCase					)
					self.parent.assertEqual(result.logits.shape			,							(self.batch_size, self.seq_length, self.vocab_size)					)





		def 				__A							(  self			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase					)							->  Any:

					'''simple docstring'''
					__UpperCAmelCase :   List[Any]    					=  self.num_labels
					__UpperCAmelCase :   int    					=  TFDebertaForSequenceClassification(config=__UpperCAmelCase					)
					__UpperCAmelCase :   Tuple    					=  {
					    """input_ids""": input_ids,
					    """attention_mask""": input_mask,
					    """token_type_ids""": token_type_ids,
					}

					__UpperCAmelCase :   List[str]    					=  model(__UpperCAmelCase					)
					self.parent.assertEqual(result.logits.shape			,							(self.batch_size, self.num_labels)					)





		def 				__A							(  self			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase					)							->  int:

					'''simple docstring'''
					__UpperCAmelCase :   Optional[int]    					=  self.num_labels
					__UpperCAmelCase :   Optional[int]    					=  TFDebertaForTokenClassification(config=__UpperCAmelCase					)
					__UpperCAmelCase :   Tuple    					=  {
					    """input_ids""": input_ids,
					    """attention_mask""": input_mask,
					    """token_type_ids""": token_type_ids,
					}
					__UpperCAmelCase :   Dict    					=  model(__UpperCAmelCase					)
					self.parent.assertEqual(result.logits.shape			,							(self.batch_size, self.seq_length, self.num_labels)					)





		def 				__A							(  self			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase					)							->  Dict:

					'''simple docstring'''
					__UpperCAmelCase :   Union[str, Any]    					=  TFDebertaForQuestionAnswering(config=__UpperCAmelCase					)
					__UpperCAmelCase :   Optional[int]    					=  {
					    """input_ids""": input_ids,
					    """attention_mask""": input_mask,
					    """token_type_ids""": token_type_ids,
					}

					__UpperCAmelCase :   List[str]    					=  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 				__A							(  self					)							->  Any:

					'''simple docstring'''
					__UpperCAmelCase :   Any    					=  self.prepare_config_and_inputs()
					(
					    (
					    __UpperCAmelCase
					)					,	(
					    __UpperCAmelCase
					)					,	(
					    __UpperCAmelCase
					)					,	(
					    __UpperCAmelCase
					)					,	(
					    __UpperCAmelCase
					)					,	(
					    __UpperCAmelCase
					)					,	(
					    __UpperCAmelCase
					)					,	
					) :   Tuple    					=  config_and_inputs
					__UpperCAmelCase :   Dict    					=  {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
					return config, inputs_dict



@require_tf
class _A	(     __SCREAMING_SNAKE_CASE						,					__SCREAMING_SNAKE_CASE						,					unittest.TestCase     ):
		_SCREAMING_SNAKE_CASE       :     Union[str, Any]       =      (
		    (
		        TFDebertaModel,
		        TFDebertaForMaskedLM,
		        TFDebertaForQuestionAnswering,
		        TFDebertaForSequenceClassification,
		        TFDebertaForTokenClassification,
		    )
		    if is_tf_available()
		    else ()
		)
		_SCREAMING_SNAKE_CASE       :     Union[str, Any]       =      (
		    {
		        "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       :     Optional[Any]       =      False
		_SCREAMING_SNAKE_CASE       :     Tuple       =      False





		def 				__A							(  self					)							->  Dict:

					'''simple docstring'''
					__UpperCAmelCase :   Optional[int]    					=  TFDebertaModelTester(self					)
					__UpperCAmelCase :   List[Any]    					=  ConfigTester(self			,							config_class=__UpperCAmelCase			,							hidden_size=37					)





		def 				__A							(  self					)							->  Dict:

					'''simple docstring'''
					self.config_tester.run_common_tests()





		def 				__A							(  self					)							->  List[Any]:

					'''simple docstring'''
					__UpperCAmelCase :   Dict    					=  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*__UpperCAmelCase					)





		def 				__A							(  self					)							->  Optional[int]:

					'''simple docstring'''
					__UpperCAmelCase :   Tuple    					=  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_masked_lm(*__UpperCAmelCase					)





		def 				__A							(  self					)							->  Union[str, Any]:

					'''simple docstring'''
					__UpperCAmelCase :   Dict    					=  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_question_answering(*__UpperCAmelCase					)





		def 				__A							(  self					)							->  Optional[Any]:

					'''simple docstring'''
					__UpperCAmelCase :   List[Any]    					=  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_sequence_classification(*__UpperCAmelCase					)





		def 				__A							(  self					)							->  Any:

					'''simple docstring'''
					__UpperCAmelCase :   str    					=  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_token_classification(*__UpperCAmelCase					)





		@slow
		def 				__A							(  self					)							->  Any:

					'''simple docstring'''
					__UpperCAmelCase :   str    					=  TFDebertaModel.from_pretrained("""kamalkraj/deberta-base"""					)
					self.assertIsNotNone(__UpperCAmelCase					)



@require_tf
class _A	(     unittest.TestCase     ):





		@unittest.skip(reason="""Model not available yet"""					)
		def 				__A							(  self					)							->  Union[str, Any]:

					'''simple docstring'''
					pass





		@slow
		def 				__A							(  self					)							->  str:

					'''simple docstring'''
					__UpperCAmelCase :   str    					=  TFDebertaModel.from_pretrained("""kamalkraj/deberta-base"""					)
					__UpperCAmelCase :   Dict    					=  tf.constant([[0, 31_414, 232, 328, 740, 1_140, 12_695, 69, 46_078, 1_588, 2]]					)
					__UpperCAmelCase :   Optional[Any]    					=  tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]					)
					__UpperCAmelCase :   int    					=  model(__UpperCAmelCase			,							attention_mask=__UpperCAmelCase					)[0]

					__UpperCAmelCase :   List[Any]    					=  tf.constant(
					    [
					        [
					            [-0.5985_5896, -0.8055_2566, -0.846_2135],
					            [1.448_4025, -0.9348_3794, -0.8059_3085],
					            [0.312_2741, 0.0031_6059, -1.413_1377],
					        ]
					    ]					)
					tf.debugging.assert_near(output[:, 1:4, 1:4]			,							__UpperCAmelCase			,							atol=1E-4					)









'''simple docstring'''
from .hash_table import HashTable



class _A	(     __SCREAMING_SNAKE_CASE     ):





		def __init__(  self			,							*__UpperCAmelCase			,							**__UpperCAmelCase					)							->  List[Any]:

					'''simple docstring'''
					super().__init__(*__UpperCAmelCase			,							**__UpperCAmelCase					)





		def 				__A							(  self			,							__UpperCAmelCase			,							__UpperCAmelCase=None					)							->  str:

					'''simple docstring'''
					__UpperCAmelCase :   List[str]    					=  1
					__UpperCAmelCase :   Optional[Any]    					=  self.hash_function(key + i * i					)

					while self.values[new_key] is not None and self.values[new_key] != key:
								i += 1
								__UpperCAmelCase :   str    					=  (
								    self.hash_function(key + i * i					)
								    if not self.balanced_factor() >= self.lim_charge
								    else None
								)

								if new_key is None:
											break

					return new_key




