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


 '''simple docstring'''






 def __init__(				self       :     Optional[Any]				,	SCREAMING_SNAKE_CASE__       :     Optional[Any]				,	SCREAMING_SNAKE_CASE__       :     int=13				,	SCREAMING_SNAKE_CASE__       :     Optional[Any]=7				,	SCREAMING_SNAKE_CASE__       :     Tuple=True				,	SCREAMING_SNAKE_CASE__       :     Dict=True				,	SCREAMING_SNAKE_CASE__       :     Optional[int]=False				,	SCREAMING_SNAKE_CASE__       :     str=True				,	SCREAMING_SNAKE_CASE__       :     List[str]=99				,	SCREAMING_SNAKE_CASE__       :     Dict=64				,	SCREAMING_SNAKE_CASE__       :     Any=2				,	SCREAMING_SNAKE_CASE__       :     int=4				,	SCREAMING_SNAKE_CASE__       :     Optional[Any]=64				,	SCREAMING_SNAKE_CASE__       :     int="gelu"				,	SCREAMING_SNAKE_CASE__       :     Any=0.1				,	SCREAMING_SNAKE_CASE__       :     Tuple=0.1				,	SCREAMING_SNAKE_CASE__       :     Union[str, Any]=5_12				,	SCREAMING_SNAKE_CASE__       :     Dict=16				,	SCREAMING_SNAKE_CASE__       :     str=2				,	SCREAMING_SNAKE_CASE__       :     Dict=0.0_2				,	SCREAMING_SNAKE_CASE__       :     Union[str, Any]=3				,	SCREAMING_SNAKE_CASE__       :     Any=4				,	SCREAMING_SNAKE_CASE__       :     Optional[int]=None				,	)  ->   int:
  __lowerCAmelCase    							=						parent
  __lowerCAmelCase    							=						batch_size
  __lowerCAmelCase    							=						seq_length
  __lowerCAmelCase    							=						is_training
  __lowerCAmelCase    							=						use_input_mask
  __lowerCAmelCase    							=						use_token_type_ids
  __lowerCAmelCase    							=						use_labels
  __lowerCAmelCase    							=						vocab_size
  __lowerCAmelCase    							=						hidden_size
  __lowerCAmelCase    							=						num_hidden_layers
  __lowerCAmelCase    							=						num_attention_heads
  __lowerCAmelCase    							=						intermediate_size
  __lowerCAmelCase    							=						hidden_act
  __lowerCAmelCase    							=						hidden_dropout_prob
  __lowerCAmelCase    							=						attention_probs_dropout_prob
  __lowerCAmelCase    							=						max_position_embeddings
  __lowerCAmelCase    							=						type_vocab_size
  __lowerCAmelCase    							=						type_sequence_label_size
  __lowerCAmelCase    							=						initializer_range
  __lowerCAmelCase    							=						num_labels
  __lowerCAmelCase    							=						num_choices
  __lowerCAmelCase    							=						scope
 def a (				self       :     Optional[Any]							)  ->   List[str]:
  __lowerCAmelCase    							=						ids_tensor([self.batch_size, self.seq_length]				,	self.vocab_size							)

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

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

  __lowerCAmelCase    							=						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 a (				self       :     Optional[Any]				,	SCREAMING_SNAKE_CASE__       :     Optional[int]				,	SCREAMING_SNAKE_CASE__       :     Optional[int]				,	SCREAMING_SNAKE_CASE__       :     Dict				,	SCREAMING_SNAKE_CASE__       :     str				,	SCREAMING_SNAKE_CASE__       :     Any				,	SCREAMING_SNAKE_CASE__       :     List[str]							)  ->   str:
  __lowerCAmelCase    							=						TFMPNetModel(config=SCREAMING_SNAKE_CASE__							)
  __lowerCAmelCase    							=						{"""input_ids""": input_ids, """attention_mask""": input_mask}
  __lowerCAmelCase    							=						model(SCREAMING_SNAKE_CASE__							)
  __lowerCAmelCase    							=						[input_ids, input_mask]
  __lowerCAmelCase    							=						model(SCREAMING_SNAKE_CASE__							)
  self.parent.assertEqual(result.last_hidden_state.shape				,	(self.batch_size, self.seq_length, self.hidden_size)							)
 def a (				self       :     Optional[Any]				,	SCREAMING_SNAKE_CASE__       :     str				,	SCREAMING_SNAKE_CASE__       :     Any				,	SCREAMING_SNAKE_CASE__       :     str				,	SCREAMING_SNAKE_CASE__       :     Optional[int]				,	SCREAMING_SNAKE_CASE__       :     Union[str, Any]				,	SCREAMING_SNAKE_CASE__       :     Optional[Any]							)  ->   Optional[int]:
  __lowerCAmelCase    							=						TFMPNetForMaskedLM(config=SCREAMING_SNAKE_CASE__							)
  __lowerCAmelCase    							=						{"""input_ids""": input_ids, """attention_mask""": input_mask}
  __lowerCAmelCase    							=						model(SCREAMING_SNAKE_CASE__							)
  self.parent.assertEqual(result.logits.shape				,	(self.batch_size, self.seq_length, self.vocab_size)							)
 def a (				self       :     Union[str, Any]				,	SCREAMING_SNAKE_CASE__       :     Tuple				,	SCREAMING_SNAKE_CASE__       :     Any				,	SCREAMING_SNAKE_CASE__       :     Tuple				,	SCREAMING_SNAKE_CASE__       :     List[Any]				,	SCREAMING_SNAKE_CASE__       :     Tuple				,	SCREAMING_SNAKE_CASE__       :     Dict							)  ->   Any:
  __lowerCAmelCase    							=						TFMPNetForQuestionAnswering(config=SCREAMING_SNAKE_CASE__							)
  __lowerCAmelCase    							=						{
      """input_ids""": input_ids,
      """attention_mask""": input_mask,
  }
  __lowerCAmelCase    							=						model(SCREAMING_SNAKE_CASE__							)
  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       :     List[Any]				,	SCREAMING_SNAKE_CASE__       :     str				,	SCREAMING_SNAKE_CASE__       :     Any				,	SCREAMING_SNAKE_CASE__       :     Optional[int]				,	SCREAMING_SNAKE_CASE__       :     Optional[int]				,	SCREAMING_SNAKE_CASE__       :     List[str]				,	SCREAMING_SNAKE_CASE__       :     Any							)  ->   str:
  __lowerCAmelCase    							=						self.num_labels
  __lowerCAmelCase    							=						TFMPNetForSequenceClassification(SCREAMING_SNAKE_CASE__							)
  __lowerCAmelCase    							=						{"""input_ids""": input_ids, """attention_mask""": input_mask}
  __lowerCAmelCase    							=						model(SCREAMING_SNAKE_CASE__							)
  self.parent.assertEqual(result.logits.shape				,	(self.batch_size, self.num_labels)							)
 def a (				self       :     List[str]				,	SCREAMING_SNAKE_CASE__       :     Union[str, Any]				,	SCREAMING_SNAKE_CASE__       :     Any				,	SCREAMING_SNAKE_CASE__       :     str				,	SCREAMING_SNAKE_CASE__       :     Any				,	SCREAMING_SNAKE_CASE__       :     int				,	SCREAMING_SNAKE_CASE__       :     Union[str, Any]							)  ->   List[Any]:
  __lowerCAmelCase    							=						self.num_choices
  __lowerCAmelCase    							=						TFMPNetForMultipleChoice(SCREAMING_SNAKE_CASE__							)
  __lowerCAmelCase    							=						tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE__				,	1							)				,	(1, self.num_choices, 1)							)
  __lowerCAmelCase    							=						tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE__				,	1							)				,	(1, self.num_choices, 1)							)
  __lowerCAmelCase    							=						{
      """input_ids""": multiple_choice_inputs_ids,
      """attention_mask""": multiple_choice_input_mask,
  }
  __lowerCAmelCase    							=						model(SCREAMING_SNAKE_CASE__							)
  self.parent.assertEqual(result.logits.shape				,	(self.batch_size, self.num_choices)							)
 def a (				self       :     Union[str, Any]				,	SCREAMING_SNAKE_CASE__       :     Optional[int]				,	SCREAMING_SNAKE_CASE__       :     Any				,	SCREAMING_SNAKE_CASE__       :     int				,	SCREAMING_SNAKE_CASE__       :     Dict				,	SCREAMING_SNAKE_CASE__       :     Tuple				,	SCREAMING_SNAKE_CASE__       :     str							)  ->   int:
  __lowerCAmelCase    							=						self.num_labels
  __lowerCAmelCase    							=						TFMPNetForTokenClassification(SCREAMING_SNAKE_CASE__							)
  __lowerCAmelCase    							=						{"""input_ids""": input_ids, """attention_mask""": input_mask}
  __lowerCAmelCase    							=						model(SCREAMING_SNAKE_CASE__							)
  self.parent.assertEqual(result.logits.shape				,	(self.batch_size, self.seq_length, self.num_labels)							)





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







@require_tf
class     _lowercase					(    UpperCAmelCase__  ,							UpperCAmelCase__  ,							unittest.TestCase      ):


 '''simple docstring'''






 _SCREAMING_SNAKE_CASE					:	str				     = (
     (
         TFMPNetForMaskedLM,
         TFMPNetForMultipleChoice,
         TFMPNetForQuestionAnswering,
         TFMPNetForSequenceClassification,
         TFMPNetForTokenClassification,
         TFMPNetModel,
     )
     if is_tf_available()
     else ()
 )
 _SCREAMING_SNAKE_CASE					:	Any				     = (
     {
         """feature-extraction""": TFMPNetModel,
         """fill-mask""": TFMPNetForMaskedLM,
         """question-answering""": TFMPNetForQuestionAnswering,
         """text-classification""": TFMPNetForSequenceClassification,
         """token-classification""": TFMPNetForTokenClassification,
         """zero-shot""": TFMPNetForSequenceClassification,
     }
     if is_tf_available()
     else {}
 )
 _SCREAMING_SNAKE_CASE					:	Tuple				     = False
 _SCREAMING_SNAKE_CASE					:	Tuple				     = False
 def a (				self       :     Optional[Any]							)  ->   List[Any]:
  __lowerCAmelCase    							=						TFMPNetModelTester(self							)
  __lowerCAmelCase    							=						ConfigTester(self				,	config_class=SCREAMING_SNAKE_CASE__				,	hidden_size=37							)
 def a (				self       :     Dict							)  ->   str:
  self.config_tester.run_common_tests()
 def a (				self       :     str							)  ->   str:
  __lowerCAmelCase    							=						self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_mpnet_model(*SCREAMING_SNAKE_CASE__							)
 def a (				self       :     Optional[Any]							)  ->   List[str]:
  __lowerCAmelCase    							=						self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_mpnet_for_masked_lm(*SCREAMING_SNAKE_CASE__							)
 def a (				self       :     List[str]							)  ->   Union[str, Any]:
  __lowerCAmelCase    							=						self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_mpnet_for_question_answering(*SCREAMING_SNAKE_CASE__							)
 def a (				self       :     List[Any]							)  ->   str:
  __lowerCAmelCase    							=						self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_mpnet_for_sequence_classification(*SCREAMING_SNAKE_CASE__							)
 def a (				self       :     str							)  ->   Dict:
  __lowerCAmelCase    							=						self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_mpnet_for_multiple_choice(*SCREAMING_SNAKE_CASE__							)
 def a (				self       :     Dict							)  ->   Dict:
  __lowerCAmelCase    							=						self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_mpnet_for_token_classification(*SCREAMING_SNAKE_CASE__							)





 @slow
 def a (				self       :     str							)  ->   Union[str, Any]:
  for model_name in ["microsoft/mpnet-base"]:
   __lowerCAmelCase    							=						TFMPNetModel.from_pretrained(SCREAMING_SNAKE_CASE__							)
   self.assertIsNotNone(SCREAMING_SNAKE_CASE__							)







@require_tf
class     _lowercase					(    unittest.TestCase      ):


 '''simple docstring'''






 @slow
 def a (				self       :     Optional[Any]							)  ->   Any:
  __lowerCAmelCase    							=						TFMPNetModel.from_pretrained("""microsoft/mpnet-base"""							)
  __lowerCAmelCase    							=						tf.constant([[0, 1, 2, 3, 4, 5]]							)
  __lowerCAmelCase    							=						model(SCREAMING_SNAKE_CASE__							)[0]

  __lowerCAmelCase    							=						[1, 6, 7_68]
  self.assertEqual(output.shape				,	SCREAMING_SNAKE_CASE__							)

  __lowerCAmelCase    							=						tf.constant(
      [
          [
              [-0.1_0_6_7_1_7_2, 0.0_8_2_1_6_4_7_3, 0.0_0_2_4_5_4_3],
              [-0.0_3_4_6_5_8_7_9, 0.8_3_5_4_1_1_8, -0.0_3_2_5_2_2_8_8],
              [-0.0_6_5_6_9_4_7_6, -0.1_2_4_2_4_1_1_1, -0.0_4_9_4_4_3_6],
          ]
      ]							)
  tf.debugging.assert_near(output[:, :3, :3]				,	SCREAMING_SNAKE_CASE__				,	atol=1e-4							)







'''simple docstring'''

from unittest.mock import patch

import datasets
from datasets import Dataset







def 					UpperCamelCase_						( ) ->					Dict:






 '''simple docstring'''

 __lowerCAmelCase    							=						Dataset.from_dict({"""col_1""": [3, 2, 0, 1]}				)

 with patch("""tqdm.auto.tqdm"""				) as mock_tqdm:
  datasets.disable_progress_bar()
  dset.map(lambda snake_case_				: {"col_2": x["col_1"] + 1}				)
  mock_tqdm.assert_not_called()

  mock_tqdm.reset_mock()

  datasets.enable_progress_bar()
  dset.map(lambda snake_case_				: {"col_2": x["col_1"] + 1}				)
  mock_tqdm.assert_called()






