
import unittest

from transformers import DebertaConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
				import torch

				from transformers import (
				    DebertaForMaskedLM,
				    DebertaForQuestionAnswering,
				    DebertaForSequenceClassification,
				    DebertaForTokenClassification,
				    DebertaModel,
				)
				from transformers.models.deberta.modeling_deberta import DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST




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

						SCREAMING_SNAKE_CASE__						=					None
						if self.use_input_mask:
											SCREAMING_SNAKE_CASE__						=					ids_tensor([self.batch_size, self.seq_length]			,  vocab_size=2				)

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

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

						SCREAMING_SNAKE_CASE__						=					self.get_config()

						return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
	def 	A_							(     self				:  Optional[Any]				):
						return 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			,  initializer_range=self.initializer_range			,  relative_attention=self.relative_attention			,  position_biased_input=self.position_biased_input			,  pos_att_type=self.pos_att_type			,  )
	def 	A_							(     self				:  int				):
						SCREAMING_SNAKE_CASE__						=					self.get_config()
						SCREAMING_SNAKE_CASE__						=					300
						return config
	def 	A_							(     self				:  List[Any]			,  UpperCAmelCase_				:  Dict				):
						self.parent.assertListEqual(list(result.loss.size()				)			,  []				)
	def 	A_							(     self				:  Tuple			,  UpperCAmelCase_				:  Optional[Any]			,  UpperCAmelCase_				:  int			,  UpperCAmelCase_				:  Tuple			,  UpperCAmelCase_				:  Any			,  UpperCAmelCase_				:  List[Any]			,  UpperCAmelCase_				:  str			,  UpperCAmelCase_				:  Union[str, Any]				):
						SCREAMING_SNAKE_CASE__						=					DebertaModel(config=a__				)
						model.to(a__				)
						model.eval()
						SCREAMING_SNAKE_CASE__						=					model(a__			,  attention_mask=a__			,  token_type_ids=a__				)[0]
						SCREAMING_SNAKE_CASE__						=					model(a__			,  token_type_ids=a__				)[0]
						SCREAMING_SNAKE_CASE__						=					model(a__				)[0]

						self.parent.assertListEqual(list(sequence_output.size()				)			,  [self.batch_size, self.seq_length, self.hidden_size]				)
	def 	A_							(     self				:  Optional[Any]			,  UpperCAmelCase_				:  Tuple			,  UpperCAmelCase_				:  int			,  UpperCAmelCase_				:  Union[str, Any]			,  UpperCAmelCase_				:  List[Any]			,  UpperCAmelCase_				:  str			,  UpperCAmelCase_				:  Tuple			,  UpperCAmelCase_				:  List[str]				):
						SCREAMING_SNAKE_CASE__						=					DebertaForMaskedLM(config=a__				)
						model.to(a__				)
						model.eval()
						SCREAMING_SNAKE_CASE__						=					model(a__			,  attention_mask=a__			,  token_type_ids=a__			,  labels=a__				)

						self.parent.assertEqual(result.logits.shape			,  (self.batch_size, self.seq_length, self.vocab_size)				)
	def 	A_							(     self				:  Optional[Any]			,  UpperCAmelCase_				:  Any			,  UpperCAmelCase_				:  int			,  UpperCAmelCase_				:  Optional[int]			,  UpperCAmelCase_				:  int			,  UpperCAmelCase_				:  Optional[int]			,  UpperCAmelCase_				:  Tuple			,  UpperCAmelCase_				:  str				):
						SCREAMING_SNAKE_CASE__						=					self.num_labels
						SCREAMING_SNAKE_CASE__						=					DebertaForSequenceClassification(a__				)
						model.to(a__				)
						model.eval()
						SCREAMING_SNAKE_CASE__						=					model(a__			,  attention_mask=a__			,  token_type_ids=a__			,  labels=a__				)
						self.parent.assertListEqual(list(result.logits.size()				)			,  [self.batch_size, self.num_labels]				)
						self.check_loss_output(a__				)
	def 	A_							(     self				:  List[str]			,  UpperCAmelCase_				:  Any			,  UpperCAmelCase_				:  List[str]			,  UpperCAmelCase_				:  Dict			,  UpperCAmelCase_				:  str			,  UpperCAmelCase_				:  int			,  UpperCAmelCase_				:  List[Any]			,  UpperCAmelCase_				:  str				):
						SCREAMING_SNAKE_CASE__						=					self.num_labels
						SCREAMING_SNAKE_CASE__						=					DebertaForTokenClassification(config=a__				)
						model.to(a__				)
						model.eval()
						SCREAMING_SNAKE_CASE__						=					model(a__			,  attention_mask=a__			,  token_type_ids=a__			,  labels=a__				)
						self.parent.assertEqual(result.logits.shape			,  (self.batch_size, self.seq_length, self.num_labels)				)
	def 	A_							(     self				:  Optional[int]			,  UpperCAmelCase_				:  List[str]			,  UpperCAmelCase_				:  Dict			,  UpperCAmelCase_				:  int			,  UpperCAmelCase_				:  Any			,  UpperCAmelCase_				:  Dict			,  UpperCAmelCase_				:  List[str]			,  UpperCAmelCase_				:  Dict				):
						SCREAMING_SNAKE_CASE__						=					DebertaForQuestionAnswering(config=a__				)
						model.to(a__				)
						model.eval()
						SCREAMING_SNAKE_CASE__						=					model(
						    a__			,  attention_mask=a__			,  token_type_ids=a__			,  start_positions=a__			,  end_positions=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 	A_							(     self				:  Dict				):
						SCREAMING_SNAKE_CASE__						=					self.prepare_config_and_inputs()
						(
						    SCREAMING_SNAKE_CASE__     
						)						=					config_and_inputs
						SCREAMING_SNAKE_CASE__						=					{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
						return config, inputs_dict





@require_torch
class 		lowercase__    (		UpperCamelCase_	,			UpperCamelCase_	,			unittest.TestCase    ):
	A__       :  Optional[Any]										=(
	    (
	        DebertaModel,
	        DebertaForMaskedLM,
	        DebertaForSequenceClassification,
	        DebertaForTokenClassification,
	        DebertaForQuestionAnswering,
	    )
	    if is_torch_available()
	    else ()
	)
	A__       :  int										=(
	    {
	        """feature-extraction""": DebertaModel,
	        """fill-mask""": DebertaForMaskedLM,
	        """question-answering""": DebertaForQuestionAnswering,
	        """text-classification""": DebertaForSequenceClassification,
	        """token-classification""": DebertaForTokenClassification,
	        """zero-shot""": DebertaForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)

	A__       :  Dict										=True
	A__       :  Any										=False
	A__       :  Optional[int]										=False
	A__       :  Optional[Any]										=False
	A__       :  List[Any]										=False
	def 	A_							(     self				:  Tuple				):
						SCREAMING_SNAKE_CASE__						=					DebertaModelTester(self				)
						SCREAMING_SNAKE_CASE__						=					ConfigTester(self			,  config_class=a__			,  hidden_size=37				)
	def 	A_							(     self				:  Optional[int]				):
						self.config_tester.run_common_tests()
	def 	A_							(     self				:  Any				):
						SCREAMING_SNAKE_CASE__						=					self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_model(*a__				)
	def 	A_							(     self				:  List[Any]				):
						SCREAMING_SNAKE_CASE__						=					self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_sequence_classification(*a__				)
	def 	A_							(     self				:  List[Any]				):
						SCREAMING_SNAKE_CASE__						=					self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_masked_lm(*a__				)
	def 	A_							(     self				:  List[Any]				):
						SCREAMING_SNAKE_CASE__						=					self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_question_answering(*a__				)
	def 	A_							(     self				:  Optional[Any]				):
						SCREAMING_SNAKE_CASE__						=					self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_token_classification(*a__				)





	@slow
	def 	A_							(     self				:  Optional[int]				):

						for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											SCREAMING_SNAKE_CASE__						=					DebertaModel.from_pretrained(a__				)
											self.assertIsNotNone(a__				)





@require_torch
@require_sentencepiece
@require_tokenizers
class 		lowercase__    (		unittest.TestCase    ):
	@unittest.skip(reason='Model not available yet'				)
	def 	A_							(     self				:  List[Any]				):
						pass





	@slow
	def 	A_							(     self				:  str				):
						SCREAMING_SNAKE_CASE__						=					DebertaModel.from_pretrained('microsoft/deberta-base'				)

						SCREAMING_SNAKE_CASE__						=					torch.tensor([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]				)
						SCREAMING_SNAKE_CASE__						=					torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]				)
						with torch.no_grad():
											SCREAMING_SNAKE_CASE__						=					model(a__			,  attention_mask=a__				)[0]
						# compare the actual values for a slice.
						SCREAMING_SNAKE_CASE__						=					torch.tensor(
						    [[[-0.5_986, -0.8_055, -0.8_462], [1.4_484, -0.9_348, -0.8_059], [0.3_123, 0.0_032, -1.4_131]]]				)
						self.assertTrue(torch.allclose(output[:, 1:4, 1:4]			,  a__			,  atol=1e-4				)			,  F'{output[:, 1:4, 1:4]}'				)







'''simple docstring'''

# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from ..models.whisper import WhisperForConditionalGeneration, WhisperProcessor
from .base import PipelineTool




class    lowerCAmelCase       (     UpperCamelCase_  ):
 A_				:				int	=			"""openai/whisper-base"""
 A_				:				str	=			(
     """This is a tool that transcribes an audio into text. It takes an input named `audio` and returns the """
     """transcribed text."""
 )
 A_				:				Union[str, Any]	=			"""transcriber"""
 A_				:				Tuple	=			WhisperProcessor
 A_				:				Dict	=			WhisperForConditionalGeneration

 A_				:				Tuple	=			["""audio"""]
 A_				:				Optional[int]	=			["""text"""]


 def    _A	(    self  : Optional[int]			,							a__  : Optional[int]    ):
  '''simple docstring'''

  return self.pre_processor(a__			,							return_tensors="pt"    ).input_features


 def    _A	(    self  : List[str]			,							a__  : Union[str, Any]    ):
  '''simple docstring'''

  return self.model.generate(inputs=a__    )


 def    _A	(    self  : Optional[Any]			,							a__  : Dict    ):
  '''simple docstring'''

  return self.pre_processor.batch_decode(a__			,							skip_special_tokens=a__    )[0]





