






'''simple docstring'''

from __future__ import annotations

import unittest

from transformers import MobileBertConfig, is_tf_available
from transformers.models.auto import get_values
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 import (
          TF_MODEL_FOR_PRETRAINING_MAPPING,
          TFMobileBertForMaskedLM,
          TFMobileBertForMultipleChoice,
          TFMobileBertForNextSentencePrediction,
          TFMobileBertForPreTraining,
          TFMobileBertForQuestionAnswering,
          TFMobileBertForSequenceClassification,
          TFMobileBertForTokenClassification,
          TFMobileBertModel,
      )




@require_tf
class      A     (   SCREAMING_SNAKE_CASE__, SCREAMING_SNAKE_CASE__, unittest.TestCase    ):






 """simple docstring"""





 __a      :    Optional[Any]			  =    (
     (
         TFMobileBertModel,
         TFMobileBertForMaskedLM,
         TFMobileBertForNextSentencePrediction,
         TFMobileBertForPreTraining,
         TFMobileBertForQuestionAnswering,
         TFMobileBertForSequenceClassification,
         TFMobileBertForTokenClassification,
         TFMobileBertForMultipleChoice,
     )
     if is_tf_available()
     else ()
 )
 __a      :    Union[str, Any]			  =    (
     {
         '''feature-extraction''': TFMobileBertModel,
         '''fill-mask''': TFMobileBertForMaskedLM,
         '''question-answering''': TFMobileBertForQuestionAnswering,
         '''text-classification''': TFMobileBertForSequenceClassification,
         '''token-classification''': TFMobileBertForTokenClassification,
         '''zero-shot''': TFMobileBertForSequenceClassification,
     }
     if is_tf_available()
     else {}
 )
 __a      :    Union[str, Any]			  =    False
 __a      :    str			  =    False
 def 	_UpperCAmelCase							(				self      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase=False			):
       UpperCamelCase_					: Optional[int]            =				super()._prepare_for_class(__lowerCAmelCase      ,  __lowerCAmelCase      ,  return_labels=__lowerCAmelCase			)

       if return_labels:
             if model_class in get_values(__lowerCAmelCase			):
                   UpperCamelCase_					: List[str]            =				tf.zeros(self.model_tester.batch_size      ,  dtype=tf.intaa			)

       return inputs_dict




 class      A     (   SCREAMING_SNAKE_CASE__    ):






  """simple docstring"""





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

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

        UpperCamelCase_					: Tuple            =				None
        if self.use_token_type_ids:
              UpperCamelCase_					: Tuple            =				ids_tensor([self.batch_size, self.seq_length]      ,  self.type_vocab_size			)

        UpperCamelCase_					: Tuple            =				None
        UpperCamelCase_					: Dict            =				None
        UpperCamelCase_					: int            =				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_					: List[Any]            =				ids_tensor([self.batch_size]      ,  self.num_choices			)

        UpperCamelCase_					: List[Any]            =				MobileBertConfig(
            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      ,  type_vocab_size=self.type_vocab_size      ,  initializer_range=self.initializer_range      ,  embedding_size=self.embedding_size      ,  )

        return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
  def 	_UpperCAmelCase							(				self      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase			):
        UpperCamelCase_					: Tuple            =				TFMobileBertModel(config=__lowerCAmelCase			)
        UpperCamelCase_					: Dict            =				{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
        UpperCamelCase_					: str            =				model(__lowerCAmelCase			)

        UpperCamelCase_					: Any            =				[input_ids, input_mask]
        UpperCamelCase_					: Union[str, Any]            =				model(__lowerCAmelCase			)

        UpperCamelCase_					: List[Any]            =				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 	_UpperCAmelCase							(				self      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase			):
        UpperCamelCase_					: str            =				TFMobileBertForMaskedLM(config=__lowerCAmelCase			)
        UpperCamelCase_					: Optional[Any]            =				{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
        UpperCamelCase_					: str            =				model(__lowerCAmelCase			)
        self.parent.assertEqual(result.logits.shape      ,  (self.batch_size, self.seq_length, self.vocab_size)			)
  def 	_UpperCAmelCase							(				self      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase			):
        UpperCamelCase_					: Optional[Any]            =				TFMobileBertForNextSentencePrediction(config=__lowerCAmelCase			)
        UpperCamelCase_					: str            =				{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
        UpperCamelCase_					: Optional[int]            =				model(__lowerCAmelCase			)
        self.parent.assertEqual(result.logits.shape      ,  (self.batch_size, 2)			)
  def 	_UpperCAmelCase							(				self      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase			):
        UpperCamelCase_					: List[Any]            =				TFMobileBertForPreTraining(config=__lowerCAmelCase			)
        UpperCamelCase_					: Dict            =				{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
        UpperCamelCase_					: Optional[Any]            =				model(__lowerCAmelCase			)
        self.parent.assertEqual(
            result.prediction_logits.shape      ,  (self.batch_size, self.seq_length, self.vocab_size)			)
        self.parent.assertEqual(result.seq_relationship_logits.shape      ,  (self.batch_size, 2)			)
  def 	_UpperCAmelCase							(				self      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase			):
        UpperCamelCase_					: List[Any]            =				self.num_labels
        UpperCamelCase_					: List[Any]            =				TFMobileBertForSequenceClassification(config=__lowerCAmelCase			)
        UpperCamelCase_					: str            =				{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
        UpperCamelCase_					: Optional[int]            =				model(__lowerCAmelCase			)
        self.parent.assertEqual(result.logits.shape      ,  (self.batch_size, self.num_labels)			)
  def 	_UpperCAmelCase							(				self      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase			):
        UpperCamelCase_					: str            =				self.num_choices
        UpperCamelCase_					: Union[str, Any]            =				TFMobileBertForMultipleChoice(config=__lowerCAmelCase			)
        UpperCamelCase_					: Union[str, Any]            =				tf.tile(tf.expand_dims(__lowerCAmelCase      ,  1			)      ,  (1, self.num_choices, 1)			)
        UpperCamelCase_					: List[str]            =				tf.tile(tf.expand_dims(__lowerCAmelCase      ,  1			)      ,  (1, self.num_choices, 1)			)
        UpperCamelCase_					: List[str]            =				tf.tile(tf.expand_dims(__lowerCAmelCase      ,  1			)      ,  (1, self.num_choices, 1)			)
        UpperCamelCase_					: int            =				{
            """input_ids""": multiple_choice_inputs_ids,
            """attention_mask""": multiple_choice_input_mask,
            """token_type_ids""": multiple_choice_token_type_ids,
        }
        UpperCamelCase_					: Any            =				model(__lowerCAmelCase			)
        self.parent.assertEqual(result.logits.shape      ,  (self.batch_size, self.num_choices)			)
  def 	_UpperCAmelCase							(				self      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase			):
        UpperCamelCase_					: Optional[int]            =				self.num_labels
        UpperCamelCase_					: int            =				TFMobileBertForTokenClassification(config=__lowerCAmelCase			)
        UpperCamelCase_					: List[str]            =				{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
        UpperCamelCase_					: int            =				model(__lowerCAmelCase			)
        self.parent.assertEqual(result.logits.shape      ,  (self.batch_size, self.seq_length, self.num_labels)			)
  def 	_UpperCAmelCase							(				self      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase      ,  __lowerCAmelCase			):
        UpperCamelCase_					: int            =				TFMobileBertForQuestionAnswering(config=__lowerCAmelCase			)
        UpperCamelCase_					: Dict            =				{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
        UpperCamelCase_					: Optional[int]            =				model(__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 	_UpperCAmelCase							(				self			):
        UpperCamelCase_					: Optional[int]            =				self.prepare_config_and_inputs()
        (
            (
            UpperCamelCase_
        )     ,      (
            UpperCamelCase_
        )     ,      (
            UpperCamelCase_
        )     ,      (
            UpperCamelCase_
        )     ,      (
            UpperCamelCase_
        )     ,      (
            UpperCamelCase_
        )     ,      (
            UpperCamelCase_
        )     ,      
        )					: Any            =				config_and_inputs
        UpperCamelCase_					: Union[str, Any]            =				{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
        return config, inputs_dict






 def 	_UpperCAmelCase							(				self			):
       UpperCamelCase_					: Dict            =				TFMobileBertModelTest.TFMobileBertModelTester(self			)
       UpperCamelCase_					: Tuple            =				ConfigTester(self      ,  config_class=__lowerCAmelCase      ,  hidden_size=37			)
 def 	_UpperCAmelCase							(				self			):
       self.config_tester.run_common_tests()
 def 	_UpperCAmelCase							(				self			):
       UpperCamelCase_					: Union[str, Any]            =				self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_model(*__lowerCAmelCase			)
 def 	_UpperCAmelCase							(				self			):
       UpperCamelCase_					: Tuple            =				self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_masked_lm(*__lowerCAmelCase			)
 def 	_UpperCAmelCase							(				self			):
       UpperCamelCase_					: Optional[int]            =				self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_multiple_choice(*__lowerCAmelCase			)
 def 	_UpperCAmelCase							(				self			):
       UpperCamelCase_					: int            =				self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*__lowerCAmelCase			)
 def 	_UpperCAmelCase							(				self			):
       UpperCamelCase_					: int            =				self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_pretraining(*__lowerCAmelCase			)
 def 	_UpperCAmelCase							(				self			):
       UpperCamelCase_					: Optional[int]            =				self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_question_answering(*__lowerCAmelCase			)
 def 	_UpperCAmelCase							(				self			):
       UpperCamelCase_					: int            =				self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_sequence_classification(*__lowerCAmelCase			)
 def 	_UpperCAmelCase							(				self			):
       UpperCamelCase_					: List[str]            =				self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mobilebert_for_token_classification(*__lowerCAmelCase			)





 @slow
 def 	_UpperCAmelCase							(				self			):
       # for model_name in TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       for model_name in ["google/mobilebert-uncased"]:
             UpperCamelCase_					: Any            =				TFMobileBertModel.from_pretrained(__lowerCAmelCase			)
             self.assertIsNotNone(__lowerCAmelCase			)






@require_tf
class      A     (   unittest.TestCase    ):






 """simple docstring"""





 @slow
 def 	_UpperCAmelCase							(				self			):
       UpperCamelCase_					: Optional[int]            =				TFMobileBertForPreTraining.from_pretrained("""google/mobilebert-uncased"""			)
       UpperCamelCase_					: Any            =				tf.constant([[0, 1, 2, 3, 4, 5]]			)
       UpperCamelCase_					: Any            =				model(__lowerCAmelCase			)[0]

       UpperCamelCase_					: Tuple            =				[1, 6, 3_05_22]
       self.assertEqual(output.shape      ,  __lowerCAmelCase			)

       UpperCamelCase_					: str            =				tf.constant(
           [
               [
                   [-4.5_91_95_47, -9.24_82_95, -9.64_52_56],
                   [-6.7_30_61_75, -6.44_02_84, -6.6_05_28_37],
                   [-7.2_74_35_06, -6.7_84_79_15, -6.02_46_73],
               ]
           ]			)
       tf.debugging.assert_near(output[:, :3, :3]      ,  __lowerCAmelCase      ,  atol=1E-4			)














'''simple docstring'''

from __future__ import annotations

from collections import namedtuple



def 				snake_case       (  a_				:			float     , a_				:			float     , a_				:			float						)							->					tuple:





      """simple docstring"""

      UpperCamelCase_					: Tuple            =				namedtuple("""result"""     , """name value"""						)
      if (voltage, current, power).count(0						) != 1:
            raise ValueError("""Only one argument must be 0"""						)
      elif power < 0:
            raise ValueError(
                """Power cannot be negative in any electrical/electronics system"""						)
      elif voltage == 0:
            return result("""voltage"""     , power / current						)
      elif current == 0:
            return result("""current"""     , power / voltage						)
      elif power == 0:
            return result("""power"""     , float(round(abs(voltage * current						)     , 2						)						)						)
      else:
            raise ValueError("""Exactly one argument must be 0"""						)


if __name__ == "__main__":
      import doctest

      doctest.testmod()






