






'''simple docstring'''





import random
import unittest

import torch

from diffusers import IFInpaintingSuperResolutionPipeline
from diffusers.utils import floats_tensor
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import skip_mps, torch_device

from ..pipeline_params import (
    TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_INPAINTING_PARAMS,
)
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin
@skip_mps
class 				lowercase       (							_lowerCamelCase ,       _lowerCamelCase ,       unittest.TestCase      ):


    '''simple docstring'''

    lowerCAmelCase__      				=							IFInpaintingSuperResolutionPipeline
    lowerCAmelCase__      				=							TEXT_GUIDED_IMAGE_INPAINTING_PARAMS - {"width", "height"}
    lowerCAmelCase__      				=							TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS.union({"original_image"}      )
    lowerCAmelCase__      				=							PipelineTesterMixin.required_optional_params - {"latents"}

    def    a__				(					self     :     List[Any]     )							->							List[str]:

     '''simple docstring'''




     return self._get_superresolution_dummy_components()

    def    a__				(					self     :     Optional[Any]				,     __lowerCamelCase     :     Optional[int]				,     __lowerCamelCase     :     int=0     )							->							List[Any]:

     '''simple docstring'''




     if str(__lowerCamelCase     ).startswith("mps"     ):
      lowerCamelCase__  =     torch.manual_seed(__lowerCamelCase     )
     else:
      lowerCamelCase__  =     torch.Generator(device=__lowerCamelCase     ).manual_seed(__lowerCamelCase     )

     lowerCamelCase__  =     floats_tensor((1, 3, 16, 16)				,     rng=random.Random(__lowerCamelCase     )     ).to(__lowerCamelCase     )
     lowerCamelCase__  =     floats_tensor((1, 3, 32, 32)				,     rng=random.Random(__lowerCamelCase     )     ).to(__lowerCamelCase     )
     lowerCamelCase__  =     floats_tensor((1, 3, 32, 32)				,     rng=random.Random(__lowerCamelCase     )     ).to(__lowerCamelCase     )

     lowerCamelCase__  =     {
         "prompt": "A painting of a squirrel eating a burger",
         "image": image,
         "original_image": original_image,
         "mask_image": mask_image,
         "generator": generator,
         "num_inference_steps": 2,
         "output_type": "numpy",
     }

     return inputs

    @unittest.skipIf(
        torch_device != "cuda" or not is_xformers_available()				,     reason="XFormers attention is only available with CUDA and `xformers` installed"				,     )
    def    a__				(					self     :     str     )							->							Dict:

     '''simple docstring'''




     self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3     )

    def    a__				(					self     :     List[str]     )							->							Tuple:

     '''simple docstring'''




     self._test_save_load_optional_components()

    @unittest.skipIf(torch_device != "cuda"				,     reason="float16 requires CUDA"     )
    def    a__				(					self     :     List[Any]     )							->							Tuple:

     '''simple docstring'''




     super().test_save_load_floataa(expected_max_diff=1E-1     )

    def    a__				(					self     :     Tuple     )							->							Tuple:

     '''simple docstring'''




     self._test_attention_slicing_forward_pass(expected_max_diff=1E-2     )

    def    a__				(					self     :     str     )							->							str:

     '''simple docstring'''




     self._test_save_load_local()




    def    a__				(					self     :     int     )							->							Dict:

     '''simple docstring'''




     self._test_inference_batch_single_identical(
         expected_max_diff=1E-2				,     )









'''simple docstring'''





from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__A							:							Optional[int]  							=		logging.get_logger(__name__)

__A							:							Tuple  							=		{
    """google/mobilenet_v1_1.0_224""": """https://huggingface.co/google/mobilenet_v1_1.0_224/resolve/main/config.json""",
    """google/mobilenet_v1_0.75_192""": """https://huggingface.co/google/mobilenet_v1_0.75_192/resolve/main/config.json""",
    # See all MobileNetV1 models at https://huggingface.co/models?filter=mobilenet_v1
}
class 				lowercase       (							_lowerCamelCase      ):


    '''simple docstring'''

    lowerCAmelCase__      				=							"mobilenet_v1"

    def __init__(					self     :     Union[str, Any]				,     __lowerCamelCase     :     Tuple=3				,     __lowerCamelCase     :     Any=224				,     __lowerCamelCase     :     Tuple=1.0				,     __lowerCamelCase     :     Optional[int]=8				,     __lowerCamelCase     :     str="relu6"				,     __lowerCamelCase     :     Any=True				,     __lowerCamelCase     :     Union[str, Any]=0.9_9_9				,     __lowerCamelCase     :     List[Any]=0.0_2				,     __lowerCamelCase     :     str=0.0_0_1				,     **__lowerCamelCase     :     str				,     )							->							Dict:

     '''simple docstring'''




     super().__init__(**__lowerCamelCase     )

     if depth_multiplier <= 0:
      raise ValueError("depth_multiplier must be greater than zero."     )

     lowerCamelCase__  =     num_channels
     lowerCamelCase__  =     image_size
     lowerCamelCase__  =     depth_multiplier
     lowerCamelCase__  =     min_depth
     lowerCamelCase__  =     hidden_act
     lowerCamelCase__  =     tf_padding
     lowerCamelCase__  =     classifier_dropout_prob
     lowerCamelCase__  =     initializer_range
     lowerCamelCase__  =     layer_norm_eps
class 				lowercase       (							_lowerCamelCase      ):


    '''simple docstring'''

    lowerCAmelCase__      				=							version.parse("1.11"      )

    @property
    def    a__				(					self     :     List[str]     )							->							Mapping[str, Mapping[int, str]]:

     '''simple docstring'''




     return OrderedDict([("pixel_values", {0: "batch"})]     )

    @property
    def    a__				(					self     :     str     )							->							Mapping[str, Mapping[int, str]]:

     '''simple docstring'''




     if self.task == "image-classification":
      return OrderedDict([("logits", {0: "batch"})]     )
     else:
      return OrderedDict([("last_hidden_state", {0: "batch"}), ("pooler_output", {0: "batch"})]     )




    @property
    def    a__				(					self     :     List[Any]     )							->							float:

     '''simple docstring'''




     return 1E-4

