



'''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				,	lowerCAmelCase_				,	lowerCAmelCase_=1_3				,	lowerCAmelCase_=7				,	lowerCAmelCase_=True				,	lowerCAmelCase_=True				,	lowerCAmelCase_=False				,	lowerCAmelCase_=True				,	lowerCAmelCase_=9_9				,	lowerCAmelCase_=6_4				,	lowerCAmelCase_=2				,	lowerCAmelCase_=4				,	lowerCAmelCase_=6_4				,	lowerCAmelCase_="gelu"				,	lowerCAmelCase_=0.1				,	lowerCAmelCase_=0.1				,	lowerCAmelCase_=5_1_2				,	lowerCAmelCase_=1_6				,	lowerCAmelCase_=2				,	lowerCAmelCase_=0.0_2				,	lowerCAmelCase_=3				,	lowerCAmelCase_=4				,	lowerCAmelCase_=None				,	)			->   List[Any]:



      """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    lowercase_	( self)			->   str:



      """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    lowercase_	( self				,	lowerCAmelCase_				,	lowerCAmelCase_				,	lowerCAmelCase_				,	lowerCAmelCase_				,	lowerCAmelCase_				,	lowerCAmelCase_)			->   int:



      """simple docstring"""







      a_									=TFMPNetModel(config=lowerCAmelCase_)
      a_									={"input_ids": input_ids, "attention_mask": input_mask}
      a_									=model(lowerCAmelCase_)
      a_									=[input_ids, input_mask]
      a_									=model(lowerCAmelCase_)
      self.parent.assertEqual(result.last_hidden_state.shape				,	(self.batch_size, self.seq_length, self.hidden_size))




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



      """simple docstring"""







      a_									=TFMPNetForMaskedLM(config=lowerCAmelCase_)
      a_									={"input_ids": input_ids, "attention_mask": input_mask}
      a_									=model(lowerCAmelCase_)
      self.parent.assertEqual(result.logits.shape				,	(self.batch_size, self.seq_length, self.vocab_size))




 def    lowercase_	( self				,	lowerCAmelCase_				,	lowerCAmelCase_				,	lowerCAmelCase_				,	lowerCAmelCase_				,	lowerCAmelCase_				,	lowerCAmelCase_)			->   Union[str, Any]:



      """simple docstring"""







      a_									=TFMPNetForQuestionAnswering(config=lowerCAmelCase_)
      a_									={
          "input_ids": input_ids,
          "attention_mask": input_mask,
      }
      a_									=model(lowerCAmelCase_)
      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				,	lowerCAmelCase_				,	lowerCAmelCase_				,	lowerCAmelCase_				,	lowerCAmelCase_				,	lowerCAmelCase_				,	lowerCAmelCase_)			->   Tuple:



      """simple docstring"""







      a_									=self.num_labels
      a_									=TFMPNetForSequenceClassification(lowerCAmelCase_)
      a_									={"input_ids": input_ids, "attention_mask": input_mask}
      a_									=model(lowerCAmelCase_)
      self.parent.assertEqual(result.logits.shape				,	(self.batch_size, self.num_labels))




 def    lowercase_	( self				,	lowerCAmelCase_				,	lowerCAmelCase_				,	lowerCAmelCase_				,	lowerCAmelCase_				,	lowerCAmelCase_				,	lowerCAmelCase_)			->   int:



      """simple docstring"""







      a_									=self.num_choices
      a_									=TFMPNetForMultipleChoice(lowerCAmelCase_)
      a_									=tf.tile(tf.expand_dims(lowerCAmelCase_				,	1)				,	(1, self.num_choices, 1))
      a_									=tf.tile(tf.expand_dims(lowerCAmelCase_				,	1)				,	(1, self.num_choices, 1))
      a_									={
          "input_ids": multiple_choice_inputs_ids,
          "attention_mask": multiple_choice_input_mask,
      }
      a_									=model(lowerCAmelCase_)
      self.parent.assertEqual(result.logits.shape				,	(self.batch_size, self.num_choices))




 def    lowercase_	( self				,	lowerCAmelCase_				,	lowerCAmelCase_				,	lowerCAmelCase_				,	lowerCAmelCase_				,	lowerCAmelCase_				,	lowerCAmelCase_)			->   Tuple:



      """simple docstring"""







      a_									=self.num_labels
      a_									=TFMPNetForTokenClassification(lowerCAmelCase_)
      a_									={"input_ids": input_ids, "attention_mask": input_mask}
      a_									=model(lowerCAmelCase_)
      self.parent.assertEqual(result.logits.shape				,	(self.batch_size, self.seq_length, self.num_labels))




 def    lowercase_	( self)			->   Tuple:



      """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 						UpperCAmelCase						(		__a       ,						__a       ,						unittest.TestCase):


 '''simple docstring'''




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




 def    lowercase_	( self)			->   Tuple:



      """simple docstring"""







      a_									=TFMPNetModelTester(self)
      a_									=ConfigTester(self				,	config_class=lowerCAmelCase_				,	hidden_size=3_7)




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



      """simple docstring"""







      self.config_tester.run_common_tests()




 def    lowercase_	( self)			->   Tuple:



      """simple docstring"""







      a_									=self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_mpnet_model(*lowerCAmelCase_)




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



      """simple docstring"""







      a_									=self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_mpnet_for_masked_lm(*lowerCAmelCase_)




 def    lowercase_	( self)			->   Optional[Any]:



      """simple docstring"""







      a_									=self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_mpnet_for_question_answering(*lowerCAmelCase_)




 def    lowercase_	( self)			->   str:



      """simple docstring"""







      a_									=self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_mpnet_for_sequence_classification(*lowerCAmelCase_)




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



      """simple docstring"""







      a_									=self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_mpnet_for_multiple_choice(*lowerCAmelCase_)




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



      """simple docstring"""







      a_									=self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_mpnet_for_token_classification(*lowerCAmelCase_)




 @slow
 def    lowercase_	( self)			->   Optional[int]:



      """simple docstring"""







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







@require_tf
class 						UpperCAmelCase						(		unittest.TestCase):


 '''simple docstring'''




 @slow
 def    lowercase_	( self)			->   Union[str, Any]:



      """simple docstring"""







      a_									=TFMPNetModel.from_pretrained("microsoft/mpnet-base")
      a_									=tf.constant([[0, 1, 2, 3, 4, 5]])
      a_									=model(lowerCAmelCase_)[0]

      a_									=[1, 6, 7_6_8]
      self.assertEqual(output.shape				,	lowerCAmelCase_)

      a_									=tf.constant(
          [
              [
                  [-0.1_0_6_7_1_7_2, 0.0_8_2_1_6_4_7_3, 0.0_0_2_4_5_4_3],
                  [-0.0_3_4_6_5_8_7_9, 0.8_3_5_4_1_1_8, -0.0_3_2_5_2_2_8_8],
                  [-0.0_6_5_6_9_4_7_6, -0.1_2_4_2_4_1_1_1, -0.0_4_9_4_4_3_6],
              ]
          ])
      tf.debugging.assert_near(output[:, :3, :3]				,	lowerCAmelCase_				,	atol=1e-4)







'''simple docstring'''


from typing import TYPE_CHECKING

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


lowercase											=      {
    '''configuration_align''': [
        '''ALIGN_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''AlignConfig''',
        '''AlignTextConfig''',
        '''AlignVisionConfig''',
    ],
    '''processing_align''': ['''AlignProcessor'''],
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  lowercase											=      [
      '''ALIGN_PRETRAINED_MODEL_ARCHIVE_LIST''',
      '''AlignModel''',
      '''AlignPreTrainedModel''',
      '''AlignTextModel''',
      '''AlignVisionModel''',
  ]

if TYPE_CHECKING:
  from .configuration_align import (
      ALIGN_PRETRAINED_CONFIG_ARCHIVE_MAP,
      AlignConfig,
      AlignTextConfig,
      AlignVisionConfig,
  )
  from .processing_align import AlignProcessor

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_align import (
        ALIGN_PRETRAINED_MODEL_ARCHIVE_LIST,
        AlignModel,
        AlignPreTrainedModel,
        AlignTextModel,
        AlignVisionModel,
    )

else:
  import sys

  lowercase											=      _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)


