






import json
import os
import tempfile
import unittest

from transformers.modelcard import ModelCard


class 					__SCREAMING_SNAKE_CASE(		unittest.TestCase		):
							def lowerCAmelCase_	(       self: Any  )						->						int:
											snake_case__													=       {
											    'model_details': {
											        'Organization': 'testing',
											        'Model date': 'today',
											        'Model version': 'v2.1, Developed by Test Corp in 2019.',
											        'Architecture': 'Convolutional Neural Network.',
											    },
											    'metrics': 'BLEU and ROUGE-1',
											    'evaluation_data': {
											        'Datasets': {'BLEU': 'My-great-dataset-v1', 'ROUGE-1': 'My-short-dataset-v2.1'},
											        'Preprocessing': 'See details on https://arxiv.org/pdf/1810.03993.pdf',
											    },
											    'training_data': {
											        'Dataset': 'English Wikipedia dump dated 2018-12-01',
											        'Preprocessing': (
											            'Using SentencePiece vocabulary of size 52k tokens. See details on'
											            ' https://arxiv.org/pdf/1810.03993.pdf'
											        ),
											    },
											    'quantitative_analyses': {'BLEU': 55.1, 'ROUGE-1': 76},
											}
							def lowerCAmelCase_	(       self: Tuple  )						->						str:
											snake_case__													=       ModelCard.from_dict(self.inputs_dict  )
											self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE    ,		'model_details'  )  )
											self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE    ,		'intended_use'  )  )
											self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE    ,		'factors'  )  )
											self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE    ,		'metrics'  )  )
											self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE    ,		'evaluation_data'  )  )
											self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE    ,		'training_data'  )  )
											self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE    ,		'quantitative_analyses'  )  )
											self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE    ,		'ethical_considerations'  )  )
											self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE    ,		'caveats_and_recommendations'  )  )
							def lowerCAmelCase_	(       self: Optional[int]  )						->						Union[str, Any]:
											snake_case__													=       ModelCard.from_dict(self.inputs_dict  )
											snake_case__													=       json.loads(modelcard.to_json_string()  )
											for key, value in self.inputs_dict.items():
															self.assertEqual(obj[key]    ,		__SCREAMING_SNAKE_CASE  )
							def lowerCAmelCase_	(       self: List[str]  )						->						List[str]:
											snake_case__													=       ModelCard.from_dict(self.inputs_dict  )

											with tempfile.TemporaryDirectory() as tmpdirname:
															snake_case__													=       os.path.join(__SCREAMING_SNAKE_CASE    ,		'modelcard.json'  )
															model_card_first.to_json_file(__SCREAMING_SNAKE_CASE  )
															snake_case__													=       ModelCard.from_json_file(__SCREAMING_SNAKE_CASE  )

											self.assertEqual(model_card_second.to_dict()    ,		model_card_first.to_dict()  )


							def lowerCAmelCase_	(       self: Optional[int]  )						->						List[Any]:
											snake_case__													=       ModelCard.from_dict(self.inputs_dict  )

											with tempfile.TemporaryDirectory() as tmpdirname:
															model_card_first.save_pretrained(__SCREAMING_SNAKE_CASE  )
															snake_case__													=       ModelCard.from_pretrained(__SCREAMING_SNAKE_CASE  )

											self.assertEqual(model_card_second.to_dict()    ,		model_card_first.to_dict()  )












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 					__SCREAMING_SNAKE_CASE(		unittest.TestCase		):
							def __init__(       self: int    ,		UpperCamelCase: List[str]    ,		UpperCamelCase: Dict=13    ,		UpperCamelCase: Dict=7    ,		UpperCamelCase: Union[str, Any]=True    ,		UpperCamelCase: List[Any]=True    ,		UpperCamelCase: Optional[int]=True    ,		UpperCamelCase: Union[str, Any]=True    ,		UpperCamelCase: Optional[int]=99    ,		UpperCamelCase: Optional[int]=24    ,		UpperCamelCase: Any=32    ,		UpperCamelCase: Any=5    ,		UpperCamelCase: Any=4    ,		UpperCamelCase: int=37    ,		UpperCamelCase: Union[str, Any]="gelu"    ,		UpperCamelCase: str=0.1    ,		UpperCamelCase: str=0.1    ,		UpperCamelCase: int=5_12    ,		UpperCamelCase: Tuple=16    ,		UpperCamelCase: Dict=2    ,		UpperCamelCase: Any=0.02    ,		UpperCamelCase: List[Any]=4    ,		)						->						int:
											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: List[str]  )						->						List[str]:
											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: Tuple  )						->						Any:
											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 					__SCREAMING_SNAKE_CASE(		a_      ,					unittest.TestCase		):
							_UpperCAmelCase	      =    True

							_UpperCAmelCase	      =    (
							    (
							        FlaxElectraModel,
							        FlaxElectraForCausalLM,
							        FlaxElectraForMaskedLM,
							        FlaxElectraForPreTraining,
							        FlaxElectraForTokenClassification,
							        FlaxElectraForQuestionAnswering,
							        FlaxElectraForMultipleChoice,
							        FlaxElectraForSequenceClassification,
							    )
							    if is_flax_available()
							    else ()
							)
							def lowerCAmelCase_	(       self: List[Any]  )						->						Dict:
											snake_case__													=       FlaxElectraModelTester(self  )


							@slow
							def lowerCAmelCase_	(       self: int  )						->						Optional[int]:
											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  )




