






import unittest
from pathlib import Path

from transformers import is_vision_available, load_tool
from transformers.testing_utils import get_tests_dir

from .test_tools_common import ToolTesterMixin


if is_vision_available():
				from PIL import Image


class 					__SCREAMING_SNAKE_CASE(		unittest.TestCase      ,					a_		):
							def lowerCAmelCase_	(       self: Optional[Any]  )						->						int:
											snake_case__													=       load_tool('image-question-answering'  )
											self.tool.setup()
											snake_case__													=       load_tool('image-question-answering'    ,		remote=UpperCamelCase  )
							def lowerCAmelCase_	(       self: str  )						->						Optional[int]:
											snake_case__													=       Image.open(Path(get_tests_dir('fixtures/tests_samples/COCO'  )  ) / '000000039769.png'  )
											snake_case__													=       self.tool(UpperCamelCase    ,		'How many cats are sleeping on the couch?'  )
											self.assertEqual(UpperCamelCase    ,		'2'  )
							def lowerCAmelCase_	(       self: Union[str, Any]  )						->						Union[str, Any]:
											snake_case__													=       Image.open(Path(get_tests_dir('fixtures/tests_samples/COCO'  )  ) / '000000039769.png'  )
											snake_case__													=       self.remote_tool(UpperCamelCase    ,		'How many cats are sleeping on the couch?'  )
											self.assertEqual(UpperCamelCase    ,		'2'  )
							def lowerCAmelCase_	(       self: int  )						->						List[Any]:
											snake_case__													=       Image.open(Path(get_tests_dir('fixtures/tests_samples/COCO'  )  ) / '000000039769.png'  )
											snake_case__													=       self.tool(image=UpperCamelCase    ,		question='How many cats are sleeping on the couch?'  )
											self.assertEqual(UpperCamelCase    ,		'2'  )


							def lowerCAmelCase_	(       self: Tuple  )						->						Tuple:
											snake_case__													=       Image.open(Path(get_tests_dir('fixtures/tests_samples/COCO'  )  ) / '000000039769.png'  )
											snake_case__													=       self.remote_tool(image=UpperCamelCase    ,		question='How many cats are sleeping on the couch?'  )
											self.assertEqual(UpperCamelCase    ,		'2'  )












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  )




