code: 
  
  from __future__ import annotations
  
  import unittest
  
  from transformers import MPNetConfig, 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.models.mpnet.modeling_tf_mpnet import (
             TFMPNetForMaskedLM,
             TFMPNetForMultipleChoice,
             TFMPNetForQuestionAnswering,
             TFMPNetForSequenceClassification,
             TFMPNetForTokenClassification,
             TFMPNetModel,
         )
  
  
  
  
  
  
  
  class 		__magic_name__    :
  
     '''simple docstring'''
  
  
  
  
     def __init__(       self,					lowercase_,					lowercase_=13,					lowercase_=7,					lowercase_=True,					lowercase_=True,					lowercase_=False,					lowercase_=True,					lowercase_=99,					lowercase_=64,					lowercase_=2,					lowercase_=4,					lowercase_=64,					lowercase_="gelu",					lowercase_=0.1,					lowercase_=0.1,					lowercase_=512,					lowercase_=16,					lowercase_=2,					lowercase_=0.02,					lowercase_=3,					lowercase_=4,					lowercase_=None,					)							->					Dict:
  
  
  
  
  
  
       """simple docstring"""
  
  
  
  
  
  
       a__						=parent
       a__						=batch_size
       a__						=seq_length
       a__						=is_training
       a__						=use_input_mask
       a__						=use_token_type_ids
       a__						=use_labels
       a__						=vocab_size
       a__						=hidden_size
       a__						=num_hidden_layers
       a__						=num_attention_heads
       a__						=intermediate_size
       a__						=hidden_act
       a__						=hidden_dropout_prob
       a__						=attention_probs_dropout_prob
       a__						=max_position_embeddings
       a__						=type_vocab_size
       a__						=type_sequence_label_size
       a__						=initializer_range
       a__						=num_labels
       a__						=num_choices
       a__						=scope
  
  
  
     def 				_UpperCAmelCase				(       self )							->					Optional[Any]:
  
  
  
  
  
  
       """simple docstring"""
  
  
  
  
  
  
       a__						=ids_tensor([self.batch_size, self.seq_length],					self.vocab_size )
  
       a__						=None
       if self.use_input_mask:
         a__						=random_attention_mask([self.batch_size, self.seq_length] )
  
       a__						=None
       a__						=None
       a__						=None
       if self.use_labels:
         a__						=ids_tensor([self.batch_size],					self.type_sequence_label_size )
         a__						=ids_tensor([self.batch_size, self.seq_length],					self.num_labels )
         a__						=ids_tensor([self.batch_size],					self.num_choices )
  
       a__						=MPNetConfig(
           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,					initializer_range=self.initializer_range,					)
       return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels
  
  
  
     def 				_UpperCAmelCase				(       self,					lowercase_,					lowercase_,					lowercase_,					lowercase_,					lowercase_,					lowercase_ )							->					Dict:
  
  
  
  
  
  
       """simple docstring"""
  
  
  
  
  
  
       a__						=TFMPNetModel(config=lowercase_ )
       a__						={'''input_ids''': input_ids, '''attention_mask''': input_mask}
       a__						=model(lowercase_ )
       a__						=[input_ids, input_mask]
       a__						=model(lowercase_ )
       self.parent.assertEqual(result.last_hidden_state.shape,					(self.batch_size, self.seq_length, self.hidden_size) )
  
  
  
     def 				_UpperCAmelCase				(       self,					lowercase_,					lowercase_,					lowercase_,					lowercase_,					lowercase_,					lowercase_ )							->					Optional[Any]:
  
  
  
  
  
  
       """simple docstring"""
  
  
  
  
  
  
       a__						=TFMPNetForMaskedLM(config=lowercase_ )
       a__						={'''input_ids''': input_ids, '''attention_mask''': input_mask}
       a__						=model(lowercase_ )
       self.parent.assertEqual(result.logits.shape,					(self.batch_size, self.seq_length, self.vocab_size) )
  
  
  
     def 				_UpperCAmelCase				(       self,					lowercase_,					lowercase_,					lowercase_,					lowercase_,					lowercase_,					lowercase_ )							->					List[Any]:
  
  
  
  
  
  
       """simple docstring"""
  
  
  
  
  
  
       a__						=TFMPNetForQuestionAnswering(config=lowercase_ )
       a__						={
           '''input_ids''': input_ids,
           '''attention_mask''': input_mask,
       }
       a__						=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,					lowercase_,					lowercase_,					lowercase_,					lowercase_,					lowercase_,					lowercase_ )							->					str:
  
  
  
  
  
  
       """simple docstring"""
  
  
  
  
  
  
       a__						=self.num_labels
       a__						=TFMPNetForSequenceClassification(lowercase_ )
       a__						={'''input_ids''': input_ids, '''attention_mask''': input_mask}
       a__						=model(lowercase_ )
       self.parent.assertEqual(result.logits.shape,					(self.batch_size, self.num_labels) )
  
  
  
     def 				_UpperCAmelCase				(       self,					lowercase_,					lowercase_,					lowercase_,					lowercase_,					lowercase_,					lowercase_ )							->					Optional[Any]:
  
  
  
  
  
  
       """simple docstring"""
  
  
  
  
  
  
       a__						=self.num_choices
       a__						=TFMPNetForMultipleChoice(lowercase_ )
       a__						=tf.tile(tf.expand_dims(lowercase_,					1 ),					(1, self.num_choices, 1) )
       a__						=tf.tile(tf.expand_dims(lowercase_,					1 ),					(1, self.num_choices, 1) )
       a__						={
           '''input_ids''': multiple_choice_inputs_ids,
           '''attention_mask''': multiple_choice_input_mask,
       }
       a__						=model(lowercase_ )
       self.parent.assertEqual(result.logits.shape,					(self.batch_size, self.num_choices) )
  
  
  
     def 				_UpperCAmelCase				(       self,					lowercase_,					lowercase_,					lowercase_,					lowercase_,					lowercase_,					lowercase_ )							->					List[Any]:
  
  
  
  
  
  
       """simple docstring"""
  
  
  
  
  
  
       a__						=self.num_labels
       a__						=TFMPNetForTokenClassification(lowercase_ )
       a__						={'''input_ids''': input_ids, '''attention_mask''': input_mask}
       a__						=model(lowercase_ )
       self.parent.assertEqual(result.logits.shape,					(self.batch_size, self.seq_length, self.num_labels) )
  
  
  
     def 				_UpperCAmelCase				(       self )							->					int:
  
  
  
  
  
  
       """simple docstring"""
  
  
  
  
  
  
       a__						=self.prepare_config_and_inputs()
       ((a__),   (a__),   (a__),   (a__),   (a__),   (a__))						=config_and_inputs
       a__						={'''input_ids''': input_ids, '''attention_mask''': input_mask}
       return config, inputs_dict
  
  
  
  
  
  
  
  @require_tf
  class 		__magic_name__    (							lowerCamelCase__	, lowerCamelCase__	, unittest.TestCase							):
  
     '''simple docstring'''
  
  
  
  
     lowerCamelCase__				:			Any												=     (
         (
             TFMPNetForMaskedLM,
             TFMPNetForMultipleChoice,
             TFMPNetForQuestionAnswering,
             TFMPNetForSequenceClassification,
             TFMPNetForTokenClassification,
             TFMPNetModel,
         )
         if is_tf_available()
         else ()
     )
     lowerCamelCase__				:			str												=     (
         {
             'feature-extraction': TFMPNetModel,
             'fill-mask': TFMPNetForMaskedLM,
             'question-answering': TFMPNetForQuestionAnswering,
             'text-classification': TFMPNetForSequenceClassification,
             'token-classification': TFMPNetForTokenClassification,
             'zero-shot': TFMPNetForSequenceClassification,
         }
         if is_tf_available()
         else {}
     )
     lowerCamelCase__				:			List[str]												=     False
     lowerCamelCase__				:			Dict												=     False
  
  
  
     def 				_UpperCAmelCase				(       self )							->					Any:
  
  
  
  
  
  
       """simple docstring"""
  
  
  
  
  
  
       a__						=TFMPNetModelTester(self )
       a__						=ConfigTester(self,					config_class=lowercase_,					hidden_size=37 )
  
  
  
     def 				_UpperCAmelCase				(       self )							->					int:
  
  
  
  
  
  
       """simple docstring"""
  
  
  
  
  
  
       self.config_tester.run_common_tests()
  
  
  
     def 				_UpperCAmelCase				(       self )							->					Tuple:
  
  
  
  
  
  
       """simple docstring"""
  
  
  
  
  
  
       a__						=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_model(*lowercase_ )
  
  
  
     def 				_UpperCAmelCase				(       self )							->					Any:
  
  
  
  
  
  
       """simple docstring"""
  
  
  
  
  
  
       a__						=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_for_masked_lm(*lowercase_ )
  
  
  
     def 				_UpperCAmelCase				(       self )							->					Tuple:
  
  
  
  
  
  
       """simple docstring"""
  
  
  
  
  
  
       a__						=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_for_question_answering(*lowercase_ )
  
  
  
     def 				_UpperCAmelCase				(       self )							->					Union[str, Any]:
  
  
  
  
  
  
       """simple docstring"""
  
  
  
  
  
  
       a__						=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_for_sequence_classification(*lowercase_ )
  
  
  
     def 				_UpperCAmelCase				(       self )							->					List[str]:
  
  
  
  
  
  
       """simple docstring"""
  
  
  
  
  
  
       a__						=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_for_multiple_choice(*lowercase_ )
  
  
  
     def 				_UpperCAmelCase				(       self )							->					List[Any]:
  
  
  
  
  
  
       """simple docstring"""
  
  
  
  
  
  
       a__						=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_for_token_classification(*lowercase_ )
  
  
  
     @slow
     def 				_UpperCAmelCase				(       self )							->					List[Any]:
  
  
  
  
  
  
       """simple docstring"""
  
  
  
  
  
  
       for model_name in ["microsoft/mpnet-base"]:
         a__						=TFMPNetModel.from_pretrained(lowercase_ )
         self.assertIsNotNone(lowercase_ )
  
  
  
  
  
  
  
  @require_tf
  class 		__magic_name__    (							unittest.TestCase							):
  
     '''simple docstring'''
  
  
  
  
     @slow
     def 				_UpperCAmelCase				(       self )							->					str:
  
  
  
  
  
  
       """simple docstring"""
  
  
  
  
  
  
       a__						=TFMPNetModel.from_pretrained('''microsoft/mpnet-base''' )
       a__						=tf.constant([[0, 1, 2, 3, 4, 5]] )
       a__						=model(lowercase_ )[0]
  
       a__						=[1, 6, 768]
       self.assertEqual(output.shape,					lowercase_ )
  
       a__						=tf.constant(
           [
               [
                   [-0.1067172, 0.08216473, 0.0024543],
                   [-0.03465879, 0.8354118, -0.03252288],
                   [-0.06569476, -0.12424111, -0.0494436],
               ]
           ] )
       tf.debugging.assert_near(output[:, :3, :3],					lowercase_,					atol=1E-4 )
  
style_context: 
  
  from typing import TYPE_CHECKING
  
  from ...utils import (
      OptionalDependencyNotAvailable,
      _LazyModule,
      is_tf_available,
      is_tokenizers_available,
      is_torch_available,
  )
  
  
  lowerCamelCase     =      {
      '''configuration_deberta_v2''': ['''DEBERTA_V2_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''DebertaV2Config''', '''DebertaV2OnnxConfig'''],
      '''tokenization_deberta_v2''': ['''DebertaV2Tokenizer'''],
  }
  
  try:
         if not is_tokenizers_available():
                raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
         pass
  else:
         lowerCamelCase     =      ['''DebertaV2TokenizerFast''']
  
  try:
         if not is_tf_available():
                raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
         pass
  else:
         lowerCamelCase     =      [
             '''TF_DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST''',
             '''TFDebertaV2ForMaskedLM''',
             '''TFDebertaV2ForQuestionAnswering''',
             '''TFDebertaV2ForSequenceClassification''',
             '''TFDebertaV2ForTokenClassification''',
             '''TFDebertaV2Model''',
             '''TFDebertaV2PreTrainedModel''',
         ]
  
  try:
         if not is_torch_available():
                raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
         pass
  else:
         lowerCamelCase     =      [
             '''DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST''',
             '''DebertaV2ForMaskedLM''',
             '''DebertaV2ForMultipleChoice''',
             '''DebertaV2ForQuestionAnswering''',
             '''DebertaV2ForSequenceClassification''',
             '''DebertaV2ForTokenClassification''',
             '''DebertaV2Model''',
             '''DebertaV2PreTrainedModel''',
         ]
  
  
  if TYPE_CHECKING:
         from .configuration_deberta_va import (
             DEBERTA_V2_PRETRAINED_CONFIG_ARCHIVE_MAP,
             DebertaVaConfig,
             DebertaVaOnnxConfig,
         )
         from .tokenization_deberta_va import DebertaVaTokenizer
  
         try:
                if not is_tokenizers_available():
                       raise OptionalDependencyNotAvailable()
         except OptionalDependencyNotAvailable:
                pass
         else:
                from .tokenization_deberta_va_fast import DebertaVaTokenizerFast
  
         try:
                if not is_tf_available():
                       raise OptionalDependencyNotAvailable()
         except OptionalDependencyNotAvailable:
                pass
         else:
                from .modeling_tf_deberta_va import (
                    TF_DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST,
                    TFDebertaVaForMaskedLM,
                    TFDebertaVaForQuestionAnswering,
                    TFDebertaVaForSequenceClassification,
                    TFDebertaVaForTokenClassification,
                    TFDebertaVaModel,
                    TFDebertaVaPreTrainedModel,
                )
  
         try:
                if not is_torch_available():
                       raise OptionalDependencyNotAvailable()
         except OptionalDependencyNotAvailable:
                pass
         else:
                from .modeling_deberta_va import (
                    DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST,
                    DebertaVaForMaskedLM,
                    DebertaVaForMultipleChoice,
                    DebertaVaForQuestionAnswering,
                    DebertaVaForSequenceClassification,
                    DebertaVaForTokenClassification,
                    DebertaVaModel,
                    DebertaVaPreTrainedModel,
                )
  
  else:
         import sys
  
         lowerCamelCase     =      _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)
  