


"""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							,			a_							,			a_=13							,			a_=7							,			a_=True							,			a_=True							,			a_=False							,			a_=True							,			a_=99							,			a_=64							,			a_=2							,			a_=4							,			a_=64							,			a_="gelu"							,			a_=0.1							,			a_=0.1							,			a_=5_12							,			a_=16							,			a_=2							,			a_=0.02							,			a_=3							,			a_=4							,			a_=None							,			):





			'''simple docstring'''

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



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			__snake_case      :		Any         =							ids_tensor([self.batch_size, self.seq_length]							,			self.vocab_size   )

			__snake_case      :		List[str]         =							None
			if self.use_input_mask:
				__snake_case      :		Any         =							random_attention_mask([self.batch_size, self.seq_length]   )

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

			__snake_case      :		Dict         =							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							,			a_							,			a_							,			a_							,			a_							,			a_							,			a_   ):





			'''simple docstring'''

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



		def 							SCREAMING_SNAKE_CASE    (self							,			a_							,			a_							,			a_							,			a_							,			a_							,			a_   ):





			'''simple docstring'''

			__snake_case      :		Optional[Any]         =							TFMPNetForMaskedLM(config=a_   )
			__snake_case      :		List[Any]         =							{'''input_ids''': input_ids, '''attention_mask''': input_mask}
			__snake_case      :		int         =							model(a_   )
			self.parent.assertEqual(result.logits.shape							,			(self.batch_size, self.seq_length, self.vocab_size)   )



		def 							SCREAMING_SNAKE_CASE    (self							,			a_							,			a_							,			a_							,			a_							,			a_							,			a_   ):





			'''simple docstring'''

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





			'''simple docstring'''

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



		def 							SCREAMING_SNAKE_CASE    (self							,			a_							,			a_							,			a_							,			a_							,			a_							,			a_   ):





			'''simple docstring'''

			__snake_case      :		Tuple         =							self.num_choices
			__snake_case      :		List[str]         =							TFMPNetForMultipleChoice(a_   )
			__snake_case      :		List[str]         =							tf.tile(tf.expand_dims(a_							,			1   )							,			(1, self.num_choices, 1)   )
			__snake_case      :		Tuple         =							tf.tile(tf.expand_dims(a_							,			1   )							,			(1, self.num_choices, 1)   )
			__snake_case      :		Tuple         =							{
			    '''input_ids''': multiple_choice_inputs_ids,
			    '''attention_mask''': multiple_choice_input_mask,
			}
			__snake_case      :		str         =							model(a_   )
			self.parent.assertEqual(result.logits.shape							,			(self.batch_size, self.num_choices)   )



		def 							SCREAMING_SNAKE_CASE    (self							,			a_							,			a_							,			a_							,			a_							,			a_							,			a_   ):





			'''simple docstring'''

			__snake_case      :		int         =							self.num_labels
			__snake_case      :		Tuple         =							TFMPNetForTokenClassification(a_   )
			__snake_case      :		Union[str, Any]         =							{'''input_ids''': input_ids, '''attention_mask''': input_mask}
			__snake_case      :		Optional[Any]         =							model(a_   )
			self.parent.assertEqual(result.logits.shape							,			(self.batch_size, self.seq_length, self.num_labels)   )



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

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



@require_tf
class      _UpperCAmelCase					(				__snake_case,							__snake_case,							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 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			__snake_case      :		Optional[int]         =							TFMPNetModelTester(self   )
			__snake_case      :		int         =							ConfigTester(self							,			config_class=a_							,			hidden_size=37   )



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			self.config_tester.run_common_tests()



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			__snake_case      :		Optional[int]         =							self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_mpnet_model(*a_   )



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			__snake_case      :		Optional[int]         =							self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_mpnet_for_masked_lm(*a_   )



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			__snake_case      :		Union[str, Any]         =							self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_mpnet_for_question_answering(*a_   )



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			__snake_case      :		Dict         =							self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_mpnet_for_sequence_classification(*a_   )



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			__snake_case      :		Dict         =							self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_mpnet_for_multiple_choice(*a_   )



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			__snake_case      :		Dict         =							self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_mpnet_for_token_classification(*a_   )



		@slow
		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

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



@require_tf
class      _UpperCAmelCase					(				unittest.TestCase							):






		'''simple docstring'''

		@slow
		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			__snake_case      :		Optional[int]         =							TFMPNetModel.from_pretrained('''microsoft/mpnet-base'''   )
			__snake_case      :		Tuple         =							tf.constant([[0, 1, 2, 3, 4, 5]]   )
			__snake_case      :		List[str]         =							model(a_   )[0]

			__snake_case      :		List[str]         =							[1, 6, 7_68]
			self.assertEqual(output.shape							,			a_   )

			__snake_case      :		Optional[int]         =							tf.constant(
			    [
			        [
			            [-0.106_7172, 0.0821_6473, 0.002_4543],
			            [-0.0346_5879, 0.835_4118, -0.0325_2288],
			            [-0.0656_9476, -0.1242_4111, -0.049_4436],
			        ]
			    ]   )
			tf.debugging.assert_near(output[:, :3, :3]							,			a_							,			atol=1E-4   )









"""simple docstring"""
from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


SCREAMING_SNAKE_CASE					:       Union[str, Any]							   =							{
    """configuration_bart""": ["""BART_PRETRAINED_CONFIG_ARCHIVE_MAP""", """BartConfig""", """BartOnnxConfig"""],
    """tokenization_bart""": ["""BartTokenizer"""],
}

try:
			if not is_tokenizers_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			SCREAMING_SNAKE_CASE					:       Dict							   =							["""BartTokenizerFast"""]

try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			SCREAMING_SNAKE_CASE					:       List[Any]							   =							[
			    """BART_PRETRAINED_MODEL_ARCHIVE_LIST""",
			    """BartForCausalLM""",
			    """BartForConditionalGeneration""",
			    """BartForQuestionAnswering""",
			    """BartForSequenceClassification""",
			    """BartModel""",
			    """BartPretrainedModel""",
			    """PretrainedBartModel""",
			]

try:
			if not is_tf_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			SCREAMING_SNAKE_CASE					:       Any							   =							[
			    """TFBartForConditionalGeneration""",
			    """TFBartForSequenceClassification""",
			    """TFBartModel""",
			    """TFBartPretrainedModel""",
			]

try:
			if not is_flax_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			SCREAMING_SNAKE_CASE					:       str							   =							[
			    """FlaxBartDecoderPreTrainedModel""",
			    """FlaxBartForCausalLM""",
			    """FlaxBartForConditionalGeneration""",
			    """FlaxBartForQuestionAnswering""",
			    """FlaxBartForSequenceClassification""",
			    """FlaxBartModel""",
			    """FlaxBartPreTrainedModel""",
			]

if TYPE_CHECKING:
			from .configuration_bart import BART_PRETRAINED_CONFIG_ARCHIVE_MAP, BartConfig, BartOnnxConfig
			from .tokenization_bart import BartTokenizer

			try:
						if not is_tokenizers_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .tokenization_bart_fast import BartTokenizerFast

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_bart import (
						    BART_PRETRAINED_MODEL_ARCHIVE_LIST,
						    BartForCausalLM,
						    BartForConditionalGeneration,
						    BartForQuestionAnswering,
						    BartForSequenceClassification,
						    BartModel,
						    BartPretrainedModel,
						    PretrainedBartModel,
						)

			try:
						if not is_tf_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_tf_bart import (
						    TFBartForConditionalGeneration,
						    TFBartForSequenceClassification,
						    TFBartModel,
						    TFBartPretrainedModel,
						)

			try:
						if not is_flax_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_flax_bart import (
						    FlaxBartDecoderPreTrainedModel,
						    FlaxBartForCausalLM,
						    FlaxBartForConditionalGeneration,
						    FlaxBartForQuestionAnswering,
						    FlaxBartForSequenceClassification,
						    FlaxBartModel,
						    FlaxBartPreTrainedModel,
						)

else:
			import sys

			SCREAMING_SNAKE_CASE					:       Tuple							   =							_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)





