






"""simple docstring"""



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					):
   def __init__(						self	:     Union[str, Any]				,       snake_case__	:     Optional[Any]				,       snake_case__	:     Dict=1_3				,       snake_case__	:     Optional[int]=7				,       snake_case__	:     Optional[int]=True				,       snake_case__	:     Optional[Any]=True				,       snake_case__	:     Union[str, Any]=True				,       snake_case__	:     Optional[Any]=True				,       snake_case__	:     Optional[int]=9_9				,       snake_case__	:     List[str]=2_4				,       snake_case__	:     str=3_2				,       snake_case__	:     Optional[int]=5				,       snake_case__	:     Dict=4				,       snake_case__	:     Tuple=3_7				,       snake_case__	:     Dict="gelu"				,       snake_case__	:     List[str]=0.1				,       snake_case__	:     Optional[int]=0.1				,       snake_case__	:     Optional[Any]=5_1_2				,       snake_case__	:     List[Any]=1_6				,       snake_case__	:     List[str]=2				,       snake_case__	:     Optional[int]=0.02				,       snake_case__	:     Optional[Any]=4				,       ):


        '''simple docstring'''
        UpperCAmelCase__		:  List[Any]				=				parent
        UpperCAmelCase__		:  Dict				=				batch_size
        UpperCAmelCase__		:  Any				=				seq_length
        UpperCAmelCase__		:  str				=				is_training
        UpperCAmelCase__		:  Any				=				use_attention_mask
        UpperCAmelCase__		:  Any				=				use_token_type_ids
        UpperCAmelCase__		:  int				=				use_labels
        UpperCAmelCase__		:  Union[str, Any]				=				vocab_size
        UpperCAmelCase__		:  Dict				=				hidden_size
        UpperCAmelCase__		:  List[str]				=				embedding_size
        UpperCAmelCase__		:  Tuple				=				num_hidden_layers
        UpperCAmelCase__		:  Tuple				=				num_attention_heads
        UpperCAmelCase__		:  Union[str, Any]				=				intermediate_size
        UpperCAmelCase__		:  Union[str, Any]				=				hidden_act
        UpperCAmelCase__		:  Dict				=				hidden_dropout_prob
        UpperCAmelCase__		:  str				=				attention_probs_dropout_prob
        UpperCAmelCase__		:  Union[str, Any]				=				max_position_embeddings
        UpperCAmelCase__		:  Optional[int]				=				type_vocab_size
        UpperCAmelCase__		:  Union[str, Any]				=				type_sequence_label_size
        UpperCAmelCase__		:  Tuple				=				initializer_range
        UpperCAmelCase__		:  Dict				=				num_choices
   def 	__a				(						self	:     Dict				):


        '''simple docstring'''
        UpperCAmelCase__		:  int				=				ids_tensor([self.batch_size, self.seq_length]				,       self.vocab_size				)

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

        UpperCAmelCase__		:  Any				=				None
        if self.use_token_type_ids:
             UpperCAmelCase__		:  Union[str, Any]				=				ids_tensor([self.batch_size, self.seq_length]				,       self.type_vocab_size				)

        UpperCAmelCase__		:  Optional[Any]				=				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 	__a				(						self	:     Any				):


        '''simple docstring'''
        UpperCAmelCase__		:  List[Any]				=				self.prepare_config_and_inputs()
        UpperCAmelCase__				,							UpperCAmelCase__				,							UpperCAmelCase__				,							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        lowerCAmelCase__       (  __magic_name__				,		unittest.TestCase					):
   SCREAMING_SNAKE_CASE_					      =True

   SCREAMING_SNAKE_CASE_					      =(
       (
           FlaxElectraModel,
           FlaxElectraForCausalLM,
           FlaxElectraForMaskedLM,
           FlaxElectraForPreTraining,
           FlaxElectraForTokenClassification,
           FlaxElectraForQuestionAnswering,
           FlaxElectraForMultipleChoice,
           FlaxElectraForSequenceClassification,
       )
       if is_flax_available()
       else ()
   )
   def 	__a				(						self	:     List[str]				):


        '''simple docstring'''
        UpperCAmelCase__		:  List[Any]				=				FlaxElectraModelTester(self				)




   @slow
   def 	__a				(						self	:     Any				):


        '''simple docstring'''
        for model_class_name in self.all_model_classes:
             if model_class_name == FlaxElectraForMaskedLM:
                  UpperCAmelCase__		:  Tuple				=				model_class_name.from_pretrained("google/electra-small-generator"				)
             else:
                  UpperCAmelCase__		:  Optional[Any]				=				model_class_name.from_pretrained("google/electra-small-discriminator"				)
             UpperCAmelCase__		:  List[str]				=				model(np.ones((1, 1)				)				)
             self.assertIsNotNone(snake_case__				)










"""simple docstring"""



from transformers import PretrainedConfig




class        lowerCAmelCase__       (  __magic_name__					):
   SCREAMING_SNAKE_CASE_					      ='''custom'''
   def __init__(						self	:     Any				,       snake_case__	:     Any=1				,       **snake_case__	:     Optional[Any]				):


        '''simple docstring'''
        UpperCAmelCase__		:  List[str]				=				attribute
        super().__init__(**snake_case__				)




class        lowerCAmelCase__       (  __magic_name__					):
   SCREAMING_SNAKE_CASE_					      ='''custom'''
   def __init__(						self	:     List[str]				,       snake_case__	:     Tuple=1				,       **snake_case__	:     str				):


        '''simple docstring'''
        UpperCAmelCase__		:  List[str]				=				attribute


