


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    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE=13    ,					_SCREAMING_SNAKE_CASE=7    ,					_SCREAMING_SNAKE_CASE=True    ,					_SCREAMING_SNAKE_CASE=True    ,					_SCREAMING_SNAKE_CASE=True    ,					_SCREAMING_SNAKE_CASE=True    ,					_SCREAMING_SNAKE_CASE=99    ,					_SCREAMING_SNAKE_CASE=32    ,					_SCREAMING_SNAKE_CASE=2    ,					_SCREAMING_SNAKE_CASE=4    ,					_SCREAMING_SNAKE_CASE=37    ,					_SCREAMING_SNAKE_CASE="gelu"    ,					_SCREAMING_SNAKE_CASE=0.1    ,					_SCREAMING_SNAKE_CASE=0.1    ,					_SCREAMING_SNAKE_CASE=512    ,					_SCREAMING_SNAKE_CASE=16    ,					_SCREAMING_SNAKE_CASE=2    ,					_SCREAMING_SNAKE_CASE=0.02    ,					_SCREAMING_SNAKE_CASE=3    ,					_SCREAMING_SNAKE_CASE=4    ,					_SCREAMING_SNAKE_CASE=None    ,					)				-> Any:




									"""simple docstring"""





									_UpperCAmelCase					=    parent
									_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					=    False
									_UpperCAmelCase					=    -1
									_UpperCAmelCase					=    True
									_UpperCAmelCase					=    2
									_UpperCAmelCase					=    0.02
									_UpperCAmelCase					=    3
									_UpperCAmelCase					=    4
									_UpperCAmelCase					=    None
		def 			UpperCAmelCase__       (    self		)				-> Optional[int]:




									"""simple docstring"""





									_UpperCAmelCase					=    ids_tensor([self.batch_size, self.seq_length]    ,					self.vocab_size		)

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

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

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

									_UpperCAmelCase					=    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=A_    ,					)

									return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
		def 			UpperCAmelCase__       (    self    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE		)				-> Union[str, Any]:




									"""simple docstring"""





									_UpperCAmelCase					=    TFDebertaModel(config=A_		)
									_UpperCAmelCase					=    {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}

									_UpperCAmelCase					=    [input_ids, input_mask]
									_UpperCAmelCase					=    model(A_		)

									_UpperCAmelCase					=    model(A_		)

									self.parent.assertEqual(result.last_hidden_state.shape    ,					(self.batch_size, self.seq_length, self.hidden_size)		)
		def 			UpperCAmelCase__       (    self    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE		)				-> Dict:




									"""simple docstring"""





									_UpperCAmelCase					=    TFDebertaForMaskedLM(config=A_		)
									_UpperCAmelCase					=    {
									    'input_ids': input_ids,
									    'attention_mask': input_mask,
									    'token_type_ids': token_type_ids,
									}
									_UpperCAmelCase					=    model(A_		)
									self.parent.assertEqual(result.logits.shape    ,					(self.batch_size, self.seq_length, self.vocab_size)		)
		def 			UpperCAmelCase__       (    self    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE		)				-> Union[str, Any]:




									"""simple docstring"""





									_UpperCAmelCase					=    self.num_labels
									_UpperCAmelCase					=    TFDebertaForSequenceClassification(config=A_		)
									_UpperCAmelCase					=    {
									    'input_ids': input_ids,
									    'attention_mask': input_mask,
									    'token_type_ids': token_type_ids,
									}

									_UpperCAmelCase					=    model(A_		)
									self.parent.assertEqual(result.logits.shape    ,					(self.batch_size, self.num_labels)		)
		def 			UpperCAmelCase__       (    self    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE		)				-> List[str]:




									"""simple docstring"""





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




									"""simple docstring"""





									_UpperCAmelCase					=    TFDebertaForQuestionAnswering(config=A_		)
									_UpperCAmelCase					=    {
									    'input_ids': input_ids,
									    'attention_mask': input_mask,
									    'token_type_ids': token_type_ids,
									}

									_UpperCAmelCase					=    model(A_		)
									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		)				-> str:




									"""simple docstring"""





									_UpperCAmelCase					=    self.prepare_config_and_inputs()
									(
									    (
									    _UpperCAmelCase
									)	, (
									    _UpperCAmelCase
									)	, (
									    _UpperCAmelCase
									)	, (
									    _UpperCAmelCase
									)	, (
									    _UpperCAmelCase
									)	, (
									    _UpperCAmelCase
									)	, (
									    _UpperCAmelCase
									)	, 
									)					=    config_and_inputs
									_UpperCAmelCase					=    {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
									return config, inputs_dict



@require_tf
class 	__a   (       UpperCAmelCase					,   UpperCAmelCase					,   unittest.TestCase    ):
		_a			:						List[str]    			=			(
		    (
		        TFDebertaModel,
		        TFDebertaForMaskedLM,
		        TFDebertaForQuestionAnswering,
		        TFDebertaForSequenceClassification,
		        TFDebertaForTokenClassification,
		    )
		    if is_tf_available()
		    else ()
		)
		_a			:						Dict    			=			(
		    {
		        'feature-extraction': TFDebertaModel,
		        'fill-mask': TFDebertaForMaskedLM,
		        'question-answering': TFDebertaForQuestionAnswering,
		        'text-classification': TFDebertaForSequenceClassification,
		        'token-classification': TFDebertaForTokenClassification,
		        'zero-shot': TFDebertaForSequenceClassification,
		    }
		    if is_tf_available()
		    else {}
		)

		_a			:						List[Any]    			=			False
		_a			:						Union[str, Any]    			=			False
		def 			UpperCAmelCase__       (    self		)				-> Optional[int]:




									"""simple docstring"""





									_UpperCAmelCase					=    TFDebertaModelTester(self		)
									_UpperCAmelCase					=    ConfigTester(self    ,					config_class=A_    ,					hidden_size=37		)
		def 			UpperCAmelCase__       (    self		)				-> Dict:




									"""simple docstring"""





									self.config_tester.run_common_tests()
		def 			UpperCAmelCase__       (    self		)				-> List[str]:




									"""simple docstring"""





									_UpperCAmelCase					=    self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*A_		)
		def 			UpperCAmelCase__       (    self		)				-> Union[str, Any]:




									"""simple docstring"""





									_UpperCAmelCase					=    self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_masked_lm(*A_		)
		def 			UpperCAmelCase__       (    self		)				-> Union[str, Any]:




									"""simple docstring"""





									_UpperCAmelCase					=    self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_question_answering(*A_		)
		def 			UpperCAmelCase__       (    self		)				-> Tuple:




									"""simple docstring"""





									_UpperCAmelCase					=    self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_sequence_classification(*A_		)
		def 			UpperCAmelCase__       (    self		)				-> Optional[Any]:




									"""simple docstring"""





									_UpperCAmelCase					=    self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_token_classification(*A_		)






		@slow
		def 			UpperCAmelCase__       (    self		)				-> Any:




									"""simple docstring"""





									_UpperCAmelCase					=    TFDebertaModel.from_pretrained('kamalkraj/deberta-base'		)
									self.assertIsNotNone(A_		)



@require_tf
class 	__a   (       unittest.TestCase    ):
		@unittest.skip(reason='Model not available yet'		)
		def 			UpperCAmelCase__       (    self		)				-> Tuple:




									"""simple docstring"""





									pass






		@slow
		def 			UpperCAmelCase__       (    self		)				-> Optional[int]:




									"""simple docstring"""





									_UpperCAmelCase					=    TFDebertaModel.from_pretrained('kamalkraj/deberta-base'		)
									_UpperCAmelCase					=    tf.constant([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]		)
									_UpperCAmelCase					=    tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
									_UpperCAmelCase					=    model(A_    ,					attention_mask=A_		)[0]

									_UpperCAmelCase					=    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]    ,					A_    ,					atol=1e-4		)




import unittest

from transformers import load_tool
from transformers.tools.agent_types import AGENT_TYPE_MAPPING

from .test_tools_common import ToolTesterMixin, output_types

class 	__a   (       unittest.TestCase					,   UpperCAmelCase    ):
		def 			UpperCAmelCase__       (    self		)				-> str:




									"""simple docstring"""





									_UpperCAmelCase					=    load_tool('translation'		)
									self.tool.setup()
									_UpperCAmelCase					=    load_tool('translation'    ,					remote=_SCREAMING_SNAKE_CASE		)
		def 			UpperCAmelCase__       (    self		)				-> Optional[int]:




									"""simple docstring"""





									_UpperCAmelCase					=    self.tool('Hey, what\'s up?'    ,					src_lang='English'    ,					tgt_lang='French'		)
									self.assertEqual(_SCREAMING_SNAKE_CASE    ,					'- Hé, comment ça va?'		)
		def 			UpperCAmelCase__       (    self		)				-> Tuple:




									"""simple docstring"""





									_UpperCAmelCase					=    self.remote_tool('Hey, what\'s up?'    ,					src_lang='English'    ,					tgt_lang='French'		)
									self.assertEqual(_SCREAMING_SNAKE_CASE    ,					'- Hé, comment ça va?'		)
		def 			UpperCAmelCase__       (    self		)				-> Optional[int]:




									"""simple docstring"""





									_UpperCAmelCase					=    self.tool(text='Hey, what\'s up?'    ,					src_lang='English'    ,					tgt_lang='French'		)
									self.assertEqual(_SCREAMING_SNAKE_CASE    ,					'- Hé, comment ça va?'		)
		def 			UpperCAmelCase__       (    self		)				-> int:




									"""simple docstring"""





									_UpperCAmelCase					=    self.remote_tool(text='Hey, what\'s up?'    ,					src_lang='English'    ,					tgt_lang='French'		)
									self.assertEqual(_SCREAMING_SNAKE_CASE    ,					'- Hé, comment ça va?'		)
		def 			UpperCAmelCase__       (    self		)				-> Tuple:




									"""simple docstring"""





									_UpperCAmelCase					=    ['Hey, what\'s up?', 'English', 'Spanish']
									_UpperCAmelCase					=    self.tool(*_SCREAMING_SNAKE_CASE		)

									# There is a single output
									if len(self.tool.outputs		) == 1:
																_UpperCAmelCase					=    [outputs]

									self.assertListEqual(output_types(_SCREAMING_SNAKE_CASE		)    ,					self.tool.outputs		)
		def 			UpperCAmelCase__       (    self		)				-> Union[str, Any]:




									"""simple docstring"""





									_UpperCAmelCase					=    ['Hey, what\'s up?', 'English', 'Spanish']
									_UpperCAmelCase					=    self.tool(*_SCREAMING_SNAKE_CASE		)

									if not isinstance(_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE		):
																_UpperCAmelCase					=    [outputs]

									self.assertEqual(len(_SCREAMING_SNAKE_CASE		)    ,					len(self.tool.outputs		)		)

									for output, output_type in zip(_SCREAMING_SNAKE_CASE    ,					self.tool.outputs		):
																_UpperCAmelCase					=    AGENT_TYPE_MAPPING[output_type]
																self.assertTrue(isinstance(_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE		)		)






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




									"""simple docstring"""





									_UpperCAmelCase					=    ['Hey, what\'s up?', 'English', 'Spanish']

									_UpperCAmelCase					=    []

									for _input, input_type in zip(_SCREAMING_SNAKE_CASE    ,					self.tool.inputs		):
																if isinstance(_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE		):
																							_inputs.append([AGENT_TYPE_MAPPING[_input_type](_input		) for _input_type in input_type]		)
																else:
																							_inputs.append(AGENT_TYPE_MAPPING[input_type](_input		)		)

        # Should not raise an error
									_UpperCAmelCase					=    self.tool(*_SCREAMING_SNAKE_CASE		)

									if not isinstance(_SCREAMING_SNAKE_CASE    ,					_SCREAMING_SNAKE_CASE		):
																_UpperCAmelCase					=    [outputs]

									self.assertEqual(len(_SCREAMING_SNAKE_CASE		)    ,					len(self.tool.outputs		)		)
