




'''simple docstring'''





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  _snake_case		(	lowercase_						,						unittest.TestCase							):
			# FIXME: add fast tests
			pass




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




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

										'''simple docstring'''




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




			@property
			def    lowerCAmelCase__				(					self							)				->				Optional[int]:

										'''simple docstring'''




										snake_case_						=      ort.SessionOptions()
										snake_case_						=      False
										return options




			def    lowerCAmelCase__				(					self							)				->				str:

										'''simple docstring'''




										snake_case_						=      load_image(
										    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
										    "/in_paint/overture-creations-5sI6fQgYIuo.png"							)
										snake_case_						=      load_image(
										    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
										    "/in_paint/overture-creations-5sI6fQgYIuo_mask.png"							)
										snake_case_						=      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__							)

										snake_case_						=      "A red cat sitting on a park bench"

										snake_case_						=      np.random.RandomState(0							)
										snake_case_						=      pipe(
										    prompt=a__				,							image=a__				,							mask_image=a__				,							guidance_scale=7.5				,							num_inference_steps=10				,							generator=a__				,							output_type="np"				,							)
										snake_case_						=      output.images
										snake_case_						=      images[0, 255:258, 255:258, -1]

										assert images.shape == (1, 512, 512, 3)
										snake_case_						=      np.array([0.2_5_1_4, 0.3_0_0_7, 0.3_5_1_7, 0.1_7_9_0, 0.2_3_8_2, 0.3_1_6_7, 0.1_9_4_4, 0.2_2_7_3, 0.2_4_6_4]							)

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




			def    lowerCAmelCase__				(					self							)				->				Any:

										'''simple docstring'''




										snake_case_						=      load_image(
										    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
										    "/in_paint/overture-creations-5sI6fQgYIuo.png"							)
										snake_case_						=      load_image(
										    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
										    "/in_paint/overture-creations-5sI6fQgYIuo_mask.png"							)
										snake_case_						=      LMSDiscreteScheduler.from_pretrained(
										    "runwayml/stable-diffusion-inpainting"				,							subfolder="scheduler"				,							revision="onnx"							)
										snake_case_						=      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__							)

										snake_case_						=      "A red cat sitting on a park bench"

										snake_case_						=      np.random.RandomState(0							)
										snake_case_						=      pipe(
										    prompt=a__				,							image=a__				,							mask_image=a__				,							guidance_scale=7.5				,							num_inference_steps=20				,							generator=a__				,							output_type="np"				,							)
										snake_case_						=      output.images
										snake_case_						=      images[0, 255:258, 255:258, -1]

										assert images.shape == (1, 512, 512, 3)
										snake_case_						=      np.array([0.0_0_8_6, 0.0_0_7_7, 0.0_0_8_3, 0.0_0_9_3, 0.0_1_0_7, 0.0_1_3_9, 0.0_0_9_4, 0.0_0_9_7, 0.0_1_2_5]							)

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












import warnings


warnings.warn(
    'memory_utils has been reorganized to utils.memory. Import `find_executable_batchsize` from the main `__init__`: '
    '`from accelerate import find_executable_batch_size` to avoid this warning.',
    FutureWarning,
)




