



"""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			:List[Any]       ,  lowercase_			:List[Any]       ,  lowercase_			:Any=13       ,  lowercase_			:Dict=7       ,  lowercase_			:List[Any]=True       ,  lowercase_			:Union[str, Any]=True       ,  lowercase_			:str=False       ,  lowercase_			:Optional[int]=True       ,  lowercase_			:Union[str, Any]=99       ,  lowercase_			:List[Any]=64       ,  lowercase_			:List[Any]=5       ,  lowercase_			:Dict=4       ,  lowercase_			:Union[str, Any]=64       ,  lowercase_			:str="gelu"       ,  lowercase_			:Any=0.1       ,  lowercase_			:List[str]=0.1       ,  lowercase_			:List[Any]=5_12       ,  lowercase_			:Tuple=16       ,  lowercase_			:Any=2       ,  lowercase_			:Union[str, Any]=0.02       ,  lowercase_			:Any=3       ,  lowercase_			:Tuple=4       ,  lowercase_			:int=None       ,  )    ->      Optional[Any]:
												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      UpperCAmelCase__					( self			:Tuple )    ->      List[str]:
												return MPNetConfig.from_pretrained('microsoft/mpnet-base' )






						def      UpperCAmelCase__					( self			:List[str] )    ->      Dict:
												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					=			self.get_config()
												return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels






						def      UpperCAmelCase__					( self			:Dict )    ->      int:
												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      UpperCAmelCase__					( self			:Any       ,  lowercase_			:Optional[int]       ,  lowercase_			:List[Any]       ,  lowercase_			:List[str]       ,  lowercase_			:List[Any]       ,  lowercase_			:List[str]       ,  lowercase_			:List[Any] )    ->      Any:
												UpperCAmelCase					=			MPNetModel(config=lowercase_ )
												model.to(lowercase_ )
												model.eval()
												UpperCAmelCase					=			model(lowercase_       ,  lowercase_ )
												UpperCAmelCase					=			model(lowercase_ )
												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      UpperCAmelCase__					( self			:Optional[Any]       ,  lowercase_			:Optional[Any]       ,  lowercase_			:Tuple       ,  lowercase_			:Any       ,  lowercase_			:List[Any]       ,  lowercase_			:int       ,  lowercase_			:Dict )    ->      Union[str, Any]:
												UpperCAmelCase					=			MPNetForQuestionAnswering(config=lowercase_ )
												model.to(lowercase_ )
												model.eval()
												UpperCAmelCase					=			model(
												    lowercase_       ,  attention_mask=lowercase_       ,  start_positions=lowercase_       ,  end_positions=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      UpperCAmelCase__					( self			:Union[str, Any]       ,  lowercase_			:List[Any]       ,  lowercase_			:str       ,  lowercase_			:Tuple       ,  lowercase_			:Optional[int]       ,  lowercase_			:Any       ,  lowercase_			:List[Any] )    ->      Tuple:
												UpperCAmelCase					=			self.num_labels
												UpperCAmelCase					=			MPNetForSequenceClassification(lowercase_ )
												model.to(lowercase_ )
												model.eval()
												UpperCAmelCase					=			model(lowercase_       ,  attention_mask=lowercase_       ,  labels=lowercase_ )
												self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.num_labels) )






						def      UpperCAmelCase__					( self			:Optional[int]       ,  lowercase_			:int       ,  lowercase_			:int       ,  lowercase_			:List[Any]       ,  lowercase_			:Tuple       ,  lowercase_			:int       ,  lowercase_			:List[str] )    ->      Optional[int]:
												UpperCAmelCase					=			self.num_choices
												UpperCAmelCase					=			MPNetForMultipleChoice(config=lowercase_ )
												model.to(lowercase_ )
												model.eval()
												UpperCAmelCase					=			input_ids.unsqueeze(1 ).expand(-1       ,  self.num_choices       ,  -1 ).contiguous()
												UpperCAmelCase					=			input_mask.unsqueeze(1 ).expand(-1       ,  self.num_choices       ,  -1 ).contiguous()
												UpperCAmelCase					=			model(
												    lowercase_       ,  attention_mask=lowercase_       ,  labels=lowercase_       ,  )
												self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.num_choices) )






						def      UpperCAmelCase__					( self			:int       ,  lowercase_			:Dict       ,  lowercase_			:List[Any]       ,  lowercase_			:Tuple       ,  lowercase_			:int       ,  lowercase_			:Any       ,  lowercase_			:List[str] )    ->      Optional[Any]:
												UpperCAmelCase					=			self.num_labels
												UpperCAmelCase					=			MPNetForTokenClassification(config=lowercase_ )
												model.to(lowercase_ )
												model.eval()
												UpperCAmelCase					=			model(lowercase_       ,  attention_mask=lowercase_       ,  labels=lowercase_ )
												self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.seq_length, self.num_labels) )






						def      UpperCAmelCase__					( self			:Union[str, Any] )    ->      List[str]:
												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_torch
class 				A_      (					SCREAMING_SNAKE_CASE_     ,       SCREAMING_SNAKE_CASE_     ,       unittest.TestCase    ):



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






						def      UpperCAmelCase__					( self			:int )    ->      Union[str, Any]:
												UpperCAmelCase					=			MPNetModelTester(self )
												UpperCAmelCase					=			ConfigTester(self       ,  config_class=lowercase_       ,  hidden_size=37 )






						def      UpperCAmelCase__					( self			:Optional[Any] )    ->      Any:
												self.config_tester.run_common_tests()






						def      UpperCAmelCase__					( self			:Union[str, Any] )    ->      str:
												UpperCAmelCase					=			self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_mpnet_model(*lowercase_ )






						def      UpperCAmelCase__					( self			:Any )    ->      Tuple:
												UpperCAmelCase					=			self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_mpnet_for_sequence_classification(*lowercase_ )






						def      UpperCAmelCase__					( self			:str )    ->      Optional[Any]:
												UpperCAmelCase					=			self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_mpnet_for_multiple_choice(*lowercase_ )






						def      UpperCAmelCase__					( self			:Tuple )    ->      int:
												UpperCAmelCase					=			self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_mpnet_for_token_classification(*lowercase_ )






						def      UpperCAmelCase__					( self			:Dict )    ->      Optional[int]:
												UpperCAmelCase					=			self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_mpnet_for_question_answering(*lowercase_ )







@require_torch
class 				A_      (					unittest.TestCase    ):



						"""simple docstring"""






						@slow
						def      UpperCAmelCase__					( self			:Optional[int] )    ->      List[Any]:
												UpperCAmelCase					=			MPNetModel.from_pretrained('microsoft/mpnet-base' )
												UpperCAmelCase					=			torch.tensor([[0, 3_45, 2_32, 3_28, 7_40, 1_40, 16_95, 69, 60_78, 15_88, 2]] )
												UpperCAmelCase					=			model(lowercase_ )[0]
												UpperCAmelCase					=			torch.Size((1, 11, 7_68) )
												self.assertEqual(output.shape       ,  lowercase_ )
												UpperCAmelCase					=			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]       ,  lowercase_       ,  atol=1E-4 ) )










"""simple docstring"""


import math

def 			_lowerCAmelCase				(       lowercase_						):
						assert isinstance(lowercase_		,     lowercase_						) and (
						    number >= 0
						), "'number' must been an int and positive"

						if 1 < number < 4:
												# 2 and 3 are primes
												return True
						elif number < 2 or not number % 2:
												# Negatives, 0, 1 and all even numbers are not primes
												return False

						UpperCAmelCase					=			range(3		,     int(math.sqrt(lowercase_						) + 1						)		,     2						)
						return not any(not number % i for i in odd_numbers						)






def 			_lowerCAmelCase				(       lowercase_		,     lowercase_=1		,     **lowercase_						):
						UpperCAmelCase					=			factor * value
						UpperCAmelCase					=			value

						while not is_prime(lowercase_						):
												value += 1 if not ("desc" in kwargs and kwargs["desc"] is True) else -1

						if value == first_value_val:
												return next_prime(value + 1		,     **lowercase_						)
						return value





