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





     """simple docstring"""







     def __init__(							self						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE=1_3						,						__SCREAMING_SNAKE_CASE=7						,						__SCREAMING_SNAKE_CASE=True						,						__SCREAMING_SNAKE_CASE=True						,						__SCREAMING_SNAKE_CASE=True						,						__SCREAMING_SNAKE_CASE=True						,						__SCREAMING_SNAKE_CASE=9_9						,						__SCREAMING_SNAKE_CASE=3_2						,						__SCREAMING_SNAKE_CASE=2						,						__SCREAMING_SNAKE_CASE=4						,						__SCREAMING_SNAKE_CASE=3_7						,						__SCREAMING_SNAKE_CASE="gelu"						,						__SCREAMING_SNAKE_CASE=0.1						,						__SCREAMING_SNAKE_CASE=0.1						,						__SCREAMING_SNAKE_CASE=5_1_2						,						__SCREAMING_SNAKE_CASE=1_6						,						__SCREAMING_SNAKE_CASE=2						,						__SCREAMING_SNAKE_CASE=0.02						,						__SCREAMING_SNAKE_CASE=False						,						__SCREAMING_SNAKE_CASE=True						,						__SCREAMING_SNAKE_CASE="None"						,						__SCREAMING_SNAKE_CASE=3						,						__SCREAMING_SNAKE_CASE=4						,						__SCREAMING_SNAKE_CASE=None						,						)  ->   Union[str, Any]:




           """simple docstring"""







           UpperCamelCase__    :   Optional[int]					=				parent
           UpperCamelCase__    :   Any					=				batch_size
           UpperCamelCase__    :   List[str]					=				seq_length
           UpperCamelCase__    :   str					=				is_training
           UpperCamelCase__    :   Union[str, Any]					=				use_input_mask
           UpperCamelCase__    :   Union[str, Any]					=				use_token_type_ids
           UpperCamelCase__    :   Dict					=				use_labels
           UpperCamelCase__    :   Tuple					=				vocab_size
           UpperCamelCase__    :   Union[str, Any]					=				hidden_size
           UpperCamelCase__    :   int					=				num_hidden_layers
           UpperCamelCase__    :   Optional[Any]					=				num_attention_heads
           UpperCamelCase__    :   Any					=				intermediate_size
           UpperCamelCase__    :   str					=				hidden_act
           UpperCamelCase__    :   Tuple					=				hidden_dropout_prob
           UpperCamelCase__    :   Dict					=				attention_probs_dropout_prob
           UpperCamelCase__    :   Dict					=				max_position_embeddings
           UpperCamelCase__    :   Any					=				type_vocab_size
           UpperCamelCase__    :   Union[str, Any]					=				type_sequence_label_size
           UpperCamelCase__    :   Any					=				initializer_range
           UpperCamelCase__    :   Optional[int]					=				num_labels
           UpperCamelCase__    :   Optional[int]					=				num_choices
           UpperCamelCase__    :   List[str]					=				relative_attention
           UpperCamelCase__    :   Dict					=				position_biased_input
           UpperCamelCase__    :   Optional[Any]					=				pos_att_type
           UpperCamelCase__    :   Optional[int]					=				scope






     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   Tuple:




           """simple docstring"""







           UpperCamelCase__    :   List[Any]					=				ids_tensor([self.batch_size, self.seq_length]						,						self.vocab_size  )

           UpperCamelCase__    :   int					=				None
           if self.use_input_mask:
                 UpperCamelCase__    :   List[str]					=				random_attention_mask([self.batch_size, self.seq_length]  )

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

           UpperCamelCase__    :   int					=				None
           UpperCamelCase__    :   Tuple					=				None
           UpperCamelCase__    :   str					=				None
           if self.use_labels:
                 UpperCamelCase__    :   Union[str, Any]					=				ids_tensor([self.batch_size]						,						self.type_sequence_label_size  )
                 UpperCamelCase__    :   int					=				ids_tensor([self.batch_size, self.seq_length]						,						self.num_labels  )

           UpperCamelCase__    :   Tuple					=				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=__SCREAMING_SNAKE_CASE						,						)

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






     def    __SCREAMING_SNAKE_CASE			(							self						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE  )  ->   List[Any]:




           """simple docstring"""







           UpperCamelCase__    :   str					=				TFDebertaVaModel(config=__SCREAMING_SNAKE_CASE  )
           UpperCamelCase__    :   Dict					=				{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

           UpperCamelCase__    :   Any					=				[input_ids, input_mask]
           UpperCamelCase__    :   List[str]					=				model(__SCREAMING_SNAKE_CASE  )

           UpperCamelCase__    :   Optional[int]					=				model(__SCREAMING_SNAKE_CASE  )

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






     def    __SCREAMING_SNAKE_CASE			(							self						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE  )  ->   str:




           """simple docstring"""







           UpperCamelCase__    :   Optional[int]					=				TFDebertaVaForMaskedLM(config=__SCREAMING_SNAKE_CASE  )
           UpperCamelCase__    :   Optional[int]					=				{
               '''input_ids''': input_ids,
               '''attention_mask''': input_mask,
               '''token_type_ids''': token_type_ids,
           }
           UpperCamelCase__    :   Optional[Any]					=				model(__SCREAMING_SNAKE_CASE  )
           self.parent.assertEqual(result.logits.shape						,						(self.batch_size, self.seq_length, self.vocab_size)  )






     def    __SCREAMING_SNAKE_CASE			(							self						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE  )  ->   Tuple:




           """simple docstring"""







           UpperCamelCase__    :   Tuple					=				self.num_labels
           UpperCamelCase__    :   List[str]					=				TFDebertaVaForSequenceClassification(config=__SCREAMING_SNAKE_CASE  )
           UpperCamelCase__    :   Dict					=				{
               '''input_ids''': input_ids,
               '''attention_mask''': input_mask,
               '''token_type_ids''': token_type_ids,
           }

           UpperCamelCase__    :   Optional[int]					=				model(__SCREAMING_SNAKE_CASE  )
           self.parent.assertEqual(result.logits.shape						,						(self.batch_size, self.num_labels)  )






     def    __SCREAMING_SNAKE_CASE			(							self						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE  )  ->   Dict:




           """simple docstring"""







           UpperCamelCase__    :   str					=				self.num_labels
           UpperCamelCase__    :   int					=				TFDebertaVaForTokenClassification(config=__SCREAMING_SNAKE_CASE  )
           UpperCamelCase__    :   Union[str, Any]					=				{
               '''input_ids''': input_ids,
               '''attention_mask''': input_mask,
               '''token_type_ids''': token_type_ids,
           }
           UpperCamelCase__    :   Dict					=				model(__SCREAMING_SNAKE_CASE  )
           self.parent.assertEqual(result.logits.shape						,						(self.batch_size, self.seq_length, self.num_labels)  )






     def    __SCREAMING_SNAKE_CASE			(							self						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE  )  ->   List[str]:




           """simple docstring"""







           UpperCamelCase__    :   str					=				TFDebertaVaForQuestionAnswering(config=__SCREAMING_SNAKE_CASE  )
           UpperCamelCase__    :   Dict					=				{
               '''input_ids''': input_ids,
               '''attention_mask''': input_mask,
               '''token_type_ids''': token_type_ids,
           }

           UpperCamelCase__    :   Union[str, Any]					=				model(__SCREAMING_SNAKE_CASE  )
           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    __SCREAMING_SNAKE_CASE			(							self  )  ->   List[Any]:




           """simple docstring"""







           UpperCamelCase__    :   Dict					=				self.prepare_config_and_inputs()
           (
               UpperCamelCase__
           )    :   Any					=				config_and_inputs
           UpperCamelCase__    :   Union[str, Any]					=				{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
           return config, inputs_dict
@require_tf
class 				_lowerCamelCase (      UpperCamelCase_	,							UpperCamelCase_	,							unittest.TestCase ):





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		   =  (
         (
             TFDebertaVaModel,
             TFDebertaVaForMaskedLM,
             TFDebertaVaForQuestionAnswering,
             TFDebertaVaForSequenceClassification,
             TFDebertaVaForTokenClassification,
         )
         if is_tf_available()
         else ()
     )
     SCREAMING_SNAKE_CASE_		   =  (
         {
             '''feature-extraction''': TFDebertaVaModel,
             '''fill-mask''': TFDebertaVaForMaskedLM,
             '''question-answering''': TFDebertaVaForQuestionAnswering,
             '''text-classification''': TFDebertaVaForSequenceClassification,
             '''token-classification''': TFDebertaVaForTokenClassification,
             '''zero-shot''': TFDebertaVaForSequenceClassification,
         }
         if is_tf_available()
         else {}
     )

     SCREAMING_SNAKE_CASE_		   =  False
     SCREAMING_SNAKE_CASE_		   =  False






     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   str:




           """simple docstring"""







           UpperCamelCase__    :   Dict					=				TFDebertaVaModelTester(self  )
           UpperCamelCase__    :   Optional[int]					=				ConfigTester(self						,						config_class=__SCREAMING_SNAKE_CASE						,						hidden_size=3_7  )






     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   Any:




           """simple docstring"""







           self.config_tester.run_common_tests()






     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   Tuple:




           """simple docstring"""







           UpperCamelCase__    :   str					=				self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*__SCREAMING_SNAKE_CASE  )






     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   int:




           """simple docstring"""







           UpperCamelCase__    :   Union[str, Any]					=				self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_masked_lm(*__SCREAMING_SNAKE_CASE  )






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




           """simple docstring"""







           UpperCamelCase__    :   int					=				self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_question_answering(*__SCREAMING_SNAKE_CASE  )






     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   Optional[int]:




           """simple docstring"""







           UpperCamelCase__    :   Union[str, Any]					=				self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_sequence_classification(*__SCREAMING_SNAKE_CASE  )






     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   List[Any]:




           """simple docstring"""







           UpperCamelCase__    :   Dict					=				self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_token_classification(*__SCREAMING_SNAKE_CASE  )






     @slow
     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   List[Any]:




           """simple docstring"""







           UpperCamelCase__    :   Optional[int]					=				TFDebertaVaModel.from_pretrained('''kamalkraj/deberta-v2-xlarge'''  )
           self.assertIsNotNone(__SCREAMING_SNAKE_CASE  )
@require_tf
class 				_lowerCamelCase (      unittest.TestCase ):





     """simple docstring"""







     @unittest.skip(reason='''Model not available yet'''  )
     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   Tuple:




           """simple docstring"""







           pass






     @slow
     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   List[Any]:




           """simple docstring"""







           UpperCamelCase__    :   List[str]					=				TFDebertaVaModel.from_pretrained('''kamalkraj/deberta-v2-xlarge'''  )
           UpperCamelCase__    :   str					=				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]]  )
           UpperCamelCase__    :   str					=				tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]  )
           UpperCamelCase__    :   Optional[Any]					=				model(__SCREAMING_SNAKE_CASE						,						attention_mask=__SCREAMING_SNAKE_CASE  )[0]

           UpperCamelCase__    :   str					=				tf.constant(
               [[[0.2356, 0.1948, 0.0369], [-0.1063, 0.3586, -0.5152], [-0.6399, -0.0259, -0.2525]]]  )
           tf.debugging.assert_near(output[:, 1:4, 1:4]						,						__SCREAMING_SNAKE_CASE						,						atol=1e-4  )




from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


lowerCamelCase      ={
    "configuration_mobilebert": [
        "MOBILEBERT_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "MobileBertConfig",
        "MobileBertOnnxConfig",
    ],
    "tokenization_mobilebert": ["MobileBertTokenizer"],
}

try:
    if not is_tokenizers_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    lowerCamelCase      =["MobileBertTokenizerFast"]

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    lowerCamelCase      =[
        "MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
        "MobileBertForMaskedLM",
        "MobileBertForMultipleChoice",
        "MobileBertForNextSentencePrediction",
        "MobileBertForPreTraining",
        "MobileBertForQuestionAnswering",
        "MobileBertForSequenceClassification",
        "MobileBertForTokenClassification",
        "MobileBertLayer",
        "MobileBertModel",
        "MobileBertPreTrainedModel",
        "load_tf_weights_in_mobilebert",
    ]

try:
    if not is_tf_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    lowerCamelCase      =[
        "TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
        "TFMobileBertForMaskedLM",
        "TFMobileBertForMultipleChoice",
        "TFMobileBertForNextSentencePrediction",
        "TFMobileBertForPreTraining",
        "TFMobileBertForQuestionAnswering",
        "TFMobileBertForSequenceClassification",
        "TFMobileBertForTokenClassification",
        "TFMobileBertMainLayer",
        "TFMobileBertModel",
        "TFMobileBertPreTrainedModel",
    ]


if TYPE_CHECKING:
    from .configuration_mobilebert import (
        MOBILEBERT_PRETRAINED_CONFIG_ARCHIVE_MAP,
        MobileBertConfig,
        MobileBertOnnxConfig,
    )
    from .tokenization_mobilebert import MobileBertTokenizer

    try:
        if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .tokenization_mobilebert_fast import MobileBertTokenizerFast

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_mobilebert import (
            MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
            MobileBertForMaskedLM,
            MobileBertForMultipleChoice,
            MobileBertForNextSentencePrediction,
            MobileBertForPreTraining,
            MobileBertForQuestionAnswering,
            MobileBertForSequenceClassification,
            MobileBertForTokenClassification,
            MobileBertLayer,
            MobileBertModel,
            MobileBertPreTrainedModel,
            load_tf_weights_in_mobilebert,
        )

    try:
        if not is_tf_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_tf_mobilebert import (
            TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
            TFMobileBertForMaskedLM,
            TFMobileBertForMultipleChoice,
            TFMobileBertForNextSentencePrediction,
            TFMobileBertForPreTraining,
            TFMobileBertForQuestionAnswering,
            TFMobileBertForSequenceClassification,
            TFMobileBertForTokenClassification,
            TFMobileBertMainLayer,
            TFMobileBertModel,
            TFMobileBertPreTrainedModel,
        )

else:
    import sys

    lowerCamelCase      =_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)


