





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        __snake_case			:





       '''simple docstring'''







       def __init__(    self					:       Tuple				,							A					:       List[Any]				,							A					:       Union[str, Any]=13				,							A					:       Optional[int]=32				,							A					:       int=3				,							A					:       Any=[3, 3, 5]				,							A					:       Optional[Any]=[32, 16, 24]				,							A					:       int=[16, 24, 40]				,							A					:       Union[str, Any]=[1, 1, 2]				,							A					:       Union[str, Any]=[1, 1, 2]				,							A					:       int=[1, 6, 6]				,							A					:       List[Any]=True				,							A					:       List[str]=True				,							A					:       Tuple=37				,							A					:       Tuple="gelu"				,							A					:       int=10				,							):
         __snake_case:		List[Any]					    =		parent
         __snake_case:		Tuple					    =		batch_size
         __snake_case:		List[str]					    =		image_size
         __snake_case:		List[str]					    =		num_channels
         __snake_case:		Optional[Any]					    =		kernel_sizes
         __snake_case:		Optional[int]					    =		in_channels
         __snake_case:		Dict					    =		out_channels
         __snake_case:		Union[str, Any]					    =		strides
         __snake_case:		str					    =		num_block_repeats
         __snake_case:		Union[str, Any]					    =		expand_ratios
         __snake_case:		int					    =		is_training
         __snake_case:		Dict					    =		hidden_act
         __snake_case:		Any					    =		num_labels
         __snake_case:		str					    =		use_labels




       def 				UpperCAmelCase__					(    self					:       Union[str, Any]						):
         __snake_case:		Dict					    =		floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

         __snake_case:		List[Any]					    =		None
         if self.use_labels:
           __snake_case:		Union[str, Any]					    =		ids_tensor([self.batch_size]				,							self.num_labels						)

         __snake_case:		Tuple					    =		self.get_config()
         return config, pixel_values, labels




       def 				UpperCAmelCase__					(    self					:       Dict						):
         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 				UpperCAmelCase__					(    self					:       List[Any]				,							A					:       List[str]				,							A					:       Optional[int]				,							A					:       Union[str, Any]						):
         __snake_case:		Optional[Any]					    =		EfficientNetModel(config=UpperCamelCase__						)
         model.to(UpperCamelCase__						)
         model.eval()
         __snake_case:		List[Any]					    =		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 				UpperCAmelCase__					(    self					:       Optional[int]				,							A					:       str				,							A					:       Optional[Any]				,							A					:       List[Any]						):
         __snake_case:		int					    =		EfficientNetForImageClassification(UpperCamelCase__						)
         model.to(UpperCamelCase__						)
         model.eval()
         __snake_case:		Any					    =		model(UpperCamelCase__				,							labels=UpperCamelCase__						)
         self.parent.assertEqual(result.logits.shape				,							(self.batch_size, self.num_labels)						)






       def 				UpperCAmelCase__					(    self					:       Dict						):
         __snake_case:		Any					    =		self.prepare_config_and_inputs()
         __snake_case:		str					    =		config_and_inputs
         __snake_case:		Any					    =		{"""pixel_values""": pixel_values}
         return config, inputs_dict







@require_torch
class        __snake_case			(				_lowercase  ,     _lowercase  ,     unittest.TestCase     ):





       '''simple docstring'''







       lowerCAmelCase__ 						=	(EfficientNetModel, EfficientNetForImageClassification) if is_torch_available() else ()
       lowerCAmelCase__ 						=	(
           {"""feature-extraction""": EfficientNetModel, """image-classification""": EfficientNetForImageClassification}
           if is_torch_available()
           else {}
       )

       lowerCAmelCase__ 						=	False
       lowerCAmelCase__ 						=	False
       lowerCAmelCase__ 						=	False
       lowerCAmelCase__ 						=	False
       lowerCAmelCase__ 						=	False




       def 				UpperCAmelCase__					(    self					:       str						):
         __snake_case:		Union[str, Any]					    =		EfficientNetModelTester(self						)
         __snake_case:		Dict					    =		ConfigTester(
             self				,							config_class=UpperCamelCase__				,							has_text_modality=UpperCamelCase__				,							hidden_size=37						)




       def 				UpperCAmelCase__					(    self					:       Any						):
         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 				UpperCAmelCase__					(    self					:       Optional[Any]						):
         return




       @unittest.skip(reason="""EfficientNet does not use inputs_embeds"""						)
       def 				UpperCAmelCase__					(    self					:       Optional[Any]						):
         pass




       @unittest.skip(reason="""EfficientNet does not support input and output embeddings"""						)
       def 				UpperCAmelCase__					(    self					:       Dict						):
         pass




       @unittest.skip(reason="""EfficientNet does not use feedforward chunking"""						)
       def 				UpperCAmelCase__					(    self					:       Union[str, Any]						):
         pass




       def 				UpperCAmelCase__					(    self					:       str						):
         __snake_case:		Optional[Any]					    =		self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in self.all_model_classes:
           __snake_case:		Optional[Any]					    =		model_class(UpperCamelCase__						)
           __snake_case:		Any					    =		inspect.signature(model.forward						)
           # signature.parameters is an OrderedDict => so arg_names order is deterministic
           __snake_case:		Dict					    =		[*signature.parameters.keys()]

           __snake_case:		Dict					    =		["""pixel_values"""]
           self.assertListEqual(arg_names[:1]				,							UpperCamelCase__						)




       def 				UpperCAmelCase__					(    self					:       Union[str, Any]						):
         __snake_case:		int					    =		self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*UpperCamelCase__						)




       def 				UpperCAmelCase__					(    self					:       Union[str, Any]						):
         def check_hidden_states_output(A					:       List[str]				,							A					:       Union[str, Any]				,							A					:       Tuple						):
           __snake_case:		Tuple					    =		model_class(UpperCamelCase__						)
           model.to(UpperCamelCase__						)
           model.eval()

           with torch.no_grad():
             __snake_case:		Optional[Any]					    =		model(**self._prepare_for_class(UpperCamelCase__				,							UpperCamelCase__						)						)

           __snake_case:		Optional[Any]					    =		outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states
           __snake_case:		int					    =		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:		Optional[int]					    =		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:		Optional[int]					    =		True

           check_hidden_states_output(UpperCamelCase__				,							UpperCamelCase__				,							UpperCamelCase__						)




       def 				UpperCAmelCase__					(    self					:       Any						):
         __snake_case:		Tuple					    =		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 				UpperCAmelCase__					(    self					:       str						):
         pass




       @slow
       def 				UpperCAmelCase__					(    self					:       Optional[Any]						):
         for model_name in EFFICIENTNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           __snake_case:		int					    =		EfficientNetModel.from_pretrained(UpperCamelCase__						)
           self.assertIsNotNone(UpperCamelCase__						)






       @is_pipeline_test
       @require_vision
       @slow
       def 				UpperCAmelCase__					(    self					:       Optional[int]						):
         super().test_pipeline_image_classification()







def      A__				(       )  ->       Optional[Any]:
  __snake_case:		Dict					    =		Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png""")
  return image







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





       '''simple docstring'''







       @cached_property
       def 				UpperCAmelCase__					(    self					:       List[str]						):
         return AutoImageProcessor.from_pretrained("""google/efficientnet-b7"""						) if is_vision_available() else None






       @slow
       def 				UpperCAmelCase__					(    self					:       int						):
         __snake_case:		int					    =		EfficientNetForImageClassification.from_pretrained("""google/efficientnet-b7"""						).to(UpperCamelCase__						)

         __snake_case:		List[Any]					    =		self.default_image_processor
         __snake_case:		Union[str, Any]					    =		prepare_img()
         __snake_case:		List[str]					    =		image_processor(images=UpperCamelCase__				,							return_tensors="""pt"""						).to(UpperCamelCase__						)

         # forward pass
         with torch.no_grad():
           __snake_case:		List[str]					    =		model(**UpperCamelCase__						)

         # verify the logits
         __snake_case:		int					    =		torch.Size((1, 1_000)						)
         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						)						)














'''simple docstring'''







from ...configuration_utils import PretrainedConfig
from ...utils import logging


_A      :     Union[str, Any]       	=logging.get_logger(__name__)

_A      :     Tuple       	={
    '''tau/splinter-base''': '''https://huggingface.co/tau/splinter-base/resolve/main/config.json''',
    '''tau/splinter-base-qass''': '''https://huggingface.co/tau/splinter-base-qass/resolve/main/config.json''',
    '''tau/splinter-large''': '''https://huggingface.co/tau/splinter-large/resolve/main/config.json''',
    '''tau/splinter-large-qass''': '''https://huggingface.co/tau/splinter-large-qass/resolve/main/config.json''',
    # See all Splinter models at https://huggingface.co/models?filter=splinter
}

class _lowercase      (							_lowercase						):
							a							 =			"""splinter"""




							def __init__(				self:							List[str]     ,				UpperCamelCase__:							List[Any]=30_522     ,				UpperCamelCase__:							Union[str, Any]=768     ,				UpperCamelCase__:							str=12     ,				UpperCamelCase__:							Dict=12     ,				UpperCamelCase__:							Tuple=3_072     ,				UpperCamelCase__:							Optional[int]="gelu"     ,				UpperCamelCase__:							Optional[int]=0.1     ,				UpperCamelCase__:							str=0.1     ,				UpperCamelCase__:							List[Any]=512     ,				UpperCamelCase__:							List[str]=2     ,				UpperCamelCase__:							Any=0.02     ,				UpperCamelCase__:							Optional[Any]=1e-12     ,				UpperCamelCase__:							Dict=True     ,				UpperCamelCase__:							str=0     ,				UpperCamelCase__:							int=104     ,				**UpperCamelCase__:							Any     ,				):
														super().__init__(pad_token_id=UpperCamelCase__     ,				**UpperCamelCase__	)

														lowerCamelCase__   :      Union[str, Any]			    =			vocab_size
														lowerCamelCase__   :      str			    =			max_position_embeddings
														lowerCamelCase__   :      Tuple			    =			hidden_size
														lowerCamelCase__   :      Dict			    =			num_hidden_layers
														lowerCamelCase__   :      Tuple			    =			num_attention_heads
														lowerCamelCase__   :      Tuple			    =			intermediate_size
														lowerCamelCase__   :      Any			    =			hidden_act
														lowerCamelCase__   :      int			    =			hidden_dropout_prob
														lowerCamelCase__   :      List[str]			    =			attention_probs_dropout_prob
														lowerCamelCase__   :      Dict			    =			initializer_range
														lowerCamelCase__   :      List[Any]			    =			type_vocab_size
														lowerCamelCase__   :      Tuple			    =			layer_norm_eps
														lowerCamelCase__   :      Optional[Any]			    =			use_cache
														lowerCamelCase__   :      Optional[Any]			    =			question_token_id

