



'''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 							a__( snake_case__		,			snake_case__		,			unittest.TestCase     ):
    lowercase__			=   IFInpaintingSuperResolutionPipeline
    lowercase__			=   TEXT_GUIDED_IMAGE_INPAINTING_PARAMS - {"""width""", """height"""}
    lowercase__			=   TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS.union({"""original_image"""}     )
    lowercase__			=   PipelineTesterMixin.required_optional_params - {"""latents"""}







    def       lowercase_	(				self			:  List[Any]     ):
      return self._get_superresolution_dummy_components()







    def       lowercase_	(				self			:  Optional[int]						,      __snake_case			:  Optional[Any]						,      __snake_case			:  List[Any]=0     ):



      if str(_A     ).startswith('mps'     ):
        a						: Any					       =					torch.manual_seed(_A     )
      else:
        a						: Any					       =					torch.Generator(device=_A     ).manual_seed(_A     )

      a						: int					       =					floats_tensor((1, 3, 16, 16)						,      rng=random.Random(_A     )     ).to(_A     )
      a						: Union[str, Any]					       =					floats_tensor((1, 3, 32, 32)						,      rng=random.Random(_A     )     ).to(_A     )
      a						: Optional[int]					       =					floats_tensor((1, 3, 32, 32)						,      rng=random.Random(_A     )     ).to(_A     )

      a						: List[Any]					       =					{
          '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       lowercase_	(				self			:  Union[str, Any]     ):
      self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3     )







    def       lowercase_	(				self			:  Optional[Any]     ):
      self._test_save_load_optional_components()







    @unittest.skipIf(torch_device != 'cuda'						,      reason='float16 requires CUDA'     )
    def       lowercase_	(				self			:  List[Any]     ):
      super().test_save_load_floataa(expected_max_diff=1e-1     )







    def       lowercase_	(				self			:  int     ):
      self._test_attention_slicing_forward_pass(expected_max_diff=1e-2     )







    def       lowercase_	(				self			:  str     ):
      self._test_save_load_local()







    def       lowercase_	(				self			:  List[Any]     ):
      self._test_inference_batch_single_identical(
          expected_max_diff=1e-2						,      )




'''simple docstring'''






lowerCAmelCase: Union[str, Any]							=						{
    'meter': 'm',
    'kilometer': 'km',
    'megametre': 'Mm',
    'gigametre': 'Gm',
    'terametre': 'Tm',
    'petametre': 'Pm',
    'exametre': 'Em',
    'zettametre': 'Zm',
    'yottametre': 'Ym',
}
# Exponent of the factor(meter)
lowerCAmelCase: Optional[Any]							=						{
    'm': 0,
    'km': 3,
    'Mm': 6,
    'Gm': 9,
    'Tm': 1_2,
    'Pm': 1_5,
    'Em': 1_8,
    'Zm': 2_1,
    'Ym': 2_4,
}
def 				lowerCamelCase__	(						_A			,      _A			,      _A    ):
  a						: Optional[int]					       =					from_type.lower().strip('s'    )
  a						: Optional[Any]					       =					to_type.lower().strip('s'    )

  a						: Dict					       =					UNIT_SYMBOL.get(_A			,      _A    )
  a						: Optional[Any]					       =					UNIT_SYMBOL.get(_A			,      _A    )

  if from_sanitized not in METRIC_CONVERSION:
    a						: Optional[Any]					       =					(
        f"""Invalid 'from_type' value: {from_type!r}.\n"""
        f"""Conversion abbreviations are: {", ".join(_A    )}"""
    )
    raise ValueError(_A    )
  if to_sanitized not in METRIC_CONVERSION:
    a						: Union[str, Any]					       =					(
        f"""Invalid 'to_type' value: {to_type!r}.\n"""
        f"""Conversion abbreviations are: {", ".join(_A    )}"""
    )
    raise ValueError(_A    )
  a						: List[Any]					       =					METRIC_CONVERSION[from_sanitized]
  a						: int					       =					METRIC_CONVERSION[to_sanitized]
  a						: Tuple					       =					1

  if from_exponent > to_exponent:
    a						: Optional[int]					       =					from_exponent - to_exponent
  else:
    a						: Optional[Any]					       =					-(to_exponent - from_exponent)

  return value * pow(10			,      _A    )


if __name__ == "__main__":
     from doctest import testmod

     testmod()