


'''simple docstring'''



import unittest

from transformers import YosoConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

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


if is_torch_available():
      import torch

      from transformers import (
          YosoForMaskedLM,
          YosoForMultipleChoice,
          YosoForQuestionAnswering,
          YosoForSequenceClassification,
          YosoForTokenClassification,
          YosoModel,
      )
      from transformers.models.yoso.modeling_yoso import YOSO_PRETRAINED_MODEL_ARCHIVE_LIST



class       a							:


     """simple docstring"""






     def __init__(							self	:						Union[str, Any]				,					snake_case	:						str				,					snake_case	:						List[Any]=13				,					snake_case	:						Optional[int]=7				,					snake_case	:						int=True				,					snake_case	:						Any=True				,					snake_case	:						Dict=True				,					snake_case	:						Tuple=True				,					snake_case	:						Optional[Any]=99				,					snake_case	:						List[str]=32				,					snake_case	:						Optional[Any]=5				,					snake_case	:						Optional[int]=4				,					snake_case	:						Dict=37				,					snake_case	:						Optional[int]="gelu"				,					snake_case	:						Dict=0.1				,					snake_case	:						Tuple=0.1				,					snake_case	:						str=512				,					snake_case	:						Dict=16				,					snake_case	:						Optional[Any]=2				,					snake_case	:						Tuple=0.02				,					snake_case	:						Optional[Any]=3				,					snake_case	:						Any=4				,					snake_case	:						Dict=None				,					)		->				Union[str, Any]:
          __UpperCAmelCase      :					Dict    				=     parent
          __UpperCAmelCase      :					str    				=     batch_size
          __UpperCAmelCase      :					Union[str, Any]    				=     seq_length
          __UpperCAmelCase      :					Dict    				=     is_training
          __UpperCAmelCase      :					int    				=     use_input_mask
          __UpperCAmelCase      :					List[Any]    				=     use_token_type_ids
          __UpperCAmelCase      :					str    				=     use_labels
          __UpperCAmelCase      :					Union[str, Any]    				=     vocab_size
          __UpperCAmelCase      :					Dict    				=     hidden_size
          __UpperCAmelCase      :					List[str]    				=     num_hidden_layers
          __UpperCAmelCase      :					str    				=     num_attention_heads
          __UpperCAmelCase      :					List[str]    				=     intermediate_size
          __UpperCAmelCase      :					Union[str, Any]    				=     hidden_act
          __UpperCAmelCase      :					Optional[Any]    				=     hidden_dropout_prob
          __UpperCAmelCase      :					Optional[int]    				=     attention_probs_dropout_prob
          __UpperCAmelCase      :					Dict    				=     max_position_embeddings
          __UpperCAmelCase      :					Any    				=     type_vocab_size
          __UpperCAmelCase      :					Dict    				=     type_sequence_label_size
          __UpperCAmelCase      :					int    				=     initializer_range
          __UpperCAmelCase      :					Any    				=     num_labels
          __UpperCAmelCase      :					List[str]    				=     num_choices
          __UpperCAmelCase      :					Union[str, Any]    				=     scope

     def 					lowerCamelCase__					(							self	:						Optional[int]     )		->				Dict:
          __UpperCAmelCase      :					Any    				=     ids_tensor([self.batch_size, self.seq_length]				,					self.vocab_size     )

          __UpperCAmelCase      :					Tuple    				=     None
          if self.use_input_mask:
               __UpperCAmelCase      :					Tuple    				=     random_attention_mask([self.batch_size, self.seq_length]     )

          __UpperCAmelCase      :					Optional[int]    				=     None
          if self.use_token_type_ids:
               __UpperCAmelCase      :					Dict    				=     ids_tensor([self.batch_size, self.seq_length]				,					self.type_vocab_size     )

          __UpperCAmelCase      :					Union[str, Any]    				=     None
          __UpperCAmelCase      :					Tuple    				=     None
          __UpperCAmelCase      :					Union[str, Any]    				=     None
          if self.use_labels:
               __UpperCAmelCase      :					int    				=     ids_tensor([self.batch_size]				,					self.type_sequence_label_size     )
               __UpperCAmelCase      :					List[str]    				=     ids_tensor([self.batch_size, self.seq_length]				,					self.num_labels     )
               __UpperCAmelCase      :					Union[str, Any]    				=     ids_tensor([self.batch_size]				,					self.num_choices     )

          __UpperCAmelCase      :					int    				=     self.get_config()

          return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels

     def 					lowerCamelCase__					(							self	:						int     )		->				Optional[Any]:
          return YosoConfig(
              vocab_size=self.vocab_size				,					hidden_size=self.hidden_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				,					is_decoder=snake_case				,					initializer_range=self.initializer_range				,					)

     def 					lowerCamelCase__					(							self	:						str     )		->				List[Any]:
          __UpperCAmelCase      :					Any    				=     self.get_config()
          __UpperCAmelCase      :					Optional[Any]    				=     300
          return config

     def 					lowerCamelCase__					(							self	:						List[str]     )		->				List[Any]:
          (
              (
              __UpperCAmelCase
          )				,  (
              __UpperCAmelCase
          )				,  (
              __UpperCAmelCase
          )				,  (
              __UpperCAmelCase
          )				,  (
              __UpperCAmelCase
          )				,  (
              __UpperCAmelCase
          )				,  (
              __UpperCAmelCase
          )				,  
          )      :					Union[str, Any]    				=     self.prepare_config_and_inputs()

          __UpperCAmelCase      :					List[Any]    				=     True
          __UpperCAmelCase      :					Optional[Any]    				=     floats_tensor([self.batch_size, self.seq_length, self.hidden_size]     )
          __UpperCAmelCase      :					Optional[Any]    				=     ids_tensor([self.batch_size, self.seq_length]				,					vocab_size=2     )

          return (
              config,
              input_ids,
              token_type_ids,
              input_mask,
              sequence_labels,
              token_labels,
              choice_labels,
              encoder_hidden_states,
              encoder_attention_mask,
          )

     def 					lowerCamelCase__					(							self	:						Optional[int]				,					snake_case	:						Optional[int]				,					snake_case	:						Union[str, Any]				,					snake_case	:						Optional[Any]				,					snake_case	:						Optional[Any]				,					snake_case	:						List[Any]				,					snake_case	:						int				,					snake_case	:						str     )		->				Optional[int]:
          __UpperCAmelCase      :					Optional[int]    				=     YosoModel(config=snake_case     )
          model.to(snake_case     )
          model.eval()
          __UpperCAmelCase      :					Optional[int]    				=     model(snake_case				,					attention_mask=snake_case				,					token_type_ids=snake_case     )
          __UpperCAmelCase      :					int    				=     model(snake_case				,					token_type_ids=snake_case     )
          __UpperCAmelCase      :					Tuple    				=     model(snake_case     )
          self.parent.assertEqual(result.last_hidden_state.shape				,					(self.batch_size, self.seq_length, self.hidden_size)     )

     def 					lowerCamelCase__					(							self	:						Optional[int]				,					snake_case	:						Optional[int]				,					snake_case	:						str				,					snake_case	:						Optional[int]				,					snake_case	:						Tuple				,					snake_case	:						List[Any]				,					snake_case	:						Any				,					snake_case	:						Union[str, Any]				,					snake_case	:						List[Any]				,					snake_case	:						str				,					)		->				Union[str, Any]:
          __UpperCAmelCase      :					Union[str, Any]    				=     True
          __UpperCAmelCase      :					Tuple    				=     YosoModel(snake_case     )
          model.to(snake_case     )
          model.eval()
          __UpperCAmelCase      :					int    				=     model(
              snake_case				,					attention_mask=snake_case				,					token_type_ids=snake_case				,					encoder_hidden_states=snake_case				,					encoder_attention_mask=snake_case				,					)
          __UpperCAmelCase      :					int    				=     model(
              snake_case				,					attention_mask=snake_case				,					token_type_ids=snake_case				,					encoder_hidden_states=snake_case				,					)
          __UpperCAmelCase      :					Any    				=     model(snake_case				,					attention_mask=snake_case				,					token_type_ids=snake_case     )
          self.parent.assertEqual(result.last_hidden_state.shape				,					(self.batch_size, self.seq_length, self.hidden_size)     )

     def 					lowerCamelCase__					(							self	:						str				,					snake_case	:						Tuple				,					snake_case	:						Any				,					snake_case	:						int				,					snake_case	:						Optional[Any]				,					snake_case	:						str				,					snake_case	:						List[str]				,					snake_case	:						Tuple     )		->				Any:
          __UpperCAmelCase      :					List[Any]    				=     YosoForMaskedLM(config=snake_case     )
          model.to(snake_case     )
          model.eval()
          __UpperCAmelCase      :					int    				=     model(snake_case				,					attention_mask=snake_case				,					token_type_ids=snake_case				,					labels=snake_case     )
          self.parent.assertEqual(result.logits.shape				,					(self.batch_size, self.seq_length, self.vocab_size)     )

     def 					lowerCamelCase__					(							self	:						Dict				,					snake_case	:						Dict				,					snake_case	:						Optional[int]				,					snake_case	:						Dict				,					snake_case	:						int				,					snake_case	:						Optional[Any]				,					snake_case	:						Optional[int]				,					snake_case	:						Any     )		->				Dict:
          __UpperCAmelCase      :					Optional[int]    				=     YosoForQuestionAnswering(config=snake_case     )
          model.to(snake_case     )
          model.eval()
          __UpperCAmelCase      :					List[str]    				=     model(
              snake_case				,					attention_mask=snake_case				,					token_type_ids=snake_case				,					start_positions=snake_case				,					end_positions=snake_case				,					)
          self.parent.assertEqual(result.start_logits.shape				,					(self.batch_size, self.seq_length)     )
          self.parent.assertEqual(result.end_logits.shape				,					(self.batch_size, self.seq_length)     )

     def 					lowerCamelCase__					(							self	:						Dict				,					snake_case	:						str				,					snake_case	:						Any				,					snake_case	:						List[Any]				,					snake_case	:						Tuple				,					snake_case	:						List[Any]				,					snake_case	:						Any				,					snake_case	:						Optional[int]     )		->				Tuple:
          __UpperCAmelCase      :					Optional[int]    				=     self.num_labels
          __UpperCAmelCase      :					Tuple    				=     YosoForSequenceClassification(snake_case     )
          model.to(snake_case     )
          model.eval()
          __UpperCAmelCase      :					List[Any]    				=     model(snake_case				,					attention_mask=snake_case				,					token_type_ids=snake_case				,					labels=snake_case     )
          self.parent.assertEqual(result.logits.shape				,					(self.batch_size, self.num_labels)     )

     def 					lowerCamelCase__					(							self	:						Union[str, Any]				,					snake_case	:						List[Any]				,					snake_case	:						Optional[Any]				,					snake_case	:						List[Any]				,					snake_case	:						str				,					snake_case	:						Tuple				,					snake_case	:						int				,					snake_case	:						Any     )		->				Dict:
          __UpperCAmelCase      :					int    				=     self.num_labels
          __UpperCAmelCase      :					List[Any]    				=     YosoForTokenClassification(config=snake_case     )
          model.to(snake_case     )
          model.eval()
          __UpperCAmelCase      :					Optional[Any]    				=     model(snake_case				,					attention_mask=snake_case				,					token_type_ids=snake_case				,					labels=snake_case     )
          self.parent.assertEqual(result.logits.shape				,					(self.batch_size, self.seq_length, self.num_labels)     )

     def 					lowerCamelCase__					(							self	:						str				,					snake_case	:						List[Any]				,					snake_case	:						List[Any]				,					snake_case	:						Union[str, Any]				,					snake_case	:						Union[str, Any]				,					snake_case	:						Optional[int]				,					snake_case	:						int				,					snake_case	:						List[str]     )		->				List[str]:
          __UpperCAmelCase      :					Tuple    				=     self.num_choices
          __UpperCAmelCase      :					Dict    				=     YosoForMultipleChoice(config=snake_case     )
          model.to(snake_case     )
          model.eval()
          __UpperCAmelCase      :					List[str]    				=     input_ids.unsqueeze(1     ).expand(-1				,					self.num_choices				,					-1     ).contiguous()
          __UpperCAmelCase      :					List[str]    				=     token_type_ids.unsqueeze(1     ).expand(-1				,					self.num_choices				,					-1     ).contiguous()
          __UpperCAmelCase      :					Tuple    				=     input_mask.unsqueeze(1     ).expand(-1				,					self.num_choices				,					-1     ).contiguous()
          __UpperCAmelCase      :					Dict    				=     model(
              snake_case				,					attention_mask=snake_case				,					token_type_ids=snake_case				,					labels=snake_case				,					)
          self.parent.assertEqual(result.logits.shape				,					(self.batch_size, self.num_choices)     )






     def 					lowerCamelCase__					(							self	:						Optional[int]     )		->				Optional[int]:
          __UpperCAmelCase      :					Any    				=     self.prepare_config_and_inputs()
          (
              (
              __UpperCAmelCase
          )				,  (
              __UpperCAmelCase
          )				,  (
              __UpperCAmelCase
          )				,  (
              __UpperCAmelCase
          )				,  (
              __UpperCAmelCase
          )				,  (
              __UpperCAmelCase
          )				,  (
              __UpperCAmelCase
          )				,  
          )      :					List[str]    				=     config_and_inputs
          __UpperCAmelCase      :					int    				=     {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
          return config, inputs_dict



@require_torch
class       a							(						_a      ,    _a      ,    unittest.TestCase			):


     """simple docstring"""






     SCREAMING_SNAKE_CASE			:					List[Any]				  =  (
         (
             YosoModel,
             YosoForMaskedLM,
             YosoForMultipleChoice,
             YosoForQuestionAnswering,
             YosoForSequenceClassification,
             YosoForTokenClassification,
         )
         if is_torch_available()
         else ()
     )
     SCREAMING_SNAKE_CASE			:					Optional[Any]				  =  False
     SCREAMING_SNAKE_CASE			:					Dict				  =  False
     SCREAMING_SNAKE_CASE			:					str				  =  False

     SCREAMING_SNAKE_CASE			:					Any				  =  ()
     SCREAMING_SNAKE_CASE			:					int				  =  (
         {
             "feature-extraction": YosoModel,
             "fill-mask": YosoForMaskedLM,
             "question-answering": YosoForQuestionAnswering,
             "text-classification": YosoForSequenceClassification,
             "token-classification": YosoForTokenClassification,
             "zero-shot": YosoForSequenceClassification,
         }
         if is_torch_available()
         else {}
     )

     def 					lowerCamelCase__					(							self	:						Any     )		->				Optional[int]:
          __UpperCAmelCase      :					Optional[Any]    				=     YosoModelTester(self     )
          __UpperCAmelCase      :					Dict    				=     ConfigTester(self				,					config_class=snake_case				,					hidden_size=37     )

     def 					lowerCamelCase__					(							self	:						List[str]     )		->				Optional[Any]:
          self.config_tester.run_common_tests()

     def 					lowerCamelCase__					(							self	:						int     )		->				List[Any]:
          __UpperCAmelCase      :					Dict    				=     self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*snake_case     )

     def 					lowerCamelCase__					(							self	:						List[Any]     )		->				int:
          __UpperCAmelCase      :					str    				=     self.model_tester.prepare_config_and_inputs()
          for type in ["absolute", "relative_key", "relative_key_query"]:
               __UpperCAmelCase      :					Dict    				=     type
               self.model_tester.create_and_check_model(*snake_case     )

     def 					lowerCamelCase__					(							self	:						Optional[Any]     )		->				str:
          __UpperCAmelCase      :					Dict    				=     self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_masked_lm(*snake_case     )

     def 					lowerCamelCase__					(							self	:						Tuple     )		->				Optional[int]:
          __UpperCAmelCase      :					List[Any]    				=     self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_multiple_choice(*snake_case     )

     def 					lowerCamelCase__					(							self	:						str     )		->				List[Any]:
          __UpperCAmelCase      :					int    				=     self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_question_answering(*snake_case     )

     def 					lowerCamelCase__					(							self	:						Any     )		->				Optional[int]:
          __UpperCAmelCase      :					Any    				=     self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_sequence_classification(*snake_case     )

     def 					lowerCamelCase__					(							self	:						Tuple     )		->				int:
          __UpperCAmelCase      :					Optional[Any]    				=     self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_token_classification(*snake_case     )

     @slow
     def 					lowerCamelCase__					(							self	:						List[str]     )		->				str:
          for model_name in YOSO_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               __UpperCAmelCase      :					Dict    				=     YosoModel.from_pretrained(snake_case     )
               self.assertIsNotNone(snake_case     )






     def 					lowerCamelCase__					(							self	:						int     )		->				Dict:
          return



@require_torch
class       a							(						unittest.TestCase			):


     """simple docstring"""






     @slow
     def 					lowerCamelCase__					(							self	:						List[str]     )		->				List[str]:
          __UpperCAmelCase      :					Tuple    				=     YosoModel.from_pretrained('''uw-madison/yoso-4096'''     )
          __UpperCAmelCase      :					Dict    				=     torch.tensor([[0, 1, 2, 3, 4, 5]]     )

          with torch.no_grad():
               __UpperCAmelCase      :					List[Any]    				=     model(snake_case     )[0]

          __UpperCAmelCase      :					int    				=     torch.Size((1, 6, 768)     )
          self.assertEqual(output.shape				,					snake_case     )

          __UpperCAmelCase      :					List[str]    				=     torch.tensor(
              [[[-0.0_611, 0.1_242, 0.0_840], [0.0_280, -0.0_048, 0.1_125], [0.0_106, 0.0_226, 0.0_751]]]     )

          self.assertTrue(torch.allclose(output[:, :3, :3]				,					snake_case				,					atol=1E-4     )     )

     @slow
     def 					lowerCamelCase__					(							self	:						Dict     )		->				Tuple:
          __UpperCAmelCase      :					Optional[int]    				=     YosoForMaskedLM.from_pretrained('''uw-madison/yoso-4096'''     )
          __UpperCAmelCase      :					Union[str, Any]    				=     torch.tensor([[0, 1, 2, 3, 4, 5]]     )

          with torch.no_grad():
               __UpperCAmelCase      :					Tuple    				=     model(snake_case     )[0]

          __UpperCAmelCase      :					Dict    				=     5_0265

          __UpperCAmelCase      :					Optional[int]    				=     torch.Size((1, 6, vocab_size)     )
          self.assertEqual(output.shape				,					snake_case     )

          __UpperCAmelCase      :					Optional[Any]    				=     torch.tensor(
              [[[-2.1_313, -3.7_285, -2.2_407], [-2.7_047, -3.3_314, -2.6_408], [0.0_629, -2.5_166, -0.3_356]]]     )

          self.assertTrue(torch.allclose(output[:, :3, :3]				,					snake_case				,					atol=1E-4     )     )






     @slow
     def 					lowerCamelCase__					(							self	:						List[Any]     )		->				Union[str, Any]:
          __UpperCAmelCase      :					Tuple    				=     YosoForMaskedLM.from_pretrained('''uw-madison/yoso-4096'''     )
          __UpperCAmelCase      :					Any    				=     torch.arange(4096     ).unsqueeze(0     )

          with torch.no_grad():
               __UpperCAmelCase      :					Union[str, Any]    				=     model(snake_case     )[0]

          __UpperCAmelCase      :					int    				=     5_0265

          __UpperCAmelCase      :					Optional[int]    				=     torch.Size((1, 4096, vocab_size)     )
          self.assertEqual(output.shape				,					snake_case     )

          __UpperCAmelCase      :					Optional[Any]    				=     torch.tensor(
              [[[-2.3_914, -4.3_742, -5.0_956], [-4.0_988, -4.2_384, -7.0_406], [-3.1_427, -3.7_192, -6.6_800]]]     )

          self.assertTrue(torch.allclose(output[:, :3, :3]				,					snake_case				,					atol=1E-4     )     )



'''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       a							:


     """simple docstring"""






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

     def 					lowerCamelCase__					(							self	:						Dict     )		->				Tuple:
          __UpperCAmelCase      :					Tuple    				=     floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]     )

          __UpperCAmelCase      :					int    				=     None
          if self.use_labels:
               __UpperCAmelCase      :					Optional[Any]    				=     ids_tensor([self.batch_size]				,					self.num_labels     )

          __UpperCAmelCase      :					int    				=     self.get_config()
          return config, pixel_values, labels

     def 					lowerCamelCase__					(							self	:						str     )		->				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 					lowerCamelCase__					(							self	:						Any				,					snake_case	:						Tuple				,					snake_case	:						Tuple				,					snake_case	:						Optional[int]     )		->				Union[str, Any]:
          __UpperCAmelCase      :					Union[str, Any]    				=     EfficientNetModel(config=snake_case     )
          model.to(snake_case     )
          model.eval()
          __UpperCAmelCase      :					Union[str, Any]    				=     model(snake_case     )
          # 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	:						List[str]				,					snake_case	:						Optional[int]				,					snake_case	:						List[str]				,					snake_case	:						List[str]     )		->				Optional[int]:
          __UpperCAmelCase      :					List[str]    				=     EfficientNetForImageClassification(snake_case     )
          model.to(snake_case     )
          model.eval()
          __UpperCAmelCase      :					Any    				=     model(snake_case				,					labels=snake_case     )
          self.parent.assertEqual(result.logits.shape				,					(self.batch_size, self.num_labels)     )






     def 					lowerCamelCase__					(							self	:						str     )		->				Tuple:
          __UpperCAmelCase      :					List[Any]    				=     self.prepare_config_and_inputs()
          __UpperCAmelCase				,  __UpperCAmelCase				,  __UpperCAmelCase      :					Union[str, Any]    				=     config_and_inputs
          __UpperCAmelCase      :					Union[str, Any]    				=     {'''pixel_values''': pixel_values}
          return config, inputs_dict



@require_torch
class       a							(						_a      ,    _a      ,    unittest.TestCase			):


     """simple docstring"""






     SCREAMING_SNAKE_CASE			:					str				  =  (EfficientNetModel, EfficientNetForImageClassification) if is_torch_available() else ()
     SCREAMING_SNAKE_CASE			:					List[str]				  =  (
         {"feature-extraction": EfficientNetModel, "image-classification": EfficientNetForImageClassification}
         if is_torch_available()
         else {}
     )

     SCREAMING_SNAKE_CASE			:					Union[str, Any]				  =  False
     SCREAMING_SNAKE_CASE			:					Optional[int]				  =  False
     SCREAMING_SNAKE_CASE			:					Optional[int]				  =  False
     SCREAMING_SNAKE_CASE			:					List[Any]				  =  False
     SCREAMING_SNAKE_CASE			:					List[str]				  =  False

     def 					lowerCamelCase__					(							self	:						List[str]     )		->				List[str]:
          __UpperCAmelCase      :					Dict    				=     EfficientNetModelTester(self     )
          __UpperCAmelCase      :					Optional[Any]    				=     ConfigTester(
              self				,					config_class=snake_case				,					has_text_modality=snake_case				,					hidden_size=37     )

     def 					lowerCamelCase__					(							self	:						List[str]     )		->				str:
          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	:						Dict     )		->				str:
          return

     @unittest.skip(reason='''EfficientNet does not use inputs_embeds'''     )
     def 					lowerCamelCase__					(							self	:						List[Any]     )		->				Optional[int]:
          pass

     @unittest.skip(reason='''EfficientNet does not support input and output embeddings'''     )
     def 					lowerCamelCase__					(							self	:						List[str]     )		->				Dict:
          pass

     @unittest.skip(reason='''EfficientNet does not use feedforward chunking'''     )
     def 					lowerCamelCase__					(							self	:						Union[str, Any]     )		->				Optional[int]:
          pass

     def 					lowerCamelCase__					(							self	:						List[str]     )		->				Optional[Any]:
          __UpperCAmelCase				,  __UpperCAmelCase      :					List[str]    				=     self.model_tester.prepare_config_and_inputs_for_common()

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

               __UpperCAmelCase      :					Union[str, Any]    				=     ['''pixel_values''']
               self.assertListEqual(arg_names[:1]				,					snake_case     )

     def 					lowerCamelCase__					(							self	:						int     )		->				List[str]:
          __UpperCAmelCase      :					Union[str, Any]    				=     self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*snake_case     )

     def 					lowerCamelCase__					(							self	:						int     )		->				str:
          def check_hidden_states_output(snake_case	:						Union[str, Any]				,					snake_case	:						str				,					snake_case	:						Tuple     ):
               __UpperCAmelCase      :					List[str]    				=     model_class(snake_case     )
               model.to(snake_case     )
               model.eval()

               with torch.no_grad():
                    __UpperCAmelCase      :					int    				=     model(**self._prepare_for_class(snake_case				,					snake_case     )     )

               __UpperCAmelCase      :					Optional[int]    				=     outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states
               __UpperCAmelCase      :					List[str]    				=     sum(config.num_block_repeats     ) * 4
               self.assertEqual(len(snake_case     )				,					snake_case     )

               # 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]				,					)

          __UpperCAmelCase				,  __UpperCAmelCase      :					Union[str, Any]    				=     self.model_tester.prepare_config_and_inputs_for_common()

          for model_class in self.all_model_classes:
               __UpperCAmelCase      :					int    				=     True
               check_hidden_states_output(snake_case				,					snake_case				,					snake_case     )

               # check that output_hidden_states also work using config
               del inputs_dict["output_hidden_states"]
               __UpperCAmelCase      :					Union[str, Any]    				=     True

               check_hidden_states_output(snake_case				,					snake_case				,					snake_case     )

     def 					lowerCamelCase__					(							self	:						str     )		->				Any:
          __UpperCAmelCase      :					Any    				=     self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_image_classification(*snake_case     )

     @unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''     )
     def 					lowerCamelCase__					(							self	:						List[Any]     )		->				Tuple:
          pass

     @slow
     def 					lowerCamelCase__					(							self	:						Optional[int]     )		->				List[str]:
          for model_name in EFFICIENTNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               __UpperCAmelCase      :					str    				=     EfficientNetModel.from_pretrained(snake_case     )
               self.assertIsNotNone(snake_case     )






     @is_pipeline_test
     @require_vision
     @slow
     def 					lowerCamelCase__					(							self	:						Union[str, Any]     )		->				List[str]:
          super().test_pipeline_image_classification()




def       _a      (		):





     '''simple docstring'''






     __UpperCAmelCase      :					Any    				=     Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''    )
     return image



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


     """simple docstring"""






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






     @slow
     def 					lowerCamelCase__					(							self	:						str     )		->				Any:
          __UpperCAmelCase      :					Tuple    				=     EfficientNetForImageClassification.from_pretrained('''google/efficientnet-b7'''     ).to(snake_case     )

          __UpperCAmelCase      :					List[str]    				=     self.default_image_processor
          __UpperCAmelCase      :					List[Any]    				=     prepare_img()
          __UpperCAmelCase      :					Union[str, Any]    				=     image_processor(images=snake_case				,					return_tensors='''pt'''     ).to(snake_case     )

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

          # verify the logits
          __UpperCAmelCase      :					Any    				=     torch.Size((1, 1000)     )
          self.assertEqual(outputs.logits.shape				,					snake_case     )

          __UpperCAmelCase      :					Dict    				=     torch.tensor([0.0_001, 0.0_002, 0.0_002]     ).to(snake_case     )
          self.assertTrue(torch.allclose(outputs.logits[0, :3]				,					snake_case				,					atol=1E-4     )     )