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







       def __init__( self,							lowerCAmelCase__,							lowerCAmelCase__=13,							lowerCAmelCase__=7,							lowerCAmelCase__=True,							lowerCAmelCase__=True,							lowerCAmelCase__=False,							lowerCAmelCase__=True,							lowerCAmelCase__=99,							lowerCAmelCase__=64,							lowerCAmelCase__=5,							lowerCAmelCase__=4,							lowerCAmelCase__=64,							lowerCAmelCase__="gelu",							lowerCAmelCase__=0.1,							lowerCAmelCase__=0.1,							lowerCAmelCase__=512,							lowerCAmelCase__=16,							lowerCAmelCase__=2,							lowerCAmelCase__=0.02,							lowerCAmelCase__=3,							lowerCAmelCase__=4,							lowerCAmelCase__=None,							)      ->      Dict:
            snake_case_					       =					parent
            snake_case_					       =					batch_size
            snake_case_					       =					seq_length
            snake_case_					       =					is_training
            snake_case_					       =					use_input_mask
            snake_case_					       =					use_token_type_ids
            snake_case_					       =					use_labels
            snake_case_					       =					vocab_size
            snake_case_					       =					hidden_size
            snake_case_					       =					num_hidden_layers
            snake_case_					       =					num_attention_heads
            snake_case_					       =					intermediate_size
            snake_case_					       =					hidden_act
            snake_case_					       =					hidden_dropout_prob
            snake_case_					       =					attention_probs_dropout_prob
            snake_case_					       =					max_position_embeddings
            snake_case_					       =					type_vocab_size
            snake_case_					       =					type_sequence_label_size
            snake_case_					       =					initializer_range
            snake_case_					       =					num_labels
            snake_case_					       =					num_choices
            snake_case_					       =					scope







       def 		a_						( self)      ->      List[str]:
            return MPNetConfig.from_pretrained('microsoft/mpnet-base')







       def 		a_						( self)      ->      List[str]:
            snake_case_					       =					ids_tensor([self.batch_size, self.seq_length],							self.vocab_size)

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

            snake_case_					       =					None
            snake_case_					       =					None
            snake_case_					       =					None
            if self.use_labels:
                 snake_case_					       =					ids_tensor([self.batch_size],							self.type_sequence_label_size)
                 snake_case_					       =					ids_tensor([self.batch_size, self.seq_length],							self.num_labels)
                 snake_case_					       =					ids_tensor([self.batch_size],							self.num_choices)

            snake_case_					       =					self.get_config()
            return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels







       def 		a_						( self)      ->      List[str]:
            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 		a_						( self,							lowerCAmelCase__,							lowerCAmelCase__,							lowerCAmelCase__,							lowerCAmelCase__,							lowerCAmelCase__,							lowerCAmelCase__)      ->      List[str]:
            snake_case_					       =					MPNetModel(config=lowerCAmelCase__)
            model.to(lowerCAmelCase__)
            model.eval()
            snake_case_					       =					model(lowerCAmelCase__,							lowerCAmelCase__)
            snake_case_					       =					model(lowerCAmelCase__)
            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 		a_						( self,							lowerCAmelCase__,							lowerCAmelCase__,							lowerCAmelCase__,							lowerCAmelCase__,							lowerCAmelCase__,							lowerCAmelCase__)      ->      Dict:
            snake_case_					       =					MPNetForQuestionAnswering(config=lowerCAmelCase__)
            model.to(lowerCAmelCase__)
            model.eval()
            snake_case_					       =					model(
                lowerCAmelCase__,							attention_mask=lowerCAmelCase__,							start_positions=lowerCAmelCase__,							end_positions=lowerCAmelCase__,							)
            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 		a_						( self,							lowerCAmelCase__,							lowerCAmelCase__,							lowerCAmelCase__,							lowerCAmelCase__,							lowerCAmelCase__,							lowerCAmelCase__)      ->      Union[str, Any]:
            snake_case_					       =					self.num_labels
            snake_case_					       =					MPNetForSequenceClassification(lowerCAmelCase__)
            model.to(lowerCAmelCase__)
            model.eval()
            snake_case_					       =					model(lowerCAmelCase__,							attention_mask=lowerCAmelCase__,							labels=lowerCAmelCase__)
            self.parent.assertEqual(result.logits.shape,							(self.batch_size, self.num_labels))







       def 		a_						( self,							lowerCAmelCase__,							lowerCAmelCase__,							lowerCAmelCase__,							lowerCAmelCase__,							lowerCAmelCase__,							lowerCAmelCase__)      ->      List[Any]:
            snake_case_					       =					self.num_choices
            snake_case_					       =					MPNetForMultipleChoice(config=lowerCAmelCase__)
            model.to(lowerCAmelCase__)
            model.eval()
            snake_case_					       =					input_ids.unsqueeze(1).expand(-1,							self.num_choices,							-1).contiguous()
            snake_case_					       =					input_mask.unsqueeze(1).expand(-1,							self.num_choices,							-1).contiguous()
            snake_case_					       =					model(
                lowerCAmelCase__,							attention_mask=lowerCAmelCase__,							labels=lowerCAmelCase__,							)
            self.parent.assertEqual(result.logits.shape,							(self.batch_size, self.num_choices))







       def 		a_						( self,							lowerCAmelCase__,							lowerCAmelCase__,							lowerCAmelCase__,							lowerCAmelCase__,							lowerCAmelCase__,							lowerCAmelCase__)      ->      str:
            snake_case_					       =					self.num_labels
            snake_case_					       =					MPNetForTokenClassification(config=lowerCAmelCase__)
            model.to(lowerCAmelCase__)
            model.eval()
            snake_case_					       =					model(lowerCAmelCase__,							attention_mask=lowerCAmelCase__,							labels=lowerCAmelCase__)
            self.parent.assertEqual(result.logits.shape,							(self.batch_size, self.seq_length, self.num_labels))







       def 		a_						( self)      ->      int:
            snake_case_					       =					self.prepare_config_and_inputs()
            (snake_case_)					       =					config_and_inputs
            snake_case_					       =					{"input_ids": input_ids, "attention_mask": input_mask}
            return config, inputs_dict




@require_torch
class  UpperCamelCase					(				snake_case__    ,		snake_case__    ,		unittest.TestCase   ):
       SCREAMING_SNAKE_CASE_			=      (
           (
               MPNetForMaskedLM,
               MPNetForMultipleChoice,
               MPNetForQuestionAnswering,
               MPNetForSequenceClassification,
               MPNetForTokenClassification,
               MPNetModel,
           )
           if is_torch_available()
           else ()
       )
       SCREAMING_SNAKE_CASE_			=      (
           {
               "feature-extraction": MPNetModel,
               "fill-mask": MPNetForMaskedLM,
               "question-answering": MPNetForQuestionAnswering,
               "text-classification": MPNetForSequenceClassification,
               "token-classification": MPNetForTokenClassification,
               "zero-shot": MPNetForSequenceClassification,
           }
           if is_torch_available()
           else {}
       )
       SCREAMING_SNAKE_CASE_			=      False
       SCREAMING_SNAKE_CASE_			=      True







       def 		a_						( self)      ->      Dict:
            snake_case_					       =					MPNetModelTester(self)
            snake_case_					       =					ConfigTester(self,							config_class=lowerCAmelCase__,							hidden_size=37)







       def 		a_						( self)      ->      Optional[int]:
            self.config_tester.run_common_tests()







       def 		a_						( self)      ->      List[Any]:
            snake_case_					       =					self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_mpnet_model(*lowerCAmelCase__)







       def 		a_						( self)      ->      Any:
            snake_case_					       =					self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_mpnet_for_sequence_classification(*lowerCAmelCase__)







       def 		a_						( self)      ->      Dict:
            snake_case_					       =					self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_mpnet_for_multiple_choice(*lowerCAmelCase__)







       def 		a_						( self)      ->      str:
            snake_case_					       =					self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_mpnet_for_token_classification(*lowerCAmelCase__)







       def 		a_						( self)      ->      str:
            snake_case_					       =					self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_mpnet_for_question_answering(*lowerCAmelCase__)




@require_torch
class  UpperCamelCase					(				unittest.TestCase   ):







       @slow
       def 		a_						( self)      ->      List[Any]:
            snake_case_					       =					MPNetModel.from_pretrained('microsoft/mpnet-base')
            snake_case_					       =					torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]])
            snake_case_					       =					model(lowerCAmelCase__)[0]
            snake_case_					       =					torch.Size((1, 11, 768))
            self.assertEqual(output.shape,							lowerCAmelCase__)
            snake_case_					       =					torch.tensor(
                [[[-0.0550, 0.1943, -0.0740], [-0.0562, 0.2211, -0.0579], [-0.0437, 0.3337, -0.0641]]])
            # compare the actual values for a slice.
            self.assertTrue(torch.allclose(output[:, :3, :3],							lowerCAmelCase__,							atol=1e-4))


'''simple docstring'''




__SCREAMING_SNAKE_CASE       :     Dict     =  8.3_1_4_4_6_2  # Unit - J mol-1 K-1

def 	UpperCamelCase_							(					_UpperCAmelCase  :      float			,	_UpperCAmelCase  :      float			,	_UpperCAmelCase  :      float    )    ->    float:


       """simple docstring"""







       if moles < 0 or kelvin < 0 or volume < 0:
              raise ValueError("Invalid inputs. Enter positive value."    )
       return moles * kelvin * UNIVERSAL_GAS_CONSTANT / volume

def 	UpperCamelCase_							(					_UpperCAmelCase  :      float			,	_UpperCAmelCase  :      float			,	_UpperCAmelCase  :      float    )    ->    float:


       """simple docstring"""







       if moles < 0 or kelvin < 0 or pressure < 0:
              raise ValueError("Invalid inputs. Enter positive value."    )
       return moles * kelvin * UNIVERSAL_GAS_CONSTANT / pressure


if __name__ == "__main__":
  from doctest import testmod

  testmod()

