


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 				SCREAMING_SNAKE_CASE__						(       lowercase__		,					lowercase__		,					unittest.TestCase    ):
      snake_case__       :  Tuple       =		(
          (
              TFMobileBertModel,
              TFMobileBertForMaskedLM,
              TFMobileBertForNextSentencePrediction,
              TFMobileBertForPreTraining,
              TFMobileBertForQuestionAnswering,
              TFMobileBertForSequenceClassification,
              TFMobileBertForTokenClassification,
              TFMobileBertForMultipleChoice,
          )
          if is_tf_available()
          else ()
      )
      snake_case__       :  Optional[int]       =		(
          {
              '''feature-extraction''': TFMobileBertModel,
              '''fill-mask''': TFMobileBertForMaskedLM,
              '''question-answering''': TFMobileBertForQuestionAnswering,
              '''text-classification''': TFMobileBertForSequenceClassification,
              '''token-classification''': TFMobileBertForTokenClassification,
              '''zero-shot''': TFMobileBertForSequenceClassification,
          }
          if is_tf_available()
          else {}
      )
      snake_case__       :  Dict       =		False
      snake_case__       :  int       =		False
      def  SCREAMING_SNAKE_CASE							( self       : Optional[int]  ,							SCREAMING_SNAKE_CASE__       : List[str]  ,							SCREAMING_SNAKE_CASE__       : List[Any]  ,							SCREAMING_SNAKE_CASE__       : Union[str, Any]=False  )	->    List[str]:
             a_      :	Tuple							=						super()._prepare_for_class(SCREAMING_SNAKE_CASE__  ,							SCREAMING_SNAKE_CASE__  ,							return_labels=SCREAMING_SNAKE_CASE__  )

             if return_labels:
                    if model_class in get_values(SCREAMING_SNAKE_CASE__  ):
                           a_      :	Any							=						tf.zeros(self.model_tester.batch_size  ,							dtype=tf.intaa  )

             return inputs_dict
      class 				SCREAMING_SNAKE_CASE__						(       lowercase__    ):
            def __init__( self       : List[str]  ,							SCREAMING_SNAKE_CASE__       : List[str]  ,							SCREAMING_SNAKE_CASE__       : Optional[Any]=1_3  ,							SCREAMING_SNAKE_CASE__       : int=7  ,							SCREAMING_SNAKE_CASE__       : Dict=True  ,							SCREAMING_SNAKE_CASE__       : Any=True  ,							SCREAMING_SNAKE_CASE__       : Union[str, Any]=True  ,							SCREAMING_SNAKE_CASE__       : Dict=True  ,							SCREAMING_SNAKE_CASE__       : str=9_9  ,							SCREAMING_SNAKE_CASE__       : int=3_2  ,							SCREAMING_SNAKE_CASE__       : Dict=3_2  ,							SCREAMING_SNAKE_CASE__       : int=2  ,							SCREAMING_SNAKE_CASE__       : Dict=4  ,							SCREAMING_SNAKE_CASE__       : Dict=3_7  ,							SCREAMING_SNAKE_CASE__       : Optional[int]="gelu"  ,							SCREAMING_SNAKE_CASE__       : str=0.1  ,							SCREAMING_SNAKE_CASE__       : int=0.1  ,							SCREAMING_SNAKE_CASE__       : Dict=5_1_2  ,							SCREAMING_SNAKE_CASE__       : int=1_6  ,							SCREAMING_SNAKE_CASE__       : List[Any]=2  ,							SCREAMING_SNAKE_CASE__       : Any=0.02  ,							SCREAMING_SNAKE_CASE__       : Tuple=3  ,							SCREAMING_SNAKE_CASE__       : List[str]=4  ,							SCREAMING_SNAKE_CASE__       : Any=None  ,							)	->    Tuple:
                   a_      :	Tuple							=						parent
                   a_      :	str							=						batch_size
                   a_      :	str							=						seq_length
                   a_      :	str							=						is_training
                   a_      :	Optional[Any]							=						use_input_mask
                   a_      :	Optional[Any]							=						use_token_type_ids
                   a_      :	Optional[int]							=						use_labels
                   a_      :	Union[str, Any]							=						vocab_size
                   a_      :	Tuple							=						hidden_size
                   a_      :	Dict							=						num_hidden_layers
                   a_      :	List[str]							=						num_attention_heads
                   a_      :	Optional[Any]							=						intermediate_size
                   a_      :	int							=						hidden_act
                   a_      :	Any							=						hidden_dropout_prob
                   a_      :	Tuple							=						attention_probs_dropout_prob
                   a_      :	Any							=						max_position_embeddings
                   a_      :	str							=						type_vocab_size
                   a_      :	List[str]							=						type_sequence_label_size
                   a_      :	Tuple							=						initializer_range
                   a_      :	Dict							=						num_labels
                   a_      :	Optional[int]							=						num_choices
                   a_      :	List[Any]							=						scope
                   a_      :	Dict							=						embedding_size
            def  SCREAMING_SNAKE_CASE							( self       : Optional[int]  )	->    Union[str, Any]:
                   a_      :	List[str]							=						ids_tensor([self.batch_size, self.seq_length]  ,							self.vocab_size  )

                   a_      :	Union[str, Any]							=						None
                   if self.use_input_mask:
                          a_      :	Optional[Any]							=						random_attention_mask([self.batch_size, self.seq_length]  )

                   a_      :	Optional[int]							=						None
                   if self.use_token_type_ids:
                          a_      :	List[Any]							=						ids_tensor([self.batch_size, self.seq_length]  ,							self.type_vocab_size  )

                   a_      :	Tuple							=						None
                   a_      :	List[Any]							=						None
                   a_      :	str							=						None
                   if self.use_labels:
                          a_      :	Union[str, Any]							=						ids_tensor([self.batch_size]  ,							self.type_sequence_label_size  )
                          a_      :	int							=						ids_tensor([self.batch_size, self.seq_length]  ,							self.num_labels  )
                          a_      :	int							=						ids_tensor([self.batch_size]  ,							self.num_choices  )

                   a_      :	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  SCREAMING_SNAKE_CASE							( self       : str  ,							SCREAMING_SNAKE_CASE__       : Dict  ,							SCREAMING_SNAKE_CASE__       : Union[str, Any]  ,							SCREAMING_SNAKE_CASE__       : str  ,							SCREAMING_SNAKE_CASE__       : Any  ,							SCREAMING_SNAKE_CASE__       : List[str]  ,							SCREAMING_SNAKE_CASE__       : List[Any]  ,							SCREAMING_SNAKE_CASE__       : Optional[int]  )	->    Tuple:
                   a_      :	str							=						TFMobileBertModel(config=SCREAMING_SNAKE_CASE__  )
                   a_      :	str							=						{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
                   a_      :	Union[str, Any]							=						model(SCREAMING_SNAKE_CASE__  )

                   a_      :	List[Any]							=						[input_ids, input_mask]
                   a_      :	Tuple							=						model(SCREAMING_SNAKE_CASE__  )

                   a_      :	Dict							=						model(SCREAMING_SNAKE_CASE__  )

                   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  SCREAMING_SNAKE_CASE							( self       : Union[str, Any]  ,							SCREAMING_SNAKE_CASE__       : Tuple  ,							SCREAMING_SNAKE_CASE__       : List[Any]  ,							SCREAMING_SNAKE_CASE__       : Optional[int]  ,							SCREAMING_SNAKE_CASE__       : str  ,							SCREAMING_SNAKE_CASE__       : Optional[int]  ,							SCREAMING_SNAKE_CASE__       : Optional[int]  ,							SCREAMING_SNAKE_CASE__       : int  )	->    Any:
                   a_      :	Any							=						TFMobileBertForMaskedLM(config=SCREAMING_SNAKE_CASE__  )
                   a_      :	str							=						{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
                   a_      :	Tuple							=						model(SCREAMING_SNAKE_CASE__  )
                   self.parent.assertEqual(result.logits.shape  ,							(self.batch_size, self.seq_length, self.vocab_size)  )
            def  SCREAMING_SNAKE_CASE							( self       : str  ,							SCREAMING_SNAKE_CASE__       : int  ,							SCREAMING_SNAKE_CASE__       : Dict  ,							SCREAMING_SNAKE_CASE__       : Dict  ,							SCREAMING_SNAKE_CASE__       : Any  ,							SCREAMING_SNAKE_CASE__       : Union[str, Any]  ,							SCREAMING_SNAKE_CASE__       : Any  ,							SCREAMING_SNAKE_CASE__       : Tuple  )	->    Tuple:
                   a_      :	Union[str, Any]							=						TFMobileBertForNextSentencePrediction(config=SCREAMING_SNAKE_CASE__  )
                   a_      :	int							=						{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
                   a_      :	List[Any]							=						model(SCREAMING_SNAKE_CASE__  )
                   self.parent.assertEqual(result.logits.shape  ,							(self.batch_size, 2)  )
            def  SCREAMING_SNAKE_CASE							( self       : Tuple  ,							SCREAMING_SNAKE_CASE__       : int  ,							SCREAMING_SNAKE_CASE__       : Tuple  ,							SCREAMING_SNAKE_CASE__       : Optional[int]  ,							SCREAMING_SNAKE_CASE__       : List[str]  ,							SCREAMING_SNAKE_CASE__       : int  ,							SCREAMING_SNAKE_CASE__       : Any  ,							SCREAMING_SNAKE_CASE__       : Dict  )	->    int:
                   a_      :	List[str]							=						TFMobileBertForPreTraining(config=SCREAMING_SNAKE_CASE__  )
                   a_      :	Any							=						{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
                   a_      :	int							=						model(SCREAMING_SNAKE_CASE__  )
                   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  SCREAMING_SNAKE_CASE							( self       : Any  ,							SCREAMING_SNAKE_CASE__       : Optional[int]  ,							SCREAMING_SNAKE_CASE__       : Union[str, Any]  ,							SCREAMING_SNAKE_CASE__       : Any  ,							SCREAMING_SNAKE_CASE__       : int  ,							SCREAMING_SNAKE_CASE__       : str  ,							SCREAMING_SNAKE_CASE__       : Tuple  ,							SCREAMING_SNAKE_CASE__       : Any  )	->    List[Any]:
                   a_      :	List[str]							=						self.num_labels
                   a_      :	str							=						TFMobileBertForSequenceClassification(config=SCREAMING_SNAKE_CASE__  )
                   a_      :	Union[str, Any]							=						{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
                   a_      :	int							=						model(SCREAMING_SNAKE_CASE__  )
                   self.parent.assertEqual(result.logits.shape  ,							(self.batch_size, self.num_labels)  )
            def  SCREAMING_SNAKE_CASE							( self       : Tuple  ,							SCREAMING_SNAKE_CASE__       : str  ,							SCREAMING_SNAKE_CASE__       : int  ,							SCREAMING_SNAKE_CASE__       : Union[str, Any]  ,							SCREAMING_SNAKE_CASE__       : Union[str, Any]  ,							SCREAMING_SNAKE_CASE__       : Tuple  ,							SCREAMING_SNAKE_CASE__       : Optional[int]  ,							SCREAMING_SNAKE_CASE__       : List[str]  )	->    Optional[int]:
                   a_      :	Tuple							=						self.num_choices
                   a_      :	Optional[int]							=						TFMobileBertForMultipleChoice(config=SCREAMING_SNAKE_CASE__  )
                   a_      :	Optional[int]							=						tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE__  ,							1  )  ,							(1, self.num_choices, 1)  )
                   a_      :	List[Any]							=						tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE__  ,							1  )  ,							(1, self.num_choices, 1)  )
                   a_      :	Tuple							=						tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE__  ,							1  )  ,							(1, self.num_choices, 1)  )
                   a_      :	Tuple							=						{
                       'input_ids': multiple_choice_inputs_ids,
                       'attention_mask': multiple_choice_input_mask,
                       'token_type_ids': multiple_choice_token_type_ids,
                   }
                   a_      :	Any							=						model(SCREAMING_SNAKE_CASE__  )
                   self.parent.assertEqual(result.logits.shape  ,							(self.batch_size, self.num_choices)  )
            def  SCREAMING_SNAKE_CASE							( self       : str  ,							SCREAMING_SNAKE_CASE__       : Optional[Any]  ,							SCREAMING_SNAKE_CASE__       : str  ,							SCREAMING_SNAKE_CASE__       : List[Any]  ,							SCREAMING_SNAKE_CASE__       : str  ,							SCREAMING_SNAKE_CASE__       : List[str]  ,							SCREAMING_SNAKE_CASE__       : Dict  ,							SCREAMING_SNAKE_CASE__       : Any  )	->    Union[str, Any]:
                   a_      :	Any							=						self.num_labels
                   a_      :	str							=						TFMobileBertForTokenClassification(config=SCREAMING_SNAKE_CASE__  )
                   a_      :	Any							=						{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
                   a_      :	int							=						model(SCREAMING_SNAKE_CASE__  )
                   self.parent.assertEqual(result.logits.shape  ,							(self.batch_size, self.seq_length, self.num_labels)  )
            def  SCREAMING_SNAKE_CASE							( self       : Dict  ,							SCREAMING_SNAKE_CASE__       : str  ,							SCREAMING_SNAKE_CASE__       : List[Any]  ,							SCREAMING_SNAKE_CASE__       : Union[str, Any]  ,							SCREAMING_SNAKE_CASE__       : Dict  ,							SCREAMING_SNAKE_CASE__       : Union[str, Any]  ,							SCREAMING_SNAKE_CASE__       : Dict  ,							SCREAMING_SNAKE_CASE__       : Any  )	->    str:
                   a_      :	List[str]							=						TFMobileBertForQuestionAnswering(config=SCREAMING_SNAKE_CASE__  )
                   a_      :	Dict							=						{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
                   a_      :	Optional[Any]							=						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  SCREAMING_SNAKE_CASE							( self       : int  )	->    Optional[Any]:
                   a_      :	Optional[Any]							=						self.prepare_config_and_inputs()
                   (
                       a_	
                   )      :	Tuple							=						config_and_inputs
                   a_      :	Optional[Any]							=						{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
                   return config, inputs_dict
      def  SCREAMING_SNAKE_CASE							( self       : Optional[int]  )	->    Optional[int]:
             a_      :	Dict							=						TFMobileBertModelTest.TFMobileBertModelTester(self  )
             a_      :	Optional[Any]							=						ConfigTester(self  ,							config_class=SCREAMING_SNAKE_CASE__  ,							hidden_size=3_7  )
      def  SCREAMING_SNAKE_CASE							( self       : List[Any]  )	->    List[str]:
             self.config_tester.run_common_tests()
      def  SCREAMING_SNAKE_CASE							( self       : Union[str, Any]  )	->    List[str]:
             a_      :	Optional[Any]							=						self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mobilebert_model(*SCREAMING_SNAKE_CASE__  )
      def  SCREAMING_SNAKE_CASE							( self       : Optional[int]  )	->    int:
             a_      :	Optional[int]							=						self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mobilebert_for_masked_lm(*SCREAMING_SNAKE_CASE__  )
      def  SCREAMING_SNAKE_CASE							( self       : str  )	->    Any:
             a_      :	List[str]							=						self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mobilebert_for_multiple_choice(*SCREAMING_SNAKE_CASE__  )
      def  SCREAMING_SNAKE_CASE							( self       : Optional[Any]  )	->    int:
             a_      :	Any							=						self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*SCREAMING_SNAKE_CASE__  )
      def  SCREAMING_SNAKE_CASE							( self       : Union[str, Any]  )	->    int:
             a_      :	Optional[Any]							=						self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mobilebert_for_pretraining(*SCREAMING_SNAKE_CASE__  )
      def  SCREAMING_SNAKE_CASE							( self       : Dict  )	->    int:
             a_      :	Any							=						self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mobilebert_for_question_answering(*SCREAMING_SNAKE_CASE__  )
      def  SCREAMING_SNAKE_CASE							( self       : str  )	->    Dict:
             a_      :	Optional[int]							=						self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mobilebert_for_sequence_classification(*SCREAMING_SNAKE_CASE__  )
      def  SCREAMING_SNAKE_CASE							( self       : List[Any]  )	->    Tuple:
             a_      :	Dict							=						self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mobilebert_for_token_classification(*SCREAMING_SNAKE_CASE__  )

      @slow
      def  SCREAMING_SNAKE_CASE							( self       : Optional[Any]  )	->    Optional[Any]:
             # for model_name in TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             for model_name in ["google/mobilebert-uncased"]:
                    a_      :	Optional[Any]							=						TFMobileBertModel.from_pretrained(SCREAMING_SNAKE_CASE__  )
                    self.assertIsNotNone(SCREAMING_SNAKE_CASE__  )
@require_tf
class 				SCREAMING_SNAKE_CASE__						(       unittest.TestCase    ):
      @slow
      def  SCREAMING_SNAKE_CASE							( self       : int  )	->    str:
             a_      :	List[Any]							=						TFMobileBertForPreTraining.from_pretrained('google/mobilebert-uncased'  )
             a_      :	Tuple							=						tf.constant([[0, 1, 2, 3, 4, 5]]  )
             a_      :	Tuple							=						model(SCREAMING_SNAKE_CASE__  )[0]

             a_      :	Tuple							=						[1, 6, 3_0_5_2_2]
             self.assertEqual(output.shape  ,							SCREAMING_SNAKE_CASE__  )

             a_      :	Optional[Any]							=						tf.constant(
                 [
                     [
                         [-4.5919547, -9.248295, -9.645256],
                         [-6.7306175, -6.440284, -6.6052837],
                         [-7.2743506, -6.7847915, -6.024673],
                     ]
                 ]  )
             tf.debugging.assert_near(output[:, :3, :3]  ,							SCREAMING_SNAKE_CASE__  ,							atol=1E-4  )





def  SCREAMING_SNAKE_CASE_		(    __A				:    int       )			->	bool:

       """simple docstring"""

       a_      :	List[Any]							=						n ** (1 / 3)
       return (val * val * val) == n


if __name__ == "__main__":
   print(perfect_cube(27))
   print(perfect_cube(4))


