
'''simple docstring'''

import unittest
from dataclasses import dataclass
from typing import Optional

from transformers.utils import ModelOutput


@dataclass
class 		_a     (							__A  ):







   """simple docstring"""




   A		= 42
   A		= None
   A		= None



class 		_a     (							unittest.TestCase  ):







   """simple docstring"""




   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  List[Any]								=		ModelOutputTest(a=30      )
    self.assertEqual(x.a    ,30      )
    self.assertIsNone(x.b      )
    self.assertIsNone(x.c      )
    with self.assertRaises(lowercase_      ):
     SCREAMING_SNAKE_CASE  :  int								=		x.d






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  List[Any]								=		ModelOutputTest(a=30    ,b=10      )
    self.assertEqual(x[0]    ,30      )
    self.assertEqual(x[1]    ,10      )
    self.assertEqual(x[:2]    ,(30, 10)      )
    self.assertEqual(x[:]    ,(30, 10)      )

    SCREAMING_SNAKE_CASE  :  List[Any]								=		ModelOutputTest(a=30    ,c=10      )
    self.assertEqual(x[0]    ,30      )
    self.assertEqual(x[1]    ,10      )
    self.assertEqual(x[:2]    ,(30, 10)      )
    self.assertEqual(x[:]    ,(30, 10)      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  int								=		ModelOutputTest(a=30    ,b=10      )
    self.assertEqual(x['a']    ,30      )
    self.assertEqual(x['b']    ,10      )
    with self.assertRaises(lowercase_      ):
     SCREAMING_SNAKE_CASE  :  List[str]								=		x["c"]

    SCREAMING_SNAKE_CASE  :  Tuple								=		ModelOutputTest(a=30    ,c=10      )
    self.assertEqual(x['a']    ,30      )
    self.assertEqual(x['c']    ,10      )
    with self.assertRaises(lowercase_      ):
     SCREAMING_SNAKE_CASE  :  List[Any]								=		x["b"]






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  Dict								=		ModelOutputTest(a=30      )
    self.assertEqual(list(x.keys()      )    ,['a']      )
    self.assertEqual(list(x.values()      )    ,[30]      )
    self.assertEqual(list(x.items()      )    ,[('a', 30)]      )
    self.assertEqual(list(lowercase_      )    ,['a']      )

    SCREAMING_SNAKE_CASE  :  Optional[int]								=		ModelOutputTest(a=30    ,b=10      )
    self.assertEqual(list(x.keys()      )    ,['a', 'b']      )
    self.assertEqual(list(x.values()      )    ,[30, 10]      )
    self.assertEqual(list(x.items()      )    ,[('a', 30), ('b', 10)]      )
    self.assertEqual(list(lowercase_      )    ,['a', 'b']      )

    SCREAMING_SNAKE_CASE  :  str								=		ModelOutputTest(a=30    ,c=10      )
    self.assertEqual(list(x.keys()      )    ,['a', 'c']      )
    self.assertEqual(list(x.values()      )    ,[30, 10]      )
    self.assertEqual(list(x.items()      )    ,[('a', 30), ('c', 10)]      )
    self.assertEqual(list(lowercase_      )    ,['a', 'c']      )

    with self.assertRaises(lowercase_      ):
     SCREAMING_SNAKE_CASE  :  Optional[Any]								=		x.update({'d': 20}      )
    with self.assertRaises(lowercase_      ):
     del x["a"]
    with self.assertRaises(lowercase_      ):
     SCREAMING_SNAKE_CASE  :  List[str]								=		x.pop('a'      )
    with self.assertRaises(lowercase_      ):
     SCREAMING_SNAKE_CASE  :  Any								=		x.setdefault('d'    ,32      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  Union[str, Any]								=		ModelOutputTest(a=30      )
    SCREAMING_SNAKE_CASE  :  Union[str, Any]								=		10
    self.assertEqual(x.a    ,10      )
    self.assertEqual(x['a']    ,10      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  Any								=		ModelOutputTest(a=30      )
    SCREAMING_SNAKE_CASE  :  List[Any]								=		10
    self.assertEqual(x.a    ,10      )
    self.assertEqual(x['a']    ,10      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  List[str]								=		ModelOutputTest({'a': 30, 'b': 10}      )
    self.assertEqual(list(x.keys()      )    ,['a', 'b']      )
    self.assertEqual(x.a    ,30      )
    self.assertEqual(x.b    ,10      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  List[str]								=		ModelOutputTest([('a', 30), ('b', 10)]      )
    self.assertEqual(list(x.keys()      )    ,['a', 'b']      )
    self.assertEqual(x.a    ,30      )
    self.assertEqual(x.b    ,10      )

    with self.assertRaises(lowercase_      ):
     SCREAMING_SNAKE_CASE  :  Optional[int]								=		ModelOutputTest([('a', 30), (10, 10)]      )

    SCREAMING_SNAKE_CASE  :  str								=		ModelOutputTest(a=(30, 30)      )
    self.assertEqual(list(x.keys()      )    ,['a']      )
    self.assertEqual(x.a    ,(30, 30)      )



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							:	Optional[Any]      ,		lowercase_							:	Tuple      ,		lowercase_							:	List[str]=13      ,		lowercase_							:	str=7      ,		lowercase_							:	str=True      ,		lowercase_							:	Dict=True      ,		lowercase_							:	List[str]=False      ,		lowercase_							:	Optional[Any]=True      ,		lowercase_							:	List[str]=99      ,		lowercase_							:	Optional[int]=64      ,		lowercase_							:	Optional[int]=2      ,		lowercase_							:	List[Any]=4      ,		lowercase_							:	Union[str, Any]=64      ,		lowercase_							:	Optional[Any]="gelu"      ,		lowercase_							:	str=0.1      ,		lowercase_							:	Union[str, Any]=0.1      ,		lowercase_							:	Optional[Any]=5_12      ,		lowercase_							:	Optional[Any]=16      ,		lowercase_							:	Optional[Any]=2      ,		lowercase_							:	Any=0.02      ,		lowercase_							:	List[Any]=3      ,		lowercase_							:	List[str]=4      ,		lowercase_							:	Union[str, Any]=None      ,		)   ->		Optional[int]:
       lowercase__					:  str          =							parent
       lowercase__					:  List[str]          =							batch_size
       lowercase__					:  Optional[int]          =							seq_length
       lowercase__					:  List[str]          =							is_training
       lowercase__					:  Union[str, Any]          =							use_input_mask
       lowercase__					:  Tuple          =							use_token_type_ids
       lowercase__					:  str          =							use_labels
       lowercase__					:  int          =							vocab_size
       lowercase__					:  Optional[Any]          =							hidden_size
       lowercase__					:  Dict          =							num_hidden_layers
       lowercase__					:  Any          =							num_attention_heads
       lowercase__					:  Dict          =							intermediate_size
       lowercase__					:  List[Any]          =							hidden_act
       lowercase__					:  int          =							hidden_dropout_prob
       lowercase__					:  Dict          =							attention_probs_dropout_prob
       lowercase__					:  Union[str, Any]          =							max_position_embeddings
       lowercase__					:  List[Any]          =							type_vocab_size
       lowercase__					:  str          =							type_sequence_label_size
       lowercase__					:  Union[str, Any]          =							initializer_range
       lowercase__					:  str          =							num_labels
       lowercase__					:  List[Any]          =							num_choices
       lowercase__					:  List[str]          =							scope






   def  __UpperCamelCase	( self							:	Dict    )   ->		Tuple:
       lowercase__					:  int          =							ids_tensor([self.batch_size, self.seq_length]      ,		self.vocab_size    )

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

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

       lowercase__					:  Any          =							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							:	int      ,		lowercase_							:	Optional[Any]      ,		lowercase_							:	Union[str, Any]      ,		lowercase_							:	Any      ,		lowercase_							:	Optional[Any]      ,		lowercase_							:	Any      ,		lowercase_							:	List[Any]    )   ->		List[str]:
       lowercase__					:  int          =							TFMPNetModel(config=lowercase_    )
       lowercase__					:  Dict          =							{"input_ids": input_ids, "attention_mask": input_mask}
       lowercase__					:  Dict          =							model(lowercase_    )
       lowercase__					:  Tuple          =							[input_ids, input_mask]
       lowercase__					:  Any          =							model(lowercase_    )
       self.parent.assertEqual(result.last_hidden_state.shape      ,		(self.batch_size, self.seq_length, self.hidden_size)    )






   def  __UpperCamelCase	( self							:	List[Any]      ,		lowercase_							:	Optional[int]      ,		lowercase_							:	Tuple      ,		lowercase_							:	str      ,		lowercase_							:	Union[str, Any]      ,		lowercase_							:	Union[str, Any]      ,		lowercase_							:	List[Any]    )   ->		Union[str, Any]:
       lowercase__					:  List[str]          =							TFMPNetForMaskedLM(config=lowercase_    )
       lowercase__					:  Dict          =							{"input_ids": input_ids, "attention_mask": input_mask}
       lowercase__					:  Optional[int]          =							model(lowercase_    )
       self.parent.assertEqual(result.logits.shape      ,		(self.batch_size, self.seq_length, self.vocab_size)    )






   def  __UpperCamelCase	( self							:	Optional[Any]      ,		lowercase_							:	List[Any]      ,		lowercase_							:	Union[str, Any]      ,		lowercase_							:	Dict      ,		lowercase_							:	Tuple      ,		lowercase_							:	Tuple      ,		lowercase_							:	Optional[Any]    )   ->		List[Any]:
       lowercase__					:  List[Any]          =							TFMPNetForQuestionAnswering(config=lowercase_    )
       lowercase__					:  Optional[int]          =							{
           "input_ids": input_ids,
           "attention_mask": input_mask,
       }
       lowercase__					:  int          =							model(lowercase_    )
       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							:	Union[str, Any]      ,		lowercase_							:	List[str]      ,		lowercase_							:	List[Any]      ,		lowercase_							:	Tuple      ,		lowercase_							:	Optional[Any]      ,		lowercase_							:	Optional[int]      ,		lowercase_							:	Any    )   ->		int:
       lowercase__					:  Optional[Any]          =							self.num_labels
       lowercase__					:  int          =							TFMPNetForSequenceClassification(lowercase_    )
       lowercase__					:  Any          =							{"input_ids": input_ids, "attention_mask": input_mask}
       lowercase__					:  Optional[Any]          =							model(lowercase_    )
       self.parent.assertEqual(result.logits.shape      ,		(self.batch_size, self.num_labels)    )






   def  __UpperCamelCase	( self							:	List[str]      ,		lowercase_							:	int      ,		lowercase_							:	Optional[int]      ,		lowercase_							:	Union[str, Any]      ,		lowercase_							:	Optional[Any]      ,		lowercase_							:	List[str]      ,		lowercase_							:	List[str]    )   ->		Optional[int]:
       lowercase__					:  List[Any]          =							self.num_choices
       lowercase__					:  List[str]          =							TFMPNetForMultipleChoice(lowercase_    )
       lowercase__					:  Tuple          =							tf.tile(tf.expand_dims(lowercase_      ,		1    )      ,		(1, self.num_choices, 1)    )
       lowercase__					:  List[str]          =							tf.tile(tf.expand_dims(lowercase_      ,		1    )      ,		(1, self.num_choices, 1)    )
       lowercase__					:  Tuple          =							{
           "input_ids": multiple_choice_inputs_ids,
           "attention_mask": multiple_choice_input_mask,
       }
       lowercase__					:  List[str]          =							model(lowercase_    )
       self.parent.assertEqual(result.logits.shape      ,		(self.batch_size, self.num_choices)    )






   def  __UpperCamelCase	( self							:	Tuple      ,		lowercase_							:	Tuple      ,		lowercase_							:	str      ,		lowercase_							:	List[Any]      ,		lowercase_							:	str      ,		lowercase_							:	str      ,		lowercase_							:	Tuple    )   ->		int:
       lowercase__					:  Dict          =							self.num_labels
       lowercase__					:  int          =							TFMPNetForTokenClassification(lowercase_    )
       lowercase__					:  List[str]          =							{"input_ids": input_ids, "attention_mask": input_mask}
       lowercase__					:  Dict          =							model(lowercase_    )
       self.parent.assertEqual(result.logits.shape      ,		(self.batch_size, self.seq_length, self.num_labels)    )







   def  __UpperCamelCase	( self							:	List[Any]    )   ->		List[str]:
       lowercase__					:  int          =							self.prepare_config_and_inputs()
       ((lowercase__)   ,  (lowercase__)   ,  (lowercase__)   ,  (lowercase__)   ,  (lowercase__)   ,  (lowercase__))					:  str          =							config_and_inputs
       lowercase__					:  Union[str, Any]          =							{"input_ids": input_ids, "attention_mask": input_mask}
       return config, inputs_dict



@require_tf
class     snake_case_			(						__A    ,__A    ,unittest.TestCase			):
   __A      :						List[str]   =							(
       (
           TFMPNetForMaskedLM,
           TFMPNetForMultipleChoice,
           TFMPNetForQuestionAnswering,
           TFMPNetForSequenceClassification,
           TFMPNetForTokenClassification,
           TFMPNetModel,
       )
       if is_tf_available()
       else ()
   )
   __A      :						int   =							(
       {
           "feature-extraction": TFMPNetModel,
           "fill-mask": TFMPNetForMaskedLM,
           "question-answering": TFMPNetForQuestionAnswering,
           "text-classification": TFMPNetForSequenceClassification,
           "token-classification": TFMPNetForTokenClassification,
           "zero-shot": TFMPNetForSequenceClassification,
       }
       if is_tf_available()
       else {}
   )
   __A      :						str   =							False
   __A      :						Union[str, Any]   =							False






   def  __UpperCamelCase	( self							:	List[Any]    )   ->		List[str]:
       lowercase__					:  Optional[int]          =							TFMPNetModelTester(self    )
       lowercase__					:  List[Any]          =							ConfigTester(self      ,		config_class=lowercase_      ,		hidden_size=37    )






   def  __UpperCamelCase	( self							:	int    )   ->		Dict:
       self.config_tester.run_common_tests()






   def  __UpperCamelCase	( self							:	Any    )   ->		Any:
       lowercase__					:  Tuple          =							self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_model(*lowercase_    )






   def  __UpperCamelCase	( self							:	Optional[Any]    )   ->		Dict:
       lowercase__					:  str          =							self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_for_masked_lm(*lowercase_    )






   def  __UpperCamelCase	( self							:	Optional[int]    )   ->		Any:
       lowercase__					:  Optional[Any]          =							self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_for_question_answering(*lowercase_    )






   def  __UpperCamelCase	( self							:	int    )   ->		List[Any]:
       lowercase__					:  Dict          =							self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_for_sequence_classification(*lowercase_    )






   def  __UpperCamelCase	( self							:	Dict    )   ->		Any:
       lowercase__					:  List[Any]          =							self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_for_multiple_choice(*lowercase_    )






   def  __UpperCamelCase	( self							:	List[Any]    )   ->		Dict:
       lowercase__					:  List[Any]          =							self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_for_token_classification(*lowercase_    )







   @slow
   def  __UpperCamelCase	( self							:	Dict    )   ->		int:
       for model_name in ["microsoft/mpnet-base"]:
           lowercase__					:  List[str]          =							TFMPNetModel.from_pretrained(lowercase_    )
           self.assertIsNotNone(lowercase_    )



@require_tf
class     snake_case_			(						unittest.TestCase			):






   @slow
   def  __UpperCamelCase	( self							:	int    )   ->		List[Any]:
       lowercase__					:  Optional[Any]          =							TFMPNetModel.from_pretrained("microsoft/mpnet-base"    )
       lowercase__					:  Tuple          =							tf.constant([[0, 1, 2, 3, 4, 5]]    )
       lowercase__					:  List[str]          =							model(lowercase_    )[0]

       lowercase__					:  List[Any]          =							[1, 6, 7_68]
       self.assertEqual(output.shape      ,		lowercase_    )

       lowercase__					:  Optional[int]          =							tf.constant(
           [
               [
                   [-0.1_06_71_72, 0.08_21_64_73, 0.0_02_45_43],
                   [-0.03_46_58_79, 0.8_35_41_18, -0.03_25_22_88],
                   [-0.06_56_94_76, -0.12_42_41_11, -0.0_49_44_36],
               ]
           ]    )
       tf.debugging.assert_near(output[:, :3, :3]      ,		lowercase_      ,		atol=1E-4    )



