'''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       lowerCamelCase_      (_a				,					_a				,					unittest.TestCase       ):
      '''simple docstring'''

      __UpperCamelCase:    Tuple         =		(
          (
              TFMobileBertModel,
              TFMobileBertForMaskedLM,
              TFMobileBertForNextSentencePrediction,
              TFMobileBertForPreTraining,
              TFMobileBertForQuestionAnswering,
              TFMobileBertForSequenceClassification,
              TFMobileBertForTokenClassification,
              TFMobileBertForMultipleChoice,
          )
          if is_tf_available()
          else ()
      )
      __UpperCamelCase:    List[Any]         =		(
          {
              "feature-extraction": TFMobileBertModel,
              "fill-mask": TFMobileBertForMaskedLM,
              "question-answering": TFMobileBertForQuestionAnswering,
              "text-classification": TFMobileBertForSequenceClassification,
              "token-classification": TFMobileBertForTokenClassification,
              "zero-shot": TFMobileBertForSequenceClassification,
          }
          if is_tf_available()
          else {}
      )
      __UpperCamelCase:    str         =		False
      __UpperCamelCase:    Optional[int]         =		False




      def 	_A      (			self		:							Any		,   A		:							Optional[Any]		,   A		:							Optional[int]		,   A		:							Tuple=False			):
             _UpperCAmelCase	:    Tuple				 =       super()._prepare_for_class(lowerCamelCase__		,   lowerCamelCase__		,   return_labels=lowerCamelCase__			)

             if return_labels:
                    if model_class in get_values(lowerCamelCase__			):
                           _UpperCAmelCase	:    Union[str, Any]				 =       tf.zeros(self.model_tester.batch_size		,   dtype=tf.intaa			)

             return inputs_dict

      class       lowerCamelCase_      (_a       ):
            '''simple docstring'''

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




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

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

                   _UpperCAmelCase	:    List[str]				 =       None
                   if self.use_token_type_ids:
                          _UpperCAmelCase	:    int				 =       ids_tensor([self.batch_size, self.seq_length]		,   self.type_vocab_size			)

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

                   _UpperCAmelCase	:    int				 =       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 	_A      (			self		:							Dict		,   A		:							List[str]		,   A		:							Optional[int]		,   A		:							Any		,   A		:							List[str]		,   A		:							str		,   A		:							Optional[Any]		,   A		:							List[str]			):
                   _UpperCAmelCase	:    Union[str, Any]				 =       TFMobileBertModel(config=lowerCamelCase__			)
                   _UpperCAmelCase	:    Optional[int]				 =       {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
                   _UpperCAmelCase	:    Any				 =       model(lowerCamelCase__			)

                   _UpperCAmelCase	:    Tuple				 =       [input_ids, input_mask]
                   _UpperCAmelCase	:    int				 =       model(lowerCamelCase__			)

                   _UpperCAmelCase	:    str				 =       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 	_A      (			self		:							Tuple		,   A		:							Any		,   A		:							List[Any]		,   A		:							List[Any]		,   A		:							Optional[Any]		,   A		:							List[str]		,   A		:							Optional[int]		,   A		:							Any			):
                   _UpperCAmelCase	:    Optional[Any]				 =       TFMobileBertForMaskedLM(config=lowerCamelCase__			)
                   _UpperCAmelCase	:    str				 =       {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
                   _UpperCAmelCase	:    List[Any]				 =       model(lowerCamelCase__			)
                   self.parent.assertEqual(result.logits.shape		,   (self.batch_size, self.seq_length, self.vocab_size)			)




            def 	_A      (			self		:							Union[str, Any]		,   A		:							List[Any]		,   A		:							List[Any]		,   A		:							int		,   A		:							Dict		,   A		:							Optional[int]		,   A		:							str		,   A		:							Union[str, Any]			):
                   _UpperCAmelCase	:    Dict				 =       TFMobileBertForNextSentencePrediction(config=lowerCamelCase__			)
                   _UpperCAmelCase	:    str				 =       {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
                   _UpperCAmelCase	:    List[str]				 =       model(lowerCamelCase__			)
                   self.parent.assertEqual(result.logits.shape		,   (self.batch_size, 2)			)




            def 	_A      (			self		:							Any		,   A		:							Union[str, Any]		,   A		:							int		,   A		:							Optional[int]		,   A		:							List[Any]		,   A		:							str		,   A		:							List[Any]		,   A		:							int			):
                   _UpperCAmelCase	:    Tuple				 =       TFMobileBertForPreTraining(config=lowerCamelCase__			)
                   _UpperCAmelCase	:    List[str]				 =       {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
                   _UpperCAmelCase	:    List[str]				 =       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 	_A      (			self		:							List[Any]		,   A		:							Dict		,   A		:							int		,   A		:							int		,   A		:							List[str]		,   A		:							Tuple		,   A		:							List[Any]		,   A		:							Union[str, Any]			):
                   _UpperCAmelCase	:    Optional[int]				 =       self.num_labels
                   _UpperCAmelCase	:    int				 =       TFMobileBertForSequenceClassification(config=lowerCamelCase__			)
                   _UpperCAmelCase	:    Optional[int]				 =       {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
                   _UpperCAmelCase	:    List[Any]				 =       model(lowerCamelCase__			)
                   self.parent.assertEqual(result.logits.shape		,   (self.batch_size, self.num_labels)			)




            def 	_A      (			self		:							List[str]		,   A		:							Union[str, Any]		,   A		:							Tuple		,   A		:							str		,   A		:							Dict		,   A		:							Dict		,   A		:							List[Any]		,   A		:							int			):
                   _UpperCAmelCase	:    Any				 =       self.num_choices
                   _UpperCAmelCase	:    Optional[int]				 =       TFMobileBertForMultipleChoice(config=lowerCamelCase__			)
                   _UpperCAmelCase	:    Optional[Any]				 =       tf.tile(tf.expand_dims(lowerCamelCase__		,   1			)		,   (1, self.num_choices, 1)			)
                   _UpperCAmelCase	:    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	:    Optional[Any]				 =       {
                       "input_ids": multiple_choice_inputs_ids,
                       "attention_mask": multiple_choice_input_mask,
                       "token_type_ids": multiple_choice_token_type_ids,
                   }
                   _UpperCAmelCase	:    Dict				 =       model(lowerCamelCase__			)
                   self.parent.assertEqual(result.logits.shape		,   (self.batch_size, self.num_choices)			)




            def 	_A      (			self		:							Optional[int]		,   A		:							Tuple		,   A		:							Tuple		,   A		:							List[str]		,   A		:							Optional[Any]		,   A		:							List[Any]		,   A		:							int		,   A		:							Any			):
                   _UpperCAmelCase	:    Dict				 =       self.num_labels
                   _UpperCAmelCase	:    Tuple				 =       TFMobileBertForTokenClassification(config=lowerCamelCase__			)
                   _UpperCAmelCase	:    Tuple				 =       {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
                   _UpperCAmelCase	:    Optional[Any]				 =       model(lowerCamelCase__			)
                   self.parent.assertEqual(result.logits.shape		,   (self.batch_size, self.seq_length, self.num_labels)			)




            def 	_A      (			self		:							Tuple		,   A		:							Any		,   A		:							List[Any]		,   A		:							List[str]		,   A		:							Optional[Any]		,   A		:							Union[str, Any]		,   A		:							Any		,   A		:							Union[str, Any]			):
                   _UpperCAmelCase	:    int				 =       TFMobileBertForQuestionAnswering(config=lowerCamelCase__			)
                   _UpperCAmelCase	:    int				 =       {"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 	_A      (			self		:							int			):
                   _UpperCAmelCase	:    Tuple				 =       self.prepare_config_and_inputs()
                   (
                       _UpperCAmelCase						
                   )	:    str				 =       config_and_inputs
                   _UpperCAmelCase	:    str				 =       {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
                   return config, inputs_dict




      def 	_A      (			self		:							Optional[int]			):
             _UpperCAmelCase	:    List[Any]				 =       TFMobileBertModelTest.TFMobileBertModelTester(self			)
             _UpperCAmelCase	:    Union[str, Any]				 =       ConfigTester(self		,   config_class=lowerCamelCase__		,   hidden_size=37			)




      def 	_A      (			self		:							Dict			):
             self.config_tester.run_common_tests()




      def 	_A      (			self		:							List[Any]			):
             _UpperCAmelCase	:    Any				 =       self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mobilebert_model(*lowerCamelCase__			)




      def 	_A      (			self		:							Any			):
             _UpperCAmelCase	:    int				 =       self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mobilebert_for_masked_lm(*lowerCamelCase__			)




      def 	_A      (			self		:							Optional[Any]			):
             _UpperCAmelCase	:    Any				 =       self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mobilebert_for_multiple_choice(*lowerCamelCase__			)




      def 	_A      (			self		:							Dict			):
             _UpperCAmelCase	:    int				 =       self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*lowerCamelCase__			)




      def 	_A      (			self		:							str			):
             _UpperCAmelCase	:    str				 =       self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mobilebert_for_pretraining(*lowerCamelCase__			)




      def 	_A      (			self		:							Optional[Any]			):
             _UpperCAmelCase	:    Dict				 =       self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mobilebert_for_question_answering(*lowerCamelCase__			)




      def 	_A      (			self		:							Union[str, Any]			):
             _UpperCAmelCase	:    List[Any]				 =       self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mobilebert_for_sequence_classification(*lowerCamelCase__			)




      def 	_A      (			self		:							Any			):
             _UpperCAmelCase	:    Any				 =       self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_mobilebert_for_token_classification(*lowerCamelCase__			)





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

@require_tf
class       lowerCamelCase_      (unittest.TestCase       ):
      '''simple docstring'''

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

             _UpperCAmelCase	:    int				 =       [1, 6, 30522]
             self.assertEqual(output.shape		,   lowerCamelCase__			)

             _UpperCAmelCase	:    Dict				 =       tf.constant(
                 [
                     [
                         [-4.5_919_547, -9.248_295, -9.645_256],
                         [-6.7_306_175, -6.440_284, -6.6_052_837],
                         [-7.2_743_506, -6.7_847_915, -6.024_673],
                     ]
                 ]			)
             tf.debugging.assert_near(output[:, :3, :3]		,   lowerCamelCase__		,   atol=1E-4			)




def 			_A	(      SCREAMING_SNAKE_CASE      ):
	UpperCAmelCase__:	Tuple									= int(SCREAMING_SNAKE_CASE      )
	if decimal in (0, 1):  # Exit cases for the recursion
		return str(SCREAMING_SNAKE_CASE      )
	UpperCAmelCase__							,						UpperCAmelCase__:	Union[str, Any]									= divmod(SCREAMING_SNAKE_CASE	,2      )
	return binary_recursive(SCREAMING_SNAKE_CASE      ) + str(SCREAMING_SNAKE_CASE      )



def 			_A	(      SCREAMING_SNAKE_CASE      ):
	UpperCAmelCase__:	List[str]									= str(SCREAMING_SNAKE_CASE      ).strip()
	if not number:
		raise ValueError("No input value was provided"      )
	UpperCAmelCase__:	Tuple									= "-" if number.startswith("-"      ) else ""
	UpperCAmelCase__:	Any									= number.lstrip("-"      )
	if not number.isnumeric():
		raise ValueError("Input value is not an integer"      )
	return f"{negative}0b{binary_recursive(int(SCREAMING_SNAKE_CASE      )      )}"


if __name__ == "__main__":
					from doctest import testmod

					testmod()