





"""simple docstring"""




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



      '''simple docstring'''

      def __init__(					self ,				snake_case_ ,				snake_case_=1_3 ,				snake_case_=7 ,				snake_case_=True ,				snake_case_=True ,				snake_case_=False ,				snake_case_=True ,				snake_case_=9_9 ,				snake_case_=6_4 ,				snake_case_=2 ,				snake_case_=4 ,				snake_case_=6_4 ,				snake_case_="gelu" ,				snake_case_=0.1 ,				snake_case_=0.1 ,				snake_case_=5_1_2 ,				snake_case_=1_6 ,				snake_case_=2 ,				snake_case_=0.02 ,				snake_case_=3 ,				snake_case_=4 ,				snake_case_=None ,				):

        """simple docstring"""

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

      def  lowerCamelCase_      (					self  ):

        """simple docstring"""

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

        A_  :	Any    						=  None
        if self.use_input_mask:
          A_  :	str    						=  random_attention_mask([self.batch_size, self.seq_length]  )

        A_  :	Optional[Any]    						=  None
        A_  :	Union[str, Any]    						=  None
        A_  :	Union[str, Any]    						=  None
        if self.use_labels:
          A_  :	List[Any]    						=  ids_tensor([self.batch_size] ,				self.type_sequence_label_size  )
          A_  :	Any    						=  ids_tensor([self.batch_size, self.seq_length] ,				self.num_labels  )
          A_  :	int    						=  ids_tensor([self.batch_size] ,				self.num_choices  )

        A_  :	Union[str, Any]    						=  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 ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_  ):

        """simple docstring"""

        A_  :	int    						=  TFMPNetModel(config=snake_case_  )
        A_  :	List[Any]    						=  {'input_ids': input_ids, 'attention_mask': input_mask}
        A_  :	Dict    						=  model(snake_case_  )
        A_  :	Optional[int]    						=  [input_ids, input_mask]
        A_  :	Optional[Any]    						=  model(snake_case_  )
        self.parent.assertEqual(result.last_hidden_state.shape ,				(self.batch_size, self.seq_length, self.hidden_size)  )

      def  lowerCamelCase_      (					self ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_  ):

        """simple docstring"""

        A_  :	List[Any]    						=  TFMPNetForMaskedLM(config=snake_case_  )
        A_  :	List[str]    						=  {'input_ids': input_ids, 'attention_mask': input_mask}
        A_  :	Union[str, Any]    						=  model(snake_case_  )
        self.parent.assertEqual(result.logits.shape ,				(self.batch_size, self.seq_length, self.vocab_size)  )

      def  lowerCamelCase_      (					self ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_  ):

        """simple docstring"""

        A_  :	List[Any]    						=  TFMPNetForQuestionAnswering(config=snake_case_  )
        A_  :	List[Any]    						=  {
            'input_ids': input_ids,
            'attention_mask': input_mask,
        }
        A_  :	Any    						=  model(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  lowerCamelCase_      (					self ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_  ):

        """simple docstring"""

        A_  :	Tuple    						=  self.num_labels
        A_  :	Union[str, Any]    						=  TFMPNetForSequenceClassification(snake_case_  )
        A_  :	Any    						=  {'input_ids': input_ids, 'attention_mask': input_mask}
        A_  :	Tuple    						=  model(snake_case_  )
        self.parent.assertEqual(result.logits.shape ,				(self.batch_size, self.num_labels)  )

      def  lowerCamelCase_      (					self ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_  ):

        """simple docstring"""

        A_  :	str    						=  self.num_choices
        A_  :	List[Any]    						=  TFMPNetForMultipleChoice(snake_case_  )
        A_  :	Dict    						=  tf.tile(tf.expand_dims(snake_case_ ,				1  ) ,				(1, self.num_choices, 1)  )
        A_  :	Dict    						=  tf.tile(tf.expand_dims(snake_case_ ,				1  ) ,				(1, self.num_choices, 1)  )
        A_  :	str    						=  {
            'input_ids': multiple_choice_inputs_ids,
            'attention_mask': multiple_choice_input_mask,
        }
        A_  :	Any    						=  model(snake_case_  )
        self.parent.assertEqual(result.logits.shape ,				(self.batch_size, self.num_choices)  )

      def  lowerCamelCase_      (					self ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_  ):

        """simple docstring"""

        A_  :	Any    						=  self.num_labels
        A_  :	str    						=  TFMPNetForTokenClassification(snake_case_  )
        A_  :	List[str]    						=  {'input_ids': input_ids, 'attention_mask': input_mask}
        A_  :	Any    						=  model(snake_case_  )
        self.parent.assertEqual(result.logits.shape ,				(self.batch_size, self.seq_length, self.num_labels)  )

      def  lowerCamelCase_      (					self  ):

        """simple docstring"""

        A_  :	Optional[Any]    						=  self.prepare_config_and_inputs()
        (A_)  :	List[Any]    						=  config_and_inputs
        A_  :	Dict    						=  {'input_ids': input_ids, 'attention_mask': input_mask}
        return config, inputs_dict


@require_tf
class 			_UpperCAmelCase  (       UpperCAmelCase__      ,       UpperCAmelCase__      ,       unittest.TestCase		):



      '''simple docstring'''
      lowercase_				:			Optional[Any]        =       (
          (
              TFMPNetForMaskedLM,
              TFMPNetForMultipleChoice,
              TFMPNetForQuestionAnswering,
              TFMPNetForSequenceClassification,
              TFMPNetForTokenClassification,
              TFMPNetModel,
          )
          if is_tf_available()
          else ()
      )
      lowercase_				:			str        =       (
          {
              """feature-extraction""": TFMPNetModel,
              """fill-mask""": TFMPNetForMaskedLM,
              """question-answering""": TFMPNetForQuestionAnswering,
              """text-classification""": TFMPNetForSequenceClassification,
              """token-classification""": TFMPNetForTokenClassification,
              """zero-shot""": TFMPNetForSequenceClassification,
          }
          if is_tf_available()
          else {}
      )
      lowercase_				:			int        =       False
      lowercase_				:			Any        =       False

      def  lowerCamelCase_      (					self  ):

        """simple docstring"""

        A_  :	int    						=  TFMPNetModelTester(self  )
        A_  :	List[Any]    						=  ConfigTester(self ,				config_class=snake_case_ ,				hidden_size=3_7  )

      def  lowerCamelCase_      (					self  ):

        """simple docstring"""

        self.config_tester.run_common_tests()

      def  lowerCamelCase_      (					self  ):

        """simple docstring"""

        A_  :	Tuple    						=  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_mpnet_model(*snake_case_  )

      def  lowerCamelCase_      (					self  ):

        """simple docstring"""

        A_  :	Union[str, Any]    						=  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_mpnet_for_masked_lm(*snake_case_  )

      def  lowerCamelCase_      (					self  ):

        """simple docstring"""

        A_  :	str    						=  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_mpnet_for_question_answering(*snake_case_  )

      def  lowerCamelCase_      (					self  ):

        """simple docstring"""

        A_  :	int    						=  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_mpnet_for_sequence_classification(*snake_case_  )

      def  lowerCamelCase_      (					self  ):

        """simple docstring"""

        A_  :	Dict    						=  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_mpnet_for_multiple_choice(*snake_case_  )

      def  lowerCamelCase_      (					self  ):

        """simple docstring"""

        A_  :	int    						=  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_mpnet_for_token_classification(*snake_case_  )

      @slow
      def  lowerCamelCase_      (					self  ):

        """simple docstring"""

        for model_name in ["microsoft/mpnet-base"]:
          A_  :	int    						=  TFMPNetModel.from_pretrained(snake_case_  )
          self.assertIsNotNone(snake_case_  )


@require_tf
class 			_UpperCAmelCase  (       unittest.TestCase		):



      '''simple docstring'''

      @slow
      def  lowerCamelCase_      (					self  ):

        """simple docstring"""

        A_  :	Optional[Any]    						=  TFMPNetModel.from_pretrained('microsoft/mpnet-base'  )
        A_  :	List[Any]    						=  tf.constant([[0, 1, 2, 3, 4, 5]]  )
        A_  :	Optional[int]    						=  model(snake_case_  )[0]

        A_  :	Optional[Any]    						=  [1, 6, 7_6_8]
        self.assertEqual(output.shape ,				snake_case_  )

        A_  :	Union[str, Any]    						=  tf.constant(
            [
                [
                    [-0.1_06_71_72, 0.08_21_64_73, 0.0_02_45_43],
                    [-0.03_46_58_79, 0.8_35_41_18, -0.03_25_22_88],
                    [-0.06_56_94_76, -0.12_42_41_11, -0.0_49_44_36],
                ]
            ]  )
        tf.debugging.assert_near(output[:, :3, :3] ,				snake_case_ ,				atol=1E-4  )






"""simple docstring"""




# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
    is_vision_available,
)


lowerCamelCase_					:						Any      = {
    'configuration_tvlt': ['TVLT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'TvltConfig'],
    'feature_extraction_tvlt': ['TvltFeatureExtractor'],
    'processing_tvlt': ['TvltProcessor'],
}

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   lowerCamelCase_					:						Union[str, Any]      = [
       'TVLT_PRETRAINED_MODEL_ARCHIVE_LIST',
       'TvltModel',
       'TvltForPreTraining',
       'TvltForAudioVisualClassification',
       'TvltPreTrainedModel',
   ]

try:
   if not is_vision_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   lowerCamelCase_					:						List[Any]      = ['TvltImageProcessor']


if TYPE_CHECKING:
   from .configuration_tvlt import TVLT_PRETRAINED_CONFIG_ARCHIVE_MAP, TvltConfig
   from .processing_tvlt import TvltProcessor
   from .feature_extraction_tvlt import TvltFeatureExtractor

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_tvlt import (
          TVLT_PRETRAINED_MODEL_ARCHIVE_LIST,
          TvltForAudioVisualClassification,
          TvltForPreTraining,
          TvltModel,
          TvltPreTrainedModel,
      )

   try:
      if not is_vision_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .image_processing_tvlt import TvltImageProcessor


else:
   import sys

   lowerCamelCase_					:						Optional[int]      = _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)