





"""simple docstring"""




import posixpath
from pathlib import Path
from unittest.mock import patch

import pytest
from fsspec.implementations.local import AbstractFileSystem, LocalFileSystem, stringify_path
from fsspec.registry import _registry as _fsspec_registry




class  _a						(      _lowerCAmelCase				):
				UpperCamelCase								=    '''mock'''






				def __init__( self		:    List[str], *lowerCAmelCase__		:    Union[str, Any], lowerCAmelCase__		:    str, **lowerCAmelCase__		:    Dict							)	->      str:




										'''simple docstring'''



										super().__init__()
										_UpperCamelCase			:					Optional[int]     =    LocalFileSystem(*lowerCAmelCase__, **lowerCAmelCase__							)
										_UpperCamelCase			:					List[Any]     =    Path(lowerCAmelCase__							).resolve().as_posix() + '''/'''






				def 				snake_case	( self		:    Any, lowerCAmelCase__		:    Optional[int], *lowerCAmelCase__		:    str, **lowerCAmelCase__		:    str							)	->      Union[str, Any]:




										'''simple docstring'''



										_UpperCamelCase			:					str     =    posixpath.join(self.local_root_dir, self._strip_protocol(lowerCAmelCase__							)							)
										return self._fs.mkdir(lowerCAmelCase__, *lowerCAmelCase__, **lowerCAmelCase__							)






				def 				snake_case	( self		:    Dict, lowerCAmelCase__		:    Any, *lowerCAmelCase__		:    int, **lowerCAmelCase__		:    Any							)	->      Optional[Any]:




										'''simple docstring'''



										_UpperCamelCase			:					Dict     =    posixpath.join(self.local_root_dir, self._strip_protocol(lowerCAmelCase__							)							)
										return self._fs.makedirs(lowerCAmelCase__, *lowerCAmelCase__, **lowerCAmelCase__							)






				def 				snake_case	( self		:    Optional[int], lowerCAmelCase__		:    Dict							)	->      Dict:




										'''simple docstring'''



										_UpperCamelCase			:					Dict     =    posixpath.join(self.local_root_dir, self._strip_protocol(lowerCAmelCase__							)							)
										return self._fs.rmdir(lowerCAmelCase__							)






				def 				snake_case	( self		:    Tuple, lowerCAmelCase__		:    str, lowerCAmelCase__		:    List[Any]=True, *lowerCAmelCase__		:    Any, **lowerCAmelCase__		:    int							)	->      int:




										'''simple docstring'''



										_UpperCamelCase			:					Union[str, Any]     =    posixpath.join(self.local_root_dir, self._strip_protocol(lowerCAmelCase__							)							)
										_UpperCamelCase			:					Dict     =    self._fs.ls(lowerCAmelCase__, detail=lowerCAmelCase__, *lowerCAmelCase__, **lowerCAmelCase__							)
										if detail:
																return [{**info, "name": info["name"][len(self.local_root_dir							) :]} for info in out]
										else:
																return [name[len(self.local_root_dir							) :] for name in out]






				def 				snake_case	( self		:    Union[str, Any], lowerCAmelCase__		:    Any, *lowerCAmelCase__		:    Any, **lowerCAmelCase__		:    Optional[int]							)	->      Union[str, Any]:




										'''simple docstring'''



										_UpperCamelCase			:					Dict     =    posixpath.join(self.local_root_dir, self._strip_protocol(lowerCAmelCase__							)							)
										_UpperCamelCase			:					List[Any]     =    dict(self._fs.info(lowerCAmelCase__, *lowerCAmelCase__, **lowerCAmelCase__							)							)
										_UpperCamelCase			:					Any     =    out['''name'''][len(self.local_root_dir							) :]
										return out






				def 				snake_case	( self		:    int, lowerCAmelCase__		:    Dict, lowerCAmelCase__		:    Optional[Any], *lowerCAmelCase__		:    Any, **lowerCAmelCase__		:    str							)	->      Union[str, Any]:




										'''simple docstring'''



										_UpperCamelCase			:					Dict     =    posixpath.join(self.local_root_dir, self._strip_protocol(lowerCAmelCase__							)							)
										_UpperCamelCase			:					Any     =    posixpath.join(self.local_root_dir, self._strip_protocol(lowerCAmelCase__							)							)
										return self._fs.cp_file(lowerCAmelCase__, lowerCAmelCase__, *lowerCAmelCase__, **lowerCAmelCase__							)






				def 				snake_case	( self		:    str, lowerCAmelCase__		:    List[Any], *lowerCAmelCase__		:    Tuple, **lowerCAmelCase__		:    Optional[int]							)	->      Optional[Any]:




										'''simple docstring'''



										_UpperCamelCase			:					str     =    posixpath.join(self.local_root_dir, self._strip_protocol(lowerCAmelCase__							)							)
										return self._fs.rm_file(lowerCAmelCase__, *lowerCAmelCase__, **lowerCAmelCase__							)






				def 				snake_case	( self		:    Optional[int], lowerCAmelCase__		:    str, *lowerCAmelCase__		:    Dict, **lowerCAmelCase__		:    List[Any]							)	->      List[str]:




										'''simple docstring'''



										_UpperCamelCase			:					Dict     =    posixpath.join(self.local_root_dir, self._strip_protocol(lowerCAmelCase__							)							)
										return self._fs.rm(lowerCAmelCase__, *lowerCAmelCase__, **lowerCAmelCase__							)






				def 				snake_case	( self		:    Optional[Any], lowerCAmelCase__		:    Optional[Any], *lowerCAmelCase__		:    List[str], **lowerCAmelCase__		:    List[Any]							)	->      Optional[int]:




										'''simple docstring'''



										_UpperCamelCase			:					Union[str, Any]     =    posixpath.join(self.local_root_dir, self._strip_protocol(lowerCAmelCase__							)							)
										return self._fs._open(lowerCAmelCase__, *lowerCAmelCase__, **lowerCAmelCase__							)






				def 				snake_case	( self		:    Any, lowerCAmelCase__		:    List[str]							)	->      Dict:




										'''simple docstring'''



										_UpperCamelCase			:					Tuple     =    posixpath.join(self.local_root_dir, self._strip_protocol(lowerCAmelCase__							)							)
										return self._fs.created(lowerCAmelCase__							)






				def 				snake_case	( self		:    Optional[Any], lowerCAmelCase__		:    Dict							)	->      List[str]:




										'''simple docstring'''



										_UpperCamelCase			:					Tuple     =    posixpath.join(self.local_root_dir, self._strip_protocol(lowerCAmelCase__							)							)
										return self._fs.modified(lowerCAmelCase__							)






				@classmethod
				def 				snake_case	( cls		:    Tuple, lowerCAmelCase__		:    List[Any]							)	->      Tuple:




										'''simple docstring'''



										_UpperCamelCase			:					List[Any]     =    stringify_path(lowerCAmelCase__							)
										if path.startswith('''mock://'''							):
																_UpperCamelCase			:					List[Any]     =    path[7:]
										return path




class  _a						(      _lowerCAmelCase				):
				UpperCamelCase								=    '''tmp'''
				UpperCamelCase								=    None






				def __init__( self		:    Optional[int], *lowerCAmelCase__		:    Optional[Any], **lowerCAmelCase__		:    List[str]							)	->      List[str]:




										'''simple docstring'''



										assert self.tmp_dir is not None, "TmpDirFileSystem.tmp_dir is not set"
										super().__init__(*lowerCAmelCase__, **lowerCAmelCase__, local_root_dir=self.tmp_dir, auto_mkdir=lowerCAmelCase__							)






				@classmethod
				def 				snake_case	( cls		:    Tuple, lowerCAmelCase__		:    int							)	->      List[Any]:




										'''simple docstring'''



										_UpperCamelCase			:					Any     =    stringify_path(lowerCAmelCase__							)
										if path.startswith('''tmp://'''							):
																_UpperCamelCase			:					Optional[int]     =    path[6:]
										return path





@pytest.fixture
def        a_				(							):
						_UpperCamelCase			:					Tuple     =    MockFileSystem
						_UpperCamelCase			:					Optional[int]     =    TmpDirFileSystem
						yield
						del _fsspec_registry["mock"]
						del _fsspec_registry["tmp"]





@pytest.fixture
def        a_				(							_lowercase       ,						_lowercase   ):
						_UpperCamelCase			:					Optional[int]     =    tmp_path_factory.mktemp('''mockfs'''   )
						return MockFileSystem(local_root_dir=_lowercase       ,						auto_mkdir=_lowercase   )






@pytest.fixture
def        a_				(							_lowercase       ,						_lowercase   ):
						_UpperCamelCase			:					Tuple     =    tmp_path_factory.mktemp('''tmpfs'''   )
						with patch.object(_lowercase       ,						'''tmp_dir'''       ,						_lowercase   ):
												yield TmpDirFileSystem()










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






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




										'''simple docstring'''



										_UpperCamelCase			:					Dict     =    parent
										_UpperCamelCase			:					Tuple     =    batch_size
										_UpperCamelCase			:					str     =    seq_length
										_UpperCamelCase			:					Any     =    is_training
										_UpperCamelCase			:					Union[str, Any]     =    use_attention_mask
										_UpperCamelCase			:					List[Any]     =    use_token_type_ids
										_UpperCamelCase			:					str     =    use_labels
										_UpperCamelCase			:					Union[str, Any]     =    vocab_size
										_UpperCamelCase			:					int     =    hidden_size
										_UpperCamelCase			:					Optional[int]     =    embedding_size
										_UpperCamelCase			:					int     =    num_hidden_layers
										_UpperCamelCase			:					int     =    num_attention_heads
										_UpperCamelCase			:					Tuple     =    intermediate_size
										_UpperCamelCase			:					Optional[int]     =    hidden_act
										_UpperCamelCase			:					Any     =    hidden_dropout_prob
										_UpperCamelCase			:					Union[str, Any]     =    attention_probs_dropout_prob
										_UpperCamelCase			:					Any     =    max_position_embeddings
										_UpperCamelCase			:					List[str]     =    type_vocab_size
										_UpperCamelCase			:					Union[str, Any]     =    type_sequence_label_size
										_UpperCamelCase			:					str     =    initializer_range
										_UpperCamelCase			:					Union[str, Any]     =    num_choices






				def 				snake_case	( self		:    Optional[Any]							)	->      Union[str, Any]:




										'''simple docstring'''



										_UpperCamelCase			:					Optional[Any]     =    ids_tensor([self.batch_size, self.seq_length], self.vocab_size							)

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

										_UpperCamelCase			:					Optional[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 				snake_case	( self		:    Any							)	->      Optional[int]:




										'''simple docstring'''



										_UpperCamelCase			:					Dict     =    self.prepare_config_and_inputs()
										_UpperCamelCase   ,							_UpperCamelCase   ,							_UpperCamelCase   ,							_UpperCamelCase			:					Tuple     =    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  _a						(      _lowerCAmelCase	,				unittest.TestCase				):
				UpperCamelCase								=    True

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






				def 				snake_case	( self		:    Union[str, Any]							)	->      Optional[Any]:




										'''simple docstring'''



										_UpperCamelCase			:					List[Any]     =    FlaxElectraModelTester(self							)






				@slow
				def 				snake_case	( self		:    Optional[Any]							)	->      str:




										'''simple docstring'''



										for model_class_name in self.all_model_classes:
																if model_class_name == FlaxElectraForMaskedLM:
																						_UpperCamelCase			:					int     =    model_class_name.from_pretrained('''google/electra-small-generator'''							)
																else:
																						_UpperCamelCase			:					Any     =    model_class_name.from_pretrained('''google/electra-small-discriminator'''							)
																_UpperCamelCase			:					List[str]     =    model(np.ones((1, 1)							)							)
																self.assertIsNotNone(lowerCAmelCase__							)



