"""simple docstring"""





import unittest

from transformers import MPNetConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch

			from transformers import (
			    MPNetForMaskedLM,
			    MPNetForMultipleChoice,
			    MPNetForQuestionAnswering,
			    MPNetForSequenceClassification,
			    MPNetForTokenClassification,
			    MPNetModel,
			)




class  _snake_case		:







				"""simple docstring"""






				def __init__(      self							:							Tuple      ,    _A							:							List[str]      ,    _A							:							List[str]=1_3      ,    _A							:							int=7      ,    _A							:							int=True      ,    _A							:							List[str]=True      ,    _A							:							Optional[int]=False      ,    _A							:							Union[str, Any]=True      ,    _A							:							int=9_9      ,    _A							:							List[str]=6_4      ,    _A							:							Tuple=5      ,    _A							:							List[str]=4      ,    _A							:							str=6_4      ,    _A							:							List[str]="gelu"      ,    _A							:							str=0.1      ,    _A							:							str=0.1      ,    _A							:							Optional[int]=5_1_2      ,    _A							:							int=1_6      ,    _A							:							Union[str, Any]=2      ,    _A							:							int=0.02      ,    _A							:							str=3      ,    _A							:							Union[str, Any]=4      ,    _A							:							Tuple=None      ,    ):



											"""simple docstring"""







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





				def 		_lowerCAmelCase		(      self							:							Dict):



											"""simple docstring"""







											return MPNetConfig.from_pretrained("""microsoft/mpnet-base""")





				def 		_lowerCAmelCase		(      self							:							int):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						int			  =    ids_tensor([self.batch_size, self.seq_length]      ,    self.vocab_size)

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

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

											_SCREAMING_SNAKE_CASE		:						List[str]			  =    self.get_config()
											return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels





				def 		_lowerCAmelCase		(      self							:							List[str]):



											"""simple docstring"""







											return 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      ,    )





				def 		_lowerCAmelCase		(      self							:							List[str]      ,    _A							:							List[str]      ,    _A							:							Any      ,    _A							:							Optional[Any]      ,    _A							:							Optional[Any]      ,    _A							:							List[Any]      ,    _A							:							str):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    MPNetModel(config=_A)
											model.to(_A)
											model.eval()
											_SCREAMING_SNAKE_CASE		:						Tuple			  =    model(_A      ,    _A)
											_SCREAMING_SNAKE_CASE		:						Dict			  =    model(_A)
											self.parent.assertEqual(result.last_hidden_state.shape      ,    (self.batch_size, self.seq_length, self.hidden_size))
											self.parent.assertEqual(result.pooler_output.shape      ,    (self.batch_size, self.hidden_size))





				def 		_lowerCAmelCase		(      self							:							Any      ,    _A							:							Tuple      ,    _A							:							Tuple      ,    _A							:							Tuple      ,    _A							:							Tuple      ,    _A							:							Any      ,    _A							:							Dict):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Dict			  =    MPNetForQuestionAnswering(config=_A)
											model.to(_A)
											model.eval()
											_SCREAMING_SNAKE_CASE		:						Optional[Any]			  =    model(
											    _A      ,    attention_mask=_A      ,    start_positions=_A      ,    end_positions=_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 		_lowerCAmelCase		(      self							:							Optional[int]      ,    _A							:							List[Any]      ,    _A							:							str      ,    _A							:							Any      ,    _A							:							List[str]      ,    _A							:							str      ,    _A							:							Optional[int]):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Optional[Any]			  =    self.num_labels
											_SCREAMING_SNAKE_CASE		:						Any			  =    MPNetForSequenceClassification(_A)
											model.to(_A)
											model.eval()
											_SCREAMING_SNAKE_CASE		:						Dict			  =    model(_A      ,    attention_mask=_A      ,    labels=_A)
											self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.num_labels))





				def 		_lowerCAmelCase		(      self							:							Union[str, Any]      ,    _A							:							List[str]      ,    _A							:							List[str]      ,    _A							:							List[str]      ,    _A							:							List[str]      ,    _A							:							Any      ,    _A							:							List[str]):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Optional[int]			  =    self.num_choices
											_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    MPNetForMultipleChoice(config=_A)
											model.to(_A)
											model.eval()
											_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    input_ids.unsqueeze(1).expand(-1      ,    self.num_choices      ,    -1).contiguous()
											_SCREAMING_SNAKE_CASE		:						int			  =    input_mask.unsqueeze(1).expand(-1      ,    self.num_choices      ,    -1).contiguous()
											_SCREAMING_SNAKE_CASE		:						Dict			  =    model(
											    _A      ,    attention_mask=_A      ,    labels=_A      ,    )
											self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.num_choices))





				def 		_lowerCAmelCase		(      self							:							Optional[int]      ,    _A							:							List[str]      ,    _A							:							int      ,    _A							:							Optional[int]      ,    _A							:							Tuple      ,    _A							:							Any      ,    _A							:							int):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    self.num_labels
											_SCREAMING_SNAKE_CASE		:						int			  =    MPNetForTokenClassification(config=_A)
											model.to(_A)
											model.eval()
											_SCREAMING_SNAKE_CASE		:						Tuple			  =    model(_A      ,    attention_mask=_A      ,    labels=_A)
											self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.seq_length, self.num_labels))





				def 		_lowerCAmelCase		(      self							:							Union[str, Any]):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						str			  =    self.prepare_config_and_inputs()
											((_SCREAMING_SNAKE_CASE)  ,				(_SCREAMING_SNAKE_CASE)  ,				(_SCREAMING_SNAKE_CASE)  ,				(_SCREAMING_SNAKE_CASE)  ,				(_SCREAMING_SNAKE_CASE)  ,				(_SCREAMING_SNAKE_CASE))		:						Tuple			  =    config_and_inputs
											_SCREAMING_SNAKE_CASE		:						int			  =    {"""input_ids""": input_ids, """attention_mask""": input_mask}
											return config, inputs_dict




@require_torch
class  _snake_case		(    __snake_case   ,       __snake_case   ,       unittest.TestCase ):







				"""simple docstring"""






				a			=						(
				    (
				        MPNetForMaskedLM,
				        MPNetForMultipleChoice,
				        MPNetForQuestionAnswering,
				        MPNetForSequenceClassification,
				        MPNetForTokenClassification,
				        MPNetModel,
				    )
				    if is_torch_available()
				    else ()
				)
				a			=						(
				    {
				        "feature-extraction": MPNetModel,
				        "fill-mask": MPNetForMaskedLM,
				        "question-answering": MPNetForQuestionAnswering,
				        "text-classification": MPNetForSequenceClassification,
				        "token-classification": MPNetForTokenClassification,
				        "zero-shot": MPNetForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)
				a			=						False
				a			=						True





				def 		_lowerCAmelCase		(      self							:							Any):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						List[str]			  =    MPNetModelTester(self)
											_SCREAMING_SNAKE_CASE		:						str			  =    ConfigTester(self      ,    config_class=_A      ,    hidden_size=3_7)





				def 		_lowerCAmelCase		(      self							:							Union[str, Any]):



											"""simple docstring"""







											self.config_tester.run_common_tests()





				def 		_lowerCAmelCase		(      self							:							Any):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						List[Any]			  =    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_mpnet_model(*_A)





				def 		_lowerCAmelCase		(      self							:							Any):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Union[str, Any]			  =    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_mpnet_for_sequence_classification(*_A)





				def 		_lowerCAmelCase		(      self							:							Tuple):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						List[str]			  =    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_mpnet_for_multiple_choice(*_A)





				def 		_lowerCAmelCase		(      self							:							int):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						Any			  =    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_mpnet_for_token_classification(*_A)





				def 		_lowerCAmelCase		(      self							:							List[str]):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						List[Any]			  =    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_mpnet_for_question_answering(*_A)




@require_torch
class  _snake_case		(    unittest.TestCase ):







				"""simple docstring"""






				@slow
				def 		_lowerCAmelCase		(      self							:							List[Any]):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE		:						str			  =    MPNetModel.from_pretrained("""microsoft/mpnet-base""")
											_SCREAMING_SNAKE_CASE		:						Any			  =    torch.tensor([[0, 3_4_5, 2_3_2, 3_2_8, 7_4_0, 1_4_0, 1_6_9_5, 6_9, 6_0_7_8, 1_5_8_8, 2]])
											_SCREAMING_SNAKE_CASE		:						Tuple			  =    model(_A)[0]
											_SCREAMING_SNAKE_CASE		:						List[str]			  =    torch.Size((1, 1_1, 7_6_8))
											self.assertEqual(output.shape      ,    _A)
											_SCREAMING_SNAKE_CASE		:						List[Any]			  =    torch.tensor(
											    [[[-0.0_550, 0.1_943, -0.0_740], [-0.0_562, 0.2_211, -0.0_579], [-0.0_437, 0.3_337, -0.0_641]]])
											# compare the actual values for a slice.
											self.assertTrue(torch.allclose(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_torch_available,
)


lowerCAmelCase_     =	{'''configuration_unispeech''': ['''UNISPEECH_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''UniSpeechConfig''']}

try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			lowerCAmelCase_     =	[
			    '''UNISPEECH_PRETRAINED_MODEL_ARCHIVE_LIST''',
			    '''UniSpeechForCTC''',
			    '''UniSpeechForPreTraining''',
			    '''UniSpeechForSequenceClassification''',
			    '''UniSpeechModel''',
			    '''UniSpeechPreTrainedModel''',
			]

if TYPE_CHECKING:
			from .configuration_unispeech import UNISPEECH_PRETRAINED_CONFIG_ARCHIVE_MAP, UniSpeechConfig

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_unispeech import (
						    UNISPEECH_PRETRAINED_MODEL_ARCHIVE_LIST,
						    UniSpeechForCTC,
						    UniSpeechForPreTraining,
						    UniSpeechForSequenceClassification,
						    UniSpeechModel,
						    UniSpeechPreTrainedModel,
						)

else:
			import sys

			lowerCAmelCase_     =	_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)


