
"""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 		lowerCamelCase__					:





			'''simple docstring'''



			def __init__(							self     ,     __UpperCAmelCase     ,     __UpperCAmelCase=13     ,     __UpperCAmelCase=7     ,     __UpperCAmelCase=True     ,     __UpperCAmelCase=True     ,     __UpperCAmelCase=False     ,     __UpperCAmelCase=True     ,     __UpperCAmelCase=99     ,     __UpperCAmelCase=64     ,     __UpperCAmelCase=2     ,     __UpperCAmelCase=4     ,     __UpperCAmelCase=64     ,     __UpperCAmelCase="gelu"     ,     __UpperCAmelCase=0.1     ,     __UpperCAmelCase=0.1     ,     __UpperCAmelCase=5_12     ,     __UpperCAmelCase=16     ,     __UpperCAmelCase=2     ,     __UpperCAmelCase=0.0_2     ,     __UpperCAmelCase=3     ,     __UpperCAmelCase=4     ,     __UpperCAmelCase=None     ,     ) ->     Optional[Any]:
				_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 					_lowerCAmelCase		(							self  ) ->     Tuple:
				_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								=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 					_lowerCAmelCase		(							self     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase  ) ->     Optional[int]:
				_lowerCAmelCase								=TFMPNetModel(config=__UpperCAmelCase  )
				_lowerCAmelCase								={"""input_ids""": input_ids, """attention_mask""": input_mask}
				_lowerCAmelCase								=model(__UpperCAmelCase  )
				_lowerCAmelCase								=[input_ids, input_mask]
				_lowerCAmelCase								=model(__UpperCAmelCase  )
				self.parent.assertEqual(result.last_hidden_state.shape     ,     (self.batch_size, self.seq_length, self.hidden_size)  )



			def 					_lowerCAmelCase		(							self     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase  ) ->     List[Any]:
				_lowerCAmelCase								=TFMPNetForMaskedLM(config=__UpperCAmelCase  )
				_lowerCAmelCase								={"""input_ids""": input_ids, """attention_mask""": input_mask}
				_lowerCAmelCase								=model(__UpperCAmelCase  )
				self.parent.assertEqual(result.logits.shape     ,     (self.batch_size, self.seq_length, self.vocab_size)  )



			def 					_lowerCAmelCase		(							self     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase  ) ->     int:
				_lowerCAmelCase								=TFMPNetForQuestionAnswering(config=__UpperCAmelCase  )
				_lowerCAmelCase								={
				    """input_ids""": input_ids,
				    """attention_mask""": input_mask,
				}
				_lowerCAmelCase								=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 					_lowerCAmelCase		(							self     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase  ) ->     Optional[Any]:
				_lowerCAmelCase								=self.num_labels
				_lowerCAmelCase								=TFMPNetForSequenceClassification(__UpperCAmelCase  )
				_lowerCAmelCase								={"""input_ids""": input_ids, """attention_mask""": input_mask}
				_lowerCAmelCase								=model(__UpperCAmelCase  )
				self.parent.assertEqual(result.logits.shape     ,     (self.batch_size, self.num_labels)  )



			def 					_lowerCAmelCase		(							self     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase  ) ->     Tuple:
				_lowerCAmelCase								=self.num_choices
				_lowerCAmelCase								=TFMPNetForMultipleChoice(__UpperCAmelCase  )
				_lowerCAmelCase								=tf.tile(tf.expand_dims(__UpperCAmelCase     ,     1  )     ,     (1, self.num_choices, 1)  )
				_lowerCAmelCase								=tf.tile(tf.expand_dims(__UpperCAmelCase     ,     1  )     ,     (1, self.num_choices, 1)  )
				_lowerCAmelCase								={
				    """input_ids""": multiple_choice_inputs_ids,
				    """attention_mask""": multiple_choice_input_mask,
				}
				_lowerCAmelCase								=model(__UpperCAmelCase  )
				self.parent.assertEqual(result.logits.shape     ,     (self.batch_size, self.num_choices)  )



			def 					_lowerCAmelCase		(							self     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase     ,     __UpperCAmelCase  ) ->     Tuple:
				_lowerCAmelCase								=self.num_labels
				_lowerCAmelCase								=TFMPNetForTokenClassification(__UpperCAmelCase  )
				_lowerCAmelCase								={"""input_ids""": input_ids, """attention_mask""": input_mask}
				_lowerCAmelCase								=model(__UpperCAmelCase  )
				self.parent.assertEqual(result.logits.shape     ,     (self.batch_size, self.seq_length, self.num_labels)  )



			def 					_lowerCAmelCase		(							self  ) ->     List[str]:
				_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_tf
class 		lowerCamelCase__					(					__magic_name__ ,	__magic_name__ ,	unittest.TestCase				):





			'''simple docstring'''
			lowerCamelCase  					=		(
			    (
			        TFMPNetForMaskedLM,
			        TFMPNetForMultipleChoice,
			        TFMPNetForQuestionAnswering,
			        TFMPNetForSequenceClassification,
			        TFMPNetForTokenClassification,
			        TFMPNetModel,
			    )
			    if is_tf_available()
			    else ()
			)
			lowerCamelCase  					=		(
			    {
			        '''feature-extraction''': TFMPNetModel,
			        '''fill-mask''': TFMPNetForMaskedLM,
			        '''question-answering''': TFMPNetForQuestionAnswering,
			        '''text-classification''': TFMPNetForSequenceClassification,
			        '''token-classification''': TFMPNetForTokenClassification,
			        '''zero-shot''': TFMPNetForSequenceClassification,
			    }
			    if is_tf_available()
			    else {}
			)
			lowerCamelCase  					=		False
			lowerCamelCase  					=		False



			def 					_lowerCAmelCase		(							self  ) ->     str:
				_lowerCAmelCase								=TFMPNetModelTester(self  )
				_lowerCAmelCase								=ConfigTester(self     ,     config_class=__UpperCAmelCase     ,     hidden_size=37  )



			def 					_lowerCAmelCase		(							self  ) ->     List[str]:
				self.config_tester.run_common_tests()



			def 					_lowerCAmelCase		(							self  ) ->     Union[str, Any]:
				_lowerCAmelCase								=self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mpnet_model(*__UpperCAmelCase  )



			def 					_lowerCAmelCase		(							self  ) ->     List[str]:
				_lowerCAmelCase								=self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mpnet_for_masked_lm(*__UpperCAmelCase  )



			def 					_lowerCAmelCase		(							self  ) ->     Dict:
				_lowerCAmelCase								=self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mpnet_for_question_answering(*__UpperCAmelCase  )



			def 					_lowerCAmelCase		(							self  ) ->     Optional[int]:
				_lowerCAmelCase								=self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mpnet_for_sequence_classification(*__UpperCAmelCase  )



			def 					_lowerCAmelCase		(							self  ) ->     int:
				_lowerCAmelCase								=self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mpnet_for_multiple_choice(*__UpperCAmelCase  )



			def 					_lowerCAmelCase		(							self  ) ->     str:
				_lowerCAmelCase								=self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mpnet_for_token_classification(*__UpperCAmelCase  )



			@slow
			def 					_lowerCAmelCase		(							self  ) ->     Optional[Any]:
				for model_name in ["microsoft/mpnet-base"]:
					_lowerCAmelCase								=TFMPNetModel.from_pretrained(__UpperCAmelCase  )
					self.assertIsNotNone(__UpperCAmelCase  )







@require_tf
class 		lowerCamelCase__					(					unittest.TestCase				):





			'''simple docstring'''



			@slow
			def 					_lowerCAmelCase		(							self  ) ->     str:
				_lowerCAmelCase								=TFMPNetModel.from_pretrained("""microsoft/mpnet-base"""  )
				_lowerCAmelCase								=tf.constant([[0, 1, 2, 3, 4, 5]]  )
				_lowerCAmelCase								=model(__UpperCAmelCase  )[0]

				_lowerCAmelCase								=[1, 6, 7_68]
				self.assertEqual(output.shape     ,     __UpperCAmelCase  )

				_lowerCAmelCase								=tf.constant(
				    [
				        [
				            [-0.1_0_6_7_1_7_2, 0.0_8_2_1_6_4_7_3, 0.0_0_2_4_5_4_3],
				            [-0.0_3_4_6_5_8_7_9, 0.8_3_5_4_1_1_8, -0.0_3_2_5_2_2_8_8],
				            [-0.0_6_5_6_9_4_7_6, -0.1_2_4_2_4_1_1_1, -0.0_4_9_4_4_3_6],
				        ]
				    ]  )
				tf.debugging.assert_near(output[:, :3, :3]     ,     __UpperCAmelCase     ,     atol=1e-4  )





"""simple docstring"""


import enum
import inspect
import warnings
from functools import wraps
from typing import Callable, Optional

from .logging import get_logger


__A       						=       set()
__A       						=       get_logger(__name__)



def     _lowerCamelCase(__UpperCamelCase = None       )				-> Optional[Any]:

	def decorator(__UpperCamelCase       ):
		global _emitted_deprecation_warnings

		if inspect.isclass(__UpperCamelCase       ):
			_lowerCAmelCase								=deprecated_class_or_function.__init__
			_lowerCAmelCase								=deprecated_class_or_function.__name__
		else:
			_lowerCAmelCase								=deprecated_class_or_function
			_lowerCAmelCase								=deprecated_function.__name__
			# Support deprecating __init__ class method: class name instead
			_lowerCAmelCase								=name if name != """__init__""" else deprecated_function.__qualname__.split("""."""       )[-2]

		_lowerCAmelCase								=(
		    F'''{name} is deprecated and will be removed in the next major version of datasets.''' + F''' {help_message}'''
		    if help_message
		    else """"""
		)

		@wraps(__UpperCamelCase       )
		def wrapper(*__UpperCamelCase    , **__UpperCamelCase       ):
			_lowerCAmelCase								=hash(__UpperCamelCase       )
			if func_hash not in _emitted_deprecation_warnings:
				warnings.warn(__UpperCamelCase    , category=__UpperCamelCase    , stacklevel=2       )
				_emitted_deprecation_warnings.add(__UpperCamelCase       )
			return deprecated_function(*__UpperCamelCase    , **__UpperCamelCase       )

		_lowerCAmelCase								="""deprecated"""

		if inspect.isclass(__UpperCamelCase       ):
			_lowerCAmelCase								=wrapper
			return deprecated_class_or_function
		else:
			return wrapper

	return decorator







class 		lowerCamelCase__					(					enum.EnumMeta				):





			'''simple docstring'''



			def __getattribute__(							cls     ,     __UpperCAmelCase  ) ->     Optional[int]:
				_lowerCAmelCase								=super().__getattribute__(__UpperCAmelCase  )
				if isinstance(__UpperCAmelCase     ,     enum.Enum  ) and obj._on_access:
					obj._on_access()
				return obj



			def __getitem__(							cls     ,     __UpperCAmelCase  ) ->     List[str]:
				_lowerCAmelCase								=super().__getitem__(__UpperCAmelCase  )
				if member._on_access:
					member._on_access()
				return member



			def __call__(							cls     ,     __UpperCAmelCase     ,     __UpperCAmelCase=None     ,     *, __UpperCAmelCase=None     ,     __UpperCAmelCase=None     ,     __UpperCAmelCase=None     ,     __UpperCAmelCase=1  ) ->     Optional[Any]:
				_lowerCAmelCase								=super().__call__(__UpperCAmelCase     ,     __UpperCAmelCase     ,     module=__UpperCAmelCase     ,     qualname=__UpperCAmelCase     ,     type=__UpperCAmelCase     ,     start=__UpperCAmelCase  )
				if isinstance(__UpperCAmelCase     ,     enum.Enum  ) and obj._on_access:
					obj._on_access()
				return obj







class 		lowerCamelCase__					(					enum.Enum ,	metaclass=__magic_name__				):





			'''simple docstring'''



			def __new__(							cls     ,     __UpperCAmelCase  ) ->     Optional[int]:
				_lowerCAmelCase								=object.__new__(cls  )
				_lowerCAmelCase								=value
				_lowerCAmelCase								=member.deprecate
				return member



			@property
			def 					_lowerCAmelCase		(							self  ) ->     List[Any]:
				return ""



			def 					_lowerCAmelCase		(							self  ) ->     Tuple:
				_lowerCAmelCase								=f''' {self.help_message}''' if self.help_message else """"""
				warnings.warn(
				    f'''\'{self.__objclass__.__name__}\' is deprecated and will be removed in the next major version of datasets.'''
				    + help_message     ,     __UpperCAmelCase     ,     stacklevel=3     ,     )



