



"""simple docstring"""






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




	'''simple docstring'''





	def __init__(  self:	Union[str, Any] ,    _SCREAMING_SNAKE_CASE:	Union[str, Any] ,    _SCREAMING_SNAKE_CASE:	Optional[Any]=13 ,    _SCREAMING_SNAKE_CASE:	Any=7 ,    _SCREAMING_SNAKE_CASE:	Any=True ,    _SCREAMING_SNAKE_CASE:	Dict=True ,    _SCREAMING_SNAKE_CASE:	Optional[int]=False ,    _SCREAMING_SNAKE_CASE:	List[str]=True ,    _SCREAMING_SNAKE_CASE:	str=99 ,    _SCREAMING_SNAKE_CASE:	Optional[int]=64 ,    _SCREAMING_SNAKE_CASE:	Optional[Any]=5 ,    _SCREAMING_SNAKE_CASE:	List[Any]=4 ,    _SCREAMING_SNAKE_CASE:	Optional[int]=64 ,    _SCREAMING_SNAKE_CASE:	Any="gelu" ,    _SCREAMING_SNAKE_CASE:	Optional[Any]=0.1 ,    _SCREAMING_SNAKE_CASE:	Union[str, Any]=0.1 ,    _SCREAMING_SNAKE_CASE:	int=512 ,    _SCREAMING_SNAKE_CASE:	List[str]=16 ,    _SCREAMING_SNAKE_CASE:	Union[str, Any]=2 ,    _SCREAMING_SNAKE_CASE:	str=0.02 ,    _SCREAMING_SNAKE_CASE:	Union[str, Any]=3 ,    _SCREAMING_SNAKE_CASE:	Any=4 ,    _SCREAMING_SNAKE_CASE:	Any=None ,    )       -> Optional[Any]:

				"""simple docstring"""

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

	def 							_SCREAMING_SNAKE_CASE     (  self:	Dict)       -> List[Any]:

				"""simple docstring"""

				return MPNetConfig.from_pretrained("microsoft/mpnet-base")

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

				"""simple docstring"""

				__lowerCAmelCase   :						Tuple				= ids_tensor([self.batch_size, self.seq_length] ,    self.vocab_size)

				__lowerCAmelCase   :						Optional[int]				= None
				if self.use_input_mask:
							__lowerCAmelCase   :						Dict				= random_attention_mask([self.batch_size, self.seq_length])

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

				__lowerCAmelCase   :						str				= self.get_config()
				return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels

	def 							_SCREAMING_SNAKE_CASE     (  self:	List[str])       -> Dict:

				"""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 							_SCREAMING_SNAKE_CASE     (  self:	str ,    _SCREAMING_SNAKE_CASE:	int ,    _SCREAMING_SNAKE_CASE:	str ,    _SCREAMING_SNAKE_CASE:	List[Any] ,    _SCREAMING_SNAKE_CASE:	Optional[Any] ,    _SCREAMING_SNAKE_CASE:	int ,    _SCREAMING_SNAKE_CASE:	Optional[int])       -> List[str]:

				"""simple docstring"""

				__lowerCAmelCase   :						Optional[int]				= MPNetModel(config=_SCREAMING_SNAKE_CASE)
				model.to(_SCREAMING_SNAKE_CASE)
				model.eval()
				__lowerCAmelCase   :						str				= model(_SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE)
				__lowerCAmelCase   :						Union[str, Any]				= model(_SCREAMING_SNAKE_CASE)
				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 							_SCREAMING_SNAKE_CASE     (  self:	List[str] ,    _SCREAMING_SNAKE_CASE:	Union[str, Any] ,    _SCREAMING_SNAKE_CASE:	List[str] ,    _SCREAMING_SNAKE_CASE:	int ,    _SCREAMING_SNAKE_CASE:	Union[str, Any] ,    _SCREAMING_SNAKE_CASE:	Dict ,    _SCREAMING_SNAKE_CASE:	int)       -> List[Any]:

				"""simple docstring"""

				__lowerCAmelCase   :						List[str]				= MPNetForQuestionAnswering(config=_SCREAMING_SNAKE_CASE)
				model.to(_SCREAMING_SNAKE_CASE)
				model.eval()
				__lowerCAmelCase   :						Tuple				= model(
				    _SCREAMING_SNAKE_CASE ,    attention_mask=_SCREAMING_SNAKE_CASE ,    start_positions=_SCREAMING_SNAKE_CASE ,    end_positions=_SCREAMING_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 							_SCREAMING_SNAKE_CASE     (  self:	Dict ,    _SCREAMING_SNAKE_CASE:	List[str] ,    _SCREAMING_SNAKE_CASE:	Optional[Any] ,    _SCREAMING_SNAKE_CASE:	int ,    _SCREAMING_SNAKE_CASE:	List[Any] ,    _SCREAMING_SNAKE_CASE:	Optional[int] ,    _SCREAMING_SNAKE_CASE:	Optional[Any])       -> Union[str, Any]:

				"""simple docstring"""

				__lowerCAmelCase   :						Dict				= self.num_labels
				__lowerCAmelCase   :						Optional[Any]				= MPNetForSequenceClassification(_SCREAMING_SNAKE_CASE)
				model.to(_SCREAMING_SNAKE_CASE)
				model.eval()
				__lowerCAmelCase   :						Union[str, Any]				= model(_SCREAMING_SNAKE_CASE ,    attention_mask=_SCREAMING_SNAKE_CASE ,    labels=_SCREAMING_SNAKE_CASE)
				self.parent.assertEqual(result.logits.shape ,    (self.batch_size, self.num_labels))

	def 							_SCREAMING_SNAKE_CASE     (  self:	Optional[Any] ,    _SCREAMING_SNAKE_CASE:	Any ,    _SCREAMING_SNAKE_CASE:	Union[str, Any] ,    _SCREAMING_SNAKE_CASE:	int ,    _SCREAMING_SNAKE_CASE:	Tuple ,    _SCREAMING_SNAKE_CASE:	Dict ,    _SCREAMING_SNAKE_CASE:	str)       -> List[str]:

				"""simple docstring"""

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

	def 							_SCREAMING_SNAKE_CASE     (  self:	Optional[int] ,    _SCREAMING_SNAKE_CASE:	Tuple ,    _SCREAMING_SNAKE_CASE:	Dict ,    _SCREAMING_SNAKE_CASE:	Dict ,    _SCREAMING_SNAKE_CASE:	Union[str, Any] ,    _SCREAMING_SNAKE_CASE:	Tuple ,    _SCREAMING_SNAKE_CASE:	int)       -> Tuple:

				"""simple docstring"""

				__lowerCAmelCase   :						Union[str, Any]				= self.num_labels
				__lowerCAmelCase   :						List[str]				= MPNetForTokenClassification(config=_SCREAMING_SNAKE_CASE)
				model.to(_SCREAMING_SNAKE_CASE)
				model.eval()
				__lowerCAmelCase   :						Dict				= model(_SCREAMING_SNAKE_CASE ,    attention_mask=_SCREAMING_SNAKE_CASE ,    labels=_SCREAMING_SNAKE_CASE)
				self.parent.assertEqual(result.logits.shape ,    (self.batch_size, self.seq_length, self.num_labels))







	def 							_SCREAMING_SNAKE_CASE     (  self:	Optional[int])       -> Any:

				"""simple docstring"""

				__lowerCAmelCase   :						Union[str, Any]				= self.prepare_config_and_inputs()
				((__lowerCAmelCase)		,			(__lowerCAmelCase)		,			(__lowerCAmelCase)		,			(__lowerCAmelCase)		,			(__lowerCAmelCase)		,			(__lowerCAmelCase))   :						Any				= config_and_inputs
				__lowerCAmelCase   :						Tuple				= {"input_ids": input_ids, "attention_mask": input_mask}
				return config, inputs_dict






@require_torch
class     A__     (						__SCREAMING_SNAKE_CASE						,	__SCREAMING_SNAKE_CASE						,	unittest.TestCase							):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE					   =			(
	    (
	        MPNetForMaskedLM,
	        MPNetForMultipleChoice,
	        MPNetForQuestionAnswering,
	        MPNetForSequenceClassification,
	        MPNetForTokenClassification,
	        MPNetModel,
	    )
	    if is_torch_available()
	    else ()
	)
	SCREAMING_SNAKE_CASE					   =			(
	    {
	        'feature-extraction': MPNetModel,
	        'fill-mask': MPNetForMaskedLM,
	        'question-answering': MPNetForQuestionAnswering,
	        'text-classification': MPNetForSequenceClassification,
	        'token-classification': MPNetForTokenClassification,
	        'zero-shot': MPNetForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)
	SCREAMING_SNAKE_CASE					   =			False
	SCREAMING_SNAKE_CASE					   =			True

	def 							_SCREAMING_SNAKE_CASE     (  self:	List[Any])       -> List[str]:

				"""simple docstring"""

				__lowerCAmelCase   :						List[str]				= MPNetModelTester(self)
				__lowerCAmelCase   :						int				= ConfigTester(self ,    config_class=_SCREAMING_SNAKE_CASE ,    hidden_size=37)

	def 							_SCREAMING_SNAKE_CASE     (  self:	Dict)       -> List[Any]:

				"""simple docstring"""

				self.config_tester.run_common_tests()

	def 							_SCREAMING_SNAKE_CASE     (  self:	int)       -> int:

				"""simple docstring"""

				__lowerCAmelCase   :						Tuple				= self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mpnet_model(*_SCREAMING_SNAKE_CASE)

	def 							_SCREAMING_SNAKE_CASE     (  self:	List[Any])       -> Optional[Any]:

				"""simple docstring"""

				__lowerCAmelCase   :						Tuple				= self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mpnet_for_sequence_classification(*_SCREAMING_SNAKE_CASE)

	def 							_SCREAMING_SNAKE_CASE     (  self:	Dict)       -> List[str]:

				"""simple docstring"""

				__lowerCAmelCase   :						Optional[int]				= self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mpnet_for_multiple_choice(*_SCREAMING_SNAKE_CASE)

	def 							_SCREAMING_SNAKE_CASE     (  self:	Optional[Any])       -> List[str]:

				"""simple docstring"""

				__lowerCAmelCase   :						List[Any]				= self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mpnet_for_token_classification(*_SCREAMING_SNAKE_CASE)







	def 							_SCREAMING_SNAKE_CASE     (  self:	List[Any])       -> str:

				"""simple docstring"""

				__lowerCAmelCase   :						Dict				= self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mpnet_for_question_answering(*_SCREAMING_SNAKE_CASE)






@require_torch
class     A__     (						unittest.TestCase							):




	'''simple docstring'''





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

				"""simple docstring"""

				__lowerCAmelCase   :						Dict				= MPNetModel.from_pretrained("microsoft/mpnet-base")
				__lowerCAmelCase   :						Any				= torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]])
				__lowerCAmelCase   :						Optional[int]				= model(_SCREAMING_SNAKE_CASE)[0]
				__lowerCAmelCase   :						List[Any]				= torch.Size((1, 11, 768))
				self.assertEqual(output.shape ,    _SCREAMING_SNAKE_CASE)
				__lowerCAmelCase   :						Any				= 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] ,    _SCREAMING_SNAKE_CASE ,    atol=1e-4))




"""simple docstring"""






from abc import ABC, abstractmethod
from argparse import ArgumentParser



class     A__     (						__SCREAMING_SNAKE_CASE							):




	'''simple docstring'''





	@staticmethod
	@abstractmethod
	def 							_SCREAMING_SNAKE_CASE     (  _SCREAMING_SNAKE_CASE:	ArgumentParser)       -> str:

				"""simple docstring"""

				raise NotImplementedError()







	@abstractmethod
	def 							_SCREAMING_SNAKE_CASE     (  self:	List[str])       -> str:

				"""simple docstring"""

				raise NotImplementedError()