






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			,       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=512			,       UpperCAmelCase=16			,       UpperCAmelCase=2			,       UpperCAmelCase=0.02			,       UpperCAmelCase=4			,       ):
							"""simple docstring"""







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

	def 			UpperCamelCase       (				self       ):
							"""simple docstring"""







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

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

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

							_UpperCAmelCase							   =     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 			UpperCamelCase       (				self       ):
							"""simple docstring"""







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





@require_flax
class __lowerCamelCase					( snake_case__	,			unittest.TestCase):





	"""simple docstring"""






	UpperCamelCase__								= True

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

	def 			UpperCamelCase       (				self       ):
							"""simple docstring"""







							_UpperCAmelCase							   =     FlaxElectraModelTester(self       )

	@slow
	def 			UpperCamelCase       (				self       ):
							"""simple docstring"""







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








from __future__ import annotations

import re


def __A       ( __lowerCAmelCase      )->    list[str]:





						"""simple docstring"""



						def alphanum_key(__lowerCAmelCase      ):
												return [int(__lowerCAmelCase      ) if s.isdigit() else s.lower() for s in re.split('([0-9]+)'					,						__lowerCAmelCase      )]

						return sorted(__lowerCAmelCase					,						key=__lowerCAmelCase      )


if __name__ == "__main__":
		import doctest

		doctest.testmod()
