'''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     :						str							,							UpperCAmelCase_     :						Optional[int]							,							UpperCAmelCase_     :						Tuple=1_3							,							UpperCAmelCase_     :						str=7							,							UpperCAmelCase_     :						List[str]=True							,							UpperCAmelCase_     :						Optional[Any]=True							,							UpperCAmelCase_     :						List[str]=False							,							UpperCAmelCase_     :						List[str]=True							,							UpperCAmelCase_     :						Optional[Any]=9_9							,							UpperCAmelCase_     :						Dict=6_4							,							UpperCAmelCase_     :						Tuple=2							,							UpperCAmelCase_     :						Tuple=4							,							UpperCAmelCase_     :						int=6_4							,							UpperCAmelCase_     :						Union[str, Any]="gelu"							,							UpperCAmelCase_     :						Dict=0.1							,							UpperCAmelCase_     :						List[str]=0.1							,							UpperCAmelCase_     :						str=5_1_2							,							UpperCAmelCase_     :						Optional[int]=1_6							,							UpperCAmelCase_     :						List[Any]=2							,							UpperCAmelCase_     :						int=0.02							,							UpperCAmelCase_     :						int=3							,							UpperCAmelCase_     :						List[str]=4							,							UpperCAmelCase_     :						Union[str, Any]=None							,							):


         """simple docstring"""







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





    def    SCREAMING_SNAKE_CASE_     (					self     :						List[str]):


         """simple docstring"""







         a					:							str							= ids_tensor([self.batch_size, self.seq_length]							,							self.vocab_size)

         a					:							Optional[Any]							= None
         if self.use_input_mask:
              a					:							Any							= random_attention_mask([self.batch_size, self.seq_length])

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

         a					:							int							= 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    SCREAMING_SNAKE_CASE_     (					self     :						int							,							UpperCAmelCase_     :						List[Any]							,							UpperCAmelCase_     :						Optional[Any]							,							UpperCAmelCase_     :						List[str]							,							UpperCAmelCase_     :						Tuple							,							UpperCAmelCase_     :						Any							,							UpperCAmelCase_     :						List[Any]):


         """simple docstring"""







         a					:							List[Any]							= TFMPNetModel(config=UpperCamelCase_)
         a					:							int							= {'input_ids': input_ids, 'attention_mask': input_mask}
         a					:							Any							= model(UpperCamelCase_)
         a					:							Optional[int]							= [input_ids, input_mask]
         a					:							Optional[Any]							= model(UpperCamelCase_)
         self.parent.assertEqual(result.last_hidden_state.shape							,							(self.batch_size, self.seq_length, self.hidden_size))





    def    SCREAMING_SNAKE_CASE_     (					self     :						str							,							UpperCAmelCase_     :						int							,							UpperCAmelCase_     :						Any							,							UpperCAmelCase_     :						Any							,							UpperCAmelCase_     :						Dict							,							UpperCAmelCase_     :						List[str]							,							UpperCAmelCase_     :						Union[str, Any]):


         """simple docstring"""







         a					:							Tuple							= TFMPNetForMaskedLM(config=UpperCamelCase_)
         a					:							str							= {'input_ids': input_ids, 'attention_mask': input_mask}
         a					:							Tuple							= model(UpperCamelCase_)
         self.parent.assertEqual(result.logits.shape							,							(self.batch_size, self.seq_length, self.vocab_size))





    def    SCREAMING_SNAKE_CASE_     (					self     :						Optional[Any]							,							UpperCAmelCase_     :						List[Any]							,							UpperCAmelCase_     :						Optional[Any]							,							UpperCAmelCase_     :						Optional[int]							,							UpperCAmelCase_     :						Dict							,							UpperCAmelCase_     :						Optional[int]							,							UpperCAmelCase_     :						Optional[int]):


         """simple docstring"""







         a					:							Any							= TFMPNetForQuestionAnswering(config=UpperCamelCase_)
         a					:							List[Any]							= {
             'input_ids': input_ids,
             'attention_mask': input_mask,
         }
         a					:							Optional[int]							= model(UpperCamelCase_)
         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     :						Any							,							UpperCAmelCase_     :						List[Any]							,							UpperCAmelCase_     :						Optional[int]							,							UpperCAmelCase_     :						Optional[Any]							,							UpperCAmelCase_     :						Union[str, Any]							,							UpperCAmelCase_     :						Dict							,							UpperCAmelCase_     :						Optional[int]):


         """simple docstring"""







         a					:							List[Any]							= self.num_labels
         a					:							Optional[int]							= TFMPNetForSequenceClassification(UpperCamelCase_)
         a					:							Dict							= {'input_ids': input_ids, 'attention_mask': input_mask}
         a					:							List[str]							= model(UpperCamelCase_)
         self.parent.assertEqual(result.logits.shape							,							(self.batch_size, self.num_labels))





    def    SCREAMING_SNAKE_CASE_     (					self     :						Optional[Any]							,							UpperCAmelCase_     :						List[Any]							,							UpperCAmelCase_     :						str							,							UpperCAmelCase_     :						Optional[int]							,							UpperCAmelCase_     :						Optional[int]							,							UpperCAmelCase_     :						List[str]							,							UpperCAmelCase_     :						List[str]):


         """simple docstring"""







         a					:							Optional[int]							= self.num_choices
         a					:							Any							= TFMPNetForMultipleChoice(UpperCamelCase_)
         a					:							Optional[Any]							= tf.tile(tf.expand_dims(UpperCamelCase_							,							1)							,							(1, self.num_choices, 1))
         a					:							Tuple							= tf.tile(tf.expand_dims(UpperCamelCase_							,							1)							,							(1, self.num_choices, 1))
         a					:							str							= {
             'input_ids': multiple_choice_inputs_ids,
             'attention_mask': multiple_choice_input_mask,
         }
         a					:							Any							= model(UpperCamelCase_)
         self.parent.assertEqual(result.logits.shape							,							(self.batch_size, self.num_choices))





    def    SCREAMING_SNAKE_CASE_     (					self     :						List[Any]							,							UpperCAmelCase_     :						Tuple							,							UpperCAmelCase_     :						Optional[Any]							,							UpperCAmelCase_     :						Optional[int]							,							UpperCAmelCase_     :						Union[str, Any]							,							UpperCAmelCase_     :						Optional[Any]							,							UpperCAmelCase_     :						Tuple):


         """simple docstring"""







         a					:							List[str]							= self.num_labels
         a					:							Any							= TFMPNetForTokenClassification(UpperCamelCase_)
         a					:							Tuple							= {'input_ids': input_ids, 'attention_mask': input_mask}
         a					:							List[str]							= model(UpperCamelCase_)
         self.parent.assertEqual(result.logits.shape							,							(self.batch_size, self.seq_length, self.num_labels))







    def    SCREAMING_SNAKE_CASE_     (					self     :						str):


         """simple docstring"""







         a					:							Optional[Any]							= self.prepare_config_and_inputs()
         (a)					:							Union[str, Any]							= config_and_inputs
         a					:							Union[str, Any]							= {'input_ids': input_ids, 'attention_mask': input_mask}
         return config, inputs_dict






@require_tf
class   UpperCamelCase					(       a_    ,     a_    ,     unittest.TestCase       ):







    """simple docstring"""





    A     :    Any				=			(
        (
            TFMPNetForMaskedLM,
            TFMPNetForMultipleChoice,
            TFMPNetForQuestionAnswering,
            TFMPNetForSequenceClassification,
            TFMPNetForTokenClassification,
            TFMPNetModel,
        )
        if is_tf_available()
        else ()
    )
    A     :    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 {}
    )
    A     :    Optional[Any]				=			False
    A     :    Tuple				=			False





    def    SCREAMING_SNAKE_CASE_     (					self     :						Optional[Any]):


         """simple docstring"""







         a					:							Dict							= TFMPNetModelTester(self)
         a					:							Dict							= ConfigTester(self							,							config_class=UpperCamelCase_							,							hidden_size=3_7)





    def    SCREAMING_SNAKE_CASE_     (					self     :						Any):


         """simple docstring"""







         self.config_tester.run_common_tests()





    def    SCREAMING_SNAKE_CASE_     (					self     :						Dict):


         """simple docstring"""







         a					:							Any							= self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_mpnet_model(*UpperCamelCase_)





    def    SCREAMING_SNAKE_CASE_     (					self     :						Dict):


         """simple docstring"""







         a					:							Dict							= self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_mpnet_for_masked_lm(*UpperCamelCase_)





    def    SCREAMING_SNAKE_CASE_     (					self     :						int):


         """simple docstring"""







         a					:							Optional[Any]							= self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_mpnet_for_question_answering(*UpperCamelCase_)





    def    SCREAMING_SNAKE_CASE_     (					self     :						List[Any]):


         """simple docstring"""







         a					:							Any							= self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_mpnet_for_sequence_classification(*UpperCamelCase_)





    def    SCREAMING_SNAKE_CASE_     (					self     :						List[str]):


         """simple docstring"""







         a					:							Dict							= self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_mpnet_for_multiple_choice(*UpperCamelCase_)





    def    SCREAMING_SNAKE_CASE_     (					self     :						int):


         """simple docstring"""







         a					:							List[str]							= self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_mpnet_for_token_classification(*UpperCamelCase_)







    @slow
    def    SCREAMING_SNAKE_CASE_     (					self     :						Union[str, Any]):


         """simple docstring"""







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






@require_tf
class   UpperCamelCase					(       unittest.TestCase       ):







    """simple docstring"""





    @slow
    def    SCREAMING_SNAKE_CASE_     (					self     :						Dict):


         """simple docstring"""







         a					:							List[str]							= TFMPNetModel.from_pretrained('microsoft/mpnet-base')
         a					:							Union[str, Any]							= tf.constant([[0, 1, 2, 3, 4, 5]])
         a					:							List[str]							= model(UpperCamelCase_)[0]

         a					:							Tuple							= [1, 6, 7_6_8]
         self.assertEqual(output.shape							,							UpperCamelCase_)

         a					:							str							= 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]							,							UpperCamelCase_							,							atol=1e-4)






'''simple docstring'''

from __future__ import annotations

_A					:     Union[str, Any]      ='''Alexander Joslin'''







def     __UpperCamelCase					(				_lowercase       )			->      int:

	if number <= 0:
		_lowercase       :							Optional[Any]  	=		f'''n must be greater than 0. Got n = {number}'''
		raise ValueError(_lowercase       )

	_lowercase       :							List[str]  	=		[number + 1] * (number + 1)

	# starting position
	_lowercase       :							str  	=		0
	for i in range(1,					_lowercase       ):
		_lowercase       :							Union[str, Any]  	=		min(table[i + 1],					table[i] + 1       )
		# check if out of bounds
		if i * 2 <= number:
			_lowercase       :							Optional[Any]  	=		min(table[i * 2],					table[i] + 1       )
		# check if out of bounds
		if i * 3 <= number:
			_lowercase       :							Any  	=		min(table[i * 3],					table[i] + 1       )
	return table[number]


if __name__ == "__main__":
		import doctest

		doctest.testmod()
