




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  __magic_name__						(  __UpperCAmelCase    ,  unittest.TestCase):
				'''simple docstring'''







				pass






@nightly
@require_onnxruntime
@require_torch_gpu
class  __magic_name__						(  unittest.TestCase):
				'''simple docstring'''







				@property
				def     _A							(							self:   Optional[Any]		):
											return (
											    "CUDAExecutionProvider",
											    {
											        "gpu_mem_limit": "15000000000",  # 15GB
											        "arena_extend_strategy": "kSameAsRequested",
											    },
											)


				@property
				def     _A							(							self:   str		):
											SCREAMING_SNAKE_CASE_   	=    ort.SessionOptions()
											SCREAMING_SNAKE_CASE_   	=    False
											return options


				def     _A							(							self:   int		):
											SCREAMING_SNAKE_CASE_   	=    load_image(
											    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'''
											    '''/in_paint/overture-creations-5sI6fQgYIuo.png'''		)
											SCREAMING_SNAKE_CASE_   	=    load_image(
											    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'''
											    '''/in_paint/overture-creations-5sI6fQgYIuo_mask.png'''		)
											SCREAMING_SNAKE_CASE_   	=    OnnxStableDiffusionInpaintPipeline.from_pretrained(
											    '''runwayml/stable-diffusion-inpainting'''		,					revision='''onnx'''		,					safety_checker=_lowerCamelCase		,					feature_extractor=_lowerCamelCase		,					provider=self.gpu_provider		,					sess_options=self.gpu_options		,					)
											pipe.set_progress_bar_config(disable=_lowerCamelCase		)

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

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

											assert images.shape == (1, 5_12, 5_12, 3)
											SCREAMING_SNAKE_CASE_   	=    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     _A							(							self:   Optional[Any]		):
											SCREAMING_SNAKE_CASE_   	=    load_image(
											    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'''
											    '''/in_paint/overture-creations-5sI6fQgYIuo.png'''		)
											SCREAMING_SNAKE_CASE_   	=    load_image(
											    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'''
											    '''/in_paint/overture-creations-5sI6fQgYIuo_mask.png'''		)
											SCREAMING_SNAKE_CASE_   	=    LMSDiscreteScheduler.from_pretrained(
											    '''runwayml/stable-diffusion-inpainting'''		,					subfolder='''scheduler'''		,					revision='''onnx'''		)
											SCREAMING_SNAKE_CASE_   	=    OnnxStableDiffusionInpaintPipeline.from_pretrained(
											    '''runwayml/stable-diffusion-inpainting'''		,					revision='''onnx'''		,					scheduler=_lowerCamelCase		,					safety_checker=_lowerCamelCase		,					feature_extractor=_lowerCamelCase		,					provider=self.gpu_provider		,					sess_options=self.gpu_options		,					)
											pipe.set_progress_bar_config(disable=_lowerCamelCase		)

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

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

											assert images.shape == (1, 5_12, 5_12, 3)
											SCREAMING_SNAKE_CASE_   	=    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








import unittest

from diffusers import FlaxAutoencoderKL
from diffusers.utils import is_flax_available
from diffusers.utils.testing_utils import require_flax

from .test_modeling_common_flax import FlaxModelTesterMixin


if is_flax_available():
			import jax






@require_flax
class  __magic_name__						(  __UpperCAmelCase    ,  unittest.TestCase):
				'''simple docstring'''







				SCREAMING_SNAKE_CASE__					:							str	      =					FlaxAutoencoderKL


				@property
				def     _A							(							self:   Any		):
											SCREAMING_SNAKE_CASE_   	=    4
											SCREAMING_SNAKE_CASE_   	=    3
											SCREAMING_SNAKE_CASE_   	=    (32, 32)

											SCREAMING_SNAKE_CASE_   	=    jax.random.PRNGKey(0		)
											SCREAMING_SNAKE_CASE_   	=    jax.random.uniform(_lowerCamelCase		,					((batch_size, num_channels) + sizes)		)

											return {"sample": image, "prng_key": prng_key}





				def     _A							(							self:   List[str]		):
											SCREAMING_SNAKE_CASE_   	=    {
											    '''block_out_channels''': [32, 64],
											    '''in_channels''': 3,
											    '''out_channels''': 3,
											    '''down_block_types''': ['''DownEncoderBlock2D''', '''DownEncoderBlock2D'''],
											    '''up_block_types''': ['''UpDecoderBlock2D''', '''UpDecoderBlock2D'''],
											    '''latent_channels''': 4,
											}
											SCREAMING_SNAKE_CASE_   	=    self.dummy_input
											return init_dict, inputs_dict


