




import unittest

from transformers import MPNetConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch

      from transformers import (
          MPNetForMaskedLM,
          MPNetForMultipleChoice,
          MPNetForQuestionAnswering,
          MPNetForSequenceClassification,
          MPNetForTokenClassification,
          MPNetModel,
      )





class     SCREAMING_SNAKE_CASE__		:
     def __init__(						self	:		Optional[Any]       ,						__lowerCamelCase	:		List[str]       ,						__lowerCamelCase	:		Union[str, Any]=13       ,						__lowerCamelCase	:		int=7       ,						__lowerCamelCase	:		Union[str, Any]=True       ,						__lowerCamelCase	:		int=True       ,						__lowerCamelCase	:		Dict=False       ,						__lowerCamelCase	:		str=True       ,						__lowerCamelCase	:		List[Any]=99       ,						__lowerCamelCase	:		Tuple=64       ,						__lowerCamelCase	:		List[str]=5       ,						__lowerCamelCase	:		List[Any]=4       ,						__lowerCamelCase	:		Tuple=64       ,						__lowerCamelCase	:		List[Any]="gelu"       ,						__lowerCamelCase	:		Tuple=0.1       ,						__lowerCamelCase	:		Optional[int]=0.1       ,						__lowerCamelCase	:		Any=5_12       ,						__lowerCamelCase	:		Optional[int]=16       ,						__lowerCamelCase	:		int=2       ,						__lowerCamelCase	:		Union[str, Any]=0.02       ,						__lowerCamelCase	:		Optional[int]=3       ,						__lowerCamelCase	:		Tuple=4       ,						__lowerCamelCase	:		Optional[int]=None       ,						):



       """simple docstring"""
       lowerCAmelCase__										=      parent
       lowerCAmelCase__										=      batch_size
       lowerCAmelCase__										=      seq_length
       lowerCAmelCase__										=      is_training
       lowerCAmelCase__										=      use_input_mask
       lowerCAmelCase__										=      use_token_type_ids
       lowerCAmelCase__										=      use_labels
       lowerCAmelCase__										=      vocab_size
       lowerCAmelCase__										=      hidden_size
       lowerCAmelCase__										=      num_hidden_layers
       lowerCAmelCase__										=      num_attention_heads
       lowerCAmelCase__										=      intermediate_size
       lowerCAmelCase__										=      hidden_act
       lowerCAmelCase__										=      hidden_dropout_prob
       lowerCAmelCase__										=      attention_probs_dropout_prob
       lowerCAmelCase__										=      max_position_embeddings
       lowerCAmelCase__										=      type_vocab_size
       lowerCAmelCase__										=      type_sequence_label_size
       lowerCAmelCase__										=      initializer_range
       lowerCAmelCase__										=      num_labels
       lowerCAmelCase__										=      num_choices
       lowerCAmelCase__										=      scope
     def        A__      (						self	:		Tuple						):



       """simple docstring"""
       return MPNetConfig.from_pretrained('''microsoft/mpnet-base'''						)
     def        A__      (						self	:		int						):



       """simple docstring"""
       lowerCAmelCase__										=      ids_tensor([self.batch_size, self.seq_length]       ,						self.vocab_size						)

       lowerCAmelCase__										=      None
       if self.use_input_mask:
         lowerCAmelCase__										=      random_attention_mask([self.batch_size, self.seq_length]						)

       lowerCAmelCase__										=      None
       lowerCAmelCase__										=      None
       lowerCAmelCase__										=      None
       if self.use_labels:
         lowerCAmelCase__										=      ids_tensor([self.batch_size]       ,						self.type_sequence_label_size						)
         lowerCAmelCase__										=      ids_tensor([self.batch_size, self.seq_length]       ,						self.num_labels						)
         lowerCAmelCase__										=      ids_tensor([self.batch_size]       ,						self.num_choices						)

       lowerCAmelCase__										=      self.get_config()
       return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels
     def        A__      (						self	:		Optional[int]						):



       """simple docstring"""
       return 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       ,						)
     def        A__      (						self	:		List[Any]       ,						__lowerCamelCase	:		List[Any]       ,						__lowerCamelCase	:		Any       ,						__lowerCamelCase	:		int       ,						__lowerCamelCase	:		Union[str, Any]       ,						__lowerCamelCase	:		Optional[int]       ,						__lowerCamelCase	:		Union[str, Any]						):



       """simple docstring"""
       lowerCAmelCase__										=      MPNetModel(config=__lowerCamelCase						)
       model.to(__lowerCamelCase						)
       model.eval()
       lowerCAmelCase__										=      model(__lowerCamelCase       ,						__lowerCamelCase						)
       lowerCAmelCase__										=      model(__lowerCamelCase						)
       self.parent.assertEqual(result.last_hidden_state.shape       ,						(self.batch_size, self.seq_length, self.hidden_size)						)
       self.parent.assertEqual(result.pooler_output.shape       ,						(self.batch_size, self.hidden_size)						)
     def        A__      (						self	:		Optional[int]       ,						__lowerCamelCase	:		str       ,						__lowerCamelCase	:		List[str]       ,						__lowerCamelCase	:		Optional[int]       ,						__lowerCamelCase	:		int       ,						__lowerCamelCase	:		Union[str, Any]       ,						__lowerCamelCase	:		Union[str, Any]						):



       """simple docstring"""
       lowerCAmelCase__										=      MPNetForQuestionAnswering(config=__lowerCamelCase						)
       model.to(__lowerCamelCase						)
       model.eval()
       lowerCAmelCase__										=      model(
           __lowerCamelCase       ,						attention_mask=__lowerCamelCase       ,						start_positions=__lowerCamelCase       ,						end_positions=__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        A__      (						self	:		Optional[int]       ,						__lowerCamelCase	:		Any       ,						__lowerCamelCase	:		Optional[int]       ,						__lowerCamelCase	:		Any       ,						__lowerCamelCase	:		Dict       ,						__lowerCamelCase	:		Tuple       ,						__lowerCamelCase	:		Union[str, Any]						):



       """simple docstring"""
       lowerCAmelCase__										=      self.num_labels
       lowerCAmelCase__										=      MPNetForSequenceClassification(__lowerCamelCase						)
       model.to(__lowerCamelCase						)
       model.eval()
       lowerCAmelCase__										=      model(__lowerCamelCase       ,						attention_mask=__lowerCamelCase       ,						labels=__lowerCamelCase						)
       self.parent.assertEqual(result.logits.shape       ,						(self.batch_size, self.num_labels)						)
     def        A__      (						self	:		Any       ,						__lowerCamelCase	:		List[str]       ,						__lowerCamelCase	:		Dict       ,						__lowerCamelCase	:		Union[str, Any]       ,						__lowerCamelCase	:		List[Any]       ,						__lowerCamelCase	:		Optional[Any]       ,						__lowerCamelCase	:		int						):



       """simple docstring"""
       lowerCAmelCase__										=      self.num_choices
       lowerCAmelCase__										=      MPNetForMultipleChoice(config=__lowerCamelCase						)
       model.to(__lowerCamelCase						)
       model.eval()
       lowerCAmelCase__										=      input_ids.unsqueeze(1						).expand(-1       ,						self.num_choices       ,						-1						).contiguous()
       lowerCAmelCase__										=      input_mask.unsqueeze(1						).expand(-1       ,						self.num_choices       ,						-1						).contiguous()
       lowerCAmelCase__										=      model(
           __lowerCamelCase       ,						attention_mask=__lowerCamelCase       ,						labels=__lowerCamelCase       ,						)
       self.parent.assertEqual(result.logits.shape       ,						(self.batch_size, self.num_choices)						)
     def        A__      (						self	:		Optional[Any]       ,						__lowerCamelCase	:		Optional[Any]       ,						__lowerCamelCase	:		Any       ,						__lowerCamelCase	:		Any       ,						__lowerCamelCase	:		int       ,						__lowerCamelCase	:		Union[str, Any]       ,						__lowerCamelCase	:		List[Any]						):



       """simple docstring"""
       lowerCAmelCase__										=      self.num_labels
       lowerCAmelCase__										=      MPNetForTokenClassification(config=__lowerCamelCase						)
       model.to(__lowerCamelCase						)
       model.eval()
       lowerCAmelCase__										=      model(__lowerCamelCase       ,						attention_mask=__lowerCamelCase       ,						labels=__lowerCamelCase						)
       self.parent.assertEqual(result.logits.shape       ,						(self.batch_size, self.seq_length, self.num_labels)						)



     def        A__      (						self	:		Any						):



       """simple docstring"""
       lowerCAmelCase__										=      self.prepare_config_and_inputs()
       ((lowerCAmelCase__)				,      (lowerCAmelCase__)				,      (lowerCAmelCase__)				,      (lowerCAmelCase__)				,      (lowerCAmelCase__)				,      (lowerCAmelCase__))										=      config_and_inputs
       lowerCAmelCase__										=      {'''input_ids''': input_ids, '''attention_mask''': input_mask}
       return config, inputs_dict





@require_torch
class     SCREAMING_SNAKE_CASE__		(_a    ,					_a    ,					unittest.TestCase			):
     lowercase_ :      Tuple				= (
         (
             MPNetForMaskedLM,
             MPNetForMultipleChoice,
             MPNetForQuestionAnswering,
             MPNetForSequenceClassification,
             MPNetForTokenClassification,
             MPNetModel,
         )
         if is_torch_available()
         else ()
     )
     lowercase_ :      Tuple				= (
         {
             "feature-extraction": MPNetModel,
             "fill-mask": MPNetForMaskedLM,
             "question-answering": MPNetForQuestionAnswering,
             "text-classification": MPNetForSequenceClassification,
             "token-classification": MPNetForTokenClassification,
             "zero-shot": MPNetForSequenceClassification,
         }
         if is_torch_available()
         else {}
     )
     lowercase_ :      int				= False
     lowercase_ :      Union[str, Any]				= True
     def        A__      (						self	:		List[Any]						):



       """simple docstring"""
       lowerCAmelCase__										=      MPNetModelTester(self						)
       lowerCAmelCase__										=      ConfigTester(self       ,						config_class=__lowerCamelCase       ,						hidden_size=37						)
     def        A__      (						self	:		List[str]						):



       """simple docstring"""
       self.config_tester.run_common_tests()
     def        A__      (						self	:		int						):



       """simple docstring"""
       lowerCAmelCase__										=      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_model(*__lowerCamelCase						)
     def        A__      (						self	:		Union[str, Any]						):



       """simple docstring"""
       lowerCAmelCase__										=      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_for_sequence_classification(*__lowerCamelCase						)
     def        A__      (						self	:		Tuple						):



       """simple docstring"""
       lowerCAmelCase__										=      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_for_multiple_choice(*__lowerCamelCase						)
     def        A__      (						self	:		Optional[int]						):



       """simple docstring"""
       lowerCAmelCase__										=      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_for_token_classification(*__lowerCamelCase						)



     def        A__      (						self	:		List[Any]						):



       """simple docstring"""
       lowerCAmelCase__										=      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_for_question_answering(*__lowerCamelCase						)





@require_torch
class     SCREAMING_SNAKE_CASE__		(unittest.TestCase			):
     @slow
     def        A__      (						self	:		Union[str, Any]						):



       """simple docstring"""
       lowerCAmelCase__										=      MPNetModel.from_pretrained('''microsoft/mpnet-base'''						)
       lowerCAmelCase__										=      torch.tensor([[0, 3_45, 2_32, 3_28, 7_40, 1_40, 16_95, 69, 60_78, 15_88, 2]]						)
       lowerCAmelCase__										=      model(__lowerCamelCase						)[0]
       lowerCAmelCase__										=      torch.Size((1, 11, 7_68)						)
       self.assertEqual(output.shape       ,						__lowerCamelCase						)
       lowerCAmelCase__										=      torch.tensor(
           [[[-0.0550, 0.1943, -0.0740], [-0.0562, 0.2211, -0.0579], [-0.0437, 0.3337, -0.0641]]]						)
       # compare the actual values for a slice.
       self.assertTrue(torch.allclose(output[:, :3, :3]       ,						__lowerCamelCase       ,						atol=1e-4						)						)







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


__magic_name__  :  Union[str, Any]					=       {
    """configuration_altclip""": [
        """ALTCLIP_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """AltCLIPConfig""",
        """AltCLIPTextConfig""",
        """AltCLIPVisionConfig""",
    ],
    """processing_altclip""": ["""AltCLIPProcessor"""],
}

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __magic_name__  :  str					=       [
          """ALTCLIP_PRETRAINED_MODEL_ARCHIVE_LIST""",
          """AltCLIPPreTrainedModel""",
          """AltCLIPModel""",
          """AltCLIPTextModel""",
          """AltCLIPVisionModel""",
      ]


if TYPE_CHECKING:
      from .configuration_altclip import (
          ALTCLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
          AltCLIPConfig,
          AltCLIPTextConfig,
          AltCLIPVisionConfig,
      )
      from .processing_altclip import AltCLIPProcessor

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_altclip import (
                ALTCLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
                AltCLIPModel,
                AltCLIPPreTrainedModel,
                AltCLIPTextModel,
                AltCLIPVisionModel,
            )


else:
      import sys

      __magic_name__  :  str					=       _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)

