




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




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






 @property
 def 						_UpperCamelCase (self       :  str    )       ->   List[str]:






    """simple docstring"""


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






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






    """simple docstring"""


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






 def 						_UpperCamelCase (self       :  Dict    )       ->   int:






    """simple docstring"""


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

    A__       =     'A red cat sitting on a park bench'

    A__       =     np.random.RandomState(0    )
    A__       =     pipe(
        prompt=a    ,		image=a    ,		mask_image=a    ,		guidance_scale=7.5    ,		num_inference_steps=10    ,		generator=a    ,		output_type='np'    ,		)
    A__       =     output.images
    A__       =     images[0, 2_55:2_58, 2_55:2_58, -1]

    assert images.shape == (1, 5_12, 5_12, 3)
    A__       =     np.array([0.2514, 0.3007, 0.3517, 0.1790, 0.2382, 0.3167, 0.1944, 0.2273, 0.2464]    )

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






 def 						_UpperCamelCase (self       :  Dict    )       ->   Dict:






    """simple docstring"""


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

    A__       =     'A red cat sitting on a park bench'

    A__       =     np.random.RandomState(0    )
    A__       =     pipe(
        prompt=a    ,		image=a    ,		mask_image=a    ,		guidance_scale=7.5    ,		num_inference_steps=20    ,		generator=a    ,		output_type='np'    ,		)
    A__       =     output.images
    A__       =     images[0, 2_55:2_58, 2_55:2_58, -1]

    assert images.shape == (1, 5_12, 5_12, 3)
    A__       =     np.array([0.0086, 0.0077, 0.0083, 0.0093, 0.0107, 0.0139, 0.0094, 0.0097, 0.0125]    )

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








'''simple docstring'''







from dataclasses import dataclass
from typing import List, Optional, Union

import numpy as np
import PIL

from ...utils import BaseOutput, OptionalDependencyNotAvailable, is_torch_available, is_transformers_available
from .timesteps import (
    fastaa_timesteps,
    smartaa_timesteps,
    smartaa_timesteps,
    smartaaa_timesteps,
    smartaaa_timesteps,
    superaa_timesteps,
    superaa_timesteps,
    superaaa_timesteps,
)

@dataclass
class 	_snake_case(			UpperCAmelCase      ):
 __snake_case:							Union[List[PIL.Image.Image], np.ndarray]
 __snake_case:							Optional[List[bool]]
 __snake_case:							Optional[List[bool]]


try:
    if not (is_transformers_available() and is_torch_available()):
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    from ...utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
    from .pipeline_if import IFPipeline
    from .pipeline_if_imgaimg import IFImgaImgPipeline
    from .pipeline_if_imgaimg_superresolution import IFImgaImgSuperResolutionPipeline
    from .pipeline_if_inpainting import IFInpaintingPipeline
    from .pipeline_if_inpainting_superresolution import IFInpaintingSuperResolutionPipeline
    from .pipeline_if_superresolution import IFSuperResolutionPipeline
    from .safety_checker import IFSafetyChecker
    from .watermark import IFWatermarker


