



from __future__ import annotations

import unittest

from transformers import DebertaVaConfig, 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 (
           TFDebertaVaForMaskedLM,
           TFDebertaVaForQuestionAnswering,
           TFDebertaVaForSequenceClassification,
           TFDebertaVaForTokenClassification,
           TFDebertaVaModel,
       )



class       UpperCAmelCase__:

   '''simple docstring'''




   def __init__(						self  :			List[str]			,				lowerCAmelCase  :			Union[str, Any]			,				lowerCAmelCase  :			str=13			,				lowerCAmelCase  :			List[str]=7			,				lowerCAmelCase  :			Tuple=True			,				lowerCAmelCase  :			Any=True			,				lowerCAmelCase  :			Dict=True			,				lowerCAmelCase  :			Tuple=True			,				lowerCAmelCase  :			Tuple=99			,				lowerCAmelCase  :			str=32			,				lowerCAmelCase  :			Union[str, Any]=2			,				lowerCAmelCase  :			Tuple=4			,				lowerCAmelCase  :			Dict=37			,				lowerCAmelCase  :			Any="gelu"			,				lowerCAmelCase  :			str=0.1			,				lowerCAmelCase  :			List[str]=0.1			,				lowerCAmelCase  :			Optional[Any]=5_12			,				lowerCAmelCase  :			Union[str, Any]=16			,				lowerCAmelCase  :			List[str]=2			,				lowerCAmelCase  :			List[str]=0.02			,				lowerCAmelCase  :			List[Any]=False			,				lowerCAmelCase  :			Union[str, Any]=True			,				lowerCAmelCase  :			Any="None"			,				lowerCAmelCase  :			List[Any]=3			,				lowerCAmelCase  :			str=4			,				lowerCAmelCase  :			List[str]=None			,				)	->				Tuple:




         """simple docstring"""

         lowercase__     =  parent
         lowercase__     =  batch_size
         lowercase__     =  seq_length
         lowercase__     =  is_training
         lowercase__     =  use_input_mask
         lowercase__     =  use_token_type_ids
         lowercase__     =  use_labels
         lowercase__     =  vocab_size
         lowercase__     =  hidden_size
         lowercase__     =  num_hidden_layers
         lowercase__     =  num_attention_heads
         lowercase__     =  intermediate_size
         lowercase__     =  hidden_act
         lowercase__     =  hidden_dropout_prob
         lowercase__     =  attention_probs_dropout_prob
         lowercase__     =  max_position_embeddings
         lowercase__     =  type_vocab_size
         lowercase__     =  type_sequence_label_size
         lowercase__     =  initializer_range
         lowercase__     =  num_labels
         lowercase__     =  num_choices
         lowercase__     =  relative_attention
         lowercase__     =  position_biased_input
         lowercase__     =  pos_att_type
         lowercase__     =  scope


   def 			UpperCAmelCase		(						self  :			int)	->				int:




         """simple docstring"""

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

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

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

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

         lowercase__     =  DebertaVaConfig(
             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			,				position_biased_input=self.position_biased_input			,				initializer_range=self.initializer_range			,				return_dict=_lowercase			,				)

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


   def 			UpperCAmelCase		(						self  :			List[Any]			,				lowerCAmelCase  :			List[str]			,				lowerCAmelCase  :			int			,				lowerCAmelCase  :			List[str]			,				lowerCAmelCase  :			List[str]			,				lowerCAmelCase  :			Any			,				lowerCAmelCase  :			Union[str, Any]			,				lowerCAmelCase  :			Any)	->				str:




         """simple docstring"""

         lowercase__     =  TFDebertaVaModel(config=_lowercase)
         lowercase__     =  {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}

         lowercase__     =  [input_ids, input_mask]
         lowercase__     =  model(_lowercase)

         lowercase__     =  model(_lowercase)

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


   def 			UpperCAmelCase		(						self  :			str			,				lowerCAmelCase  :			Tuple			,				lowerCAmelCase  :			str			,				lowerCAmelCase  :			Tuple			,				lowerCAmelCase  :			Optional[int]			,				lowerCAmelCase  :			List[str]			,				lowerCAmelCase  :			List[Any]			,				lowerCAmelCase  :			int)	->				Dict:




         """simple docstring"""

         lowercase__     =  TFDebertaVaForMaskedLM(config=_lowercase)
         lowercase__     =  {
             """input_ids""": input_ids,
             """attention_mask""": input_mask,
             """token_type_ids""": token_type_ids,
         }
         lowercase__     =  model(_lowercase)
         self.parent.assertEqual(result.logits.shape			,				(self.batch_size, self.seq_length, self.vocab_size))


   def 			UpperCAmelCase		(						self  :			Optional[int]			,				lowerCAmelCase  :			Tuple			,				lowerCAmelCase  :			Optional[int]			,				lowerCAmelCase  :			Tuple			,				lowerCAmelCase  :			Optional[Any]			,				lowerCAmelCase  :			Tuple			,				lowerCAmelCase  :			str			,				lowerCAmelCase  :			str)	->				str:




         """simple docstring"""

         lowercase__     =  self.num_labels
         lowercase__     =  TFDebertaVaForSequenceClassification(config=_lowercase)
         lowercase__     =  {
             """input_ids""": input_ids,
             """attention_mask""": input_mask,
             """token_type_ids""": token_type_ids,
         }

         lowercase__     =  model(_lowercase)
         self.parent.assertEqual(result.logits.shape			,				(self.batch_size, self.num_labels))


   def 			UpperCAmelCase		(						self  :			str			,				lowerCAmelCase  :			Tuple			,				lowerCAmelCase  :			Dict			,				lowerCAmelCase  :			int			,				lowerCAmelCase  :			Optional[int]			,				lowerCAmelCase  :			Dict			,				lowerCAmelCase  :			Tuple			,				lowerCAmelCase  :			Union[str, Any])	->				str:




         """simple docstring"""

         lowercase__     =  self.num_labels
         lowercase__     =  TFDebertaVaForTokenClassification(config=_lowercase)
         lowercase__     =  {
             """input_ids""": input_ids,
             """attention_mask""": input_mask,
             """token_type_ids""": token_type_ids,
         }
         lowercase__     =  model(_lowercase)
         self.parent.assertEqual(result.logits.shape			,				(self.batch_size, self.seq_length, self.num_labels))


   def 			UpperCAmelCase		(						self  :			str			,				lowerCAmelCase  :			Any			,				lowerCAmelCase  :			Optional[Any]			,				lowerCAmelCase  :			Dict			,				lowerCAmelCase  :			Optional[Any]			,				lowerCAmelCase  :			Dict			,				lowerCAmelCase  :			Dict			,				lowerCAmelCase  :			List[str])	->				Any:




         """simple docstring"""

         lowercase__     =  TFDebertaVaForQuestionAnswering(config=_lowercase)
         lowercase__     =  {
             """input_ids""": input_ids,
             """attention_mask""": input_mask,
             """token_type_ids""": token_type_ids,
         }

         lowercase__     =  model(_lowercase)
         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  :			List[str])	->				Optional[int]:




         """simple docstring"""

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



@require_tf
class       UpperCAmelCase__(							SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     ,							unittest.TestCase	):

   '''simple docstring'''




   A    :  str       				=    (
       (
           TFDebertaVaModel,
           TFDebertaVaForMaskedLM,
           TFDebertaVaForQuestionAnswering,
           TFDebertaVaForSequenceClassification,
           TFDebertaVaForTokenClassification,
       )
       if is_tf_available()
       else ()
   )
   A    :  Optional[Any]       				=    (
       {
           "feature-extraction": TFDebertaVaModel,
           "fill-mask": TFDebertaVaForMaskedLM,
           "question-answering": TFDebertaVaForQuestionAnswering,
           "text-classification": TFDebertaVaForSequenceClassification,
           "token-classification": TFDebertaVaForTokenClassification,
           "zero-shot": TFDebertaVaForSequenceClassification,
       }
       if is_tf_available()
       else {}
   )

   A    :  Dict       				=    False
   A    :  Any       				=    False


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




         """simple docstring"""

         lowercase__     =  TFDebertaVaModelTester(self)
         lowercase__     =  ConfigTester(self			,				config_class=_lowercase			,				hidden_size=37)


   def 			UpperCAmelCase		(						self  :			List[str])	->				str:




         """simple docstring"""

         self.config_tester.run_common_tests()


   def 			UpperCAmelCase		(						self  :			Dict)	->				Dict:




         """simple docstring"""

         lowercase__     =  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*_lowercase)


   def 			UpperCAmelCase		(						self  :			Any)	->				Optional[int]:




         """simple docstring"""

         lowercase__     =  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_masked_lm(*_lowercase)


   def 			UpperCAmelCase		(						self  :			Dict)	->				Optional[Any]:




         """simple docstring"""

         lowercase__     =  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_question_answering(*_lowercase)


   def 			UpperCAmelCase		(						self  :			Optional[int])	->				List[str]:




         """simple docstring"""

         lowercase__     =  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_sequence_classification(*_lowercase)


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




         """simple docstring"""

         lowercase__     =  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_token_classification(*_lowercase)



   @slow
   def 			UpperCAmelCase		(						self  :			Tuple)	->				List[str]:




         """simple docstring"""

         lowercase__     =  TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge')
         self.assertIsNotNone(_lowercase)



@require_tf
class       UpperCAmelCase__(							unittest.TestCase	):

   '''simple docstring'''




   @unittest.skip(reason='Model not available yet')
   def 			UpperCAmelCase		(						self  :			List[str])	->				List[Any]:




         """simple docstring"""

         pass



   @slow
   def 			UpperCAmelCase		(						self  :			Tuple)	->				List[str]:




         """simple docstring"""

         lowercase__     =  TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge')
         lowercase__     =  tf.constant([[0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]])
         lowercase__     =  tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
         lowercase__     =  model(_lowercase			,				attention_mask=_lowercase)[0]

         lowercase__     =  tf.constant(
             [[[0.23_56, 0.19_48, 0.03_69], [-0.10_63, 0.35_86, -0.51_52], [-0.63_99, -0.02_59, -0.25_25]]])
         tf.debugging.assert_near(output[:, 1:4, 1:4]			,				_lowercase			,				atol=1E-4)





from ...configuration_utils import PretrainedConfig
from ...utils import logging


a__      :				Dict   	=			logging.get_logger(__name__)

a__      :				List[Any]   	=			{
    "facebook/s2t-small-librispeech-asr": (
        "https://huggingface.co/facebook/s2t-small-librispeech-asr/resolve/main/config.json"
    ),
    # See all Speech2Text models at https://huggingface.co/models?filter=speech_to_text
}



class       UpperCAmelCase__(							lowerCamelCase	):

   '''simple docstring'''




   A    :  int       				=    "speech_to_text"
   A    :  Optional[Any]       				=    ["past_key_values"]
   A    :  Optional[int]       				=    {"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}


   def __init__(						self  :			Optional[int]			,				lowerCAmelCase  :			Tuple=1_00_00			,				lowerCAmelCase  :			int=12			,				lowerCAmelCase  :			int=20_48			,				lowerCAmelCase  :			Union[str, Any]=4			,				lowerCAmelCase  :			str=6			,				lowerCAmelCase  :			Dict=20_48			,				lowerCAmelCase  :			Dict=4			,				lowerCAmelCase  :			Optional[int]=0.0			,				lowerCAmelCase  :			Union[str, Any]=0.0			,				lowerCAmelCase  :			int=True			,				lowerCAmelCase  :			Optional[Any]=True			,				lowerCAmelCase  :			Dict="relu"			,				lowerCAmelCase  :			Tuple=2_56			,				lowerCAmelCase  :			Dict=0.1			,				lowerCAmelCase  :			Optional[Any]=0.0			,				lowerCAmelCase  :			List[Any]=0.0			,				lowerCAmelCase  :			Any=0.02			,				lowerCAmelCase  :			List[Any]=2			,				lowerCAmelCase  :			Tuple=True			,				lowerCAmelCase  :			Tuple=1			,				lowerCAmelCase  :			List[str]=0			,				lowerCAmelCase  :			Union[str, Any]=2			,				lowerCAmelCase  :			Any=60_00			,				lowerCAmelCase  :			Optional[int]=10_24			,				lowerCAmelCase  :			Optional[Any]=2			,				lowerCAmelCase  :			Optional[Any]=(5, 5)			,				lowerCAmelCase  :			Union[str, Any]=10_24			,				lowerCAmelCase  :			List[Any]=80			,				lowerCAmelCase  :			List[str]=1			,				**lowerCAmelCase  :			List[str]			,				)	->				Dict:




         """simple docstring"""

         lowercase__     =  vocab_size
         lowercase__     =  d_model
         lowercase__     =  encoder_ffn_dim
         lowercase__     =  encoder_layers
         lowercase__     =  encoder_attention_heads
         lowercase__     =  decoder_ffn_dim
         lowercase__     =  decoder_layers
         lowercase__     =  decoder_attention_heads
         lowercase__     =  dropout
         lowercase__     =  attention_dropout
         lowercase__     =  activation_dropout
         lowercase__     =  activation_function
         lowercase__     =  init_std
         lowercase__     =  encoder_layerdrop
         lowercase__     =  decoder_layerdrop
         lowercase__     =  use_cache
         lowercase__     =  encoder_layers
         lowercase__     =  scale_embedding  # scale factor will be sqrt(d_model) if True
         lowercase__     =  max_source_positions
         lowercase__     =  max_target_positions
         lowercase__     =  num_conv_layers
         lowercase__     =  list(lowerCAmelCase)
         lowercase__     =  conv_channels
         lowercase__     =  input_feat_per_channel
         lowercase__     =  input_channels

         if len(self.conv_kernel_sizes) != self.num_conv_layers:
               raise ValueError(
                   'Configuration for convolutional module is incorrect. '
                   'It is required that `len(config.conv_kernel_sizes)` == `config.num_conv_layers` '
                   f'''but is `len(config.conv_kernel_sizes) = {len(self.conv_kernel_sizes)}`, '''
                   f'''`config.num_conv_layers = {self.num_conv_layers}`.''')

         super().__init__(
             pad_token_id=lowerCAmelCase			,				bos_token_id=lowerCAmelCase			,				eos_token_id=lowerCAmelCase			,				is_encoder_decoder=lowerCAmelCase			,				decoder_start_token_id=lowerCAmelCase			,				**lowerCAmelCase			,				)
