





'''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 							__lowercase				(					unittest.TestCase  ):







	'''simple docstring'''

	def __init__(self   ,_lowerCamelCase   ,_lowerCamelCase=13   ,_lowerCamelCase=7   ,_lowerCamelCase=True   ,_lowerCamelCase=True   ,_lowerCamelCase=True   ,_lowerCamelCase=True   ,_lowerCamelCase=99   ,_lowerCamelCase=24   ,_lowerCamelCase=32   ,_lowerCamelCase=5   ,_lowerCamelCase=4   ,_lowerCamelCase=37   ,_lowerCamelCase="gelu"   ,_lowerCamelCase=0.1   ,_lowerCamelCase=0.1   ,_lowerCamelCase=512   ,_lowerCamelCase=16   ,_lowerCamelCase=2   ,_lowerCamelCase=0.0_2   ,_lowerCamelCase=4   ,)							->							List[str]:







				'''simple docstring'''





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


	def   _UpperCAmelCase   (self       )							->							Optional[int]:







				'''simple docstring'''





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

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

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

				__lowercase   =							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       )							->							List[Any]:







				'''simple docstring'''





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






@require_flax
class 							__lowercase				(					lowerCAmelCase__       ,					unittest.TestCase  ):







	'''simple docstring'''

	a			: List[str]      =				True

	a			: Any      =				(
	    (
	        FlaxElectraModel,
	        FlaxElectraForCausalLM,
	        FlaxElectraForMaskedLM,
	        FlaxElectraForPreTraining,
	        FlaxElectraForTokenClassification,
	        FlaxElectraForQuestionAnswering,
	        FlaxElectraForMultipleChoice,
	        FlaxElectraForSequenceClassification,
	    )
	    if is_flax_available()
	    else ()
	)


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







				'''simple docstring'''





				__lowercase   =							FlaxElectraModelTester(self       )


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







				'''simple docstring'''





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











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  __lowerCamelCase       (    unittest.TestCase	,				UpperCamelCase__    ):




    """simple docstring"""

    def    a      (       self     :     Any   )      ->       Tuple:
         lowerCAmelCase__		= load_tool("image-captioning"   )
         self.tool.setup()
         lowerCAmelCase__		= load_tool("image-captioning"   ,	remote=SCREAMING_SNAKE_CASE__   )


    def    a      (       self     :     int   )      ->       List[str]:
         lowerCAmelCase__		= Image.open(Path(get_tests_dir("fixtures/tests_samples/COCO"   )   ) / "000000039769.png"   )
         lowerCAmelCase__		= self.tool(SCREAMING_SNAKE_CASE__   )
         self.assertEqual(SCREAMING_SNAKE_CASE__   ,	"two cats sleeping on a couch"   )


    def    a      (       self     :     List[str]   )      ->       int:
         lowerCAmelCase__		= Image.open(Path(get_tests_dir("fixtures/tests_samples/COCO"   )   ) / "000000039769.png"   )
         lowerCAmelCase__		= self.remote_tool(SCREAMING_SNAKE_CASE__   )
         self.assertEqual(SCREAMING_SNAKE_CASE__   ,	"two cats sleeping on a couch"   )


    def    a      (       self     :     Any   )      ->       Any:
         lowerCAmelCase__		= Image.open(Path(get_tests_dir("fixtures/tests_samples/COCO"   )   ) / "000000039769.png"   )
         lowerCAmelCase__		= self.tool(image=SCREAMING_SNAKE_CASE__   )
         self.assertEqual(SCREAMING_SNAKE_CASE__   ,	"two cats sleeping on a couch"   )


    def    a      (       self     :     Dict   )      ->       Any:
         lowerCAmelCase__		= Image.open(Path(get_tests_dir("fixtures/tests_samples/COCO"   )   ) / "000000039769.png"   )
         lowerCAmelCase__		= self.remote_tool(image=SCREAMING_SNAKE_CASE__   )
         self.assertEqual(SCREAMING_SNAKE_CASE__   ,	"two cats sleeping on a couch"   )
