



'''simple docstring'''



import inspect
import unittest

from transformers import EfficientNetConfig
from transformers.testing_utils import is_pipeline_test, require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
				import torch

				from transformers import EfficientNetForImageClassification, EfficientNetModel
				from transformers.models.efficientnet.modeling_efficientnet import EFFICIENTNET_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
				from PIL import Image

				from transformers import AutoImageProcessor






class 			_SCREAMING_SNAKE_CASE				:



			def __init__(     self		:						str    ,			__UpperCamelCase		:						Optional[int]    ,			__UpperCamelCase		:						List[Any]=13    ,			__UpperCamelCase		:						Dict=32    ,			__UpperCamelCase		:						Optional[Any]=3    ,			__UpperCamelCase		:						Optional[int]=[3, 3, 5]    ,			__UpperCamelCase		:						Optional[int]=[32, 16, 24]    ,			__UpperCamelCase		:						Tuple=[16, 24, 40]    ,			__UpperCamelCase		:						List[str]=[1, 1, 2]    ,			__UpperCamelCase		:						int=[1, 1, 2]    ,			__UpperCamelCase		:						List[Any]=[1, 6, 6]    ,			__UpperCamelCase		:						Optional[Any]=True    ,			__UpperCamelCase		:						str=True    ,			__UpperCamelCase		:						Optional[int]=37    ,			__UpperCamelCase		:						Optional[Any]="gelu"    ,			__UpperCamelCase		:						Dict=10    ,			)      ->      Tuple:
							"""simple docstring"""





							snake_case__      :   Dict      =    parent
							snake_case__      :   Union[str, Any]      =    batch_size
							snake_case__      :   Optional[Any]      =    image_size
							snake_case__      :   List[Any]      =    num_channels
							snake_case__      :   Optional[int]      =    kernel_sizes
							snake_case__      :   str      =    in_channels
							snake_case__      :   Optional[Any]      =    out_channels
							snake_case__      :   int      =    strides
							snake_case__      :   Tuple      =    num_block_repeats
							snake_case__      :   Dict      =    expand_ratios
							snake_case__      :   Union[str, Any]      =    is_training
							snake_case__      :   List[str]      =    hidden_act
							snake_case__      :   Any      =    num_labels
							snake_case__      :   Dict      =    use_labels



			def 				lowerCAmelCase (     self		:						Optional[int]			)      ->      Optional[Any]:
							"""simple docstring"""





							snake_case__      :   Union[str, Any]      =    floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]			)

							snake_case__      :   Dict      =    None
							if self.use_labels:
											snake_case__      :   Any      =    ids_tensor([self.batch_size]    ,			self.num_labels			)

							snake_case__      :   List[Any]      =    self.get_config()
							return config, pixel_values, labels



			def 				lowerCAmelCase (     self		:						Union[str, Any]			)      ->      str:
							"""simple docstring"""





							return EfficientNetConfig(
							    num_channels=self.num_channels    ,			kernel_sizes=self.kernel_sizes    ,			in_channels=self.in_channels    ,			out_channels=self.out_channels    ,			strides=self.strides    ,			num_block_repeats=self.num_block_repeats    ,			expand_ratios=self.expand_ratios    ,			hidden_act=self.hidden_act    ,			num_labels=self.num_labels    ,			)



			def 				lowerCAmelCase (     self		:						Optional[int]    ,			__UpperCamelCase		:						List[Any]    ,			__UpperCamelCase		:						Union[str, Any]    ,			__UpperCamelCase		:						Union[str, Any]			)      ->      Any:
							"""simple docstring"""





							snake_case__      :   Optional[Any]      =    EfficientNetModel(config=__UpperCamelCase			)
							model.to(__UpperCamelCase			)
							model.eval()
							snake_case__      :   Tuple      =    model(__UpperCamelCase			)
							# expected last hidden states: B, C, H // 4, W // 4
							self.parent.assertEqual(
							    result.last_hidden_state.shape    ,			(self.batch_size, config.hidden_dim, self.image_size // 4, self.image_size // 4)    ,			)



			def 				lowerCAmelCase (     self		:						Optional[int]    ,			__UpperCamelCase		:						Dict    ,			__UpperCamelCase		:						List[str]    ,			__UpperCamelCase		:						List[str]			)      ->      Optional[Any]:
							"""simple docstring"""





							snake_case__      :   Union[str, Any]      =    EfficientNetForImageClassification(__UpperCamelCase			)
							model.to(__UpperCamelCase			)
							model.eval()
							snake_case__      :   Tuple      =    model(__UpperCamelCase    ,			labels=__UpperCamelCase			)
							self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.num_labels)			)







			def 				lowerCAmelCase (     self		:						Optional[Any]			)      ->      Tuple:
							"""simple docstring"""





							snake_case__      :   str      =    self.prepare_config_and_inputs()
							snake_case__  ,      snake_case__  ,      snake_case__      :   Optional[int]      =    config_and_inputs
							snake_case__      :   Any      =    {'''pixel_values''': pixel_values}
							return config, inputs_dict






@require_torch
class 			_SCREAMING_SNAKE_CASE				(lowercase__,	lowercase__,	unittest.TestCase      ):
			A__								=  (EfficientNetModel, EfficientNetForImageClassification) if is_torch_available() else ()
			A__								=  (
			    {'feature-extraction': EfficientNetModel, 'image-classification': EfficientNetForImageClassification}
			    if is_torch_available()
			    else {}
			)

			A__								=  False
			A__								=  False
			A__								=  False
			A__								=  False
			A__								=  False



			def 				lowerCAmelCase (     self		:						Tuple			)      ->      Any:
							"""simple docstring"""





							snake_case__      :   str      =    EfficientNetModelTester(self			)
							snake_case__      :   str      =    ConfigTester(
							    self    ,			config_class=__UpperCamelCase    ,			has_text_modality=__UpperCamelCase    ,			hidden_size=37			)



			def 				lowerCAmelCase (     self		:						Optional[Any]			)      ->      Optional[int]:
							"""simple docstring"""





							self.create_and_test_config_common_properties()
							self.config_tester.create_and_test_config_to_json_string()
							self.config_tester.create_and_test_config_to_json_file()
							self.config_tester.create_and_test_config_from_and_save_pretrained()
							self.config_tester.create_and_test_config_with_num_labels()
							self.config_tester.check_config_can_be_init_without_params()
							self.config_tester.check_config_arguments_init()



			def 				lowerCAmelCase (     self		:						Optional[int]			)      ->      List[Any]:
							"""simple docstring"""





							return



			@unittest.skip(reason='''EfficientNet does not use inputs_embeds'''			)
			def 				lowerCAmelCase (     self		:						Dict			)      ->      Optional[int]:
							"""simple docstring"""





							pass



			@unittest.skip(reason='''EfficientNet does not support input and output embeddings'''			)
			def 				lowerCAmelCase (     self		:						List[str]			)      ->      List[str]:
							"""simple docstring"""





							pass



			@unittest.skip(reason='''EfficientNet does not use feedforward chunking'''			)
			def 				lowerCAmelCase (     self		:						Any			)      ->      Union[str, Any]:
							"""simple docstring"""





							pass



			def 				lowerCAmelCase (     self		:						Union[str, Any]			)      ->      Dict:
							"""simple docstring"""





							snake_case__  ,      snake_case__      :   Optional[int]      =    self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
											snake_case__      :   Tuple      =    model_class(__UpperCamelCase			)
											snake_case__      :   List[Any]      =    inspect.signature(model.forward			)
											# signature.parameters is an OrderedDict => so arg_names order is deterministic
											snake_case__      :   Optional[int]      =    [*signature.parameters.keys()]

											snake_case__      :   int      =    ['''pixel_values''']
											self.assertListEqual(arg_names[:1]    ,			__UpperCamelCase			)



			def 				lowerCAmelCase (     self		:						str			)      ->      Optional[Any]:
							"""simple docstring"""





							snake_case__      :   Tuple      =    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*__UpperCamelCase			)



			def 				lowerCAmelCase (     self		:						Dict			)      ->      Optional[int]:
							"""simple docstring"""





							def check_hidden_states_output(__UpperCamelCase		:						str    ,			__UpperCamelCase		:						List[str]    ,			__UpperCamelCase		:						int			):
											snake_case__      :   int      =    model_class(__UpperCamelCase			)
											model.to(__UpperCamelCase			)
											model.eval()

											with torch.no_grad():
															snake_case__      :   Tuple      =    model(**self._prepare_for_class(__UpperCamelCase    ,			__UpperCamelCase			)			)

											snake_case__      :   Any      =    outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states
											snake_case__      :   Optional[Any]      =    sum(config.num_block_repeats			) * 4
											self.assertEqual(len(__UpperCamelCase			)    ,			__UpperCamelCase			)

											# EfficientNet's feature maps are of shape (batch_size, num_channels, height, width)
											self.assertListEqual(
											    list(hidden_states[0].shape[-2:]			)    ,			[self.model_tester.image_size // 2, self.model_tester.image_size // 2]    ,			)

							snake_case__  ,      snake_case__      :   Tuple      =    self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
											snake_case__      :   str      =    True
											check_hidden_states_output(__UpperCamelCase    ,			__UpperCamelCase    ,			__UpperCamelCase			)

											# check that output_hidden_states also work using config
											del inputs_dict["output_hidden_states"]
											snake_case__      :   Tuple      =    True

											check_hidden_states_output(__UpperCamelCase    ,			__UpperCamelCase    ,			__UpperCamelCase			)



			def 				lowerCAmelCase (     self		:						Optional[int]			)      ->      Dict:
							"""simple docstring"""





							snake_case__      :   Any      =    self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_image_classification(*__UpperCamelCase			)



			@unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''			)
			def 				lowerCAmelCase (     self		:						Dict			)      ->      Tuple:
							"""simple docstring"""





							pass



			@slow
			def 				lowerCAmelCase (     self		:						Tuple			)      ->      Tuple:
							"""simple docstring"""





							for model_name in EFFICIENTNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											snake_case__      :   List[Any]      =    EfficientNetModel.from_pretrained(__UpperCamelCase			)
											self.assertIsNotNone(__UpperCamelCase			)







			@is_pipeline_test
			@require_vision
			@slow
			def 				lowerCAmelCase (     self		:						List[str]			)      ->      Union[str, Any]:
							"""simple docstring"""





							super().test_pipeline_image_classification()



def 							__UpperCAmelCase				(				)		->						Union[str, Any]:
				snake_case__      :   Any      =    Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''			)
				return image






@require_torch
@require_vision
class 			_SCREAMING_SNAKE_CASE				(unittest.TestCase      ):



			@cached_property
			def 				lowerCAmelCase (     self		:						int			)      ->      Optional[int]:
							"""simple docstring"""





							return AutoImageProcessor.from_pretrained('''google/efficientnet-b7'''			) if is_vision_available() else None







			@slow
			def 				lowerCAmelCase (     self		:						List[str]			)      ->      Optional[Any]:
							"""simple docstring"""





							snake_case__      :   List[str]      =    EfficientNetForImageClassification.from_pretrained('''google/efficientnet-b7'''			).to(__UpperCamelCase			)

							snake_case__      :   int      =    self.default_image_processor
							snake_case__      :   Optional[int]      =    prepare_img()
							snake_case__      :   int      =    image_processor(images=__UpperCamelCase    ,			return_tensors='''pt'''			).to(__UpperCamelCase			)

							# forward pass
							with torch.no_grad():
											snake_case__      :   Optional[Any]      =    model(**__UpperCamelCase			)

							# verify the logits
							snake_case__      :   Union[str, Any]      =    torch.Size((1, 1000)			)
							self.assertEqual(outputs.logits.shape    ,			__UpperCamelCase			)

							snake_case__      :   List[Any]      =    torch.tensor([0.0001, 0.0002, 0.0002]			).to(__UpperCamelCase			)
							self.assertTrue(torch.allclose(outputs.logits[0, :3]    ,			__UpperCamelCase    ,			atol=1e-4			)			)












import json
import os
import unittest

from transformers.models.gpt_neox_japanese.tokenization_gpt_neox_japanese import (
    VOCAB_FILES_NAMES,
    GPTNeoXJapaneseTokenizer,
)
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin





@require_tokenizers
class __lowerCamelCase					( snake_case__	,			unittest.TestCase):





	"""simple docstring"""






	UpperCamelCase__								= GPTNeoXJapaneseTokenizer
	UpperCamelCase__								= False
	UpperCamelCase__								= {"do_clean_text": False, "add_prefix_space": False}

	def 			UpperCamelCase       (				self       ):
							"""simple docstring"""







							super().setUp()

							_UpperCAmelCase							   =     [
							    'こん',
							    'こんに',
							    'にちは',
							    'ばんは',
							    '世界,㔺界',
							    '、',
							    '。',
							    '<BR>',
							    '<SP>',
							    '<TAB>',
							    '<URL>',
							    '<EMAIL>',
							    '<TEL>',
							    '<DATE>',
							    '<PRICE>',
							    '<BLOCK>',
							    '<KIGOU>',
							    '<U2000U2BFF>',
							    '<|emoji1|>',
							    '<unk>',
							    '<|startoftext|>',
							    '<|endoftext|>',
							]
							_UpperCAmelCase							   =     {'emoji': {'\ud83d\ude00': '<|emoji1|>'}, 'emoji_inv': {'<|emoji1|>': '\ud83d\ude00'}}  # 😀
							_UpperCAmelCase							   =     {'unk_token': '<unk>'}

							_UpperCAmelCase							   =     os.path.join(self.tmpdirname			,       VOCAB_FILES_NAMES['vocab_file']       )
							_UpperCAmelCase							   =     os.path.join(self.tmpdirname			,       VOCAB_FILES_NAMES['emoji_file']       )
							with open(self.vocab_file			,       'w'			,       encoding='utf-8'       ) as vocab_writer:
													vocab_writer.write(''.join([x + '\n' for x in vocab_tokens]       )       )
							with open(self.emoji_file			,       'w'       ) as emoji_writer:
													emoji_writer.write(json.dumps(UpperCAmelCase       )       )

	def 			UpperCamelCase       (				self			,       **UpperCAmelCase       ):
							"""simple docstring"""







							kwargs.update(self.special_tokens_map       )
							return GPTNeoXJapaneseTokenizer.from_pretrained(self.tmpdirname			,       **UpperCAmelCase       )

	def 			UpperCamelCase       (				self			,       UpperCAmelCase       ):
							"""simple docstring"""







							_UpperCAmelCase							   =     'こんにちは、世界。 \nこんばんは、㔺界。😀'
							_UpperCAmelCase							   =     'こんにちは、世界。 \nこんばんは、世界。😀'
							return input_text, output_text

	def 			UpperCamelCase       (				self			,       UpperCAmelCase       ):
							"""simple docstring"""







							_UpperCAmelCase   ,					_UpperCAmelCase							   =     self.get_input_output_texts(UpperCAmelCase       )
							_UpperCAmelCase							   =     tokenizer.encode(UpperCAmelCase			,       add_special_tokens=UpperCAmelCase       )
							_UpperCAmelCase							   =     tokenizer.decode(UpperCAmelCase			,       clean_up_tokenization_spaces=UpperCAmelCase       )
							return text, ids

	def 			UpperCamelCase       (				self       ):
							"""simple docstring"""







							pass  # TODO add if relevant

	def 			UpperCamelCase       (				self       ):
							"""simple docstring"""







							pass  # TODO add if relevant

	def 			UpperCamelCase       (				self       ):
							"""simple docstring"""







							pass  # TODO add if relevant

	def 			UpperCamelCase       (				self       ):
							"""simple docstring"""







							_UpperCAmelCase							   =     self.get_tokenizer()

							# Testing tokenization
							_UpperCAmelCase							   =     'こんにちは、世界。　こんばんは、㔺界。'
							_UpperCAmelCase							   =     ['こん', 'にちは', '、', '世界', '。', '<SP>', 'こん', 'ばんは', '、', '㔺界', '。']
							_UpperCAmelCase							   =     tokenizer.tokenize(UpperCAmelCase       )
							self.assertListEqual(UpperCAmelCase			,       UpperCAmelCase       )

							# Testing conversion to ids without special tokens
							_UpperCAmelCase							   =     [0, 2, 5, 4, 6, 8, 0, 3, 5, 4, 6]
							_UpperCAmelCase							   =     tokenizer.convert_tokens_to_ids(UpperCAmelCase       )
							self.assertListEqual(UpperCAmelCase			,       UpperCAmelCase       )

							# Testing conversion to ids with special tokens
							_UpperCAmelCase							   =     tokens + [tokenizer.unk_token]
							_UpperCAmelCase							   =     [0, 2, 5, 4, 6, 8, 0, 3, 5, 4, 6, 19]
							_UpperCAmelCase							   =     tokenizer.convert_tokens_to_ids(UpperCAmelCase       )
							self.assertListEqual(UpperCAmelCase			,       UpperCAmelCase       )

	@slow
	def 			UpperCamelCase       (				self       ):
							"""simple docstring"""







							_UpperCAmelCase							   =     self.tokenizer_class.from_pretrained('abeja/gpt-neox-japanese-2.7b'       )

							_UpperCAmelCase							   =     tokenizer.encode('ありがとう。'			,       add_special_tokens=UpperCAmelCase       )
							_UpperCAmelCase							   =     tokenizer.encode('どういたしまして。'			,       add_special_tokens=UpperCAmelCase       )

							_UpperCAmelCase							   =     tokenizer.build_inputs_with_special_tokens(UpperCAmelCase       )
							_UpperCAmelCase							   =     tokenizer.build_inputs_with_special_tokens(UpperCAmelCase			,       UpperCAmelCase       )

							assert encoded_sentence == ids_a
							assert encoded_pair == ids_a + ids_a

	def 			UpperCamelCase       (				self       ):
							"""simple docstring"""







							pass

	def 			UpperCamelCase       (				self       ):
							"""simple docstring"""







							pass
