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






				def _snake_case    (     self							):
							lowercase__:     Optional[Any]      =   ids_tensor([self.batch_size, self.seq_length]					,    self.vocab_size							)

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

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

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






				def _snake_case    (     self					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase							):
							lowercase__:     Dict      =   TFMPNetForMaskedLM(config=_UpperCAmelCase							)
							lowercase__:     int      =   {'''input_ids''': input_ids, '''attention_mask''': input_mask}
							lowercase__:     List[Any]      =   model(_UpperCAmelCase							)
							self.parent.assertEqual(result.logits.shape					,    (self.batch_size, self.seq_length, self.vocab_size)							)






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






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






				def _snake_case    (     self					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase							):
							lowercase__:     Union[str, Any]      =   self.num_labels
							lowercase__:     Optional[int]      =   TFMPNetForTokenClassification(_UpperCAmelCase							)
							lowercase__:     List[Any]      =   {'''input_ids''': input_ids, '''attention_mask''': input_mask}
							lowercase__:     int      =   model(_UpperCAmelCase							)
							self.parent.assertEqual(result.logits.shape					,    (self.batch_size, self.seq_length, self.num_labels)							)






				def _snake_case    (     self							):
							lowercase__:     Dict      =   self.prepare_config_and_inputs()
							(lowercase__):     Any      =   config_and_inputs
							lowercase__:     Any      =   {'''input_ids''': input_ids, '''attention_mask''': input_mask}
							return config, inputs_dict



@require_tf
class 					UpperCAmelCase		(_UpperCAmelCase					,_UpperCAmelCase					,unittest.TestCase						):



				"""simple docstring"""

				_UpperCAmelCase			:int							=				(
				    (
				        TFMPNetForMaskedLM,
				        TFMPNetForMultipleChoice,
				        TFMPNetForQuestionAnswering,
				        TFMPNetForSequenceClassification,
				        TFMPNetForTokenClassification,
				        TFMPNetModel,
				    )
				    if is_tf_available()
				    else ()
				)
				_UpperCAmelCase			:List[str]							=				(
				    {
				        "feature-extraction": TFMPNetModel,
				        "fill-mask": TFMPNetForMaskedLM,
				        "question-answering": TFMPNetForQuestionAnswering,
				        "text-classification": TFMPNetForSequenceClassification,
				        "token-classification": TFMPNetForTokenClassification,
				        "zero-shot": TFMPNetForSequenceClassification,
				    }
				    if is_tf_available()
				    else {}
				)
				_UpperCAmelCase			:Any							=				False
				_UpperCAmelCase			:Dict							=				False






				def _snake_case    (     self							):
							lowercase__:     Tuple      =   TFMPNetModelTester(self							)
							lowercase__:     Dict      =   ConfigTester(self					,    config_class=_UpperCAmelCase					,    hidden_size=37							)






				def _snake_case    (     self							):
							self.config_tester.run_common_tests()






				def _snake_case    (     self							):
							lowercase__:     List[Any]      =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mpnet_model(*_UpperCAmelCase							)






				def _snake_case    (     self							):
							lowercase__:     Tuple      =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mpnet_for_masked_lm(*_UpperCAmelCase							)






				def _snake_case    (     self							):
							lowercase__:     List[str]      =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mpnet_for_question_answering(*_UpperCAmelCase							)






				def _snake_case    (     self							):
							lowercase__:     Tuple      =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mpnet_for_sequence_classification(*_UpperCAmelCase							)






				def _snake_case    (     self							):
							lowercase__:     int      =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mpnet_for_multiple_choice(*_UpperCAmelCase							)






				def _snake_case    (     self							):
							lowercase__:     Optional[int]      =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_mpnet_for_token_classification(*_UpperCAmelCase							)






				@slow
				def _snake_case    (     self							):
							for model_name in ["microsoft/mpnet-base"]:
										lowercase__:     Any      =   TFMPNetModel.from_pretrained(_UpperCAmelCase							)
										self.assertIsNotNone(_UpperCAmelCase							)



@require_tf
class 					UpperCAmelCase		(unittest.TestCase						):



				"""simple docstring"""

				@slow
				def _snake_case    (     self							):
							lowercase__:     Optional[int]      =   TFMPNetModel.from_pretrained('''microsoft/mpnet-base'''							)
							lowercase__:     Dict      =   tf.constant([[0, 1, 2, 3, 4, 5]]							)
							lowercase__:     Optional[Any]      =   model(_UpperCAmelCase							)[0]

							lowercase__:     Tuple      =   [1, 6, 768]
							self.assertEqual(output.shape					,    _UpperCAmelCase							)

							lowercase__:     Union[str, Any]      =   tf.constant(
							    [
							        [
							            [-0.1_067_172, 0.08_216_473, 0.0_024_543],
							            [-0.03_465_879, 0.8_354_118, -0.03_252_288],
							            [-0.06_569_476, -0.12_424_111, -0.0_494_436],
							        ]
							    ]							)
							tf.debugging.assert_near(output[:, :3, :3]					,    _UpperCAmelCase					,    atol=1e-4							)

"""simple docstring"""






from ...configuration_utils import PretrainedConfig
from ...utils import logging


__A         =				logging.get_logger(__name__)

__A         =				{
    "uw-madison/yoso-4096": "https://huggingface.co/uw-madison/yoso-4096/resolve/main/config.json",
    # See all YOSO models at https://huggingface.co/models?filter=yoso
}


class 					UpperCAmelCase		(_UpperCAmelCase						):



    """simple docstring"""

    _UpperCAmelCase			:Tuple							=				"yoso"






    def __init__(     self					,    _UpperCAmelCase=50265					,    _UpperCAmelCase=768					,    _UpperCAmelCase=12					,    _UpperCAmelCase=12					,    _UpperCAmelCase=3072					,    _UpperCAmelCase="gelu"					,    _UpperCAmelCase=0.1					,    _UpperCAmelCase=0.1					,    _UpperCAmelCase=4096					,    _UpperCAmelCase=1					,    _UpperCAmelCase=0.02					,    _UpperCAmelCase=1e-1_2					,    _UpperCAmelCase="absolute"					,    _UpperCAmelCase=True					,    _UpperCAmelCase=9					,    _UpperCAmelCase=64					,    _UpperCAmelCase=None					,    _UpperCAmelCase=True					,    _UpperCAmelCase=True					,    _UpperCAmelCase=1					,    _UpperCAmelCase=0					,    _UpperCAmelCase=2					,    **_UpperCAmelCase					,    ):
       super().__init__(pad_token_id=_UpperCAmelCase					,    bos_token_id=_UpperCAmelCase					,    eos_token_id=_UpperCAmelCase					,    **_UpperCAmelCase							)

       lowercase__:     int      =   vocab_size
       lowercase__:     List[str]      =   max_position_embeddings
       lowercase__:     Tuple      =   hidden_size
       lowercase__:     Optional[Any]      =   num_hidden_layers
       lowercase__:     Optional[int]      =   num_attention_heads
       lowercase__:     List[Any]      =   intermediate_size
       lowercase__:     Union[str, Any]      =   hidden_act
       lowercase__:     int      =   hidden_dropout_prob
       lowercase__:     Optional[Any]      =   attention_probs_dropout_prob
       lowercase__:     List[Any]      =   initializer_range
       lowercase__:     Optional[Any]      =   type_vocab_size
       lowercase__:     int      =   layer_norm_eps
       lowercase__:     Optional[Any]      =   position_embedding_type
       lowercase__:     int      =   use_expectation
       lowercase__:     List[str]      =   hash_code_len
       lowercase__:     Union[str, Any]      =   num_hash
       lowercase__:     Any      =   conv_window
       lowercase__:     Dict      =   use_fast_hash
       lowercase__:     Dict      =   lsh_backward
