

'''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,						lowercase_,						lowercase_=13,						lowercase_=7,						lowercase_=True,						lowercase_=True,						lowercase_=True,						lowercase_=True,						lowercase_=99,						lowercase_=24,						lowercase_=32,						lowercase_=5,						lowercase_=4,						lowercase_=37,						lowercase_="gelu",						lowercase_=0.1,						lowercase_=0.1,						lowercase_=512,						lowercase_=16,						lowercase_=2,						lowercase_=0.02,						lowercase_=4,						)    ->							Union[str, Any]:
					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 					_lowerCamelCase    (       self )    ->							int:
					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 					_lowerCamelCase    (       self )    ->							List[str]:
					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 lowerCamelCase   (    __lowerCAmelCase				,				unittest.TestCase				):
				snake_case_							     = True

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

				def 					_lowerCamelCase    (       self )    ->							str:
					snake_case							=					FlaxElectraModelTester(self )






				@slow
				def 					_lowerCamelCase    (       self )    ->							Any:
					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(lowercase_ )









from collections import OrderedDict
from dataclasses import fields
from typing import Any, Tuple

import numpy as np

from .import_utils import is_torch_available
def 				UpperCamelCase_	(					__snake_case      :    Dict  )->   str:




						'''simple docstring'''
						if is_torch_available():
												import torch

												if isinstance(__snake_case						,      torch.Tensor  ):
																		return True

						return isinstance(__snake_case						,      np.ndarray  )




class      __snake_case				(   _UpperCAmelCase):
					def 	a			(						self       :						Optional[Any]  )							->					Optional[Any]:



											'''simple docstring'''





											__magic_name__					=      fields(self  )

											# Safety and consistency checks
											if not len(_lowerCAmelCase  ):
																	raise ValueError(F'''{self.__class__.__name__} has no fields.'''  )

											__magic_name__					=      getattr(self	,      class_fields[0].name  )
											__magic_name__					=      all(getattr(self	,      field.name  ) is None for field in class_fields[1:]  )

											if other_fields_are_none and isinstance(_lowerCAmelCase	,      _lowerCAmelCase  ):
																	for key, value in first_field.items():
																							__magic_name__					=      value
											else:
																	for field in class_fields:
																							__magic_name__					=      getattr(self	,      field.name  )
																							if v is not None:
																													__magic_name__					=      v
					def __delitem__(						self       :						Dict	,      *_lowerCAmelCase       :						List[str]	,      **_lowerCAmelCase       :						List[str]  )							->					List[str]:



											'''simple docstring'''





											raise Exception(F'''You cannot use ``__delitem__`` on a {self.__class__.__name__} instance.'''  )
					def 	a			(						self       :						Optional[int]	,      *_lowerCAmelCase       :						Optional[Any]	,      **_lowerCAmelCase       :						Optional[Any]  )							->					str:



											'''simple docstring'''





											raise Exception(F'''You cannot use ``setdefault`` on a {self.__class__.__name__} instance.'''  )
					def 	a			(						self       :						Union[str, Any]	,      *_lowerCAmelCase       :						List[str]	,      **_lowerCAmelCase       :						Any  )							->					str:



											'''simple docstring'''





											raise Exception(F'''You cannot use ``pop`` on a {self.__class__.__name__} instance.'''  )
					def 	a			(						self       :						Any	,      *_lowerCAmelCase       :						str	,      **_lowerCAmelCase       :						Optional[int]  )							->					List[Any]:



											'''simple docstring'''





											raise Exception(F'''You cannot use ``update`` on a {self.__class__.__name__} instance.'''  )
					def __getitem__(						self       :						Optional[Any]	,      _lowerCAmelCase       :						Any  )							->					Tuple:



											'''simple docstring'''





											if isinstance(_lowerCAmelCase	,      _lowerCAmelCase  ):
																	__magic_name__					=      dict(self.items()  )
																	return inner_dict[k]
											else:
																	return self.to_tuple()[k]
					def __setattr__(						self       :						str	,      _lowerCAmelCase       :						Optional[Any]	,      _lowerCAmelCase       :						Optional[int]  )							->					int:



											'''simple docstring'''





											if name in self.keys() and value is not None:
																	# Don't call self.__setitem__ to avoid recursion errors
																	super().__setitem__(_lowerCAmelCase	,      _lowerCAmelCase  )
											super().__setattr__(_lowerCAmelCase	,      _lowerCAmelCase  )
					def __setitem__(						self       :						Optional[Any]	,      _lowerCAmelCase       :						Optional[Any]	,      _lowerCAmelCase       :						List[str]  )							->					Optional[int]:



											'''simple docstring'''





											super().__setitem__(_lowerCAmelCase	,      _lowerCAmelCase  )
											# Don't call self.__setattr__ to avoid recursion errors
											super().__setattr__(_lowerCAmelCase	,      _lowerCAmelCase  )







					def 	a			(						self       :						str  )							->					Tuple[Any]:



											'''simple docstring'''





											return tuple(self[k] for k in self.keys()  )

