




'''simple docstring'''


import unittest

from transformers import 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 (
           RemBertConfig,
           RemBertForCausalLM,
           RemBertForMaskedLM,
           RemBertForMultipleChoice,
           RemBertForQuestionAnswering,
           RemBertForSequenceClassification,
           RemBertForTokenClassification,
           RemBertModel,
       )
       from transformers.models.rembert.modeling_rembert import REMBERT_PRETRAINED_MODEL_ARCHIVE_LIST







class     SCREAMING_SNAKE_CASE						:






      def __init__(   self      :     List[str]	,	lowercase__      :     str	,	lowercase__      :     List[Any]=13	,	lowercase__      :     Dict=7	,	lowercase__      :     Any=True	,	lowercase__      :     int=True	,	lowercase__      :     Optional[int]=True	,	lowercase__      :     Dict=True	,	lowercase__      :     str=99	,	lowercase__      :     List[str]=32	,	lowercase__      :     Optional[int]=18	,	lowercase__      :     Tuple=43	,	lowercase__      :     List[str]=5	,	lowercase__      :     Optional[Any]=4	,	lowercase__      :     List[Any]=37	,	lowercase__      :     Union[str, Any]="gelu"	,	lowercase__      :     Optional[int]=0.1	,	lowercase__      :     int=0.1	,	lowercase__      :     str=512	,	lowercase__      :     Dict=16	,	lowercase__      :     Union[str, Any]=2	,	lowercase__      :     Any=0.02	,	lowercase__      :     str=3	,	lowercase__      :     Union[str, Any]=4	,	lowercase__      :     List[Any]=None	,	):


           '''simple docstring'''

           a_    :       Tuple    	=     parent
           a_    :       Tuple    	=     batch_size
           a_    :       Union[str, Any]    	=     seq_length
           a_    :       Any    	=     is_training
           a_    :       int    	=     use_input_mask
           a_    :       List[Any]    	=     use_token_type_ids
           a_    :       Dict    	=     use_labels
           a_    :       Optional[Any]    	=     vocab_size
           a_    :       Optional[int]    	=     hidden_size
           a_    :       Dict    	=     input_embedding_size
           a_    :       str    	=     output_embedding_size
           a_    :       List[str]    	=     num_hidden_layers
           a_    :       int    	=     num_attention_heads
           a_    :       int    	=     intermediate_size
           a_    :       Dict    	=     hidden_act
           a_    :       Dict    	=     hidden_dropout_prob
           a_    :       List[Any]    	=     attention_probs_dropout_prob
           a_    :       Optional[Any]    	=     max_position_embeddings
           a_    :       Union[str, Any]    	=     type_vocab_size
           a_    :       Optional[int]    	=     type_sequence_label_size
           a_    :       Tuple    	=     initializer_range
           a_    :       Any    	=     num_labels
           a_    :       Optional[Any]    	=     num_choices
           a_    :       Any    	=     scope






      def        lowercase_	(   self      :     Dict					):


           '''simple docstring'''

           a_    :       List[Any]    	=     ids_tensor([self.batch_size, self.seq_length]	,	self.vocab_size					)

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

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

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

           a_    :       Optional[int]    	=     RemBertConfig(
               vocab_size=self.vocab_size	,	hidden_size=self.hidden_size	,	input_embedding_size=self.input_embedding_size	,	output_embedding_size=self.output_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	,	is_decoder=lowercase__	,	initializer_range=self.initializer_range	,	)

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






      def        lowercase_	(   self      :     Tuple					):


           '''simple docstring'''

           (
               (
               a_       
           )	,    (
               a_       
           )	,    (
               a_       
           )	,    (
               a_       
           )	,    (
               a_       
           )	,    (
               a_       
           )	,    (
               a_       
           )	,           
           )    :       Tuple    	=     self.prepare_config_and_inputs()

           a_    :       Dict    	=     True
           a_    :       Dict    	=     floats_tensor([self.batch_size, self.seq_length, self.hidden_size]					)
           a_    :       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        lowercase_	(   self      :     List[str]	,	lowercase__      :     Optional[Any]	,	lowercase__      :     Optional[int]	,	lowercase__      :     List[str]	,	lowercase__      :     Optional[int]	,	lowercase__      :     Dict	,	lowercase__      :     List[str]	,	lowercase__      :     Optional[Any]					):


           '''simple docstring'''

           a_    :       Optional[int]    	=     RemBertModel(config=lowercase__					)
           model.to(lowercase__					)
           model.eval()
           a_    :       Tuple    	=     model(lowercase__	,	attention_mask=lowercase__	,	token_type_ids=lowercase__					)
           a_    :       Dict    	=     model(lowercase__	,	token_type_ids=lowercase__					)
           a_    :       Any    	=     model(lowercase__					)
           self.parent.assertEqual(result.last_hidden_state.shape	,	(self.batch_size, self.seq_length, self.hidden_size)					)






      def        lowercase_	(   self      :     str	,	lowercase__      :     List[str]	,	lowercase__      :     Tuple	,	lowercase__      :     str	,	lowercase__      :     Optional[int]	,	lowercase__      :     Tuple	,	lowercase__      :     Dict	,	lowercase__      :     List[str]	,	lowercase__      :     str	,	lowercase__      :     List[str]	,	):


           '''simple docstring'''

           a_    :       int    	=     True
           a_    :       Any    	=     RemBertModel(lowercase__					)
           model.to(lowercase__					)
           model.eval()
           a_    :       Tuple    	=     model(
               lowercase__	,	attention_mask=lowercase__	,	token_type_ids=lowercase__	,	encoder_hidden_states=lowercase__	,	encoder_attention_mask=lowercase__	,	)
           a_    :       List[Any]    	=     model(
               lowercase__	,	attention_mask=lowercase__	,	token_type_ids=lowercase__	,	encoder_hidden_states=lowercase__	,	)
           a_    :       Union[str, Any]    	=     model(lowercase__	,	attention_mask=lowercase__	,	token_type_ids=lowercase__					)
           self.parent.assertEqual(result.last_hidden_state.shape	,	(self.batch_size, self.seq_length, self.hidden_size)					)






      def        lowercase_	(   self      :     Optional[int]	,	lowercase__      :     int	,	lowercase__      :     Tuple	,	lowercase__      :     Optional[Any]	,	lowercase__      :     int	,	lowercase__      :     Optional[int]	,	lowercase__      :     Optional[int]	,	lowercase__      :     Dict	,	lowercase__      :     Optional[int]	,	lowercase__      :     int	,	):


           '''simple docstring'''

           a_    :       Any    	=     RemBertForCausalLM(config=lowercase__					)
           model.to(lowercase__					)
           model.eval()
           a_    :       Union[str, Any]    	=     model(lowercase__	,	attention_mask=lowercase__	,	token_type_ids=lowercase__	,	labels=lowercase__					)
           self.parent.assertEqual(result.logits.shape	,	(self.batch_size, self.seq_length, self.vocab_size)					)






      def        lowercase_	(   self      :     Tuple	,	lowercase__      :     Optional[Any]	,	lowercase__      :     Union[str, Any]	,	lowercase__      :     Dict	,	lowercase__      :     Dict	,	lowercase__      :     Dict	,	lowercase__      :     List[str]	,	lowercase__      :     Union[str, Any]					):


           '''simple docstring'''

           a_    :       int    	=     RemBertForMaskedLM(config=lowercase__					)
           model.to(lowercase__					)
           model.eval()
           a_    :       Dict    	=     model(lowercase__	,	attention_mask=lowercase__	,	token_type_ids=lowercase__	,	labels=lowercase__					)
           self.parent.assertEqual(result.logits.shape	,	(self.batch_size, self.seq_length, self.vocab_size)					)






      def        lowercase_	(   self      :     Optional[int]	,	lowercase__      :     Optional[Any]	,	lowercase__      :     Tuple	,	lowercase__      :     Optional[int]	,	lowercase__      :     Any	,	lowercase__      :     Optional[int]	,	lowercase__      :     List[Any]	,	lowercase__      :     str	,	lowercase__      :     Any	,	lowercase__      :     int	,	):


           '''simple docstring'''

           a_    :       str    	=     True
           a_    :       Any    	=     True
           a_    :       int    	=     RemBertForCausalLM(config=lowercase__					)
           model.to(lowercase__					)
           model.eval()

           # first forward pass
           a_    :       Union[str, Any]    	=     model(
               lowercase__	,	attention_mask=lowercase__	,	encoder_hidden_states=lowercase__	,	encoder_attention_mask=lowercase__	,	use_cache=lowercase__	,	)
           a_    :       Optional[int]    	=     outputs.past_key_values

           # create hypothetical multiple next token and extent to next_input_ids
           a_    :       int    	=     ids_tensor((self.batch_size, 3)	,	config.vocab_size					)
           a_    :       Dict    	=     ids_tensor((self.batch_size, 3)	,	vocab_size=2					)

           # append to next input_ids and
           a_    :       Tuple    	=     torch.cat([input_ids, next_tokens]	,	dim=-1					)
           a_    :       Union[str, Any]    	=     torch.cat([input_mask, next_mask]	,	dim=-1					)

           a_    :       Union[str, Any]    	=     model(
               lowercase__	,	attention_mask=lowercase__	,	encoder_hidden_states=lowercase__	,	encoder_attention_mask=lowercase__	,	output_hidden_states=lowercase__	,	)["""hidden_states"""][0]
           a_    :       Dict    	=     model(
               lowercase__	,	attention_mask=lowercase__	,	encoder_hidden_states=lowercase__	,	encoder_attention_mask=lowercase__	,	past_key_values=lowercase__	,	output_hidden_states=lowercase__	,	)["""hidden_states"""][0]

           # select random slice
           a_    :       Union[str, Any]    	=     ids_tensor((1,)	,	output_from_past.shape[-1]					).item()
           a_    :       Union[str, Any]    	=     output_from_no_past[:, -3:, random_slice_idx].detach()
           a_    :       Optional[Any]    	=     output_from_past[:, :, random_slice_idx].detach()

           self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]					)

           # test that outputs are equal for slice
           self.parent.assertTrue(torch.allclose(lowercase__	,	lowercase__	,	atol=1e-3					)					)






      def        lowercase_	(   self      :     Any	,	lowercase__      :     Any	,	lowercase__      :     Union[str, Any]	,	lowercase__      :     Dict	,	lowercase__      :     Dict	,	lowercase__      :     Union[str, Any]	,	lowercase__      :     Any	,	lowercase__      :     Tuple					):


           '''simple docstring'''

           a_    :       Union[str, Any]    	=     RemBertForQuestionAnswering(config=lowercase__					)
           model.to(lowercase__					)
           model.eval()
           a_    :       List[Any]    	=     model(
               lowercase__	,	attention_mask=lowercase__	,	token_type_ids=lowercase__	,	start_positions=lowercase__	,	end_positions=lowercase__	,	)
           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        lowercase_	(   self      :     int	,	lowercase__      :     Union[str, Any]	,	lowercase__      :     int	,	lowercase__      :     List[str]	,	lowercase__      :     Union[str, Any]	,	lowercase__      :     Optional[int]	,	lowercase__      :     Union[str, Any]	,	lowercase__      :     List[str]					):


           '''simple docstring'''

           a_    :       Optional[Any]    	=     self.num_labels
           a_    :       List[Any]    	=     RemBertForSequenceClassification(lowercase__					)
           model.to(lowercase__					)
           model.eval()
           a_    :       Union[str, Any]    	=     model(lowercase__	,	attention_mask=lowercase__	,	token_type_ids=lowercase__	,	labels=lowercase__					)
           self.parent.assertEqual(result.logits.shape	,	(self.batch_size, self.num_labels)					)






      def        lowercase_	(   self      :     Union[str, Any]	,	lowercase__      :     Tuple	,	lowercase__      :     List[Any]	,	lowercase__      :     Tuple	,	lowercase__      :     Optional[Any]	,	lowercase__      :     str	,	lowercase__      :     Dict	,	lowercase__      :     int					):


           '''simple docstring'''

           a_    :       str    	=     self.num_labels
           a_    :       int    	=     RemBertForTokenClassification(config=lowercase__					)
           model.to(lowercase__					)
           model.eval()
           a_    :       Dict    	=     model(lowercase__	,	attention_mask=lowercase__	,	token_type_ids=lowercase__	,	labels=lowercase__					)
           self.parent.assertEqual(result.logits.shape	,	(self.batch_size, self.seq_length, self.num_labels)					)






      def        lowercase_	(   self      :     int	,	lowercase__      :     int	,	lowercase__      :     int	,	lowercase__      :     Tuple	,	lowercase__      :     List[str]	,	lowercase__      :     Tuple	,	lowercase__      :     List[Any]	,	lowercase__      :     Dict					):


           '''simple docstring'''

           a_    :       List[str]    	=     self.num_choices
           a_    :       Optional[Any]    	=     RemBertForMultipleChoice(config=lowercase__					)
           model.to(lowercase__					)
           model.eval()
           a_    :       Tuple    	=     input_ids.unsqueeze(1					).expand(-1	,	self.num_choices	,	-1					).contiguous()
           a_    :       Dict    	=     token_type_ids.unsqueeze(1					).expand(-1	,	self.num_choices	,	-1					).contiguous()
           a_    :       Any    	=     input_mask.unsqueeze(1					).expand(-1	,	self.num_choices	,	-1					).contiguous()
           a_    :       Tuple    	=     model(
               lowercase__	,	attention_mask=lowercase__	,	token_type_ids=lowercase__	,	labels=lowercase__	,	)
           self.parent.assertEqual(result.logits.shape	,	(self.batch_size, self.num_choices)					)






      def        lowercase_	(   self      :     int					):


           '''simple docstring'''

           a_    :       Dict    	=     self.prepare_config_and_inputs()
           (
               (
               a_       
           )	,    (
               a_       
           )	,    (
               a_       
           )	,    (
               a_       
           )	,    (
               a_       
           )	,    (
               a_       
           )	,    (
               a_       
           )	,           
           )    :       List[str]    	=     config_and_inputs
           a_    :       Tuple    	=     {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
           return config, inputs_dict







@require_torch
class     SCREAMING_SNAKE_CASE						(	__lowerCamelCase       ,			__lowerCamelCase       ,			unittest.TestCase							):
      __magic_name__     :					str             =				(
          (
              RemBertModel,
              RemBertForMaskedLM,
              RemBertForCausalLM,
              RemBertForMultipleChoice,
              RemBertForQuestionAnswering,
              RemBertForSequenceClassification,
              RemBertForTokenClassification,
          )
          if is_torch_available()
          else ()
      )
      __magic_name__     :					Optional[Any]             =				(RemBertForCausalLM,) if is_torch_available() else ()
      __magic_name__     :					Dict             =				(
          {
              'feature-extraction': RemBertModel,
              'fill-mask': RemBertForMaskedLM,
              'question-answering': RemBertForQuestionAnswering,
              'text-classification': RemBertForSequenceClassification,
              'text-generation': RemBertForCausalLM,
              'token-classification': RemBertForTokenClassification,
              'zero-shot': RemBertForSequenceClassification,
          }
          if is_torch_available()
          else {}
      )






      def        lowercase_	(   self      :     Optional[Any]					):


           '''simple docstring'''

           a_    :       Dict    	=     RemBertModelTester(self					)
           a_    :       Union[str, Any]    	=     ConfigTester(self	,	config_class=lowercase__	,	hidden_size=37					)






      def        lowercase_	(   self      :     Dict					):


           '''simple docstring'''

           self.config_tester.run_common_tests()






      def        lowercase_	(   self      :     Dict					):


           '''simple docstring'''

           a_    :       Optional[int]    	=     self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*lowercase__					)






      def        lowercase_	(   self      :     Dict					):


           '''simple docstring'''

           a_    :       int    	=     self.model_tester.prepare_config_and_inputs()
           for type in ["absolute", "relative_key", "relative_key_query"]:
                a_    :       Optional[Any]    	=     type
                self.model_tester.create_and_check_model(*lowercase__					)






      def        lowercase_	(   self      :     Union[str, Any]					):


           '''simple docstring'''

           a_    :       Any    	=     self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_masked_lm(*lowercase__					)






      def        lowercase_	(   self      :     Tuple					):


           '''simple docstring'''

           a_    :       List[str]    	=     self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_multiple_choice(*lowercase__					)






      def        lowercase_	(   self      :     List[Any]					):


           '''simple docstring'''

           a_    :       str    	=     self.model_tester.prepare_config_and_inputs_for_decoder()
           self.model_tester.create_and_check_decoder_model_past_large_inputs(*lowercase__					)






      def        lowercase_	(   self      :     str					):


           '''simple docstring'''

           a_    :       List[Any]    	=     self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_question_answering(*lowercase__					)






      def        lowercase_	(   self      :     Dict					):


           '''simple docstring'''

           a_    :       List[Any]    	=     self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_sequence_classification(*lowercase__					)






      def        lowercase_	(   self      :     Any					):


           '''simple docstring'''

           a_    :       str    	=     self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_token_classification(*lowercase__					)






      def        lowercase_	(   self      :     List[Any]					):


           '''simple docstring'''

           a_    :       List[Any]    	=     self.model_tester.prepare_config_and_inputs_for_decoder()
           self.model_tester.create_and_check_model_as_decoder(*lowercase__					)






      def        lowercase_	(   self      :     List[str]					):


           '''simple docstring'''

           (
               (
               a_       
           )	,    (
               a_       
           )	,    (
               a_       
           )	,    (
               a_       
           )	,    (
               a_       
           )	,    (
               a_       
           )	,    (
               a_       
           )	,    (
               a_       
           )	,    (
               a_       
           )	,           
           )    :       Tuple    	=     self.model_tester.prepare_config_and_inputs_for_decoder()

           a_    :       List[Any]    	=     None

           self.model_tester.create_and_check_model_as_decoder(
               lowercase__	,	lowercase__	,	lowercase__	,	lowercase__	,	lowercase__	,	lowercase__	,	lowercase__	,	lowercase__	,	lowercase__	,	)






      @slow
      def        lowercase_	(   self      :     Tuple					):


           '''simple docstring'''

           for model_name in REMBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                a_    :       List[str]    	=     RemBertModel.from_pretrained(lowercase__					)
                self.assertIsNotNone(lowercase__					)







@require_torch
class     SCREAMING_SNAKE_CASE						(	unittest.TestCase							):






      @slow
      def        lowercase_	(   self      :     List[Any]					):


           '''simple docstring'''

           a_    :       Optional[Any]    	=     RemBertModel.from_pretrained("""google/rembert"""					)
           a_    :       Any    	=     torch.tensor([[312, 5_6498, 313, 2125, 313]]					)
           a_    :       int    	=     torch.tensor([[0, 0, 0, 1, 1]]					)
           with torch.no_grad():
                a_    :       Dict    	=     model(lowercase__	,	token_type_ids=lowercase__	,	output_hidden_states=lowercase__					)

           a_    :       Any    	=     1152

           a_    :       Dict    	=     torch.Size((1, 5, hidden_size)					)
           self.assertEqual(output["""last_hidden_state"""].shape	,	lowercase__					)

           a_    :       List[str]    	=     torch.tensor(
               [
                   [
                       [0.0754, -0.2022, 0.1904],
                       [-0.3354, -0.3692, -0.4791],
                       [-0.2314, -0.6729, -0.0749],
                       [-0.0396, -0.3105, -0.4234],
                       [-0.1571, -0.0525, 0.5353],
                   ]
               ]					)

           # Running on the original tf implementation gives slightly different results here.
           # Not clear why this variations is present
           # TODO: Find reason for discrepancy
           # expected_original_implementation = [[
           #     [0.07630594074726105, -0.20146065950393677, 0.19107051193714142],
           #     [-0.3405614495277405, -0.36971670389175415, -0.4808273911476135],
           #     [-0.22587086260318756, -0.6656315922737122, -0.07844287157058716],
           #     [-0.04145475849509239, -0.3077218234539032, -0.42316967248916626],
           #     [-0.15887849032878876, -0.054529931396245956, 0.5356100797653198]
           # ]]

           self.assertTrue(torch.allclose(output["""last_hidden_state"""][:, :, :3]	,	lowercase__	,	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     SCREAMING_SNAKE_CASE						:






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


           '''simple docstring'''

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






      def        lowercase_	(   self      :     Optional[int]					):


           '''simple docstring'''

           a_    :       List[Any]    	=     floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]					)

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

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






      def        lowercase_	(   self      :     Dict					):


           '''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        lowercase_	(   self      :     int	,	lowercase__      :     Any	,	lowercase__      :     Any	,	lowercase__      :     Optional[int]					):


           '''simple docstring'''

           a_    :       Tuple    	=     EfficientNetModel(config=lowercase__					)
           model.to(lowercase__					)
           model.eval()
           a_    :       Optional[int]    	=     model(lowercase__					)
           # 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        lowercase_	(   self      :     Optional[Any]	,	lowercase__      :     Union[str, Any]	,	lowercase__      :     Any	,	lowercase__      :     str					):


           '''simple docstring'''

           a_    :       Dict    	=     EfficientNetForImageClassification(lowercase__					)
           model.to(lowercase__					)
           model.eval()
           a_    :       str    	=     model(lowercase__	,	labels=lowercase__					)
           self.parent.assertEqual(result.logits.shape	,	(self.batch_size, self.num_labels)					)






      def        lowercase_	(   self      :     int					):


           '''simple docstring'''

           a_    :       Union[str, Any]    	=     self.prepare_config_and_inputs()
           a_	,    a_	,    a_    :       Optional[Any]    	=     config_and_inputs
           a_    :       str    	=     {"""pixel_values""": pixel_values}
           return config, inputs_dict







@require_torch
class     SCREAMING_SNAKE_CASE						(	snake_case_       ,			snake_case_       ,			unittest.TestCase							):
      __magic_name__     :					Any             =				(EfficientNetModel, EfficientNetForImageClassification) if is_torch_available() else ()
      __magic_name__     :					List[Any]             =				(
          {'''feature-extraction''': EfficientNetModel, '''image-classification''': EfficientNetForImageClassification}
          if is_torch_available()
          else {}
      )

      __magic_name__     :					int             =				False
      __magic_name__     :					Dict             =				False
      __magic_name__     :					Dict             =				False
      __magic_name__     :					Union[str, Any]             =				False
      __magic_name__     :					Optional[int]             =				False






      def        lowercase_	(   self      :     List[Any]					):


           '''simple docstring'''

           a_    :       Optional[int]    	=     EfficientNetModelTester(self					)
           a_    :       Union[str, Any]    	=     ConfigTester(
               self	,	config_class=lowercase__	,	has_text_modality=lowercase__	,	hidden_size=37					)






      def        lowercase_	(   self      :     List[str]					):


           '''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        lowercase_	(   self      :     Tuple					):


           '''simple docstring'''

           return






      @unittest.skip(reason="""EfficientNet does not use inputs_embeds"""					)
      def        lowercase_	(   self      :     Union[str, Any]					):


           '''simple docstring'''

           pass






      @unittest.skip(reason="""EfficientNet does not support input and output embeddings"""					)
      def        lowercase_	(   self      :     Optional[Any]					):


           '''simple docstring'''

           pass






      @unittest.skip(reason="""EfficientNet does not use feedforward chunking"""					)
      def        lowercase_	(   self      :     str					):


           '''simple docstring'''

           pass






      def        lowercase_	(   self      :     Union[str, Any]					):


           '''simple docstring'''

           a_	,    a_    :       Dict    	=     self.model_tester.prepare_config_and_inputs_for_common()

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

                a_    :       Dict    	=     ["""pixel_values"""]
                self.assertListEqual(arg_names[:1]	,	lowercase__					)






      def        lowercase_	(   self      :     Optional[int]					):


           '''simple docstring'''

           a_    :       Tuple    	=     self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*lowercase__					)






      def        lowercase_	(   self      :     Tuple					):


           '''simple docstring'''

           def check_hidden_states_output(lowercase__      :     Optional[int]	,	lowercase__      :     List[Any]	,	lowercase__      :     Tuple					):
                a_    :       str    	=     model_class(lowercase__					)
                model.to(lowercase__					)
                model.eval()

                with torch.no_grad():
                     a_    :       Tuple    	=     model(**self._prepare_for_class(lowercase__	,	lowercase__					)					)

                a_    :       Tuple    	=     outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states
                a_    :       Tuple    	=     sum(config.num_block_repeats					) * 4
                self.assertEqual(len(lowercase__					)	,	lowercase__					)

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

           a_	,    a_    :       Any    	=     self.model_tester.prepare_config_and_inputs_for_common()

           for model_class in self.all_model_classes:
                a_    :       Any    	=     True
                check_hidden_states_output(lowercase__	,	lowercase__	,	lowercase__					)

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

                check_hidden_states_output(lowercase__	,	lowercase__	,	lowercase__					)






      def        lowercase_	(   self      :     Union[str, Any]					):


           '''simple docstring'''

           a_    :       Optional[int]    	=     self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_image_classification(*lowercase__					)






      @unittest.skip("""Will be fixed soon by reducing the size of the model used for common tests."""					)
      def        lowercase_	(   self      :     List[Any]					):


           '''simple docstring'''

           pass






      @slow
      def        lowercase_	(   self      :     Dict					):


           '''simple docstring'''

           for model_name in EFFICIENTNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                a_    :       List[str]    	=     EfficientNetModel.from_pretrained(lowercase__					)
                self.assertIsNotNone(lowercase__					)






      @is_pipeline_test
      @require_vision
      @slow
      def        lowercase_	(   self      :     Tuple					):


           '''simple docstring'''

           super().test_pipeline_image_classification()



def    _SCREAMING_SNAKE_CASE    (			):




     """simple docstring"""


     a_    :       List[str]    	=     Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""							)
     return image







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






      @cached_property
      def        lowercase_	(   self      :     Dict					):


           '''simple docstring'''

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






      @slow
      def        lowercase_	(   self      :     Any					):


           '''simple docstring'''

           a_    :       Optional[Any]    	=     EfficientNetForImageClassification.from_pretrained("""google/efficientnet-b7"""					).to(lowercase__					)

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

           # forward pass
           with torch.no_grad():
                a_    :       Tuple    	=     model(**lowercase__					)

           # verify the logits
           a_    :       Dict    	=     torch.Size((1, 1000)					)
           self.assertEqual(outputs.logits.shape	,	lowercase__					)

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