



'''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					:						str  ,	UpperCamelCase_					:						Optional[int]  ,	UpperCamelCase_					:						Tuple=13  ,	UpperCamelCase_					:						str=7  ,	UpperCamelCase_					:						List[str]=True  ,	UpperCamelCase_					:						Optional[Any]=True  ,	UpperCamelCase_					:						List[str]=False  ,	UpperCamelCase_					:						List[str]=True  ,	UpperCamelCase_					:						Optional[Any]=99  ,	UpperCamelCase_					:						Dict=64  ,	UpperCamelCase_					:						Tuple=2  ,	UpperCamelCase_					:						Tuple=4  ,	UpperCamelCase_					:						int=64  ,	UpperCamelCase_					:						Union[str, Any]="gelu"  ,	UpperCamelCase_					:						Dict=0.1  ,	UpperCamelCase_					:						List[str]=0.1  ,	UpperCamelCase_					:						str=512  ,	UpperCamelCase_					:						Optional[int]=16  ,	UpperCamelCase_					:						List[Any]=2  ,	UpperCamelCase_					:						int=0.02  ,	UpperCamelCase_					:						int=3  ,	UpperCamelCase_					:						List[str]=4  ,	UpperCamelCase_					:						Union[str, Any]=None  ,	)	->							List[Any]:



						'''simple docstring'''





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




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



						'''simple docstring'''





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

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

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

						_lowercase       :							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     __UpperCAmelCase  (	self					:						int  ,	UpperCamelCase_					:						List[Any]  ,	UpperCamelCase_					:						Optional[Any]  ,	UpperCamelCase_					:						List[str]  ,	UpperCamelCase_					:						Tuple  ,	UpperCamelCase_					:						Any  ,	UpperCamelCase_					:						List[Any]       )	->							Dict:



						'''simple docstring'''





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




					def     __UpperCAmelCase  (	self					:						str  ,	UpperCamelCase_					:						int  ,	UpperCamelCase_					:						Any  ,	UpperCamelCase_					:						Any  ,	UpperCamelCase_					:						Dict  ,	UpperCamelCase_					:						List[str]  ,	UpperCamelCase_					:						Union[str, Any]       )	->							Tuple:



						'''simple docstring'''





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




					def     __UpperCAmelCase  (	self					:						Optional[Any]  ,	UpperCamelCase_					:						List[Any]  ,	UpperCamelCase_					:						Optional[Any]  ,	UpperCamelCase_					:						Optional[int]  ,	UpperCamelCase_					:						Dict  ,	UpperCamelCase_					:						Optional[int]  ,	UpperCamelCase_					:						Optional[int]       )	->							List[Any]:



						'''simple docstring'''





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



						'''simple docstring'''





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




					def     __UpperCAmelCase  (	self					:						Optional[Any]  ,	UpperCamelCase_					:						List[Any]  ,	UpperCamelCase_					:						str  ,	UpperCamelCase_					:						Optional[int]  ,	UpperCamelCase_					:						Optional[int]  ,	UpperCamelCase_					:						List[str]  ,	UpperCamelCase_					:						List[str]       )	->							Dict:



						'''simple docstring'''





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




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



						'''simple docstring'''





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




					def     __UpperCAmelCase  (	self					:						str       )	->							str:



						'''simple docstring'''





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






@require_tf
class 		lowerCamelCase__   (    A						, A						, 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     __UpperCAmelCase  (	self					:						Optional[Any]       )	->							Dict:



						'''simple docstring'''





						_lowercase       :							Dict  	=		TFMPNetModelTester(self       )
						_lowercase       :							Dict  	=		ConfigTester(self  ,	config_class=UpperCamelCase_  ,	hidden_size=37       )




					def     __UpperCAmelCase  (	self					:						Any       )	->							Dict:



						'''simple docstring'''





						self.config_tester.run_common_tests()




					def     __UpperCAmelCase  (	self					:						Dict       )	->							List[Any]:



						'''simple docstring'''





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




					def     __UpperCAmelCase  (	self					:						Dict       )	->							List[str]:



						'''simple docstring'''





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




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



						'''simple docstring'''





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




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



						'''simple docstring'''





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




					def     __UpperCAmelCase  (	self					:						List[str]       )	->							str:



						'''simple docstring'''





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




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



						'''simple docstring'''





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




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



						'''simple docstring'''





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






@require_tf
class 		lowerCamelCase__   (    unittest.TestCase  ):




					'''simple docstring'''



					@slow
					def     __UpperCAmelCase  (	self					:						Dict       )	->							int:



						'''simple docstring'''





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

						_lowercase       :							Tuple  	=		[1, 6, 768]
						self.assertEqual(output.shape  ,	UpperCamelCase_       )

						_lowercase       :							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



class 		lowerCamelCase__   :




					'''simple docstring'''



					def __init__(	self					:						str  ,	UpperCamelCase_					:						int       )	->							None:



						'''simple docstring'''





						_lowercase       :							Any  	=		value
						_lowercase       :							Node | None  	=		None
						_lowercase       :							Node | None  	=		None






class 		lowerCamelCase__   :




					'''simple docstring'''



					A_         =    42




					def __init__(	self					:						List[Any]       )	->							None:



						'''simple docstring'''





						_lowercase       :							Optional[int]  	=		0




					def     __UpperCAmelCase  (	self					:						str  ,	UpperCamelCase_					:						Node | None  ,	UpperCamelCase_					:						int       )	->							None:



						'''simple docstring'''





						if node is None:
							return

						if path_sum == self.target:
							self.paths += 1

						if node.left:
							self.depth_first_search(node.left  ,	path_sum + node.left.value       )
						if node.right:
							self.depth_first_search(node.right  ,	path_sum + node.right.value       )




					def     __UpperCAmelCase  (	self					:						Optional[int]  ,	UpperCamelCase_					:						Node | None  ,	UpperCamelCase_					:						int | None = None       )	->							int:



						'''simple docstring'''





						if node is None:
							return 0
						if target is not None:
							_lowercase       :							Union[str, Any]  	=		target

						self.depth_first_search(UpperCamelCase_  ,	node.value       )
						self.path_sum(node.left       )
						self.path_sum(node.right       )

						return self.paths


if __name__ == "__main__":
		import doctest

		doctest.testmod()
