

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







  """simple docstring"""




  def __init__(     self      :	Union[str, Any]			,			UpperCAmelCase__      :	Tuple			,			UpperCAmelCase__      :	Dict=1_3			,			UpperCAmelCase__      :	str=7			,			UpperCAmelCase__      :	int=True			,			UpperCAmelCase__      :	str=True			,			UpperCAmelCase__      :	Optional[Any]=True			,			UpperCAmelCase__      :	List[str]=True			,			UpperCAmelCase__      :	List[str]=9_9			,			UpperCAmelCase__      :	str=3_2			,			UpperCAmelCase__      :	int=2			,			UpperCAmelCase__      :	str=4			,			UpperCAmelCase__      :	Tuple=3_7			,			UpperCAmelCase__      :	Optional[int]="gelu"			,			UpperCAmelCase__      :	List[Any]=0.1			,			UpperCAmelCase__      :	Union[str, Any]=0.1			,			UpperCAmelCase__      :	Dict=5_1_2			,			UpperCAmelCase__      :	int=1_6			,			UpperCAmelCase__      :	Optional[Any]=2			,			UpperCAmelCase__      :	Union[str, Any]=0.02			,			UpperCAmelCase__      :	Any=3			,			UpperCAmelCase__      :	int=4			,			UpperCAmelCase__      :	str=None			,			)   ->Any:
        """simple docstring"""







        SCREAMING_SNAKE_CASE	: List[str]					       =				parent
        SCREAMING_SNAKE_CASE	: int					       =				1_3
        SCREAMING_SNAKE_CASE	: List[str]					       =				7
        SCREAMING_SNAKE_CASE	: Tuple					       =				True
        SCREAMING_SNAKE_CASE	: Any					       =				True
        SCREAMING_SNAKE_CASE	: Optional[int]					       =				True
        SCREAMING_SNAKE_CASE	: Tuple					       =				True
        SCREAMING_SNAKE_CASE	: str					       =				9_9
        SCREAMING_SNAKE_CASE	: List[str]					       =				3_2
        SCREAMING_SNAKE_CASE	: Optional[Any]					       =				2
        SCREAMING_SNAKE_CASE	: List[str]					       =				4
        SCREAMING_SNAKE_CASE	: Optional[int]					       =				3_7
        SCREAMING_SNAKE_CASE	: Union[str, Any]					       =				"""gelu"""
        SCREAMING_SNAKE_CASE	: Optional[int]					       =				0.1
        SCREAMING_SNAKE_CASE	: List[Any]					       =				0.1
        SCREAMING_SNAKE_CASE	: str					       =				5_1_2
        SCREAMING_SNAKE_CASE	: List[Any]					       =				1_6
        SCREAMING_SNAKE_CASE	: Optional[Any]					       =				False
        SCREAMING_SNAKE_CASE	: Optional[Any]					       =				-1
        SCREAMING_SNAKE_CASE	: Optional[Any]					       =				True
        SCREAMING_SNAKE_CASE	: Union[str, Any]					       =				2
        SCREAMING_SNAKE_CASE	: Any					       =				0.02
        SCREAMING_SNAKE_CASE	: Optional[Any]					       =				3
        SCREAMING_SNAKE_CASE	: Any					       =				4
        SCREAMING_SNAKE_CASE	: Tuple					       =				None


  def 	_lowercase (     self      :	Any						)   ->str:
        """simple docstring"""







        SCREAMING_SNAKE_CASE	: Tuple					       =				ids_tensor([self.batch_size, self.seq_length]			,			self.vocab_size						)

        SCREAMING_SNAKE_CASE	: Optional[int]					       =				None
        if self.use_input_mask:
              SCREAMING_SNAKE_CASE	: Union[str, Any]					       =				random_attention_mask([self.batch_size, self.seq_length]						)

        SCREAMING_SNAKE_CASE	: Tuple					       =				None
        if self.use_token_type_ids:
              SCREAMING_SNAKE_CASE	: Union[str, Any]					       =				ids_tensor([self.batch_size, self.seq_length]			,			self.type_vocab_size						)

        SCREAMING_SNAKE_CASE	: str					       =				None
        SCREAMING_SNAKE_CASE	: List[Any]					       =				None
        SCREAMING_SNAKE_CASE	: Union[str, Any]					       =				None
        if self.use_labels:
              SCREAMING_SNAKE_CASE	: List[Any]					       =				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	: str					       =				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 	_lowercase (     self      :	Optional[Any]			,			UpperCAmelCase__      :	Optional[Any]			,			UpperCAmelCase__      :	Any			,			UpperCAmelCase__      :	Optional[int]			,			UpperCAmelCase__      :	Tuple			,			UpperCAmelCase__      :	Optional[Any]			,			UpperCAmelCase__      :	str			,			UpperCAmelCase__      :	Any						)   ->Tuple:
        """simple docstring"""







        SCREAMING_SNAKE_CASE	: Tuple					       =				TFDebertaModel(config=UpperCAmelCase__						)
        SCREAMING_SNAKE_CASE	: List[Any]					       =				{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}

        SCREAMING_SNAKE_CASE	: Optional[Any]					       =				[input_ids, input_mask]
        SCREAMING_SNAKE_CASE	: List[Any]					       =				model(UpperCAmelCase__						)

        SCREAMING_SNAKE_CASE	: Any					       =				model(UpperCAmelCase__						)

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


  def 	_lowercase (     self      :	str			,			UpperCAmelCase__      :	List[str]			,			UpperCAmelCase__      :	Optional[Any]			,			UpperCAmelCase__      :	Union[str, Any]			,			UpperCAmelCase__      :	Dict			,			UpperCAmelCase__      :	List[Any]			,			UpperCAmelCase__      :	List[str]			,			UpperCAmelCase__      :	Dict						)   ->Union[str, Any]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE	: int					       =				TFDebertaForMaskedLM(config=UpperCAmelCase__						)
        SCREAMING_SNAKE_CASE	: Optional[int]					       =				{
            """input_ids""": input_ids,
            """attention_mask""": input_mask,
            """token_type_ids""": token_type_ids,
        }
        SCREAMING_SNAKE_CASE	: List[str]					       =				model(UpperCAmelCase__						)
        self.parent.assertEqual(result.logits.shape			,			(self.batch_size, self.seq_length, self.vocab_size)						)


  def 	_lowercase (     self      :	Optional[int]			,			UpperCAmelCase__      :	List[str]			,			UpperCAmelCase__      :	int			,			UpperCAmelCase__      :	Tuple			,			UpperCAmelCase__      :	Any			,			UpperCAmelCase__      :	int			,			UpperCAmelCase__      :	Optional[int]			,			UpperCAmelCase__      :	Dict						)   ->Tuple:
        """simple docstring"""







        SCREAMING_SNAKE_CASE	: Tuple					       =				self.num_labels
        SCREAMING_SNAKE_CASE	: Tuple					       =				TFDebertaForSequenceClassification(config=UpperCAmelCase__						)
        SCREAMING_SNAKE_CASE	: Union[str, Any]					       =				{
            """input_ids""": input_ids,
            """attention_mask""": input_mask,
            """token_type_ids""": token_type_ids,
        }

        SCREAMING_SNAKE_CASE	: List[str]					       =				model(UpperCAmelCase__						)
        self.parent.assertEqual(result.logits.shape			,			(self.batch_size, self.num_labels)						)


  def 	_lowercase (     self      :	List[Any]			,			UpperCAmelCase__      :	Optional[Any]			,			UpperCAmelCase__      :	Dict			,			UpperCAmelCase__      :	int			,			UpperCAmelCase__      :	Union[str, Any]			,			UpperCAmelCase__      :	str			,			UpperCAmelCase__      :	Tuple			,			UpperCAmelCase__      :	int						)   ->str:
        """simple docstring"""







        SCREAMING_SNAKE_CASE	: Any					       =				self.num_labels
        SCREAMING_SNAKE_CASE	: int					       =				TFDebertaForTokenClassification(config=UpperCAmelCase__						)
        SCREAMING_SNAKE_CASE	: Optional[int]					       =				{
            """input_ids""": input_ids,
            """attention_mask""": input_mask,
            """token_type_ids""": token_type_ids,
        }
        SCREAMING_SNAKE_CASE	: Optional[Any]					       =				model(UpperCAmelCase__						)
        self.parent.assertEqual(result.logits.shape			,			(self.batch_size, self.seq_length, self.num_labels)						)


  def 	_lowercase (     self      :	List[Any]			,			UpperCAmelCase__      :	Optional[int]			,			UpperCAmelCase__      :	List[str]			,			UpperCAmelCase__      :	Optional[Any]			,			UpperCAmelCase__      :	int			,			UpperCAmelCase__      :	Tuple			,			UpperCAmelCase__      :	Optional[Any]			,			UpperCAmelCase__      :	str						)   ->Optional[Any]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE	: Optional[int]					       =				TFDebertaForQuestionAnswering(config=UpperCAmelCase__						)
        SCREAMING_SNAKE_CASE	: Optional[int]					       =				{
            """input_ids""": input_ids,
            """attention_mask""": input_mask,
            """token_type_ids""": token_type_ids,
        }

        SCREAMING_SNAKE_CASE	: Optional[Any]					       =				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 	_lowercase (     self      :	int						)   ->Dict:
        """simple docstring"""







        SCREAMING_SNAKE_CASE	: Optional[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
        )       ,		
        )	: int					       =				config_and_inputs
        SCREAMING_SNAKE_CASE	: Any					       =				{"""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    ):







  """simple docstring"""




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

  UpperCAmelCase__ :	Optional[int]         =False
  UpperCAmelCase__ :	List[Any]         =False


  def 	_lowercase (     self      :	Dict						)   ->Tuple:
        """simple docstring"""







        SCREAMING_SNAKE_CASE	: Optional[int]					       =				TFDebertaModelTester(self						)
        SCREAMING_SNAKE_CASE	: Optional[int]					       =				ConfigTester(self			,			config_class=UpperCAmelCase__			,			hidden_size=3_7						)


  def 	_lowercase (     self      :	Any						)   ->Any:
        """simple docstring"""







        self.config_tester.run_common_tests()


  def 	_lowercase (     self      :	Optional[int]						)   ->Union[str, Any]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE	: Tuple					       =				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*UpperCAmelCase__						)


  def 	_lowercase (     self      :	int						)   ->Tuple:
        """simple docstring"""







        SCREAMING_SNAKE_CASE	: str					       =				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_masked_lm(*UpperCAmelCase__						)


  def 	_lowercase (     self      :	Optional[int]						)   ->Optional[int]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE	: Union[str, Any]					       =				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_question_answering(*UpperCAmelCase__						)


  def 	_lowercase (     self      :	int						)   ->Union[str, Any]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE	: Dict					       =				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_sequence_classification(*UpperCAmelCase__						)


  def 	_lowercase (     self      :	Any						)   ->List[str]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE	: Optional[Any]					       =				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_token_classification(*UpperCAmelCase__						)




  @slow
  def 	_lowercase (     self      :	List[Any]						)   ->Union[str, Any]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE	: Dict					       =				TFDebertaModel.from_pretrained("""kamalkraj/deberta-base"""						)
        self.assertIsNotNone(UpperCAmelCase__						)







@require_tf
class     a__    (				unittest.TestCase    ):







  """simple docstring"""




  @unittest.skip(reason="""Model not available yet"""						)
  def 	_lowercase (     self      :	Optional[int]						)   ->Union[str, Any]:
        """simple docstring"""







        pass




  @slow
  def 	_lowercase (     self      :	List[str]						)   ->Union[str, Any]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE	: List[str]					       =				TFDebertaModel.from_pretrained("""kamalkraj/deberta-base"""						)
        SCREAMING_SNAKE_CASE	: Tuple					       =				tf.constant([[0, 3_1_4_1_4, 2_3_2, 3_2_8, 7_4_0, 1_1_4_0, 1_2_6_9_5, 6_9, 4_6_0_7_8, 1_5_8_8, 2]]						)
        SCREAMING_SNAKE_CASE	: int					       =				tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]						)
        SCREAMING_SNAKE_CASE	: str					       =				model(UpperCAmelCase__			,			attention_mask=UpperCAmelCase__						)[0]

        SCREAMING_SNAKE_CASE	: Any					       =				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						)







from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_speech_available,
    is_torch_available,
)


UpperCAmelCase__	:       int			      =      {
    """configuration_speech_to_text_2""": ["""SPEECH_TO_TEXT_2_PRETRAINED_CONFIG_ARCHIVE_MAP""", """Speech2Text2Config"""],
    """processing_speech_to_text_2""": ["""Speech2Text2Processor"""],
    """tokenization_speech_to_text_2""": ["""Speech2Text2Tokenizer"""],
}


try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase__	:       int			      =      [
      """SPEECH_TO_TEXT_2_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """Speech2Text2ForCausalLM""",
      """Speech2Text2PreTrainedModel""",
  ]


if TYPE_CHECKING:
  from .configuration_speech_to_text_a import SPEECH_TO_TEXT_2_PRETRAINED_CONFIG_ARCHIVE_MAP, SpeechaTextaConfig
  from .processing_speech_to_text_a import SpeechaTextaProcessor
  from .tokenization_speech_to_text_a import SpeechaTextaTokenizer

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_speech_to_text_a import (
        SPEECH_TO_TEXT_2_PRETRAINED_MODEL_ARCHIVE_LIST,
        SpeechaTextaForCausalLM,
        SpeechaTextaPreTrainedModel,
    )

else:
  import sys

  UpperCAmelCase__	:       int			      =      _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)




