'''simple docstring'''





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



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



    def 					_lowercase						(self    :    Optional[Any] ):
         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_           =   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=__a   ,			)

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



    def 					_lowercase						(self    :    Optional[Any]   ,			__a    :    Dict   ,			__a    :    List[Any]   ,			__a    :    str   ,			__a    :    str   ,			__a    :    int   ,			__a    :    int   ,			__a    :    Tuple ):
         UpperCAmelCase_           =   TFDebertaVaModel(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 					_lowercase						(self    :    Optional[int]   ,			__a    :    Tuple   ,			__a    :    Optional[Any]   ,			__a    :    int   ,			__a    :    Dict   ,			__a    :    str   ,			__a    :    Any   ,			__a    :    Any ):
         UpperCAmelCase_           =   TFDebertaVaForMaskedLM(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 					_lowercase						(self    :    Optional[Any]   ,			__a    :    int   ,			__a    :    Any   ,			__a    :    Optional[Any]   ,			__a    :    Dict   ,			__a    :    Dict   ,			__a    :    Tuple   ,			__a    :    str ):
         UpperCAmelCase_           =   self.num_labels
         UpperCAmelCase_           =   TFDebertaVaForSequenceClassification(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 					_lowercase						(self    :    Tuple   ,			__a    :    List[Any]   ,			__a    :    str   ,			__a    :    Dict   ,			__a    :    Tuple   ,			__a    :    int   ,			__a    :    Tuple   ,			__a    :    List[str] ):
         UpperCAmelCase_           =   self.num_labels
         UpperCAmelCase_           =   TFDebertaVaForTokenClassification(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 					_lowercase						(self    :    Optional[Any]   ,			__a    :    Optional[int]   ,			__a    :    Tuple   ,			__a    :    Optional[Any]   ,			__a    :    Any   ,			__a    :    Union[str, Any]   ,			__a    :    Union[str, Any]   ,			__a    :    int ):
         UpperCAmelCase_           =   TFDebertaVaForQuestionAnswering(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 					_lowercase						(self    :    List[str] ):
         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__       :						Optional[Any]          =  (
        (
            TFDebertaVaModel,
            TFDebertaVaForMaskedLM,
            TFDebertaVaForQuestionAnswering,
            TFDebertaVaForSequenceClassification,
            TFDebertaVaForTokenClassification,
        )
        if is_tf_available()
        else ()
    )
    a__       :						int          =  (
        {
            """feature-extraction""": TFDebertaVaModel,
            """fill-mask""": TFDebertaVaForMaskedLM,
            """question-answering""": TFDebertaVaForQuestionAnswering,
            """text-classification""": TFDebertaVaForSequenceClassification,
            """token-classification""": TFDebertaVaForTokenClassification,
            """zero-shot""": TFDebertaVaForSequenceClassification,
        }
        if is_tf_available()
        else {}
    )

    a__       :						Optional[Any]          =  False
    a__       :						List[Any]          =  False



    def 					_lowercase						(self    :    Any ):
         UpperCAmelCase_           =   TFDebertaVaModelTester(self )
         UpperCAmelCase_           =   ConfigTester(self   ,			config_class=__a   ,			hidden_size=37 )



    def 					_lowercase						(self    :    Optional[int] ):
         self.config_tester.run_common_tests()



    def 					_lowercase						(self    :    int ):
         UpperCAmelCase_           =   self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*__a )



    def 					_lowercase						(self    :    Union[str, Any] ):
         UpperCAmelCase_           =   self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_masked_lm(*__a )



    def 					_lowercase						(self    :    Union[str, Any] ):
         UpperCAmelCase_           =   self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_question_answering(*__a )



    def 					_lowercase						(self    :    Union[str, Any] ):
         UpperCAmelCase_           =   self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_sequence_classification(*__a )



    def 					_lowercase						(self    :    Tuple ):
         UpperCAmelCase_           =   self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_token_classification(*__a )






    @slow
    def 					_lowercase						(self    :    Dict ):
         UpperCAmelCase_           =   TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge" )
         self.assertIsNotNone(__a )




@require_tf
class        __A      ( unittest.TestCase	):



    @unittest.skip(reason="Model not available yet" )
    def 					_lowercase						(self    :    Dict ):
         pass






    @slow
    def 					_lowercase						(self    :    str ):
         UpperCAmelCase_           =   TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge" )
         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.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]   ,			__a   ,			atol=1E-4 )








"""simple docstring"""




# This is the module that test_patching.py uses to test patch_submodule()

import os  # noqa: this is just for tests
import os as renamed_os  # noqa: this is just for tests
from os import path  # noqa: this is just for tests
from os import path as renamed_path  # noqa: this is just for tests
from os.path import join  # noqa: this is just for tests
from os.path import join as renamed_join  # noqa: this is just for tests


__UpperCamelCase						=      open  # noqa: we just need to have a builtin inside this module to test it properly


