


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    lowercase__  :





							'''simple docstring'''


							def __init__(   self   , __snake_case   , __snake_case=13   , __snake_case=7   , __snake_case=True   , __snake_case=True   , __snake_case=True   , __snake_case=True   , __snake_case=99   , __snake_case=32   , __snake_case=2   , __snake_case=4   , __snake_case=37   , __snake_case="gelu"   , __snake_case=0.1   , __snake_case=0.1   , __snake_case=512   , __snake_case=16   , __snake_case=2   , __snake_case=0.02   , __snake_case=3   , __snake_case=4   , __snake_case=None   , ):
											_SCREAMING_SNAKE_CASE			:	Union[str, Any]							=				parent
											_SCREAMING_SNAKE_CASE			:	List[Any]							=				13
											_SCREAMING_SNAKE_CASE			:	List[str]							=				7
											_SCREAMING_SNAKE_CASE			:	List[Any]							=				True
											_SCREAMING_SNAKE_CASE			:	int							=				True
											_SCREAMING_SNAKE_CASE			:	int							=				True
											_SCREAMING_SNAKE_CASE			:	Any							=				True
											_SCREAMING_SNAKE_CASE			:	List[str]							=				99
											_SCREAMING_SNAKE_CASE			:	List[Any]							=				32
											_SCREAMING_SNAKE_CASE			:	List[str]							=				2
											_SCREAMING_SNAKE_CASE			:	Union[str, Any]							=				4
											_SCREAMING_SNAKE_CASE			:	str							=				37
											_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				"""gelu"""
											_SCREAMING_SNAKE_CASE			:	List[Any]							=				0.1
											_SCREAMING_SNAKE_CASE			:	Dict							=				0.1
											_SCREAMING_SNAKE_CASE			:	List[Any]							=				512
											_SCREAMING_SNAKE_CASE			:	Union[str, Any]							=				16
											_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				False
											_SCREAMING_SNAKE_CASE			:	List[Any]							=				-1
											_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				True
											_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				2
											_SCREAMING_SNAKE_CASE			:	Union[str, Any]							=				0.02
											_SCREAMING_SNAKE_CASE			:	Dict							=				3
											_SCREAMING_SNAKE_CASE			:	Optional[int]							=				4
											_SCREAMING_SNAKE_CASE			:	str							=				None






							def UpperCAmelCase_     (   self  ):
											_SCREAMING_SNAKE_CASE			:	List[str]							=				ids_tensor([self.batch_size, self.seq_length]   , self.vocab_size  )

											_SCREAMING_SNAKE_CASE			:	Tuple							=				None
											if self.use_input_mask:
															_SCREAMING_SNAKE_CASE			:	List[str]							=				random_attention_mask([self.batch_size, self.seq_length]  )

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

											_SCREAMING_SNAKE_CASE			:	Dict							=				None
											_SCREAMING_SNAKE_CASE			:	int							=				None
											_SCREAMING_SNAKE_CASE			:	str							=				None
											if self.use_labels:
															_SCREAMING_SNAKE_CASE			:	Tuple							=				ids_tensor([self.batch_size]   , self.type_sequence_label_size  )
															_SCREAMING_SNAKE_CASE			:	List[str]							=				ids_tensor([self.batch_size, self.seq_length]   , self.num_labels  )

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

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






							def UpperCAmelCase_     (   self   , __snake_case   , __snake_case   , __snake_case   , __snake_case   , __snake_case   , __snake_case   , __snake_case  ):
											_SCREAMING_SNAKE_CASE			:	int							=				TFDebertaModel(config=__snake_case  )
											_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}

											_SCREAMING_SNAKE_CASE			:	Optional[int]							=				[input_ids, input_mask]
											_SCREAMING_SNAKE_CASE			:	List[Any]							=				model(__snake_case  )

											_SCREAMING_SNAKE_CASE			:	int							=				model(__snake_case  )

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






							def UpperCAmelCase_     (   self   , __snake_case   , __snake_case   , __snake_case   , __snake_case   , __snake_case   , __snake_case   , __snake_case  ):
											_SCREAMING_SNAKE_CASE			:	List[str]							=				TFDebertaForMaskedLM(config=__snake_case  )
											_SCREAMING_SNAKE_CASE			:	Dict							=				{
											    """input_ids""": input_ids,
											    """attention_mask""": input_mask,
											    """token_type_ids""": token_type_ids,
											}
											_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				model(__snake_case  )
											self.parent.assertEqual(result.logits.shape   , (self.batch_size, self.seq_length, self.vocab_size)  )






							def UpperCAmelCase_     (   self   , __snake_case   , __snake_case   , __snake_case   , __snake_case   , __snake_case   , __snake_case   , __snake_case  ):
											_SCREAMING_SNAKE_CASE			:	Any							=				self.num_labels
											_SCREAMING_SNAKE_CASE			:	Any							=				TFDebertaForSequenceClassification(config=__snake_case  )
											_SCREAMING_SNAKE_CASE			:	str							=				{
											    """input_ids""": input_ids,
											    """attention_mask""": input_mask,
											    """token_type_ids""": token_type_ids,
											}

											_SCREAMING_SNAKE_CASE			:	Any							=				model(__snake_case  )
											self.parent.assertEqual(result.logits.shape   , (self.batch_size, self.num_labels)  )






							def UpperCAmelCase_     (   self   , __snake_case   , __snake_case   , __snake_case   , __snake_case   , __snake_case   , __snake_case   , __snake_case  ):
											_SCREAMING_SNAKE_CASE			:	Optional[int]							=				self.num_labels
											_SCREAMING_SNAKE_CASE			:	str							=				TFDebertaForTokenClassification(config=__snake_case  )
											_SCREAMING_SNAKE_CASE			:	List[Any]							=				{
											    """input_ids""": input_ids,
											    """attention_mask""": input_mask,
											    """token_type_ids""": token_type_ids,
											}
											_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				model(__snake_case  )
											self.parent.assertEqual(result.logits.shape   , (self.batch_size, self.seq_length, self.num_labels)  )






							def UpperCAmelCase_     (   self   , __snake_case   , __snake_case   , __snake_case   , __snake_case   , __snake_case   , __snake_case   , __snake_case  ):
											_SCREAMING_SNAKE_CASE			:	Optional[int]							=				TFDebertaForQuestionAnswering(config=__snake_case  )
											_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				{
											    """input_ids""": input_ids,
											    """attention_mask""": input_mask,
											    """token_type_ids""": token_type_ids,
											}

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





@require_tf
class    lowercase__  (						_a					,					_a					,					unittest.TestCase ):





							'''simple docstring'''


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

							A_							:				Union[str, Any]				     =  False
							A_							:				str				     =  False






							def UpperCAmelCase_     (   self  ):
											_SCREAMING_SNAKE_CASE			:	Union[str, Any]							=				TFDebertaModelTester(self  )
											_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				ConfigTester(self   , config_class=__snake_case   , hidden_size=37  )






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






							def UpperCAmelCase_     (   self  ):
											_SCREAMING_SNAKE_CASE			:	List[Any]							=				self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*__snake_case  )






							def UpperCAmelCase_     (   self  ):
											_SCREAMING_SNAKE_CASE			:	Union[str, Any]							=				self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_masked_lm(*__snake_case  )






							def UpperCAmelCase_     (   self  ):
											_SCREAMING_SNAKE_CASE			:	List[str]							=				self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_question_answering(*__snake_case  )






							def UpperCAmelCase_     (   self  ):
											_SCREAMING_SNAKE_CASE			:	Tuple							=				self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_sequence_classification(*__snake_case  )






							def UpperCAmelCase_     (   self  ):
											_SCREAMING_SNAKE_CASE			:	Tuple							=				self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_token_classification(*__snake_case  )






							@slow
							def UpperCAmelCase_     (   self  ):
											_SCREAMING_SNAKE_CASE			:	Any							=				TFDebertaModel.from_pretrained("""kamalkraj/deberta-base"""  )
											self.assertIsNotNone(__snake_case  )





@require_tf
class    lowercase__  (						unittest.TestCase ):





							'''simple docstring'''


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






							@slow
							def UpperCAmelCase_     (   self  ):
											_SCREAMING_SNAKE_CASE			:	List[Any]							=				TFDebertaModel.from_pretrained("""kamalkraj/deberta-base"""  )
											_SCREAMING_SNAKE_CASE			:	List[str]							=				tf.constant([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]]  )
											_SCREAMING_SNAKE_CASE			:	str							=				tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]  )
											_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				model(__snake_case   , attention_mask=__snake_case  )[0]

											_SCREAMING_SNAKE_CASE			:	Union[str, Any]							=				tf.constant(
											    [
											        [
											            [-0.59855896, -0.80552566, -0.8462135],
											            [1.4484025, -0.93483794, -0.80593085],
											            [0.3122741, 0.00316059, -1.4131377],
											        ]
											    ]  )
											tf.debugging.assert_near(output[:, 1:4, 1:4]   , __snake_case   , atol=1e-4  )








'''simple docstring'''


def       snake_case_       (  SCREAMING_SNAKE_CASE__							,				SCREAMING_SNAKE_CASE__					):







				"""simple docstring"""





				if len(str(SCREAMING_SNAKE_CASE__					)					) == 1 or len(str(SCREAMING_SNAKE_CASE__					)					) == 1:
								return a * b

				_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				max(len(str(SCREAMING_SNAKE_CASE__					)					)							,				len(str(SCREAMING_SNAKE_CASE__					)					)					)
				_SCREAMING_SNAKE_CASE			:	Tuple							=				ma // 2

				_SCREAMING_SNAKE_CASE		,	_SCREAMING_SNAKE_CASE			:	Optional[int]							=				divmod(SCREAMING_SNAKE_CASE__							,				10**ma					)
				_SCREAMING_SNAKE_CASE		,	_SCREAMING_SNAKE_CASE			:	Optional[int]							=				divmod(SCREAMING_SNAKE_CASE__							,				10**ma					)

				_SCREAMING_SNAKE_CASE			:	Dict							=				karatsuba(SCREAMING_SNAKE_CASE__							,				SCREAMING_SNAKE_CASE__					)
				_SCREAMING_SNAKE_CASE			:	List[Any]							=				karatsuba((aa + aa)							,				(ba + ba)					)
				_SCREAMING_SNAKE_CASE			:	List[Any]							=				karatsuba(SCREAMING_SNAKE_CASE__							,				SCREAMING_SNAKE_CASE__					)

				return (z * 10 ** (2 * ma)) + ((y - z - x) * 10 ** (ma)) + (x)







def       snake_case_       (  ):







				"""simple docstring"""





				print(karatsuba(1_5463							,				2_3489					)					)


if __name__ == "__main__":
				main()




