

import inspect
import unittest

from transformers import DataaVecVisionConfig
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
       import torch
       from torch import nn

       from transformers import (
           MODEL_MAPPING,
           DataaVecVisionForImageClassification,
           DataaVecVisionForSemanticSegmentation,
           DataaVecVisionModel,
       )
       from transformers.models.dataavec.modeling_dataavec_vision import DATA2VEC_VISION_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
       from PIL import Image

       from transformers import BeitImageProcessor
class 					A_   :


    '''simple docstring'''






    def __init__(self     ,      lowercase__     ,      lowercase__=100     ,      lowercase__=13     ,      lowercase__=30     ,      lowercase__=2     ,      lowercase__=3     ,      lowercase__=True     ,      lowercase__=True     ,      lowercase__=32     ,      lowercase__=4     ,      lowercase__=4     ,      lowercase__=37     ,      lowercase__="gelu"     ,      lowercase__=0.1     ,      lowercase__=0.1     ,      lowercase__=10     ,      lowercase__=0.02     ,      lowercase__=3     ,      lowercase__=None     ,      lowercase__=[0, 1, 2, 3]     ,      )     ->      Optional[int]:
        __UpperCAmelCase									=			parent
        __UpperCAmelCase									=			100
        __UpperCAmelCase									=			batch_size
        __UpperCAmelCase									=			image_size
        __UpperCAmelCase									=			patch_size
        __UpperCAmelCase									=			num_channels
        __UpperCAmelCase									=			is_training
        __UpperCAmelCase									=			use_labels
        __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									=			type_sequence_label_size
        __UpperCAmelCase									=			initializer_range
        __UpperCAmelCase									=			scope
        __UpperCAmelCase									=			out_indices
        __UpperCAmelCase									=			num_labels

        # in BeiT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
        __UpperCAmelCase									=			(image_size // patch_size) ** 2
        __UpperCAmelCase									=			num_patches + 1


    def      lowerCAmelCase_						(self  )     ->      Optional[int]:
        __UpperCAmelCase									=			floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]  )

        __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.image_size, self.image_size]     ,      self.num_labels  )

        __UpperCAmelCase									=			self.get_config()

        return config, pixel_values, labels, pixel_labels


    def      lowerCAmelCase_						(self  )     ->      Tuple:
        return DataaVecVisionConfig(
            vocab_size=self.vocab_size     ,      image_size=self.image_size     ,      patch_size=self.patch_size     ,      num_channels=self.num_channels     ,      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     ,      is_decoder=lowercase__     ,      initializer_range=self.initializer_range     ,      out_indices=self.out_indices     ,      )


    def      lowerCAmelCase_						(self     ,      lowercase__     ,      lowercase__     ,      lowercase__     ,      lowercase__  )     ->      str:
        __UpperCAmelCase									=			DataaVecVisionModel(config=lowercase__  )
        model.to(lowercase__  )
        model.eval()
        __UpperCAmelCase									=			model(lowercase__  )
        # expected sequence length = num_patches + 1 (we add 1 for the [CLS] token)
        __UpperCAmelCase									=			(self.image_size // self.patch_size) ** 2
        self.parent.assertEqual(result.last_hidden_state.shape     ,      (self.batch_size, num_patches + 1, self.hidden_size)  )


    def      lowerCAmelCase_						(self     ,      lowercase__     ,      lowercase__     ,      lowercase__     ,      lowercase__  )     ->      int:
        __UpperCAmelCase									=			self.type_sequence_label_size
        __UpperCAmelCase									=			DataaVecVisionForImageClassification(lowercase__  )
        model.to(lowercase__  )
        model.eval()
        __UpperCAmelCase									=			model(lowercase__     ,      labels=lowercase__  )
        self.parent.assertEqual(result.logits.shape     ,      (self.batch_size, self.type_sequence_label_size)  )


    def      lowerCAmelCase_						(self     ,      lowercase__     ,      lowercase__     ,      lowercase__     ,      lowercase__  )     ->      Optional[Any]:
        __UpperCAmelCase									=			self.num_labels
        __UpperCAmelCase									=			DataaVecVisionForSemanticSegmentation(lowercase__  )
        model.to(lowercase__  )
        model.eval()
        __UpperCAmelCase									=			model(lowercase__  )
        self.parent.assertEqual(
            result.logits.shape     ,      (self.batch_size, self.num_labels, self.image_size * 2, self.image_size * 2)  )
        __UpperCAmelCase									=			model(lowercase__     ,      labels=lowercase__  )
        self.parent.assertEqual(
            result.logits.shape     ,      (self.batch_size, self.num_labels, self.image_size * 2, self.image_size * 2)  )






    def      lowerCAmelCase_						(self  )     ->      Union[str, Any]:
        __UpperCAmelCase									=			self.prepare_config_and_inputs()
        __UpperCAmelCase					,     __UpperCAmelCase					,     __UpperCAmelCase					,     __UpperCAmelCase									=			config_and_inputs
        __UpperCAmelCase									=			{'''pixel_values''': pixel_values}
        return config, inputs_dict






@require_torch
class 					A_   (      _a ,     _a ,     unittest.TestCase						):


    '''simple docstring'''






    a__     							=       (
        (DataaVecVisionModel, DataaVecVisionForImageClassification, DataaVecVisionForSemanticSegmentation)
        if is_torch_available()
        else ()
    )
    a__     							=       (
        {
            "feature-extraction": DataaVecVisionModel,
            "image-classification": DataaVecVisionForImageClassification,
            "image-segmentation": DataaVecVisionForSemanticSegmentation,
        }
        if is_torch_available()
        else {}
    )

    a__     							=       False
    a__     							=       False
    a__     							=       False


    def      lowerCAmelCase_						(self  )     ->      int:
        __UpperCAmelCase									=			DataaVecVisionModelTester(self  )
        __UpperCAmelCase									=			ConfigTester(
            self     ,      config_class=lowercase__     ,      has_text_modality=lowercase__     ,      hidden_size=37  )


    def      lowerCAmelCase_						(self  )     ->      List[str]:
        self.config_tester.run_common_tests()


    def      lowerCAmelCase_						(self  )     ->      Any:
        # Data2VecVision does not use inputs_embeds
        pass


    @require_torch_multi_gpu
    @unittest.skip(
        reason='''Data2VecVision has some layers using `add_module` which doesn\'t work well with `nn.DataParallel`'''  )
    def      lowerCAmelCase_						(self  )     ->      Optional[Any]:
        pass


    def      lowerCAmelCase_						(self  )     ->      Optional[int]:
        __UpperCAmelCase					,     __UpperCAmelCase									=			self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
            __UpperCAmelCase									=			model_class(lowercase__  )
            self.assertIsInstance(model.get_input_embeddings()     ,      (nn.Module)  )
            __UpperCAmelCase									=			model.get_output_embeddings()
            self.assertTrue(x is None or isinstance(lowercase__     ,      nn.Linear  )  )


    def      lowerCAmelCase_						(self  )     ->      Dict:
        __UpperCAmelCase					,     __UpperCAmelCase									=			self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
            __UpperCAmelCase									=			model_class(lowercase__  )
            __UpperCAmelCase									=			inspect.signature(model.forward  )
            # signature.parameters is an OrderedDict => so arg_names order is deterministic
            __UpperCAmelCase									=			[*signature.parameters.keys()]

            __UpperCAmelCase									=			['''pixel_values''']
            self.assertListEqual(arg_names[:1]     ,      lowercase__  )


    def      lowerCAmelCase_						(self  )     ->      int:
        __UpperCAmelCase									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*lowercase__  )


    def      lowerCAmelCase_						(self  )     ->      Union[str, Any]:
        __UpperCAmelCase									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_image_segmentation(*lowercase__  )


    def      lowerCAmelCase_						(self  )     ->      Dict:
        if not self.model_tester.is_training:
            return

        __UpperCAmelCase					,     __UpperCAmelCase									=			self.model_tester.prepare_config_and_inputs_for_common()
        __UpperCAmelCase									=			True

        for model_class in self.all_model_classes:
            if model_class in [*get_values(lowercase__  )]:
                continue

            __UpperCAmelCase									=			model_class(lowercase__  )
            model.to(lowercase__  )
            model.train()
            __UpperCAmelCase									=			self._prepare_for_class(lowercase__     ,      lowercase__     ,      return_labels=lowercase__  )
            __UpperCAmelCase									=			model(**lowercase__  ).loss
            loss.backward()


    def      lowerCAmelCase_						(self  )     ->      Any:
        __UpperCAmelCase					,     __UpperCAmelCase									=			self.model_tester.prepare_config_and_inputs_for_common()
        if not self.model_tester.is_training:
            return

        __UpperCAmelCase									=			False
        __UpperCAmelCase									=			True

        for model_class in self.all_model_classes:
            if model_class in [*get_values(lowercase__  )] or not model_class.supports_gradient_checkpointing:
                continue
            # TODO: remove the following 3 lines once we have a MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING
            # this can then be incorporated into _prepare_for_class in test_modeling_common.py
            elif model_class.__name__ == "Data2VecVisionForSemanticSegmentation":
                __UpperCAmelCase					,     __UpperCAmelCase					,     __UpperCAmelCase					,     __UpperCAmelCase									=			inputs_dict['''pixel_values'''].shape
                __UpperCAmelCase									=			torch.zeros(
                    [self.model_tester.batch_size, height, width]     ,      device=lowercase__  ).long()
            __UpperCAmelCase									=			model_class(lowercase__  )
            model.gradient_checkpointing_enable()
            model.to(lowercase__  )
            model.train()
            __UpperCAmelCase									=			self._prepare_for_class(lowercase__     ,      lowercase__     ,      return_labels=lowercase__  )
            __UpperCAmelCase									=			model(**lowercase__  ).loss
            loss.backward()


    def      lowerCAmelCase_						(self  )     ->      List[Any]:
        __UpperCAmelCase					,     __UpperCAmelCase									=			self.model_tester.prepare_config_and_inputs_for_common()

        __UpperCAmelCase									=			_config_zero_init(lowercase__  )
        for model_class in self.all_model_classes:
            __UpperCAmelCase									=			model_class(config=lowercase__  )
            for name, param in model.named_parameters():
                # we skip lambda parameters as these require special initial values
                # determined by config.layer_scale_init_value
                if "lambda" in name:
                    continue
                if param.requires_grad:
                    self.assertIn(
                        ((param.data.mean() * 1E9).round() / 1E9).item()     ,      [0.0, 1.0]     ,      msg=F'''Parameter {name} of model {model_class} seems not properly initialized'''     ,      )


    def      lowerCAmelCase_						(self     ,      lowercase__     ,      lowercase__     ,      lowercase__     ,      lowercase__=2E-4     ,      lowercase__="outputs"     ,      lowercase__=None  )     ->      List[str]:
        # We override with a slightly higher tol value, as semseg models tend to diverge a bit more
        super().check_pt_tf_outputs(lowercase__     ,      lowercase__     ,      lowercase__     ,      lowercase__     ,      lowercase__     ,      lowercase__  )


    def      lowerCAmelCase_						(self  )     ->      List[Any]:
        __UpperCAmelCase									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_image_classification(*lowercase__  )






    @slow
    def      lowerCAmelCase_						(self  )     ->      Optional[Any]:
        for model_name in DATA2VEC_VISION_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
            __UpperCAmelCase									=			DataaVecVisionModel.from_pretrained(lowercase__  )
            self.assertIsNotNone(lowercase__  )






def       __a       (   )      ->     Union[str, Any]:






    '''simple docstring'''
    __UpperCAmelCase									=			Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''      )
    return image
@require_torch
@require_vision
class 					A_   (      unittest.TestCase						):


    '''simple docstring'''






    @cached_property
    def      lowerCAmelCase_						(self  )     ->      Optional[int]:
        return (
            BeitImageProcessor.from_pretrained('''facebook/data2vec-vision-base-ft1k'''  ) if is_vision_available() else None
        )






    @slow
    def      lowerCAmelCase_						(self  )     ->      Tuple:
        __UpperCAmelCase									=			DataaVecVisionForImageClassification.from_pretrained('''facebook/data2vec-vision-base-ft1k'''  ).to(
            lowercase__  )

        __UpperCAmelCase									=			self.default_image_processor
        __UpperCAmelCase									=			prepare_img()
        __UpperCAmelCase									=			image_processor(images=lowercase__     ,      return_tensors='''pt'''  ).to(lowercase__  )

        # forward pass
        with torch.no_grad():
            __UpperCAmelCase									=			model(**lowercase__  )
        __UpperCAmelCase									=			outputs.logits

        # verify the logits
        __UpperCAmelCase									=			torch.Size((1, 1_000)  )
        self.assertEqual(logits.shape     ,      lowercase__  )

        __UpperCAmelCase									=			torch.tensor([0.3277, -0.1395, 0.0911]  ).to(lowercase__  )

        self.assertTrue(torch.allclose(logits[0, :3]     ,      lowercase__     ,      atol=1E-4  )  )

        __UpperCAmelCase									=			[model.config.labelaid[i] for i in ['''remote control, remote''', '''tabby, tabby cat''']]
        self.assertEqual(logits[0].topk(2  ).indices.cpu().tolist()     ,      lowercase__  )








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


    '''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     ,      )     ->      Tuple:
        __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									=			scope


    def      lowerCAmelCase_						(self  )     ->      str:
        __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
        __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									=			ids_tensor([self.batch_size]     ,      self.num_choices  )

        __UpperCAmelCase									=			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      lowerCAmelCase_						(self     ,      lowercase__     ,      lowercase__     ,      lowercase__     ,      lowercase__     ,      lowercase__     ,      lowercase__  )     ->      List[Any]:
        __UpperCAmelCase									=			TFMPNetModel(config=lowercase__  )
        __UpperCAmelCase									=			{'''input_ids''': input_ids, '''attention_mask''': input_mask}
        __UpperCAmelCase									=			model(lowercase__  )
        __UpperCAmelCase									=			[input_ids, input_mask]
        __UpperCAmelCase									=			model(lowercase__  )
        self.parent.assertEqual(result.last_hidden_state.shape     ,      (self.batch_size, self.seq_length, self.hidden_size)  )


    def      lowerCAmelCase_						(self     ,      lowercase__     ,      lowercase__     ,      lowercase__     ,      lowercase__     ,      lowercase__     ,      lowercase__  )     ->      Dict:
        __UpperCAmelCase									=			TFMPNetForMaskedLM(config=lowercase__  )
        __UpperCAmelCase									=			{'''input_ids''': input_ids, '''attention_mask''': input_mask}
        __UpperCAmelCase									=			model(lowercase__  )
        self.parent.assertEqual(result.logits.shape     ,      (self.batch_size, self.seq_length, self.vocab_size)  )


    def      lowerCAmelCase_						(self     ,      lowercase__     ,      lowercase__     ,      lowercase__     ,      lowercase__     ,      lowercase__     ,      lowercase__  )     ->      List[Any]:
        __UpperCAmelCase									=			TFMPNetForQuestionAnswering(config=lowercase__  )
        __UpperCAmelCase									=			{
            '''input_ids''': input_ids,
            '''attention_mask''': input_mask,
        }
        __UpperCAmelCase									=			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      lowerCAmelCase_						(self     ,      lowercase__     ,      lowercase__     ,      lowercase__     ,      lowercase__     ,      lowercase__     ,      lowercase__  )     ->      str:
        __UpperCAmelCase									=			self.num_labels
        __UpperCAmelCase									=			TFMPNetForSequenceClassification(lowercase__  )
        __UpperCAmelCase									=			{'''input_ids''': input_ids, '''attention_mask''': input_mask}
        __UpperCAmelCase									=			model(lowercase__  )
        self.parent.assertEqual(result.logits.shape     ,      (self.batch_size, self.num_labels)  )


    def      lowerCAmelCase_						(self     ,      lowercase__     ,      lowercase__     ,      lowercase__     ,      lowercase__     ,      lowercase__     ,      lowercase__  )     ->      str:
        __UpperCAmelCase									=			self.num_choices
        __UpperCAmelCase									=			TFMPNetForMultipleChoice(lowercase__  )
        __UpperCAmelCase									=			tf.tile(tf.expand_dims(lowercase__     ,      1  )     ,      (1, self.num_choices, 1)  )
        __UpperCAmelCase									=			tf.tile(tf.expand_dims(lowercase__     ,      1  )     ,      (1, self.num_choices, 1)  )
        __UpperCAmelCase									=			{
            '''input_ids''': multiple_choice_inputs_ids,
            '''attention_mask''': multiple_choice_input_mask,
        }
        __UpperCAmelCase									=			model(lowercase__  )
        self.parent.assertEqual(result.logits.shape     ,      (self.batch_size, self.num_choices)  )


    def      lowerCAmelCase_						(self     ,      lowercase__     ,      lowercase__     ,      lowercase__     ,      lowercase__     ,      lowercase__     ,      lowercase__  )     ->      List[str]:
        __UpperCAmelCase									=			self.num_labels
        __UpperCAmelCase									=			TFMPNetForTokenClassification(lowercase__  )
        __UpperCAmelCase									=			{'''input_ids''': input_ids, '''attention_mask''': input_mask}
        __UpperCAmelCase									=			model(lowercase__  )
        self.parent.assertEqual(result.logits.shape     ,      (self.batch_size, self.seq_length, self.num_labels)  )






    def      lowerCAmelCase_						(self  )     ->      Optional[Any]:
        __UpperCAmelCase									=			self.prepare_config_and_inputs()
        ((__UpperCAmelCase)					,     (__UpperCAmelCase)					,     (__UpperCAmelCase)					,     (__UpperCAmelCase)					,     (__UpperCAmelCase)					,     (__UpperCAmelCase))									=			config_and_inputs
        __UpperCAmelCase									=			{'''input_ids''': input_ids, '''attention_mask''': input_mask}
        return config, inputs_dict






@require_tf
class 					A_   (      _a ,     _a ,     unittest.TestCase						):


    '''simple docstring'''






    a__     							=       (
        (
            TFMPNetForMaskedLM,
            TFMPNetForMultipleChoice,
            TFMPNetForQuestionAnswering,
            TFMPNetForSequenceClassification,
            TFMPNetForTokenClassification,
            TFMPNetModel,
        )
        if is_tf_available()
        else ()
    )
    a__     							=       (
        {
            "feature-extraction": TFMPNetModel,
            "fill-mask": TFMPNetForMaskedLM,
            "question-answering": TFMPNetForQuestionAnswering,
            "text-classification": TFMPNetForSequenceClassification,
            "token-classification": TFMPNetForTokenClassification,
            "zero-shot": TFMPNetForSequenceClassification,
        }
        if is_tf_available()
        else {}
    )
    a__     							=       False
    a__     							=       False


    def      lowerCAmelCase_						(self  )     ->      int:
        __UpperCAmelCase									=			TFMPNetModelTester(self  )
        __UpperCAmelCase									=			ConfigTester(self     ,      config_class=lowercase__     ,      hidden_size=37  )


    def      lowerCAmelCase_						(self  )     ->      Optional[int]:
        self.config_tester.run_common_tests()


    def      lowerCAmelCase_						(self  )     ->      Dict:
        __UpperCAmelCase									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_mpnet_model(*lowercase__  )


    def      lowerCAmelCase_						(self  )     ->      Any:
        __UpperCAmelCase									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_mpnet_for_masked_lm(*lowercase__  )


    def      lowerCAmelCase_						(self  )     ->      int:
        __UpperCAmelCase									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_mpnet_for_question_answering(*lowercase__  )


    def      lowerCAmelCase_						(self  )     ->      Optional[int]:
        __UpperCAmelCase									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_mpnet_for_sequence_classification(*lowercase__  )


    def      lowerCAmelCase_						(self  )     ->      str:
        __UpperCAmelCase									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_mpnet_for_multiple_choice(*lowercase__  )


    def      lowerCAmelCase_						(self  )     ->      str:
        __UpperCAmelCase									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_mpnet_for_token_classification(*lowercase__  )






    @slow
    def      lowerCAmelCase_						(self  )     ->      List[str]:
        for model_name in ["microsoft/mpnet-base"]:
            __UpperCAmelCase									=			TFMPNetModel.from_pretrained(lowercase__  )
            self.assertIsNotNone(lowercase__  )






@require_tf
class 					A_   (      unittest.TestCase						):


    '''simple docstring'''






    @slow
    def      lowerCAmelCase_						(self  )     ->      Any:
        __UpperCAmelCase									=			TFMPNetModel.from_pretrained('''microsoft/mpnet-base'''  )
        __UpperCAmelCase									=			tf.constant([[0, 1, 2, 3, 4, 5]]  )
        __UpperCAmelCase									=			model(lowercase__  )[0]

        __UpperCAmelCase									=			[1, 6, 768]
        self.assertEqual(output.shape     ,      lowercase__  )

        __UpperCAmelCase									=			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  )




