


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


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

							@property
							def 				lowerCamelCase_			(							self:     List[str]							)      ->       Optional[Any]:





									"""simple docstring"""







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

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





									"""simple docstring"""







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

							def 				lowerCamelCase_			(							self:     Dict							)      ->       Optional[int]:





									"""simple docstring"""







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

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

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

									assert images.shape == (1, 512, 512, 3)
									lowercase__						=				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 				lowerCamelCase_			(							self:     Optional[Any]							)      ->       Optional[int]:





									"""simple docstring"""







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

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

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

									assert images.shape == (1, 512, 512, 3)
									lowercase__						=				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






import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
			import torch

			from transformers.activations import gelu_new, gelu_python, get_activation


@require_torch
class 	_a							(      unittest.TestCase      ):

							def 				lowerCamelCase_			(							self:     Dict							)      ->       Any:





									"""simple docstring"""







									lowercase__						=				torch.tensor([-100, -1, -0.1, 0, 0.1, 1.0, 100]							)
									lowercase__						=				get_activation('''gelu'''							)
									self.assertTrue(torch.allclose(gelu_python(UpperCamelCase_							)   ,						torch_builtin(UpperCamelCase_							)							)							)
									self.assertFalse(torch.allclose(gelu_python(UpperCamelCase_							)   ,						gelu_new(UpperCamelCase_							)							)							)

							def 				lowerCamelCase_			(							self:     Optional[int]							)      ->       str:





									"""simple docstring"""







									lowercase__						=				torch.tensor([-100, -1, -0.1, 0, 0.1, 1.0, 100]							)
									lowercase__						=				get_activation('''gelu'''							)
									lowercase__						=				get_activation('''gelu_10'''							)

									lowercase__						=				torch_builtin(UpperCamelCase_							)
									lowercase__						=				geluaa(UpperCamelCase_							)

									lowercase__						=				torch.where(y_gelu_aa < 10.0   ,						1   ,						0							)

									self.assertTrue(torch.max(UpperCamelCase_							).item() == 10.0							)
									self.assertTrue(torch.allclose(y_gelu * clipped_mask   ,						y_gelu_aa * clipped_mask							)							)

							def 				lowerCamelCase_			(							self:     Union[str, Any]							)      ->       Tuple:





									"""simple docstring"""







									get_activation('''gelu'''							)
									get_activation('''gelu_10'''							)
									get_activation('''gelu_fast'''							)
									get_activation('''gelu_new'''							)
									get_activation('''gelu_python'''							)
									get_activation('''gelu_pytorch_tanh'''							)
									get_activation('''linear'''							)
									get_activation('''mish'''							)
									get_activation('''quick_gelu'''							)
									get_activation('''relu'''							)
									get_activation('''sigmoid'''							)
									get_activation('''silu'''							)
									get_activation('''swish'''							)
									get_activation('''tanh'''							)
									with self.assertRaises(UpperCamelCase_							):
											get_activation('''bogus'''							)
									with self.assertRaises(UpperCamelCase_							):
											get_activation(UpperCamelCase_							)


							def 				lowerCamelCase_			(							self:     Tuple							)      ->       int:





									"""simple docstring"""







									lowercase__						=				get_activation('''gelu'''							)
									lowercase__						=				1
									lowercase__						=				get_activation('''gelu'''							)
									self.assertEqual(acta.a   ,						1							)
									with self.assertRaises(UpperCamelCase_							):
											lowercase__						=				acta.a


