



import unittest

import numpy as np

from transformers import ElectraConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
    from transformers.models.electra.modeling_flax_electra import (
        FlaxElectraForCausalLM,
        FlaxElectraForMaskedLM,
        FlaxElectraForMultipleChoice,
        FlaxElectraForPreTraining,
        FlaxElectraForQuestionAnswering,
        FlaxElectraForSequenceClassification,
        FlaxElectraForTokenClassification,
        FlaxElectraModel,
    )



class 						_snake_case (     unittest.TestCase			):





 """simple docstring"""



 def __init__(  self		,      a		,      a=1_3		,      a=7		,      a=True		,      a=True		,      a=True		,      a=True		,      a=9_9		,      a=2_4		,      a=3_2		,      a=5		,      a=4		,      a=3_7		,      a="gelu"		,      a=0.1		,      a=0.1		,      a=5_1_2		,      a=1_6		,      a=2		,      a=0.02		,      a=4		,      )		->							Dict:




   """simple docstring"""







   _A          =      parent
   _A          =      batch_size
   _A          =      seq_length
   _A          =      is_training
   _A          =      use_attention_mask
   _A          =      use_token_type_ids
   _A          =      use_labels
   _A          =      vocab_size
   _A          =      hidden_size
   _A          =      embedding_size
   _A          =      num_hidden_layers
   _A          =      num_attention_heads
   _A          =      intermediate_size
   _A          =      hidden_act
   _A          =      hidden_dropout_prob
   _A          =      attention_probs_dropout_prob
   _A          =      max_position_embeddings
   _A          =      type_vocab_size
   _A          =      type_sequence_label_size
   _A          =      initializer_range
   _A          =      num_choices
 def lowercase_						(  self   )		->							Tuple:




   """simple docstring"""







   _A          =      ids_tensor([self.batch_size, self.seq_length]		,      self.vocab_size   )

   _A          =      None
   if self.use_attention_mask:
     _A          =      random_attention_mask([self.batch_size, self.seq_length]   )

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

   _A          =      ElectraConfig(
       vocab_size=self.vocab_size		,      hidden_size=self.hidden_size		,      embedding_size=self.embedding_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		,      )

   return config, input_ids, token_type_ids, attention_mask



 def lowercase_						(  self   )		->							Optional[Any]:




   """simple docstring"""







   _A          =      self.prepare_config_and_inputs()
   _A      ,				_A      ,				_A      ,				_A          =      config_and_inputs
   _A          =      {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': attention_mask}
   return config, inputs_dict







@require_flax
class 						_snake_case (     lowerCamelCase   ,unittest.TestCase			):





 """simple docstring"""



 lowerCamelCase_       =     True

 lowerCamelCase_       =     (
     (
         FlaxElectraModel,
         FlaxElectraForCausalLM,
         FlaxElectraForMaskedLM,
         FlaxElectraForPreTraining,
         FlaxElectraForTokenClassification,
         FlaxElectraForQuestionAnswering,
         FlaxElectraForMultipleChoice,
         FlaxElectraForSequenceClassification,
     )
     if is_flax_available()
     else ()
 )
 def lowercase_						(  self   )		->							str:




   """simple docstring"""







   _A          =      FlaxElectraModelTester(self   )



 @slow
 def lowercase_						(  self   )		->							List[str]:




   """simple docstring"""







   for model_class_name in self.all_model_classes:
     if model_class_name == FlaxElectraForMaskedLM:
       _A          =      model_class_name.from_pretrained('''google/electra-small-generator'''   )
     else:
       _A          =      model_class_name.from_pretrained('''google/electra-small-discriminator'''   )
     _A          =      model(np.ones((1, 1)   )   )
     self.assertIsNotNone(a   )




import math
from timeit import timeit




def       UpperCAmelCase__	(							__snake_case							)				->	int:
  _A          =      0
  _A          =      abs(__snake_case							)
  while True:
    _A          =      n // 10
    digits += 1
    if n == 0:
      break
  return digits




def       UpperCAmelCase__	(							__snake_case							)				->	int:
  return 1 if n == 0 else math.floor(math.log(abs(__snake_case							)  ,			10							) + 1							)




def       UpperCAmelCase__	(							__snake_case							)				->	int:
  return len(str(abs(__snake_case							)							)							)




def       UpperCAmelCase__	(							)				->	None:
  from collections.abc import Callable

  def benchmark_a_function(__snake_case  ,			__snake_case							) -> None:
    _A          =      F'''{func.__name__}({value})'''
    _A          =      timeit(F'''__main__.{call}'''  ,			setup='''import __main__'''							)
    print(F'''{call}: {func(__snake_case							)} -- {timing} seconds'''							)

  for value in (262_144, 1_125_899_906_842_624, 1_267_650_600_228_229_401_496_703_205_376):
    for func in (num_digits, num_digits_fast, num_digits_faster):
      benchmark_a_function(__snake_case  ,			__snake_case							)
    print()


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    benchmark()