

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







						def __init__(self     ,							UpperCAmelCase_     ,							UpperCAmelCase_=1_3     ,							UpperCAmelCase_=7     ,							UpperCAmelCase_=True     ,							UpperCAmelCase_=True     ,							UpperCAmelCase_=False     ,							UpperCAmelCase_=True     ,							UpperCAmelCase_=9_9     ,							UpperCAmelCase_=6_4     ,							UpperCAmelCase_=2     ,							UpperCAmelCase_=4     ,							UpperCAmelCase_=6_4     ,							UpperCAmelCase_="gelu"     ,							UpperCAmelCase_=0.1     ,							UpperCAmelCase_=0.1     ,							UpperCAmelCase_=5_1_2     ,							UpperCAmelCase_=1_6     ,							UpperCAmelCase_=2     ,							UpperCAmelCase_=0.0_2     ,							UpperCAmelCase_=3     ,							UpperCAmelCase_=4     ,							UpperCAmelCase_=None     ,							)			->						Dict:
											__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        _UpperCamelCase    (self							)			->						Optional[Any]:
											__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        _UpperCamelCase    (self     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_							)			->						Union[str, Any]:
											__lowercase												=			TFMPNetModel(config=snake_case_							)
											__lowercase												=			{'''input_ids''': input_ids, '''attention_mask''': input_mask}
											__lowercase												=			model(snake_case_							)
											__lowercase												=			[input_ids, input_mask]
											__lowercase												=			model(snake_case_							)
											self.parent.assertEqual(result.last_hidden_state.shape     ,							(self.batch_size, self.seq_length, self.hidden_size)							)







						def        _UpperCamelCase    (self     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_							)			->						int:
											__lowercase												=			TFMPNetForMaskedLM(config=snake_case_							)
											__lowercase												=			{'''input_ids''': input_ids, '''attention_mask''': input_mask}
											__lowercase												=			model(snake_case_							)
											self.parent.assertEqual(result.logits.shape     ,							(self.batch_size, self.seq_length, self.vocab_size)							)







						def        _UpperCamelCase    (self     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_							)			->						str:
											__lowercase												=			TFMPNetForQuestionAnswering(config=snake_case_							)
											__lowercase												=			{
											    '''input_ids''': input_ids,
											    '''attention_mask''': input_mask,
											}
											__lowercase												=			model(snake_case_							)
											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     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_							)			->						Optional[int]:
											__lowercase												=			self.num_labels
											__lowercase												=			TFMPNetForSequenceClassification(snake_case_							)
											__lowercase												=			{'''input_ids''': input_ids, '''attention_mask''': input_mask}
											__lowercase												=			model(snake_case_							)
											self.parent.assertEqual(result.logits.shape     ,							(self.batch_size, self.num_labels)							)







						def        _UpperCamelCase    (self     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_							)			->						Tuple:
											__lowercase												=			self.num_choices
											__lowercase												=			TFMPNetForMultipleChoice(snake_case_							)
											__lowercase												=			tf.tile(tf.expand_dims(snake_case_     ,							1							)     ,							(1, self.num_choices, 1)							)
											__lowercase												=			tf.tile(tf.expand_dims(snake_case_     ,							1							)     ,							(1, self.num_choices, 1)							)
											__lowercase												=			{
											    '''input_ids''': multiple_choice_inputs_ids,
											    '''attention_mask''': multiple_choice_input_mask,
											}
											__lowercase												=			model(snake_case_							)
											self.parent.assertEqual(result.logits.shape     ,							(self.batch_size, self.num_choices)							)







						def        _UpperCamelCase    (self     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_     ,							UpperCAmelCase_							)			->						List[Any]:
											__lowercase												=			self.num_labels
											__lowercase												=			TFMPNetForTokenClassification(snake_case_							)
											__lowercase												=			{'''input_ids''': input_ids, '''attention_mask''': input_mask}
											__lowercase												=			model(snake_case_							)
											self.parent.assertEqual(result.logits.shape     ,							(self.batch_size, self.seq_length, self.num_labels)							)







						def        _UpperCamelCase    (self							)			->						Tuple:
											__lowercase												=			self.prepare_config_and_inputs()
											(__lowercase)												=			config_and_inputs
											__lowercase												=			{'''input_ids''': input_ids, '''attention_mask''': input_mask}
											return config, inputs_dict



@require_tf
class 			_snake_case     (						UpperCamelCase__						,			UpperCamelCase__						,			unittest.TestCase       ):
						__snake_case 			=     (
						    (
						        TFMPNetForMaskedLM,
						        TFMPNetForMultipleChoice,
						        TFMPNetForQuestionAnswering,
						        TFMPNetForSequenceClassification,
						        TFMPNetForTokenClassification,
						        TFMPNetModel,
						    )
						    if is_tf_available()
						    else ()
						)
						__snake_case 			=     (
						    {
						        'feature-extraction': TFMPNetModel,
						        'fill-mask': TFMPNetForMaskedLM,
						        'question-answering': TFMPNetForQuestionAnswering,
						        'text-classification': TFMPNetForSequenceClassification,
						        'token-classification': TFMPNetForTokenClassification,
						        'zero-shot': TFMPNetForSequenceClassification,
						    }
						    if is_tf_available()
						    else {}
						)
						__snake_case 			=     False
						__snake_case 			=     False







						def        _UpperCamelCase    (self							)			->						str:
											__lowercase												=			TFMPNetModelTester(self							)
											__lowercase												=			ConfigTester(self     ,							config_class=snake_case_     ,							hidden_size=3_7							)







						def        _UpperCamelCase    (self							)			->						Any:
											self.config_tester.run_common_tests()







						def        _UpperCamelCase    (self							)			->						Optional[Any]:
											__lowercase												=			self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_mpnet_model(*snake_case_							)







						def        _UpperCamelCase    (self							)			->						Optional[Any]:
											__lowercase												=			self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_mpnet_for_masked_lm(*snake_case_							)







						def        _UpperCamelCase    (self							)			->						List[Any]:
											__lowercase												=			self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_mpnet_for_question_answering(*snake_case_							)







						def        _UpperCamelCase    (self							)			->						Dict:
											__lowercase												=			self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_mpnet_for_sequence_classification(*snake_case_							)







						def        _UpperCamelCase    (self							)			->						Any:
											__lowercase												=			self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_mpnet_for_multiple_choice(*snake_case_							)







						def        _UpperCamelCase    (self							)			->						Optional[int]:
											__lowercase												=			self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_mpnet_for_token_classification(*snake_case_							)







						@slow
						def        _UpperCamelCase    (self							)			->						List[str]:
											for model_name in ["microsoft/mpnet-base"]:
																__lowercase												=			TFMPNetModel.from_pretrained(snake_case_							)
																self.assertIsNotNone(snake_case_							)



@require_tf
class 			_snake_case     (						unittest.TestCase       ):







						@slow
						def        _UpperCamelCase    (self							)			->						Optional[int]:
											__lowercase												=			TFMPNetModel.from_pretrained('''microsoft/mpnet-base'''							)
											__lowercase												=			tf.constant([[0, 1, 2, 3, 4, 5]]							)
											__lowercase												=			model(snake_case_							)[0]

											__lowercase												=			[1, 6, 7_6_8]
											self.assertEqual(output.shape     ,							snake_case_							)

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


"""simple docstring"""

def 				__UpperCamelCase   (    a__: list ,	a__: list ,	a__: list ,	a__: int ,	a__: int			)				->			None:




					"""simple docstring"""



					if target == 0:
										answer.append(path.copy()			)
					else:
										for index in range(a__ ,	len(a__			)			):
															if target >= candidates[index]:
																				path.append(candidates[index]			)
																				backtrack(a__ ,	a__ ,	a__ ,	target - candidates[index] ,	a__			)
																				path.pop(len(a__			) - 1			)





def 				__UpperCamelCase   (    a__: list ,	a__: int			)				->			list:




					"""simple docstring"""



					__lowercase												=			[]  # type: list[int]
					__lowercase												=			[]  # type: list[int]
					backtrack(a__ ,	a__ ,	a__ ,	a__ ,	0			)
					return answer





def 				__UpperCamelCase   (    )				->			None:




					"""simple docstring"""



					print(combination_sum([-8, 2.3, 0] ,	1			)			)


if __name__ == "__main__":
							import doctest

							doctest.testmod()
							main()


