


'''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 	lowerCAmelCase__			:




			def __init__(		self  :     Any	,  lowerCamelCase__  :     Dict	,  lowerCamelCase__  :     str=13	,  lowerCamelCase__  :     int=7	,  lowerCamelCase__  :     Union[str, Any]=True	,  lowerCamelCase__  :     Optional[Any]=True	,  lowerCamelCase__  :     Tuple=False	,  lowerCamelCase__  :     Dict=True	,  lowerCamelCase__  :     str=99	,  lowerCamelCase__  :     List[str]=64	,  lowerCamelCase__  :     Any=5	,  lowerCamelCase__  :     Dict=4	,  lowerCamelCase__  :     Union[str, Any]=64	,  lowerCamelCase__  :     str="gelu"	,  lowerCamelCase__  :     Any=0.1	,  lowerCamelCase__  :     str=0.1	,  lowerCamelCase__  :     Any=5_12	,  lowerCamelCase__  :     Optional[int]=16	,  lowerCamelCase__  :     str=2	,  lowerCamelCase__  :     Union[str, Any]=0.0_2	,  lowerCamelCase__  :     Optional[Any]=3	,  lowerCamelCase__  :     List[str]=4	,  lowerCamelCase__  :     Union[str, Any]=None	,  )   ->Any:



					'''simple docstring'''







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




			def 							lowerCAmelCase__    (		self  :     List[Any] )   ->List[Any]:



					'''simple docstring'''







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




			def 							lowerCAmelCase__    (		self  :     Optional[int] )   ->Union[str, Any]:



					'''simple docstring'''







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

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

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

					_UpperCAmelCase		:       Tuple								=      self.get_config()
					return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels




			def 							lowerCAmelCase__    (		self  :     Dict )   ->Dict:



					'''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  :     int	,  lowerCamelCase__  :     Optional[int]	,  lowerCamelCase__  :     Dict	,  lowerCamelCase__  :     Tuple	,  lowerCamelCase__  :     List[str]	,  lowerCamelCase__  :     Optional[Any]	,  lowerCamelCase__  :     Dict )   ->str:



					'''simple docstring'''







					_UpperCAmelCase		:       Optional[int]								=      MPNetModel(config=A__ )
					model.to(A__ )
					model.eval()
					_UpperCAmelCase		:       Union[str, Any]								=      model(A__	,  A__ )
					_UpperCAmelCase		:       Any								=      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  :     str	,  lowerCamelCase__  :     Union[str, Any]	,  lowerCamelCase__  :     Optional[int]	,  lowerCamelCase__  :     List[Any]	,  lowerCamelCase__  :     int	,  lowerCamelCase__  :     Union[str, Any]	,  lowerCamelCase__  :     int )   ->str:



					'''simple docstring'''







					_UpperCAmelCase		:       Union[str, Any]								=      MPNetForQuestionAnswering(config=A__ )
					model.to(A__ )
					model.eval()
					_UpperCAmelCase		:       str								=      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  :     str	,  lowerCamelCase__  :     List[Any]	,  lowerCamelCase__  :     Union[str, Any]	,  lowerCamelCase__  :     List[Any]	,  lowerCamelCase__  :     Tuple	,  lowerCamelCase__  :     Dict	,  lowerCamelCase__  :     str )   ->Dict:



					'''simple docstring'''







					_UpperCAmelCase		:       Union[str, Any]								=      self.num_labels
					_UpperCAmelCase		:       Union[str, Any]								=      MPNetForSequenceClassification(A__ )
					model.to(A__ )
					model.eval()
					_UpperCAmelCase		:       Any								=      model(A__	,  attention_mask=A__	,  labels=A__ )
					self.parent.assertEqual(result.logits.shape	,  (self.batch_size, self.num_labels) )




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



					'''simple docstring'''







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




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



					'''simple docstring'''







					_UpperCAmelCase		:       Union[str, Any]								=      self.num_labels
					_UpperCAmelCase		:       Union[str, Any]								=      MPNetForTokenClassification(config=A__ )
					model.to(A__ )
					model.eval()
					_UpperCAmelCase		:       Optional[int]								=      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  :     Optional[Any] )   ->Optional[Any]:



					'''simple docstring'''







					_UpperCAmelCase		:       List[Any]								=      self.prepare_config_and_inputs()
					((_UpperCAmelCase)					,    (_UpperCAmelCase)					,    (_UpperCAmelCase)					,    (_UpperCAmelCase)					,    (_UpperCAmelCase)					,    (_UpperCAmelCase))		:       Tuple								=      config_and_inputs
					_UpperCAmelCase		:       List[Any]								=      {"input_ids": input_ids, "attention_mask": input_mask}
					return config, inputs_dict






@require_torch
class 	lowerCAmelCase__			(			__a    ,       __a    ,       unittest.TestCase	):
			lowerCAmelCase :	List[Any]          =     (
			    (
			        MPNetForMaskedLM,
			        MPNetForMultipleChoice,
			        MPNetForQuestionAnswering,
			        MPNetForSequenceClassification,
			        MPNetForTokenClassification,
			        MPNetModel,
			    )
			    if is_torch_available()
			    else ()
			)
			lowerCAmelCase :	Dict          =     (
			    {
			        "feature-extraction": MPNetModel,
			        "fill-mask": MPNetForMaskedLM,
			        "question-answering": MPNetForQuestionAnswering,
			        "text-classification": MPNetForSequenceClassification,
			        "token-classification": MPNetForTokenClassification,
			        "zero-shot": MPNetForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)
			lowerCAmelCase :	str          =     False
			lowerCAmelCase :	Union[str, Any]          =     True




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



					'''simple docstring'''







					_UpperCAmelCase		:       Optional[Any]								=      MPNetModelTester(self )
					_UpperCAmelCase		:       int								=      ConfigTester(self	,  config_class=A__	,  hidden_size=37 )




			def 							lowerCAmelCase__    (		self  :     Optional[Any] )   ->Tuple:



					'''simple docstring'''







					self.config_tester.run_common_tests()




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



					'''simple docstring'''







					_UpperCAmelCase		:       Dict								=      self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mpnet_model(*A__ )




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



					'''simple docstring'''







					_UpperCAmelCase		:       int								=      self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mpnet_for_sequence_classification(*A__ )




			def 							lowerCAmelCase__    (		self  :     Tuple )   ->Union[str, Any]:



					'''simple docstring'''







					_UpperCAmelCase		:       Optional[Any]								=      self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mpnet_for_multiple_choice(*A__ )




			def 							lowerCAmelCase__    (		self  :     Any )   ->str:



					'''simple docstring'''







					_UpperCAmelCase		:       Optional[Any]								=      self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mpnet_for_token_classification(*A__ )






			def 							lowerCAmelCase__    (		self  :     Union[str, Any] )   ->int:



					'''simple docstring'''







					_UpperCAmelCase		:       Optional[Any]								=      self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mpnet_for_question_answering(*A__ )






@require_torch
class 	lowerCAmelCase__			(			unittest.TestCase	):




			@slow
			def 							lowerCAmelCase__    (		self  :     Optional[int] )   ->str:



					'''simple docstring'''







					_UpperCAmelCase		:       Tuple								=      MPNetModel.from_pretrained("microsoft/mpnet-base" )
					_UpperCAmelCase		:       Any								=      torch.tensor([[0, 3_45, 2_32, 3_28, 7_40, 1_40, 16_95, 69, 60_78, 15_88, 2]] )
					_UpperCAmelCase		:       str								=      model(A__ )[0]
					_UpperCAmelCase		:       str								=      torch.Size((1, 11, 7_68) )
					self.assertEqual(output.shape	,  A__ )
					_UpperCAmelCase		:       int								=      torch.tensor(
					    [[[-0.0_5_5_0, 0.1_9_4_3, -0.0_7_4_0], [-0.0_5_6_2, 0.2_2_1_1, -0.0_5_7_9], [-0.0_4_3_7, 0.3_3_3_7, -0.0_6_4_1]]] )
					# compare the actual values for a slice.
					self.assertTrue(torch.allclose(output[:, :3, :3]	,  A__	,  atol=1E-4 ) )







'''simple docstring'''


from ...utils import (
    OptionalDependencyNotAvailable,
    is_flax_available,
    is_torch_available,
    is_transformers_available,
)


try:
						if not (is_transformers_available() and is_torch_available()):
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						from ...utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
						from .multicontrolnet import MultiControlNetModel
						from .pipeline_controlnet import StableDiffusionControlNetPipeline
						from .pipeline_controlnet_imgaimg import StableDiffusionControlNetImgaImgPipeline
						from .pipeline_controlnet_inpaint import StableDiffusionControlNetInpaintPipeline


if is_transformers_available() and is_flax_available():
						from .pipeline_flax_controlnet import FlaxStableDiffusionControlNetPipeline



