





import unittest

import numpy as np

from diffusers import LMSDiscreteScheduler, OnnxStableDiffusionInpaintPipeline
from diffusers.utils.testing_utils import (
    is_onnx_available,
    load_image,
    nightly,
    require_onnxruntime,
    require_torch_gpu,
)

from ..test_pipelines_onnx_common import OnnxPipelineTesterMixin


if is_onnx_available():
    import onnxruntime as ort



class 					A__   (       __snake_case       ,   unittest.TestCase			):
      # FIXME: add fast tests
      pass



@nightly
@require_onnxruntime
@require_torch_gpu
class 					A__   (       unittest.TestCase			):





      @property
      def        __UpperCamelCase( self   ):
       '''simple docstring'''




       return (
           "CUDAExecutionProvider",
           {
               "gpu_mem_limit": "15000000000",  # 15GB
               "arena_extend_strategy": "kSameAsRequested",
           },
       )





      @property
      def        __UpperCamelCase( self   ):
       '''simple docstring'''




       UpperCamelCase	:					Optional[Any]       	=   ort.SessionOptions()
       UpperCamelCase	:					Any       	=   False
       return options





      def        __UpperCamelCase( self   ):
       '''simple docstring'''




       UpperCamelCase	:					Union[str, Any]       	=   load_image(
           "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
           "/in_paint/overture-creations-5sI6fQgYIuo.png"   )
       UpperCamelCase	:					Dict       	=   load_image(
           "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
           "/in_paint/overture-creations-5sI6fQgYIuo_mask.png"   )
       UpperCamelCase	:					Optional[Any]       	=   OnnxStableDiffusionInpaintPipeline.from_pretrained(
           "runwayml/stable-diffusion-inpainting"       ,							revision="onnx"       ,							safety_checker=A_       ,							feature_extractor=A_       ,							provider=self.gpu_provider       ,							sess_options=self.gpu_options       ,							)
       pipe.set_progress_bar_config(disable=A_   )

       UpperCamelCase	:					Any       	=   "A red cat sitting on a park bench"

       UpperCamelCase	:					List[Any]       	=   np.random.RandomState(0   )
       UpperCamelCase	:					Union[str, Any]       	=   pipe(
           prompt=A_       ,							image=A_       ,							mask_image=A_       ,							guidance_scale=7.5       ,							num_inference_steps=10       ,							generator=A_       ,							output_type="np"       ,							)
       UpperCamelCase	:					Optional[int]       	=   output.images
       UpperCamelCase	:					Any       	=   images[0, 255:258, 255:258, -1]

       assert images.shape == (1, 512, 512, 3)
       UpperCamelCase	:					Dict       	=   np.array([0.25_14, 0.30_07, 0.35_17, 0.17_90, 0.23_82, 0.31_67, 0.19_44, 0.22_73, 0.24_64]   )

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





      def        __UpperCamelCase( self   ):
       '''simple docstring'''




       UpperCamelCase	:					Optional[int]       	=   load_image(
           "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
           "/in_paint/overture-creations-5sI6fQgYIuo.png"   )
       UpperCamelCase	:					Tuple       	=   load_image(
           "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
           "/in_paint/overture-creations-5sI6fQgYIuo_mask.png"   )
       UpperCamelCase	:					Optional[Any]       	=   LMSDiscreteScheduler.from_pretrained(
           "runwayml/stable-diffusion-inpainting"       ,							subfolder="scheduler"       ,							revision="onnx"   )
       UpperCamelCase	:					Optional[Any]       	=   OnnxStableDiffusionInpaintPipeline.from_pretrained(
           "runwayml/stable-diffusion-inpainting"       ,							revision="onnx"       ,							scheduler=A_       ,							safety_checker=A_       ,							feature_extractor=A_       ,							provider=self.gpu_provider       ,							sess_options=self.gpu_options       ,							)
       pipe.set_progress_bar_config(disable=A_   )

       UpperCamelCase	:					Optional[int]       	=   "A red cat sitting on a park bench"

       UpperCamelCase	:					List[str]       	=   np.random.RandomState(0   )
       UpperCamelCase	:					Union[str, Any]       	=   pipe(
           prompt=A_       ,							image=A_       ,							mask_image=A_       ,							guidance_scale=7.5       ,							num_inference_steps=20       ,							generator=A_       ,							output_type="np"       ,							)
       UpperCamelCase	:					Optional[Any]       	=   output.images
       UpperCamelCase	:					List[str]       	=   images[0, 255:258, 255:258, -1]

       assert images.shape == (1, 512, 512, 3)
       UpperCamelCase	:					List[Any]       	=   np.array([0.00_86, 0.00_77, 0.00_83, 0.00_93, 0.01_07, 0.01_39, 0.00_94, 0.00_97, 0.01_25]   )

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




"""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


a__				:							Tuple						=     False




class  UpperCamelCase_	( unittest.TestCase):

	"""simple docstring"""





	pass




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

	"""simple docstring"""





	def   UpperCAmelCase_      ( self			:				int   )       ->	int:
						__SCREAMING_SNAKE_CASE						   =				VersatileDiffusionImageVariationPipeline.from_pretrained("shi-labs/versatile-diffusion"   )
						pipe.to(UpperCAmelCase__   )
						pipe.set_progress_bar_config(disable=UpperCAmelCase__   )

						__SCREAMING_SNAKE_CASE						   =				load_image(
						    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg"   )
						__SCREAMING_SNAKE_CASE						   =				torch.manual_seed(0   )
						__SCREAMING_SNAKE_CASE						   =				pipe(
						    image=UpperCAmelCase__			,			generator=UpperCAmelCase__			,			guidance_scale=7.5			,			num_inference_steps=5_0			,			output_type="numpy"			,			).images

						__SCREAMING_SNAKE_CASE						   =				image[0, 2_5_3:2_5_6, 2_5_3:2_5_6, -1]

						assert image.shape == (1, 5_1_2, 5_1_2, 3)
						__SCREAMING_SNAKE_CASE						   =				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
