'''simple docstring'''






import random
import unittest

import torch

from diffusers import IFInpaintingPipeline
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_       (		_UpperCamelCase    ,    _UpperCamelCase    ,    unittest.TestCase			):







   """simple docstring"""

   __lowerCAmelCase         =   IFInpaintingPipeline
   __lowerCAmelCase         =   TEXT_GUIDED_IMAGE_INPAINTING_PARAMS - {"width", "height"}
   __lowerCAmelCase         =   TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS
   __lowerCAmelCase         =   PipelineTesterMixin.required_optional_params - {"latents"}
   def 	__UpperCAmelCase   (      self      :			Union[str, Any]     )  ->			Any:
        return self._get_dummy_components()
   def 	__UpperCAmelCase   (      self      :			Dict, UpperCamelCase__      :			Any, UpperCamelCase__      :			Any=0     )  ->			Union[str, Any]:
        if str(UpperCamelCase__     ).startswith('mps'     ):
             _A    		=  torch.manual_seed(UpperCamelCase__     )
        else:
             _A    		=  torch.Generator(device=UpperCamelCase__     ).manual_seed(UpperCamelCase__     )

        _A    		=  floats_tensor((1, 3, 32, 32), rng=random.Random(UpperCamelCase__     )     ).to(UpperCamelCase__     )
        _A    		=  floats_tensor((1, 3, 32, 32), rng=random.Random(UpperCamelCase__     )     ).to(UpperCamelCase__     )

        _A    		=  {
            'prompt': 'A painting of a squirrel eating a burger',
            'image': 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 	__UpperCAmelCase   (      self      :			Dict     )  ->			Union[str, Any]:
        self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3     )
   def 	__UpperCAmelCase   (      self      :			Optional[int]     )  ->			int:
        self._test_save_load_optional_components()
   @unittest.skipIf(torch_device != 'cuda', reason='float16 requires CUDA'     )
   def 	__UpperCAmelCase   (      self      :			Any     )  ->			int:
        # Due to non-determinism in save load of the hf-internal-testing/tiny-random-t5 text encoder
        super().test_save_load_floataa(expected_max_diff=1e-1     )
   def 	__UpperCAmelCase   (      self      :			Optional[int]     )  ->			Optional[int]:
        self._test_attention_slicing_forward_pass(expected_max_diff=1e-2     )
   def 	__UpperCAmelCase   (      self      :			Dict     )  ->			Any:
        self._test_save_load_local()

   def 	__UpperCAmelCase   (      self      :			Optional[int]     )  ->			List[Any]:
        self._test_inference_batch_single_identical(
            expected_max_diff=1e-2, )




'''simple docstring'''






import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionImageVariationPipeline
from diffusers.utils.testing_utils import load_image, require_torch_gpu, slow, torch_device


_UpperCAmelCase    :     List[Any]         =       False







class lowercase_       (		unittest.TestCase			):







   """simple docstring"""

   pass







@slow
@require_torch_gpu
class lowercase_       (		unittest.TestCase			):







   """simple docstring"""

   def 	__UpperCAmelCase   (      self      :			List[str]     )  ->			Dict:
        _A    		=  VersatileDiffusionImageVariationPipeline.from_pretrained('shi-labs/versatile-diffusion'     )
        pipe.to(UpperCamelCase__     )
        pipe.set_progress_bar_config(disable=UpperCamelCase__     )

        _A    		=  load_image(
            'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg'     )
        _A    		=  torch.manual_seed(0     )
        _A    		=  pipe(
            image=UpperCamelCase__, generator=UpperCamelCase__, guidance_scale=7.5, num_inference_steps=50, output_type='numpy', ).images

        _A    		=  image[0, 2_53:2_56, 2_53:2_56, -1]

        assert image.shape == (1, 5_12, 5_12, 3)
        _A    		=  np.array([0.0_441, 0.0_469, 0.0_507, 0.0_575, 0.0_632, 0.0_650, 0.0_865, 0.0_909, 0.0_945]     )

        assert np.abs(image_slice.flatten() - expected_slice     ).max() < 1e-2



