

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			,   _UpperCamelCase			,   _UpperCamelCase=13			,   _UpperCamelCase=7			,   _UpperCamelCase=True			,   _UpperCamelCase=True			,   _UpperCamelCase=True			,   _UpperCamelCase=True			,   _UpperCamelCase=99			,   _UpperCamelCase=24			,   _UpperCamelCase=32			,   _UpperCamelCase=5			,   _UpperCamelCase=4			,   _UpperCamelCase=37			,   _UpperCamelCase="gelu"			,   _UpperCamelCase=0.1			,   _UpperCamelCase=0.1			,   _UpperCamelCase=5_12			,   _UpperCamelCase=16			,   _UpperCamelCase=2			,   _UpperCamelCase=0.02			,   _UpperCamelCase=4			,   )			->       Any:






              """simple docstring"""


              __snake_case					  =       parent
              __snake_case					  =       batch_size
              __snake_case					  =       seq_length
              __snake_case					  =       is_training
              __snake_case					  =       use_attention_mask
              __snake_case					  =       use_token_type_ids
              __snake_case					  =       use_labels
              __snake_case					  =       vocab_size
              __snake_case					  =       hidden_size
              __snake_case					  =       embedding_size
              __snake_case					  =       num_hidden_layers
              __snake_case					  =       num_attention_heads
              __snake_case					  =       intermediate_size
              __snake_case					  =       hidden_act
              __snake_case					  =       hidden_dropout_prob
              __snake_case					  =       attention_probs_dropout_prob
              __snake_case					  =       max_position_embeddings
              __snake_case					  =       type_vocab_size
              __snake_case					  =       type_sequence_label_size
              __snake_case					  =       initializer_range
              __snake_case					  =       num_choices


       def  a		(		self      )			->       Optional[int]:






              """simple docstring"""


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

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

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

              __snake_case					  =       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      )			->       Union[str, Any]:






              """simple docstring"""


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






@require_flax
class 						__snake_case						(							snake_case__ ,  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  a		(		self      )			->       List[Any]:






              """simple docstring"""


              __snake_case					  =       FlaxElectraModelTester(self      )






       @slow
       def  a		(		self      )			->       Any:






              """simple docstring"""


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




from __future__ import annotations

class 						__snake_case						:
       """simple docstring"""







       def __init__(		self			,   _UpperCamelCase      )			->       None:






              """simple docstring"""


              __snake_case					  =       value
              __snake_case					  =       None
              __snake_case					  =       None






class 						__snake_case						:
       """simple docstring"""







       __SCREAMING_SNAKE_CASE													=       42


       def __init__(		self      )			->       None:






              """simple docstring"""


              __snake_case					  =       0


       def  a		(		self			,   _UpperCamelCase			,   _UpperCamelCase      )			->       None:






              """simple docstring"""


              if node is None:
                     return

              if path_sum == self.target:
                     self.paths += 1

              if node.left:
                     self.depth_first_search(node.left			,   path_sum + node.left.value      )
              if node.right:
                     self.depth_first_search(node.right			,   path_sum + node.right.value      )






       def  a		(		self			,   _UpperCamelCase			,   _UpperCamelCase = None      )			->       int:






              """simple docstring"""


              if node is None:
                     return 0
              if target is not None:
                     __snake_case					  =       target

              self.depth_first_search(_UpperCamelCase			,   node.value      )
              self.path_sum(node.left      )
              self.path_sum(node.right      )

              return self.paths


if __name__ == "__main__":
    import doctest

    doctest.testmod()

