






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 							A_			(  unittest.TestCase	):






 '''simple docstring'''




 def __init__(		self							,     _A							,     _A=13							,     _A=7							,     _A=True							,     _A=True							,     _A=True							,     _A=True							,     _A=99							,     _A=24							,     _A=32							,     _A=5							,     _A=4							,     _A=37							,     _A="gelu"							,     _A=0.1							,     _A=0.1							,     _A=512							,     _A=16							,     _A=2							,     _A=0.02							,     _A=4							,     )       ->						int:

     """simple docstring"""



     _UpperCAmelCase :					List[str]	     = parent
     _UpperCAmelCase :					List[Any]	     = batch_size
     _UpperCAmelCase :					Dict	     = seq_length
     _UpperCAmelCase :					List[str]	     = is_training
     _UpperCAmelCase :					Optional[Any]	     = use_attention_mask
     _UpperCAmelCase :					Union[str, Any]	     = use_token_type_ids
     _UpperCAmelCase :					Union[str, Any]	     = use_labels
     _UpperCAmelCase :					Tuple	     = vocab_size
     _UpperCAmelCase :					Any	     = hidden_size
     _UpperCAmelCase :					Optional[int]	     = embedding_size
     _UpperCAmelCase :					Any	     = num_hidden_layers
     _UpperCAmelCase :					List[Any]	     = num_attention_heads
     _UpperCAmelCase :					Any	     = intermediate_size
     _UpperCAmelCase :					Tuple	     = hidden_act
     _UpperCAmelCase :					str	     = hidden_dropout_prob
     _UpperCAmelCase :					int	     = attention_probs_dropout_prob
     _UpperCAmelCase :					str	     = max_position_embeddings
     _UpperCAmelCase :					Optional[Any]	     = type_vocab_size
     _UpperCAmelCase :					Optional[int]	     = type_sequence_label_size
     _UpperCAmelCase :					Tuple	     = initializer_range
     _UpperCAmelCase :					List[str]	     = num_choices


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

     """simple docstring"""



     _UpperCAmelCase :					Union[str, Any]	     = ids_tensor([self.batch_size, self.seq_length]							,     self.vocab_size)

     _UpperCAmelCase :					Tuple	     = None
     if self.use_attention_mask:
         _UpperCAmelCase :					int	     = random_attention_mask([self.batch_size, self.seq_length])

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

     _UpperCAmelCase :					Dict	     = 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        snake_case__ (		self)       ->						str:

     """simple docstring"""



     _UpperCAmelCase :					Dict	     = self.prepare_config_and_inputs()
     _UpperCAmelCase :					List[Any]	     = config_and_inputs
     _UpperCAmelCase :					List[Any]	     = {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': attention_mask}
     return config, inputs_dict



@require_flax
class 							A_			(  a_       ,      unittest.TestCase	):






 '''simple docstring'''




 _SCREAMING_SNAKE_CASE							:	int       =    True

 _SCREAMING_SNAKE_CASE							:	Union[str, Any]       =    (
     (
         FlaxElectraModel,
         FlaxElectraForCausalLM,
         FlaxElectraForMaskedLM,
         FlaxElectraForPreTraining,
         FlaxElectraForTokenClassification,
         FlaxElectraForQuestionAnswering,
         FlaxElectraForMultipleChoice,
         FlaxElectraForSequenceClassification,
     )
     if is_flax_available()
     else ()
 )


 def        snake_case__ (		self)       ->						List[Any]:

     """simple docstring"""



     _UpperCAmelCase :					str	     = FlaxElectraModelTester(self)


 @slow
 def        snake_case__ (		self)       ->						List[Any]:

     """simple docstring"""



     for model_class_name in self.all_model_classes:
         if model_class_name == FlaxElectraForMaskedLM:
             _UpperCAmelCase :					Union[str, Any]	     = model_class_name.from_pretrained('''google/electra-small-generator''')
         else:
             _UpperCAmelCase :					Dict	     = model_class_name.from_pretrained('''google/electra-small-discriminator''')
         _UpperCAmelCase :					Tuple	     = model(np.ones((1, 1)))
         self.assertIsNotNone(_A)








'''simple docstring'''







from __future__ import annotations






def       lowerCAmelCase__       (				lowerCamelCase     :			list   ):
       _A     :	Union[str, Any]      =					sorted(lowerCamelCase   )
       _A     :	Tuple      =					len(lowerCamelCase   )
       _A     :	int      =					length >> 1
       return (
           (sorted_list[mid_index] + sorted_list[mid_index - 1]) / 2
           if length % 2 == 0
           else sorted_list[mid_index]
       )






def       lowerCAmelCase__       (				):
       import doctest

       doctest.testmod()


if __name__ == "__main__":
   main()






