




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 :
						def __init__(     self				:Dict	, lowerCamelCase				:Tuple	, lowerCamelCase				:List[Any]=13	, lowerCamelCase				:Optional[Any]=7	, lowerCamelCase				:Optional[Any]=True	, lowerCamelCase				:List[Any]=True	, lowerCamelCase				:Union[str, Any]=False	, lowerCamelCase				:Optional[int]=True	, lowerCamelCase				:Tuple=99	, lowerCamelCase				:int=64	, lowerCamelCase				:int=2	, lowerCamelCase				:Tuple=4	, lowerCamelCase				:List[str]=64	, lowerCamelCase				:int="gelu"	, lowerCamelCase				:Dict=0.1	, lowerCamelCase				:Tuple=0.1	, lowerCamelCase				:Optional[Any]=512	, lowerCamelCase				:Optional[int]=16	, lowerCamelCase				:Any=2	, lowerCamelCase				:Optional[int]=0.02	, lowerCamelCase				:List[Any]=3	, lowerCamelCase				:Dict=4	, lowerCamelCase				:Tuple=None	, )       ->     List[str]:
							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				:Any )       ->     Union[str, Any]:
							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__								=  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 		UpperCAmelCase_  (     self				:Tuple	, lowerCamelCase				:Union[str, Any]	, lowerCamelCase				:Union[str, Any]	, lowerCamelCase				:List[Any]	, lowerCamelCase				:List[str]	, lowerCamelCase				:Any	, lowerCamelCase				:Dict )       ->     Optional[int]:
							UpperCAmelCase__								=  TFMPNetModel(config=_lowerCamelCase )
							UpperCAmelCase__								=  {"input_ids": input_ids, "attention_mask": input_mask}
							UpperCAmelCase__								=  model(_lowerCamelCase )
							UpperCAmelCase__								=  [input_ids, input_mask]
							UpperCAmelCase__								=  model(_lowerCamelCase )
							self.parent.assertEqual(result.last_hidden_state.shape	, (self.batch_size, self.seq_length, self.hidden_size) )
						def 		UpperCAmelCase_  (     self				:Dict	, lowerCamelCase				:Optional[int]	, lowerCamelCase				:Optional[int]	, lowerCamelCase				:Tuple	, lowerCamelCase				:Any	, lowerCamelCase				:int	, lowerCamelCase				:Union[str, Any] )       ->     int:
							UpperCAmelCase__								=  TFMPNetForMaskedLM(config=_lowerCamelCase )
							UpperCAmelCase__								=  {"input_ids": input_ids, "attention_mask": input_mask}
							UpperCAmelCase__								=  model(_lowerCamelCase )
							self.parent.assertEqual(result.logits.shape	, (self.batch_size, self.seq_length, self.vocab_size) )
						def 		UpperCAmelCase_  (     self				:Union[str, Any]	, lowerCamelCase				:Tuple	, lowerCamelCase				:int	, lowerCamelCase				:Any	, lowerCamelCase				:List[str]	, lowerCamelCase				:int	, lowerCamelCase				:Any )       ->     List[Any]:
							UpperCAmelCase__								=  TFMPNetForQuestionAnswering(config=_lowerCamelCase )
							UpperCAmelCase__								=  {
							    "input_ids": input_ids,
							    "attention_mask": input_mask,
							}
							UpperCAmelCase__								=  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 		UpperCAmelCase_  (     self				:Union[str, Any]	, lowerCamelCase				:Tuple	, lowerCamelCase				:Any	, lowerCamelCase				:Dict	, lowerCamelCase				:Optional[int]	, lowerCamelCase				:Dict	, lowerCamelCase				:str )       ->     Optional[Any]:
							UpperCAmelCase__								=  self.num_labels
							UpperCAmelCase__								=  TFMPNetForSequenceClassification(_lowerCamelCase )
							UpperCAmelCase__								=  {"input_ids": input_ids, "attention_mask": input_mask}
							UpperCAmelCase__								=  model(_lowerCamelCase )
							self.parent.assertEqual(result.logits.shape	, (self.batch_size, self.num_labels) )
						def 		UpperCAmelCase_  (     self				:int	, lowerCamelCase				:Union[str, Any]	, lowerCamelCase				:Optional[Any]	, lowerCamelCase				:Union[str, Any]	, lowerCamelCase				:List[str]	, lowerCamelCase				:Tuple	, lowerCamelCase				:List[Any] )       ->     Optional[int]:
							UpperCAmelCase__								=  self.num_choices
							UpperCAmelCase__								=  TFMPNetForMultipleChoice(_lowerCamelCase )
							UpperCAmelCase__								=  tf.tile(tf.expand_dims(_lowerCamelCase	, 1 )	, (1, self.num_choices, 1) )
							UpperCAmelCase__								=  tf.tile(tf.expand_dims(_lowerCamelCase	, 1 )	, (1, self.num_choices, 1) )
							UpperCAmelCase__								=  {
							    "input_ids": multiple_choice_inputs_ids,
							    "attention_mask": multiple_choice_input_mask,
							}
							UpperCAmelCase__								=  model(_lowerCamelCase )
							self.parent.assertEqual(result.logits.shape	, (self.batch_size, self.num_choices) )
						def 		UpperCAmelCase_  (     self				:List[str]	, lowerCamelCase				:Optional[int]	, lowerCamelCase				:Dict	, lowerCamelCase				:Dict	, lowerCamelCase				:Optional[int]	, lowerCamelCase				:Tuple	, lowerCamelCase				:Tuple )       ->     List[Any]:
							UpperCAmelCase__								=  self.num_labels
							UpperCAmelCase__								=  TFMPNetForTokenClassification(_lowerCamelCase )
							UpperCAmelCase__								=  {"input_ids": input_ids, "attention_mask": input_mask}
							UpperCAmelCase__								=  model(_lowerCamelCase )
							self.parent.assertEqual(result.logits.shape	, (self.batch_size, self.seq_length, self.num_labels) )







						def 		UpperCAmelCase_  (     self				:Tuple )       ->     int:
							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_tf
class      _UpperCamelCase (			_lowerCAmelCase		,    _lowerCAmelCase		,    unittest.TestCase						):
						UpperCAmelCase_            =						(
						    (
						        TFMPNetForMaskedLM,
						        TFMPNetForMultipleChoice,
						        TFMPNetForQuestionAnswering,
						        TFMPNetForSequenceClassification,
						        TFMPNetForTokenClassification,
						        TFMPNetModel,
						    )
						    if is_tf_available()
						    else ()
						)
						UpperCAmelCase_            =						(
						    {
						        "feature-extraction": TFMPNetModel,
						        "fill-mask": TFMPNetForMaskedLM,
						        "question-answering": TFMPNetForQuestionAnswering,
						        "text-classification": TFMPNetForSequenceClassification,
						        "token-classification": TFMPNetForTokenClassification,
						        "zero-shot": TFMPNetForSequenceClassification,
						    }
						    if is_tf_available()
						    else {}
						)
						UpperCAmelCase_            =						False
						UpperCAmelCase_            =						False
						def 		UpperCAmelCase_  (     self				:str )       ->     Tuple:
							UpperCAmelCase__								=  TFMPNetModelTester(self )
							UpperCAmelCase__								=  ConfigTester(self	, config_class=_lowerCamelCase	, hidden_size=37 )
						def 		UpperCAmelCase_  (     self				:Tuple )       ->     Dict:
							self.config_tester.run_common_tests()
						def 		UpperCAmelCase_  (     self				:Tuple )       ->     Dict:
							UpperCAmelCase__								=  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mpnet_model(*_lowerCamelCase )
						def 		UpperCAmelCase_  (     self				:List[str] )       ->     List[str]:
							UpperCAmelCase__								=  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mpnet_for_masked_lm(*_lowerCamelCase )
						def 		UpperCAmelCase_  (     self				:List[str] )       ->     str:
							UpperCAmelCase__								=  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mpnet_for_question_answering(*_lowerCamelCase )
						def 		UpperCAmelCase_  (     self				:str )       ->     Any:
							UpperCAmelCase__								=  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mpnet_for_sequence_classification(*_lowerCamelCase )
						def 		UpperCAmelCase_  (     self				:Tuple )       ->     Tuple:
							UpperCAmelCase__								=  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mpnet_for_multiple_choice(*_lowerCamelCase )
						def 		UpperCAmelCase_  (     self				:Tuple )       ->     str:
							UpperCAmelCase__								=  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mpnet_for_token_classification(*_lowerCamelCase )







						@slow
						def 		UpperCAmelCase_  (     self				:List[Any] )       ->     Tuple:
							for model_name in ["microsoft/mpnet-base"]:
								UpperCAmelCase__								=  TFMPNetModel.from_pretrained(_lowerCamelCase )
								self.assertIsNotNone(_lowerCamelCase )



@require_tf
class      _UpperCamelCase (			unittest.TestCase						):
						@slow
						def 		UpperCAmelCase_  (     self				:str )       ->     List[Any]:
							UpperCAmelCase__								=  TFMPNetModel.from_pretrained("microsoft/mpnet-base" )
							UpperCAmelCase__								=  tf.constant([[0, 1, 2, 3, 4, 5]] )
							UpperCAmelCase__								=  model(_lowerCamelCase )[0]

							UpperCAmelCase__								=  [1, 6, 768]
							self.assertEqual(output.shape	, _lowerCamelCase )

							UpperCAmelCase__								=  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]	, _lowerCamelCase	, atol=1e-4 )











def   lowerCAmelCase						(						_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				int		):




 """simple docstring"""







 if a < b:
  return gcd(_lowerCAmelCase  ,							_lowerCAmelCase		)
 if a % b == 0:
  return b
 return gcd(_lowerCAmelCase  ,							a % b		)



def   lowerCAmelCase						(						_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				int		):




 """simple docstring"""







 if y == 0:
  return 1
 UpperCAmelCase__								=  power(_lowerCAmelCase  ,							y // 2  ,							_lowerCAmelCase		) % mod
 UpperCAmelCase__								=  (temp * temp) % mod
 if y % 2 == 1:
  UpperCAmelCase__								=  (temp * x) % mod
 return temp



def   lowerCAmelCase						(						_lowerCAmelCase							:				int		):




 """simple docstring"""







 UpperCAmelCase__								=  2
 while b < n:
  if gcd(_lowerCAmelCase  ,							_lowerCAmelCase		) == 1 and power(_lowerCAmelCase  ,							n - 1  ,							_lowerCAmelCase		) != 1:
   return False
  b += 1
 return True


if __name__ == "__main__":
  _lowerCAmelCase  :				Dict						=				int(input("Enter number: ").strip())
  if is_carmichael_number(number):
    print(F'''{number} is a Carmichael Number.''')
  else:
    print(F'''{number} is not a Carmichael Number.''')





