


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




     '''simple docstring'''


     def __init__(						self			,						__lowerCamelCase			,						__lowerCamelCase=1_3			,						__lowerCamelCase=7			,						__lowerCamelCase=True			,						__lowerCamelCase=True			,						__lowerCamelCase=True			,						__lowerCamelCase=True			,						__lowerCamelCase=9_9			,						__lowerCamelCase=2_4			,						__lowerCamelCase=3_2			,						__lowerCamelCase=5			,						__lowerCamelCase=4			,						__lowerCamelCase=3_7			,						__lowerCamelCase="gelu"			,						__lowerCamelCase=0.1			,						__lowerCamelCase=0.1			,						__lowerCamelCase=5_1_2			,						__lowerCamelCase=1_6			,						__lowerCamelCase=2			,						__lowerCamelCase=0.0_2			,						__lowerCamelCase=4			,						)      ->    int:
            _A				:	List[Any]       =			parent
            _A				:	str       =			batch_size
            _A				:	int       =			seq_length
            _A				:	Optional[int]       =			is_training
            _A				:	List[str]       =			use_attention_mask
            _A				:	str       =			use_token_type_ids
            _A				:	Optional[int]       =			use_labels
            _A				:	Optional[int]       =			vocab_size
            _A				:	Any       =			hidden_size
            _A				:	str       =			embedding_size
            _A				:	Optional[int]       =			num_hidden_layers
            _A				:	str       =			num_attention_heads
            _A				:	Optional[Any]       =			intermediate_size
            _A				:	Any       =			hidden_act
            _A				:	Tuple       =			hidden_dropout_prob
            _A				:	Union[str, Any]       =			attention_probs_dropout_prob
            _A				:	List[str]       =			max_position_embeddings
            _A				:	Optional[int]       =			type_vocab_size
            _A				:	Optional[Any]       =			type_sequence_label_size
            _A				:	str       =			initializer_range
            _A				:	str       =			num_choices


     def 			_lowerCamelCase			(						self)      ->    str:
            _A				:	Dict       =			ids_tensor([self.batch_size, self.seq_length]			,						self.vocab_size)

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

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

            _A				:	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 			_lowerCamelCase			(						self)      ->    int:
            _A				:	Optional[int]       =			self.prepare_config_and_inputs()
            _A   ,      _A   ,      _A   ,      _A				:	Optional[int]       =			config_and_inputs
            _A				:	Any       =			{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": attention_mask}
            return config, inputs_dict







@require_flax
class 					lowerCAmelCase__	(    a					,   unittest.TestCase):




     '''simple docstring'''
     __SCREAMING_SNAKE_CASE        =			True

     __SCREAMING_SNAKE_CASE        =			(
         (
             FlaxElectraModel,
             FlaxElectraForCausalLM,
             FlaxElectraForMaskedLM,
             FlaxElectraForPreTraining,
             FlaxElectraForTokenClassification,
             FlaxElectraForQuestionAnswering,
             FlaxElectraForMultipleChoice,
             FlaxElectraForSequenceClassification,
         )
         if is_flax_available()
         else ()
     )


     def 			_lowerCamelCase			(						self)      ->    Optional[int]:
            _A				:	Any       =			FlaxElectraModelTester(self)


     @slow
     def 			_lowerCamelCase			(						self)      ->    Any:
            for model_class_name in self.all_model_classes:
                   if model_class_name == FlaxElectraForMaskedLM:
                          _A				:	List[Any]       =			model_class_name.from_pretrained("google/electra-small-generator")
                   else:
                          _A				:	Any       =			model_class_name.from_pretrained("google/electra-small-discriminator")
                   _A				:	Tuple       =			model(np.ones((1, 1)))
                   self.assertIsNotNone(__lowerCamelCase)




def 							_UpperCAmelCase    (UpperCamelCase__					:  str						):
       _A				:	Tuple       =			str(UpperCamelCase__						).strip()
       if not bin_string:
              raise ValueError("Empty string was passed to the function"						)
       _A				:	Dict       =			bin_string[0] == "-"
       if is_negative:
              _A				:	Any       =			bin_string[1:]
       if not all(char in "01" for char in bin_string						):
              raise ValueError("Non-binary value was passed to the function"						)
       _A				:	Union[str, Any]       =			0
       for char in bin_string:
              _A				:	Union[str, Any]       =			2 * decimal_number + int(UpperCamelCase__						)
       return -decimal_number if is_negative else decimal_number


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

    testmod()
