






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

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

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

	def 	UpperCamelCase   (							self	,   UpperCAmelCase	,   UpperCAmelCase	,   UpperCAmelCase	,   UpperCAmelCase	,   UpperCAmelCase	,   UpperCAmelCase	,   UpperCAmelCase   ):
							"""simple docstring"""







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

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

							_UpperCAmelCase     =      model(UpperCAmelCase   )

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

	def 	UpperCamelCase   (							self	,   UpperCAmelCase	,   UpperCAmelCase	,   UpperCAmelCase	,   UpperCAmelCase	,   UpperCAmelCase	,   UpperCAmelCase	,   UpperCAmelCase   ):
							"""simple docstring"""







							_UpperCAmelCase     =      TFDebertaForMaskedLM(config=UpperCAmelCase   )
							_UpperCAmelCase     =      {
							    'input_ids': input_ids,
							    'attention_mask': input_mask,
							    'token_type_ids': token_type_ids,
							}
							_UpperCAmelCase     =      model(UpperCAmelCase   )
							self.parent.assertEqual(result.logits.shape	,   (self.batch_size, self.seq_length, self.vocab_size)   )

	def 	UpperCamelCase   (							self	,   UpperCAmelCase	,   UpperCAmelCase	,   UpperCAmelCase	,   UpperCAmelCase	,   UpperCAmelCase	,   UpperCAmelCase	,   UpperCAmelCase   ):
							"""simple docstring"""







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

							_UpperCAmelCase     =      model(UpperCAmelCase   )
							self.parent.assertEqual(result.logits.shape	,   (self.batch_size, self.num_labels)   )

	def 	UpperCamelCase   (							self	,   UpperCAmelCase	,   UpperCAmelCase	,   UpperCAmelCase	,   UpperCAmelCase	,   UpperCAmelCase	,   UpperCAmelCase	,   UpperCAmelCase   ):
							"""simple docstring"""







							_UpperCAmelCase     =      self.num_labels
							_UpperCAmelCase     =      TFDebertaForTokenClassification(config=UpperCAmelCase   )
							_UpperCAmelCase     =      {
							    'input_ids': input_ids,
							    'attention_mask': input_mask,
							    'token_type_ids': token_type_ids,
							}
							_UpperCAmelCase     =      model(UpperCAmelCase   )
							self.parent.assertEqual(result.logits.shape	,   (self.batch_size, self.seq_length, self.num_labels)   )

	def 	UpperCamelCase   (							self	,   UpperCAmelCase	,   UpperCAmelCase	,   UpperCAmelCase	,   UpperCAmelCase	,   UpperCAmelCase	,   UpperCAmelCase	,   UpperCAmelCase   ):
							"""simple docstring"""







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

							_UpperCAmelCase     =      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 	UpperCamelCase   (							self   ):
							"""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 __lowerCamelCase			(				snake_case__					,	snake_case__					,	unittest.TestCase):
	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 	UpperCamelCase   (							self   ):
							"""simple docstring"""







							_UpperCAmelCase     =      TFDebertaModelTester(self   )
							_UpperCAmelCase     =      ConfigTester(self	,   config_class=UpperCAmelCase	,   hidden_size=37   )

	def 	UpperCamelCase   (							self   ):
							"""simple docstring"""







							self.config_tester.run_common_tests()

	def 	UpperCamelCase   (							self   ):
							"""simple docstring"""







							_UpperCAmelCase     =      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*UpperCAmelCase   )

	def 	UpperCamelCase   (							self   ):
							"""simple docstring"""







							_UpperCAmelCase     =      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_lm(*UpperCAmelCase   )

	def 	UpperCamelCase   (							self   ):
							"""simple docstring"""







							_UpperCAmelCase     =      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_question_answering(*UpperCAmelCase   )

	def 	UpperCamelCase   (							self   ):
							"""simple docstring"""







							_UpperCAmelCase     =      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_sequence_classification(*UpperCAmelCase   )

	def 	UpperCamelCase   (							self   ):
							"""simple docstring"""







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

	@slow
	def 	UpperCamelCase   (							self   ):
							"""simple docstring"""







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





@require_tf
class __lowerCamelCase			(				unittest.TestCase):

	@unittest.skip(reason='Model not available yet'   )
	def 	UpperCamelCase   (							self   ):
							"""simple docstring"""







							pass

	@slow
	def 	UpperCamelCase   (							self   ):
							"""simple docstring"""







							_UpperCAmelCase     =      TFDebertaModel.from_pretrained('kamalkraj/deberta-base'   )
							_UpperCAmelCase     =      tf.constant([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]]   )
							_UpperCAmelCase     =      tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]   )
							_UpperCAmelCase     =      model(UpperCAmelCase	,   attention_mask=UpperCAmelCase   )[0]

							_UpperCAmelCase     =      tf.constant(
							    [
							        [
							            [-0.59_85_58_96, -0.80_55_25_66, -0.8_46_21_35],
							            [1.4_48_40_25, -0.93_48_37_94, -0.80_59_30_85],
							            [0.3_12_27_41, 0.00_31_60_59, -1.4_13_13_77],
							        ]
							    ]   )
							tf.debugging.assert_near(output[:, 1:4, 1:4]	,   UpperCAmelCase	,   atol=1e-4   )








import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


_a				     =  '''
Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf originally as a company that developed a chatbot app targeted at teenagers.[2] After open-sourcing the model behind the chatbot, the company pivoted to focus on being a platform for machine learning.

In March 2021, Hugging Face raised $40 million in a Series B funding round.[3]

On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model.[4] In 2022, the workshop concluded with the announcement of BLOOM, a multilingual large language model with 176 billion parameters.[5]
'''





class __lowerCamelCase			(				unittest.TestCase					,	snake_case__):





	"""simple docstring"""






	def 	UpperCamelCase   (							self   ):
							"""simple docstring"""







							_UpperCAmelCase     =      load_tool('summarization'   )
							self.tool.setup()
							_UpperCAmelCase     =      load_tool('summarization'	,   remote=UpperCAmelCase   )

	def 	UpperCamelCase   (							self   ):
							"""simple docstring"""







							_UpperCAmelCase     =      self.tool(UpperCAmelCase   )
							self.assertEqual(
							    UpperCAmelCase	,   'Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'	,   )

	def 	UpperCamelCase   (							self   ):
							"""simple docstring"""







							_UpperCAmelCase     =      self.remote_tool(UpperCAmelCase   )
							self.assertEqual(
							    UpperCAmelCase	,   'Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'	,   )

	def 	UpperCamelCase   (							self   ):
							"""simple docstring"""







							_UpperCAmelCase     =      self.tool(text=UpperCAmelCase   )
							self.assertEqual(
							    UpperCAmelCase	,   'Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'	,   )

	def 	UpperCamelCase   (							self   ):
							"""simple docstring"""







							_UpperCAmelCase     =      self.remote_tool(text=UpperCAmelCase   )
							self.assertEqual(
							    UpperCAmelCase	,   'Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'	,   )
