

import math
from dataclasses import dataclass
from typing import Optional, Tuple, Union

import numpy as np
import torch

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput, randn_tensor
from .scheduling_utils import SchedulerMixin







@dataclass
class     a__    (				lowerCAmelCase__    ):







  """simple docstring"""




  UpperCAmelCase__ :	torch.FloatTensor
  UpperCAmelCase__ :	torch.FloatTensor






def    __lowercase (       _A  ,      _A=0.999  ,      _A="cosine"  ,      )       ->  List[str]:
      if alpha_transform_type == "cosine":

            def alpha_bar_fn(_A     ):
                  return math.cos((t + 0.008) / 1.008 * math.pi / 2     ) ** 2

      elif alpha_transform_type == "exp":

            def alpha_bar_fn(_A     ):
                  return math.exp(t * -12.0     )

      else:
            raise ValueError(F"Unsupported alpha_tranform_type: {alpha_transform_type}"     )

      SCREAMING_SNAKE_CASE	: List[Any]					       =				[]
      for i in range(_A     ):
            SCREAMING_SNAKE_CASE	: List[str]					       =				i / num_diffusion_timesteps
            SCREAMING_SNAKE_CASE	: Dict					       =				(i + 1) / num_diffusion_timesteps
            betas.append(min(1 - alpha_bar_fn(_A     ) / alpha_bar_fn(_A     )  ,      _A     )     )
      return torch.tensor(_A  ,      dtype=torch.floataa     )







class     a__    (				lowerCAmelCase__		,     lowerCAmelCase__    ):







  """simple docstring"""




  UpperCAmelCase__ :	List[str]         =1


  @register_to_config
  def __init__(     self      :	Optional[Any]			,			UpperCAmelCase__      :	int = 1_0_0_0			,			UpperCAmelCase__      :	float = 0.00_01			,			UpperCAmelCase__      :	float = 0.02			,			UpperCAmelCase__      :	str = "linear"			,			UpperCAmelCase__      :	float = 0.0			,			UpperCAmelCase__      :	Optional[np.ndarray] = None			,			UpperCAmelCase__      :	bool = True			,			)   ->Tuple:
        """simple docstring"""







        if trained_betas is not None:
              SCREAMING_SNAKE_CASE	: Optional[int]					       =				torch.from_numpy(_UpperCAmelCase						)
        elif beta_schedule == "linear":
              SCREAMING_SNAKE_CASE	: Union[str, Any]					       =				torch.linspace(_UpperCAmelCase			,			_UpperCAmelCase			,			_UpperCAmelCase			,			dtype=torch.floataa						)
        elif beta_schedule == "scaled_linear":
              # this schedule is very specific to the latent diffusion model.
              SCREAMING_SNAKE_CASE	: int					       =				(
                  torch.linspace(beta_start**0.5			,			beta_end**0.5			,			_UpperCAmelCase			,			dtype=torch.floataa						) ** 2
              )
        elif beta_schedule == "squaredcos_cap_v2":
              # Glide cosine schedule
              SCREAMING_SNAKE_CASE	: Optional[int]					       =				betas_for_alpha_bar(_UpperCAmelCase						)
        elif beta_schedule == "sigmoid":
              # GeoDiff sigmoid schedule
              SCREAMING_SNAKE_CASE	: Optional[int]					       =				torch.linspace(-6			,			6			,			_UpperCAmelCase						)
              SCREAMING_SNAKE_CASE	: Dict					       =				torch.sigmoid(_UpperCAmelCase						) * (beta_end - beta_start) + beta_start
        else:
              raise NotImplementedError(f"{beta_schedule} does is not implemented for {self.__class__}"						)

        SCREAMING_SNAKE_CASE	: Any					       =				1.0 - self.betas
        SCREAMING_SNAKE_CASE	: Any					       =				torch.cumprod(self.alphas			,			dim=0						)
        SCREAMING_SNAKE_CASE	: Dict					       =				torch.tensor(1.0						)

        SCREAMING_SNAKE_CASE	: Union[str, Any]					       =				torch.tensor(1.0						)

        # standard deviation of the initial noise distribution
        SCREAMING_SNAKE_CASE	: Optional[int]					       =				1.0

        # setable values
        SCREAMING_SNAKE_CASE	: int					       =				None
        SCREAMING_SNAKE_CASE	: Optional[Any]					       =				torch.from_numpy(np.arange(0			,			_UpperCAmelCase						)[::-1].copy()						)

        SCREAMING_SNAKE_CASE	: int					       =				eta


  def 	_lowercase (     self      :	int			,			UpperCAmelCase__      :	torch.FloatTensor			,			UpperCAmelCase__      :	Optional[int] = None						)   ->torch.FloatTensor:
        """simple docstring"""







        return sample


  def 	_lowercase (     self      :	int			,			UpperCAmelCase__      :	int			,			UpperCAmelCase__      :	int = 1_0			,			UpperCAmelCase__      :	int = 1_0			,			UpperCAmelCase__      :	Union[str, torch.device] = None			,			)   ->Optional[int]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE	: int					       =				min(self.config.num_train_timesteps			,			_UpperCAmelCase						)
        SCREAMING_SNAKE_CASE	: List[str]					       =				num_inference_steps

        SCREAMING_SNAKE_CASE	: Dict					       =				[]

        SCREAMING_SNAKE_CASE	: Optional[Any]					       =				{}
        for j in range(0			,			num_inference_steps - jump_length			,			_UpperCAmelCase						):
              SCREAMING_SNAKE_CASE	: int					       =				jump_n_sample - 1

        SCREAMING_SNAKE_CASE	: List[str]					       =				num_inference_steps
        while t >= 1:
              SCREAMING_SNAKE_CASE	: Dict					       =				t - 1
              timesteps.append(_UpperCAmelCase						)

              if jumps.get(_UpperCAmelCase			,			0						) > 0:
                    SCREAMING_SNAKE_CASE	: Any					       =				jumps[t] - 1
                    for _ in range(_UpperCAmelCase						):
                          SCREAMING_SNAKE_CASE	: Union[str, Any]					       =				t + 1
                          timesteps.append(_UpperCAmelCase						)

        SCREAMING_SNAKE_CASE	: Union[str, Any]					       =				np.array(_UpperCAmelCase						) * (self.config.num_train_timesteps // self.num_inference_steps)
        SCREAMING_SNAKE_CASE	: Dict					       =				torch.from_numpy(_UpperCAmelCase						).to(_UpperCAmelCase						)


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







        SCREAMING_SNAKE_CASE	: Union[str, Any]					       =				t - self.config.num_train_timesteps // self.num_inference_steps

        SCREAMING_SNAKE_CASE	: Tuple					       =				self.alphas_cumprod[t]
        SCREAMING_SNAKE_CASE	: Dict					       =				self.alphas_cumprod[prev_timestep] if prev_timestep >= 0 else self.final_alpha_cumprod
        SCREAMING_SNAKE_CASE	: Optional[int]					       =				1 - alpha_prod_t
        SCREAMING_SNAKE_CASE	: List[str]					       =				1 - alpha_prod_t_prev

        # For t > 0, compute predicted variance βt (see formula (6) and (7) from
        # https://arxiv.org/pdf/2006.11239.pdf) and sample from it to get
        # previous sample x_{t-1} ~ N(pred_prev_sample, variance) == add
        # variance to pred_sample
        # Is equivalent to formula (16) in https://arxiv.org/pdf/2010.02502.pdf
        # without eta.
        # variance = (1 - alpha_prod_t_prev) / (1 - alpha_prod_t) * self.betas[t]
        SCREAMING_SNAKE_CASE	: Tuple					       =				(beta_prod_t_prev / beta_prod_t) * (1 - alpha_prod_t / alpha_prod_t_prev)

        return variance


  def 	_lowercase (     self      :	List[Any]			,			UpperCAmelCase__      :	torch.FloatTensor			,			UpperCAmelCase__      :	int			,			UpperCAmelCase__      :	torch.FloatTensor			,			UpperCAmelCase__      :	torch.FloatTensor			,			UpperCAmelCase__      :	torch.FloatTensor			,			UpperCAmelCase__      :	Optional[torch.Generator] = None			,			UpperCAmelCase__      :	bool = True			,			)   ->Union[RePaintSchedulerOutput, Tuple]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE	: str					       =				timestep
        SCREAMING_SNAKE_CASE	: Optional[Any]					       =				timestep - self.config.num_train_timesteps // self.num_inference_steps

        # 1. compute alphas, betas
        SCREAMING_SNAKE_CASE	: str					       =				self.alphas_cumprod[t]
        SCREAMING_SNAKE_CASE	: Tuple					       =				self.alphas_cumprod[prev_timestep] if prev_timestep >= 0 else self.final_alpha_cumprod
        SCREAMING_SNAKE_CASE	: List[Any]					       =				1 - alpha_prod_t

        # 2. compute predicted original sample from predicted noise also called
        # "predicted x_0" of formula (15) from https://arxiv.org/pdf/2006.11239.pdf
        SCREAMING_SNAKE_CASE	: str					       =				(sample - beta_prod_t**0.5 * model_output) / alpha_prod_t**0.5

        # 3. Clip "predicted x_0"
        if self.config.clip_sample:
              SCREAMING_SNAKE_CASE	: Optional[int]					       =				torch.clamp(_UpperCAmelCase			,			-1			,			1						)

        # We choose to follow RePaint Algorithm 1 to get x_{t-1}, however we
        # substitute formula (7) in the algorithm coming from DDPM paper
        # (formula (4) Algorithm 2 - Sampling) with formula (12) from DDIM paper.
        # DDIM schedule gives the same results as DDPM with eta = 1.0
        # Noise is being reused in 7. and 8., but no impact on quality has
        # been observed.

        # 5. Add noise
        SCREAMING_SNAKE_CASE	: Optional[int]					       =				model_output.device
        SCREAMING_SNAKE_CASE	: str					       =				randn_tensor(model_output.shape			,			generator=_UpperCAmelCase			,			device=_UpperCAmelCase			,			dtype=model_output.dtype						)
        SCREAMING_SNAKE_CASE	: Optional[Any]					       =				self.eta * self._get_variance(_UpperCAmelCase						) ** 0.5

        SCREAMING_SNAKE_CASE	: List[Any]					       =				0
        if t > 0 and self.eta > 0:
              SCREAMING_SNAKE_CASE	: Dict					       =				std_dev_t * noise

        # 6. compute "direction pointing to x_t" of formula (12)
        # from https://arxiv.org/pdf/2010.02502.pdf
        SCREAMING_SNAKE_CASE	: Dict					       =				(1 - alpha_prod_t_prev - std_dev_t**2) ** 0.5 * model_output

        # 7. compute x_{t-1} of formula (12) from https://arxiv.org/pdf/2010.02502.pdf
        SCREAMING_SNAKE_CASE	: str					       =				alpha_prod_t_prev**0.5 * pred_original_sample + pred_sample_direction + variance

        # 8. Algorithm 1 Line 5 https://arxiv.org/pdf/2201.09865.pdf
        SCREAMING_SNAKE_CASE	: Dict					       =				(alpha_prod_t_prev**0.5) * original_image + ((1 - alpha_prod_t_prev) ** 0.5) * noise

        # 9. Algorithm 1 Line 8 https://arxiv.org/pdf/2201.09865.pdf
        SCREAMING_SNAKE_CASE	: int					       =				mask * prev_known_part + (1.0 - mask) * prev_unknown_part

        if not return_dict:
              return (
                  pred_prev_sample,
                  pred_original_sample,
              )

        return RePaintSchedulerOutput(prev_sample=_UpperCAmelCase			,			pred_original_sample=_UpperCAmelCase						)


  def 	_lowercase (     self      :	Optional[int]			,			UpperCAmelCase__      :	List[str]			,			UpperCAmelCase__      :	List[str]			,			UpperCAmelCase__      :	Dict=None						)   ->List[Any]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE	: List[str]					       =				self.config.num_train_timesteps // self.num_inference_steps

        for i in range(_UpperCAmelCase						):
              SCREAMING_SNAKE_CASE	: Dict					       =				self.betas[timestep + i]
              if sample.device.type == "mps":
                    # randn does not work reproducibly on mps
                    SCREAMING_SNAKE_CASE	: str					       =				randn_tensor(sample.shape			,			dtype=sample.dtype			,			generator=_UpperCAmelCase						)
                    SCREAMING_SNAKE_CASE	: List[Any]					       =				noise.to(sample.device						)
              else:
                    SCREAMING_SNAKE_CASE	: int					       =				randn_tensor(sample.shape			,			generator=_UpperCAmelCase			,			device=sample.device			,			dtype=sample.dtype						)

              # 10. Algorithm 1 Line 10 https://arxiv.org/pdf/2201.09865.pdf
              SCREAMING_SNAKE_CASE	: Any					       =				(1 - beta) ** 0.5 * sample + beta**0.5 * noise

        return sample


  def 	_lowercase (     self      :	Tuple			,			UpperCAmelCase__      :	torch.FloatTensor			,			UpperCAmelCase__      :	torch.FloatTensor			,			UpperCAmelCase__      :	torch.IntTensor			,			)   ->torch.FloatTensor:
        """simple docstring"""







        raise NotImplementedError("""Use `DDPMScheduler.add_noise()` to train for sampling with RePaint."""						)




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







        return self.config.num_train_timesteps


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      :	Any			,			UpperCAmelCase__      :	Union[str, Any]			,			UpperCAmelCase__      :	List[str]=1_3			,			UpperCAmelCase__      :	Any=3_2			,			UpperCAmelCase__      :	Union[str, Any]=3			,			UpperCAmelCase__      :	List[str]=[3, 3, 5]			,			UpperCAmelCase__      :	int=[3_2, 1_6, 2_4]			,			UpperCAmelCase__      :	Dict=[1_6, 2_4, 4_0]			,			UpperCAmelCase__      :	Optional[Any]=[1, 1, 2]			,			UpperCAmelCase__      :	List[Any]=[1, 1, 2]			,			UpperCAmelCase__      :	str=[1, 6, 6]			,			UpperCAmelCase__      :	List[Any]=True			,			UpperCAmelCase__      :	int=True			,			UpperCAmelCase__      :	Any=3_7			,			UpperCAmelCase__      :	Any="gelu"			,			UpperCAmelCase__      :	List[Any]=1_0			,			)   ->Dict:
        """simple docstring"""







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


  def 	_lowercase (     self      :	Any						)   ->Any:
        """simple docstring"""







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

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

        SCREAMING_SNAKE_CASE	: Dict					       =				self.get_config()
        return config, pixel_values, labels


  def 	_lowercase (     self      :	Tuple						)   ->Optional[int]:
        """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      :	List[Any]			,			UpperCAmelCase__      :	str			,			UpperCAmelCase__      :	int			,			UpperCAmelCase__      :	Optional[Any]						)   ->Union[str, Any]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE	: List[Any]					       =				EfficientNetModel(config=UpperCAmelCase__						)
        model.to(UpperCAmelCase__						)
        model.eval()
        SCREAMING_SNAKE_CASE	: str					       =				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 	_lowercase (     self      :	Optional[int]			,			UpperCAmelCase__      :	List[Any]			,			UpperCAmelCase__      :	Optional[int]			,			UpperCAmelCase__      :	Union[str, Any]						)   ->int:
        """simple docstring"""







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




  def 	_lowercase (     self      :	Dict						)   ->str:
        """simple docstring"""







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







@require_torch
class     a__    (				UpperCAmelCase		,     UpperCAmelCase		,     unittest.TestCase    ):







  """simple docstring"""




  UpperCAmelCase__ :	Tuple         =(EfficientNetModel, EfficientNetForImageClassification) if is_torch_available() else ()
  UpperCAmelCase__ :	Optional[int]         =(
      {"""feature-extraction""": EfficientNetModel, """image-classification""": EfficientNetForImageClassification}
      if is_torch_available()
      else {}
  )

  UpperCAmelCase__ :	List[str]         =False
  UpperCAmelCase__ :	Any         =False
  UpperCAmelCase__ :	Union[str, Any]         =False
  UpperCAmelCase__ :	Dict         =False
  UpperCAmelCase__ :	List[str]         =False


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







        SCREAMING_SNAKE_CASE	: Optional[Any]					       =				EfficientNetModelTester(self						)
        SCREAMING_SNAKE_CASE	: Any					       =				ConfigTester(
            self			,			config_class=UpperCAmelCase__			,			has_text_modality=UpperCAmelCase__			,			hidden_size=3_7						)


  def 	_lowercase (     self      :	Optional[int]						)   ->List[Any]:
        """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      :	List[Any]						)   ->Optional[int]:
        """simple docstring"""







        return


  @unittest.skip(reason="""EfficientNet does not use inputs_embeds"""						)
  def 	_lowercase (     self      :	Dict						)   ->Tuple:
        """simple docstring"""







        pass


  @unittest.skip(reason="""EfficientNet does not support input and output embeddings"""						)
  def 	_lowercase (     self      :	Dict						)   ->Dict:
        """simple docstring"""







        pass


  @unittest.skip(reason="""EfficientNet does not use feedforward chunking"""						)
  def 	_lowercase (     self      :	Optional[Any]						)   ->Any:
        """simple docstring"""







        pass


  def 	_lowercase (     self      :	str						)   ->Optional[int]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE       ,		SCREAMING_SNAKE_CASE	: Optional[Any]					       =				self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
              SCREAMING_SNAKE_CASE	: str					       =				model_class(UpperCAmelCase__						)
              SCREAMING_SNAKE_CASE	: Union[str, Any]					       =				inspect.signature(model.forward						)
              # signature.parameters is an OrderedDict => so arg_names order is deterministic
              SCREAMING_SNAKE_CASE	: List[str]					       =				[*signature.parameters.keys()]

              SCREAMING_SNAKE_CASE	: Dict					       =				["""pixel_values"""]
              self.assertListEqual(arg_names[:1]			,			UpperCAmelCase__						)


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







        SCREAMING_SNAKE_CASE	: Optional[int]					       =				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*UpperCAmelCase__						)


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







        def check_hidden_states_output(UpperCAmelCase__      :	Optional[Any]			,			UpperCAmelCase__      :	Any			,			UpperCAmelCase__      :	Dict						):
              SCREAMING_SNAKE_CASE	: Optional[Any]					       =				model_class(UpperCAmelCase__						)
              model.to(UpperCAmelCase__						)
              model.eval()

              with torch.no_grad():
                    SCREAMING_SNAKE_CASE	: Any					       =				model(**self._prepare_for_class(UpperCAmelCase__			,			UpperCAmelCase__						)						)

              SCREAMING_SNAKE_CASE	: Optional[int]					       =				outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states
              SCREAMING_SNAKE_CASE	: 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]			,			)

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

        for model_class in self.all_model_classes:
              SCREAMING_SNAKE_CASE	: Optional[Any]					       =				True
              check_hidden_states_output(UpperCAmelCase__			,			UpperCAmelCase__			,			UpperCAmelCase__						)

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

              check_hidden_states_output(UpperCAmelCase__			,			UpperCAmelCase__			,			UpperCAmelCase__						)


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







        SCREAMING_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 	_lowercase (     self      :	List[str]						)   ->Optional[Any]:
        """simple docstring"""







        pass


  @slow
  def 	_lowercase (     self      :	Dict						)   ->List[Any]:
        """simple docstring"""







        for model_name in EFFICIENTNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              SCREAMING_SNAKE_CASE	: str					       =				EfficientNetModel.from_pretrained(UpperCAmelCase__						)
              self.assertIsNotNone(UpperCAmelCase__						)




  @is_pipeline_test
  @require_vision
  @slow
  def 	_lowercase (     self      :	Any						)   ->Any:
        """simple docstring"""







        super().test_pipeline_image_classification()






def    __lowercase (       )       ->  List[Any]:
      SCREAMING_SNAKE_CASE	: List[str]					       =				Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""     )
      return image







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







  """simple docstring"""




  @cached_property
  def 	_lowercase (     self      :	List[str]						)   ->Tuple:
        """simple docstring"""







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




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







        SCREAMING_SNAKE_CASE	: Tuple					       =				EfficientNetForImageClassification.from_pretrained("""google/efficientnet-b7"""						).to(UpperCAmelCase__						)

        SCREAMING_SNAKE_CASE	: int					       =				self.default_image_processor
        SCREAMING_SNAKE_CASE	: List[Any]					       =				prepare_img()
        SCREAMING_SNAKE_CASE	: Optional[Any]					       =				image_processor(images=UpperCAmelCase__			,			return_tensors="""pt"""						).to(UpperCAmelCase__						)

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

        # verify the logits
        SCREAMING_SNAKE_CASE	: Union[str, Any]					       =				torch.Size((1, 1_0_0_0)						)
        self.assertEqual(outputs.logits.shape			,			UpperCAmelCase__						)

        SCREAMING_SNAKE_CASE	: Any					       =				torch.tensor([0.00_01, 0.00_02, 0.00_02]						).to(UpperCAmelCase__						)
        self.assertTrue(torch.allclose(outputs.logits[0, :3]			,			UpperCAmelCase__			,			atol=1e-4						)						)




