


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 							A					:
					'''simple docstring'''






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




							"""simple docstring"""


							lowercase__      =	parent
							lowercase__      =	batch_size
							lowercase__      =	seq_length
							lowercase__      =	is_training
							lowercase__      =	use_input_mask
							lowercase__      =	use_token_type_ids
							lowercase__      =	use_labels
							lowercase__      =	vocab_size
							lowercase__      =	hidden_size
							lowercase__      =	num_hidden_layers
							lowercase__      =	num_attention_heads
							lowercase__      =	intermediate_size
							lowercase__      =	hidden_act
							lowercase__      =	hidden_dropout_prob
							lowercase__      =	attention_probs_dropout_prob
							lowercase__      =	max_position_embeddings
							lowercase__      =	type_vocab_size
							lowercase__      =	type_sequence_label_size
							lowercase__      =	initializer_range
							lowercase__      =	num_labels
							lowercase__      =	num_choices
							lowercase__      =	scope

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




							"""simple docstring"""


							lowercase__      =	ids_tensor([self.batch_size, self.seq_length]   ,      self.vocab_size	)

							lowercase__      =	None
							if self.use_input_mask:
									lowercase__      =	random_attention_mask([self.batch_size, self.seq_length]	)

							lowercase__      =	None
							lowercase__      =	None
							lowercase__      =	None
							if self.use_labels:
									lowercase__      =	ids_tensor([self.batch_size]   ,      self.type_sequence_label_size	)
									lowercase__      =	ids_tensor([self.batch_size, self.seq_length]   ,      self.num_labels	)
									lowercase__      =	ids_tensor([self.batch_size]   ,      self.num_choices	)

							lowercase__      =	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					:		Tuple   ,      _UpperCAmelCase					:		List[str]   ,      _UpperCAmelCase					:		Optional[int]   ,      _UpperCAmelCase					:		str   ,      _UpperCAmelCase					:		List[str]   ,      _UpperCAmelCase					:		List[str]   ,      _UpperCAmelCase					:		int	)		->     Any:




							"""simple docstring"""


							lowercase__      =	TFMPNetModel(config=_UpperCAmelCase	)
							lowercase__      =	{"""input_ids""": input_ids, """attention_mask""": input_mask}
							lowercase__      =	model(_UpperCAmelCase	)
							lowercase__      =	[input_ids, input_mask]
							lowercase__      =	model(_UpperCAmelCase	)
							self.parent.assertEqual(result.last_hidden_state.shape   ,      (self.batch_size, self.seq_length, self.hidden_size)	)

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




							"""simple docstring"""


							lowercase__      =	TFMPNetForMaskedLM(config=_UpperCAmelCase	)
							lowercase__      =	{"""input_ids""": input_ids, """attention_mask""": input_mask}
							lowercase__      =	model(_UpperCAmelCase	)
							self.parent.assertEqual(result.logits.shape   ,      (self.batch_size, self.seq_length, self.vocab_size)	)

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




							"""simple docstring"""


							lowercase__      =	TFMPNetForQuestionAnswering(config=_UpperCAmelCase	)
							lowercase__      =	{
							    """input_ids""": input_ids,
							    """attention_mask""": input_mask,
							}
							lowercase__      =	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					:		Optional[int]   ,      _UpperCAmelCase					:		Dict   ,      _UpperCAmelCase					:		Any   ,      _UpperCAmelCase					:		Tuple   ,      _UpperCAmelCase					:		str   ,      _UpperCAmelCase					:		str   ,      _UpperCAmelCase					:		Dict	)		->     List[Any]:




							"""simple docstring"""


							lowercase__      =	self.num_labels
							lowercase__      =	TFMPNetForSequenceClassification(_UpperCAmelCase	)
							lowercase__      =	{"""input_ids""": input_ids, """attention_mask""": input_mask}
							lowercase__      =	model(_UpperCAmelCase	)
							self.parent.assertEqual(result.logits.shape   ,      (self.batch_size, self.num_labels)	)

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




							"""simple docstring"""


							lowercase__      =	self.num_choices
							lowercase__      =	TFMPNetForMultipleChoice(_UpperCAmelCase	)
							lowercase__      =	tf.tile(tf.expand_dims(_UpperCAmelCase   ,      1	)   ,      (1, self.num_choices, 1)	)
							lowercase__      =	tf.tile(tf.expand_dims(_UpperCAmelCase   ,      1	)   ,      (1, self.num_choices, 1)	)
							lowercase__      =	{
							    """input_ids""": multiple_choice_inputs_ids,
							    """attention_mask""": multiple_choice_input_mask,
							}
							lowercase__      =	model(_UpperCAmelCase	)
							self.parent.assertEqual(result.logits.shape   ,      (self.batch_size, self.num_choices)	)

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




							"""simple docstring"""


							lowercase__      =	self.num_labels
							lowercase__      =	TFMPNetForTokenClassification(_UpperCAmelCase	)
							lowercase__      =	{"""input_ids""": input_ids, """attention_mask""": input_mask}
							lowercase__      =	model(_UpperCAmelCase	)
							self.parent.assertEqual(result.logits.shape   ,      (self.batch_size, self.seq_length, self.num_labels)	)


					def 						lowerCamelCase__  (self					:		str	)		->     int:




							"""simple docstring"""


							lowercase__      =	self.prepare_config_and_inputs()
							((lowercase__)    ,			(lowercase__)    ,			(lowercase__)    ,			(lowercase__)    ,			(lowercase__)    ,			(lowercase__))      =	config_and_inputs
							lowercase__      =	{"""input_ids""": input_ids, """attention_mask""": input_mask}
							return config, inputs_dict






@require_tf
class 							A					( UpperCAmelCase__				,						UpperCAmelCase__				,						unittest.TestCase							):
					'''simple docstring'''






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

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




							"""simple docstring"""


							lowercase__      =	TFMPNetModelTester(self	)
							lowercase__      =	ConfigTester(self   ,      config_class=_UpperCAmelCase   ,      hidden_size=37	)

					def 						lowerCamelCase__  (self					:		Dict	)		->     Union[str, Any]:




							"""simple docstring"""


							self.config_tester.run_common_tests()

					def 						lowerCamelCase__  (self					:		str	)		->     Dict:




							"""simple docstring"""


							lowercase__      =	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mpnet_model(*_UpperCAmelCase	)

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




							"""simple docstring"""


							lowercase__      =	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mpnet_for_masked_lm(*_UpperCAmelCase	)

					def 						lowerCamelCase__  (self					:		Dict	)		->     Optional[Any]:




							"""simple docstring"""


							lowercase__      =	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mpnet_for_question_answering(*_UpperCAmelCase	)

					def 						lowerCamelCase__  (self					:		str	)		->     Dict:




							"""simple docstring"""


							lowercase__      =	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mpnet_for_sequence_classification(*_UpperCAmelCase	)

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




							"""simple docstring"""


							lowercase__      =	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mpnet_for_multiple_choice(*_UpperCAmelCase	)

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




							"""simple docstring"""


							lowercase__      =	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mpnet_for_token_classification(*_UpperCAmelCase	)


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




							"""simple docstring"""


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






@require_tf
class 							A					( unittest.TestCase							):
					'''simple docstring'''






					@slow
					def 						lowerCamelCase__  (self					:		Tuple	)		->     Tuple:




							"""simple docstring"""


							lowercase__      =	TFMPNetModel.from_pretrained("""microsoft/mpnet-base"""	)
							lowercase__      =	tf.constant([[0, 1, 2, 3, 4, 5]]	)
							lowercase__      =	model(_UpperCAmelCase	)[0]

							lowercase__      =	[1, 6, 768]
							self.assertEqual(output.shape   ,      _UpperCAmelCase	)

							lowercase__      =	tf.constant(
							    [
							        [
							            [-0.1_067_172, 0.08_216_473, 0.0_024_543],
							            [-0.03_465_879, 0.8_354_118, -0.03_252_288],
							            [-0.06_569_476, -0.12_424_111, -0.0_494_436],
							        ]
							    ]	)
							tf.debugging.assert_near(output[:, :3, :3]   ,      _UpperCAmelCase   ,      atol=1E-4	)





from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


A :	int												=     {
    'configuration_rwkv': ['RWKV_PRETRAINED_CONFIG_ARCHIVE_MAP', 'RwkvConfig', 'RwkvOnnxConfig'],
}

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	A :	List[Any]												=     [
	    'RWKV_PRETRAINED_MODEL_ARCHIVE_LIST',
	    'RwkvForCausalLM',
	    'RwkvModel',
	    'RwkvPreTrainedModel',
	]


if TYPE_CHECKING:
	from .configuration_rwkv import RWKV_PRETRAINED_CONFIG_ARCHIVE_MAP, RwkvConfig, RwkvOnnxConfig

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_rwkv import (
		    RWKV_PRETRAINED_MODEL_ARCHIVE_LIST,
		    RwkvForCausalLM,
		    RwkvModel,
		    RwkvPreTrainedModel,
		)
else:
	import sys

	A :	Optional[int]												=     _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)

