
"""simple docstring"""


import inspect
import unittest

import numpy as np

from tests.test_modeling_common import floats_tensor
from transformers import MaskaFormerConfig, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
		import torch

		from transformers import MaskaFormerForUniversalSegmentation, MaskaFormerModel

		if is_vision_available():
				from transformers import MaskaFormerImageProcessor

if is_vision_available():
		from PIL import Image







class 				lowerCAmelCase_				:



						'''simple docstring'''


						def __init__( self     :      Optional[Any]  ,A_     :      Optional[Any]  ,A_     :      Optional[int]=2  ,A_     :      Any=True  ,A_     :      List[str]=False  ,A_     :      Tuple=10  ,A_     :      List[Any]=3  ,A_     :      Any=32 * 8  ,A_     :      Dict=32 * 8  ,A_     :      List[Any]=4  ,A_     :      Tuple=64  ,)     ->   List[str]:
							A						   =   parent
							A						   =   batch_size
							A						   =   is_training
							A						   =   use_auxiliary_loss
							A						   =   num_queries
							A						   =   num_channels
							A						   =   min_size
							A						   =   max_size
							A						   =   num_labels
							A						   =   hidden_dim
							A						   =   hidden_dim


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[int]      )     ->   List[str]:
							A						   =   floats_tensor([self.batch_size, self.num_channels, self.min_size, self.max_size]      ).to(
							    A_      )

							A						   =   torch.ones([self.batch_size, self.min_size, self.max_size]  ,device=A_      )

							A						   =   (
							    torch.rand([self.batch_size, self.num_labels, self.min_size, self.max_size]  ,device=A_      ) > 0.5
							).float()
							A						   =   (torch.rand((self.batch_size, self.num_labels)  ,device=A_      ) > 0.5).long()

							A						   =   self.get_config()
							return config, pixel_values, pixel_mask, mask_labels, class_labels


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Union[str, Any]      )     ->   Optional[int]:
							A						   =   MaskaFormerConfig(
							    hidden_size=self.hidden_dim  ,)
							A						   =   self.num_queries
							A						   =   self.num_labels

							A						   =   [1, 1, 1, 1]
							A						   =   self.num_channels

							A						   =   64
							A						   =   128
							A						   =   self.hidden_dim
							A						   =   self.hidden_dim
							A						   =   self.hidden_dim
							return config


						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[Any]      )     ->   Any:
							A   ,      A   ,      A   ,      A   ,      A						   =   self.prepare_config_and_inputs()
							A						   =   {'pixel_values': pixel_values, 'pixel_mask': pixel_mask}
							return config, inputs_dict


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[int]  ,A_     :      Union[str, Any]  ,A_     :      Optional[int]      )     ->   Union[str, Any]:
							A						   =   output.encoder_hidden_states
							A						   =   output.pixel_decoder_hidden_states
							A						   =   output.transformer_decoder_hidden_states

							self.parent.assertTrue(len(A_      )  ,len(config.backbone_config.depths      )      )
							self.parent.assertTrue(len(A_      )  ,len(config.backbone_config.depths      )      )
							self.parent.assertTrue(len(A_      )  ,config.decoder_layers      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[Any]  ,A_     :      List[Any]  ,A_     :      Dict  ,A_     :      List[str]  ,A_     :      Union[str, Any]=False      )     ->   str:
							with torch.no_grad():
								A						   =   MaskaFormerModel(config=A_      )
								model.to(A_      )
								model.eval()

								A						   =   model(pixel_values=A_  ,pixel_mask=A_      )
								A						   =   model(A_  ,output_hidden_states=A_      )

							self.parent.assertEqual(
							    output.transformer_decoder_last_hidden_state.shape  ,(self.batch_size, self.num_queries, self.hidden_dim)  ,)
							# let's ensure the other two hidden state exists
							self.parent.assertTrue(output.pixel_decoder_last_hidden_state is not None      )
							self.parent.assertTrue(output.encoder_last_hidden_state is not None      )

							if output_hidden_states:
								self.check_output_hidden_state(A_  ,A_      )




						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[Any]  ,A_     :      List[Any]  ,A_     :      Any  ,A_     :      Dict  ,A_     :      Any  ,A_     :      Dict      )     ->   Optional[Any]:
							A						   =   MaskaFormerForUniversalSegmentation(config=A_      )
							model.to(A_      )
							model.eval()

							def comm_check_on_output(A_     :      str      ):
								# let's still check that all the required stuff is there
								self.parent.assertTrue(result.transformer_decoder_last_hidden_state is not None      )
								self.parent.assertTrue(result.pixel_decoder_last_hidden_state is not None      )
								self.parent.assertTrue(result.encoder_last_hidden_state is not None      )
								# okay, now we need to check the logits shape
								# due to the encoder compression, masks have a //4 spatial size
								self.parent.assertEqual(
								    result.masks_queries_logits.shape  ,(self.batch_size, self.num_queries, self.min_size // 4, self.max_size // 4)  ,)
								# + 1 for null class
								self.parent.assertEqual(
								    result.class_queries_logits.shape  ,(self.batch_size, self.num_queries, self.num_labels + 1)      )

							with torch.no_grad():
								A						   =   model(pixel_values=A_  ,pixel_mask=A_      )
								A						   =   model(A_      )

								comm_check_on_output(A_      )

								A						   =   model(
								    pixel_values=A_  ,pixel_mask=A_  ,mask_labels=A_  ,class_labels=A_      )

							comm_check_on_output(A_      )

							self.parent.assertTrue(result.loss is not None      )
							self.parent.assertEqual(result.loss.shape  ,torch.Size([1]      )      )







@require_torch
class 				lowerCAmelCase_				(      _lowercase		,					_lowercase		,					unittest.TestCase    ):



						'''simple docstring'''


						_lowerCamelCase:    Union[str, Any]      =    (MaskaFormerModel, MaskaFormerForUniversalSegmentation) if is_torch_available() else ()
						_lowerCamelCase:    Optional[Any]      =    {'''feature-extraction''': MaskaFormerModel} if is_torch_available() else {}

						_lowerCamelCase:    int      =    False
						_lowerCamelCase:    Dict      =    False
						_lowerCamelCase:    List[str]      =    False
						_lowerCamelCase:    int      =    False


						def 						_SCREAMING_SNAKE_CASE      ( self     :      int      )     ->   Dict:
							A						   =   MaskaFormerModelTester(self      )
							A						   =   ConfigTester(self  ,config_class=A_  ,has_text_modality=A_      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      int      )     ->   Optional[Any]:
							self.config_tester.run_common_tests()


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Any      )     ->   Dict:
							A   ,      A						   =   self.model_tester.prepare_config_and_inputs_for_common()
							self.model_tester.create_and_check_maskaformer_model(A_  ,**A_  ,output_hidden_states=A_      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[Any]      )     ->   str:
							A						   =   self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_maskaformer_instance_segmentation_head_model(*A_      )


						@unittest.skip(reason='Mask2Former does not use inputs_embeds'      )
						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[Any]      )     ->   Tuple:
							pass


						@unittest.skip(reason='Mask2Former does not have a get_input_embeddings method'      )
						def 						_SCREAMING_SNAKE_CASE      ( self     :      Union[str, Any]      )     ->   Union[str, Any]:
							pass


						@unittest.skip(reason='Mask2Former is not a generative model'      )
						def 						_SCREAMING_SNAKE_CASE      ( self     :      Dict      )     ->   Dict:
							pass


						@unittest.skip(reason='Mask2Former does not use token embeddings'      )
						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[str]      )     ->   Union[str, Any]:
							pass


						@require_torch_multi_gpu
						@unittest.skip(
						    reason='Mask2Former has some layers using `add_module` which doesn\'t work well with `nn.DataParallel`'      )
						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[Any]      )     ->   str:
							pass


						@unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.'      )
						def 						_SCREAMING_SNAKE_CASE      ( self     :      Dict      )     ->   Any:
							pass


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[Any]      )     ->   Tuple:
							A   ,      A						   =   self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
								A						   =   model_class(A_      )
								A						   =   inspect.signature(model.forward      )
								# signature.parameters is an OrderedDict => so arg_names order is deterministic
								A						   =   [*signature.parameters.keys()]

								A						   =   ['pixel_values']
								self.assertListEqual(arg_names[:1]  ,A_      )


						@slow
						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[Any]      )     ->   Any:
							for model_name in ["facebook/mask2former-swin-small-coco-instance"]:
								A						   =   MaskaFormerModel.from_pretrained(A_      )
								self.assertIsNotNone(A_      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Any      )     ->   List[str]:
							A						   =   (self.model_tester.min_size,) * 2
							A						   =   {
							    'pixel_values': torch.randn((2, 3, *size)  ,device=A_      ),
							    'mask_labels': torch.randn((2, 10, *size)  ,device=A_      ),
							    'class_labels': torch.zeros(2  ,10  ,device=A_      ).long(),
							}
							A						   =   self.model_tester.get_config()

							A						   =   MaskaFormerForUniversalSegmentation(A_      ).to(A_      )
							A						   =   model(**A_      )
							self.assertTrue(outputs.loss is not None      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[str]      )     ->   Optional[Any]:
							A   ,      A						   =   self.model_tester.prepare_config_and_inputs_for_common()
							self.model_tester.create_and_check_maskaformer_model(A_  ,**A_  ,output_hidden_states=A_      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Tuple      )     ->   List[str]:
							A   ,      A						   =   self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
								A						   =   model_class(A_      ).to(A_      )
								A						   =   model(**A_  ,output_attentions=A_      )
								self.assertTrue(outputs.attentions is not None      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[Any]      )     ->   Tuple:
							if not self.model_tester.is_training:
								return

							A						   =   self.all_model_classes[1]
							A   ,      A   ,      A   ,      A   ,      A						   =   self.model_tester.prepare_config_and_inputs()

							A						   =   model_class(A_      )
							model.to(A_      )
							model.train()

							A						   =   model(A_  ,mask_labels=A_  ,class_labels=A_      ).loss
							loss.backward()




						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[Any]      )     ->   Tuple:
							A						   =   self.all_model_classes[1]
							A   ,      A   ,      A   ,      A   ,      A						   =   self.model_tester.prepare_config_and_inputs()
							A						   =   True
							A						   =   True

							A						   =   model_class(A_      ).to(A_      )
							model.train()

							A						   =   model(A_  ,mask_labels=A_  ,class_labels=A_      )

							A						   =   outputs.encoder_hidden_states[0]
							encoder_hidden_states.retain_grad()

							A						   =   outputs.pixel_decoder_hidden_states[0]
							pixel_decoder_hidden_states.retain_grad()

							A						   =   outputs.transformer_decoder_hidden_states[0]
							transformer_decoder_hidden_states.retain_grad()

							A						   =   outputs.attentions[0]
							attentions.retain_grad()

							outputs.loss.backward(retain_graph=A_      )

							self.assertIsNotNone(encoder_hidden_states.grad      )
							self.assertIsNotNone(pixel_decoder_hidden_states.grad      )
							self.assertIsNotNone(transformer_decoder_hidden_states.grad      )
							self.assertIsNotNone(attentions.grad      )

_lowercase							   =				1e-4






def       _snake_case				(		):
	A						   =   Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'     )
	return image







@require_vision
@slow
class 				lowerCAmelCase_				(      unittest.TestCase    ):



						'''simple docstring'''


						@cached_property
						def 						_SCREAMING_SNAKE_CASE      ( self     :      Dict      )     ->   int:
							return "facebook/mask2former-swin-small-coco-instance"


						@cached_property
						def 						_SCREAMING_SNAKE_CASE      ( self     :      int      )     ->   List[str]:
							return MaskaFormerImageProcessor.from_pretrained(self.model_checkpoints      ) if is_vision_available() else None


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[int]      )     ->   Optional[int]:
							A						   =   MaskaFormerModel.from_pretrained(self.model_checkpoints      ).to(A_      )
							A						   =   self.default_image_processor
							A						   =   prepare_img()
							A						   =   image_processor(A_  ,return_tensors='pt'      ).to(A_      )
							A						   =   inputs['pixel_values'].shape
							# check size is divisible by 32
							self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0      )
							# check size
							self.assertEqual(A_  ,(1, 3, 384, 384)      )

							with torch.no_grad():
								A						   =   model(**A_      )

							A						   =   torch.tensor(
							    [[-0.27_90, -1.07_17, -1.16_68], [-0.51_28, -0.31_28, -0.49_87], [-0.58_32, 0.19_71, -0.01_97]]      ).to(A_      )
							self.assertTrue(
							    torch.allclose(
							        outputs.encoder_last_hidden_state[0, 0, :3, :3]  ,A_  ,atol=A_      )      )

							A						   =   torch.tensor(
							    [[0.89_73, 1.18_47, 1.17_76], [1.19_34, 1.50_40, 1.51_28], [1.11_53, 1.44_86, 1.49_51]]      ).to(A_      )
							self.assertTrue(
							    torch.allclose(
							        outputs.pixel_decoder_last_hidden_state[0, 0, :3, :3]  ,A_  ,atol=A_      )      )

							A						   =   torch.tensor(
							    [[2.11_52, 1.70_00, -0.86_03], [1.58_08, 1.80_04, -0.93_53], [1.60_43, 1.74_95, -0.59_99]]      ).to(A_      )
							self.assertTrue(
							    torch.allclose(
							        outputs.transformer_decoder_last_hidden_state[0, :3, :3]  ,A_  ,atol=A_      )      )


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[Any]      )     ->   Union[str, Any]:
							A						   =   MaskaFormerForUniversalSegmentation.from_pretrained(self.model_checkpoints      ).to(A_      ).eval()
							A						   =   self.default_image_processor
							A						   =   prepare_img()
							A						   =   image_processor(A_  ,return_tensors='pt'      ).to(A_      )
							A						   =   inputs['pixel_values'].shape
							# check size is divisible by 32
							self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0      )
							# check size
							self.assertEqual(A_  ,(1, 3, 384, 384)      )

							with torch.no_grad():
								A						   =   model(**A_      )
							# masks_queries_logits
							A						   =   outputs.masks_queries_logits
							self.assertEqual(
							    masks_queries_logits.shape  ,(1, model.config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)      )
							A						   =   [
							    [-8.78_39, -9.00_56, -8.81_21],
							    [-7.41_04, -7.03_13, -6.54_01],
							    [-6.61_05, -6.34_27, -6.46_75],
							]
							A						   =   torch.tensor(A_      ).to(A_      )
							self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]  ,A_  ,atol=A_      )      )
							# class_queries_logits
							A						   =   outputs.class_queries_logits
							self.assertEqual(class_queries_logits.shape  ,(1, model.config.num_queries, model.config.num_labels + 1)      )
							A						   =   torch.tensor(
							    [
							        [1.83_24, -8.08_35, -4.19_22],
							        [0.84_50, -9.00_50, -3.60_53],
							        [0.30_45, -7.72_93, -3.02_75],
							    ]      ).to(A_      )
							self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]  ,A_  ,atol=A_      )      )




						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[str]      )     ->   int:
							A						   =   MaskaFormerForUniversalSegmentation.from_pretrained(self.model_checkpoints      ).to(A_      ).eval()
							A						   =   self.default_image_processor

							A						   =   image_processor(
							    [np.zeros((3, 800, 1333)      ), np.zeros((3, 800, 1333)      )]  ,segmentation_maps=[np.zeros((384, 384)      ).astype(np.floataa      ), np.zeros((384, 384)      ).astype(np.floataa      )]  ,return_tensors='pt'  ,)

							A						   =   inputs['pixel_values'].to(A_      )
							A						   =   [el.to(A_      ) for el in inputs['mask_labels']]
							A						   =   [el.to(A_      ) for el in inputs['class_labels']]

							with torch.no_grad():
								A						   =   model(**A_      )

							self.assertTrue(outputs.loss is not None      )

"""simple docstring"""


import random
import unittest

import numpy as np

from diffusers import (
    DPMSolverMultistepScheduler,
    EulerAncestralDiscreteScheduler,
    EulerDiscreteScheduler,
    LMSDiscreteScheduler,
    OnnxStableDiffusionImgaImgPipeline,
    PNDMScheduler,
)
from diffusers.utils import floats_tensor
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 				lowerCAmelCase_				(      _lowercase		,					unittest.TestCase    ):



						'''simple docstring'''


						_lowerCamelCase:    Tuple      =    '''hf-internal-testing/tiny-random-OnnxStableDiffusionPipeline'''


						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[Any]  ,A_     :      List[str]=0      )     ->   Dict:
							A						   =   floats_tensor((1, 3, 128, 128)  ,rng=random.Random(A_      )      )
							A						   =   np.random.RandomState(A_      )
							A						   =   {
							    'prompt': 'A painting of a squirrel eating a burger',
							    'image': image,
							    'generator': generator,
							    'num_inference_steps': 3,
							    'strength': 0.75,
							    'guidance_scale': 7.5,
							    'output_type': 'numpy',
							}
							return inputs


						def 						_SCREAMING_SNAKE_CASE      ( self     :      str      )     ->   Optional[int]:
							A						   =   OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint  ,provider='CPUExecutionProvider'      )
							pipe.set_progress_bar_config(disable=A_      )

							A						   =   self.get_dummy_inputs()
							A						   =   pipe(**A_      ).images
							A						   =   image[0, -3:, -3:, -1].flatten()

							assert image.shape == (1, 128, 128, 3)
							A						   =   np.array([0.6_96_43, 0.5_84_84, 0.5_03_14, 0.5_87_60, 0.5_53_68, 0.5_96_43, 0.5_15_29, 0.4_12_17, 0.4_90_87]      )
							assert np.abs(image_slice - expected_slice      ).max() < 1e-1


						def 						_SCREAMING_SNAKE_CASE      ( self     :      str      )     ->   Union[str, Any]:
							A						   =   OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint  ,provider='CPUExecutionProvider'      )
							A						   =   PNDMScheduler.from_config(pipe.scheduler.config  ,skip_prk_steps=A_      )
							pipe.set_progress_bar_config(disable=A_      )

							A						   =   self.get_dummy_inputs()
							A						   =   pipe(**A_      ).images
							A						   =   image[0, -3:, -3:, -1]

							assert image.shape == (1, 128, 128, 3)
							A						   =   np.array([0.6_17_37, 0.5_46_42, 0.5_31_83, 0.5_44_65, 0.5_27_42, 0.6_05_25, 0.4_99_69, 0.4_06_55, 0.4_81_54]      )

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


						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[Any]      )     ->   Dict:
							A						   =   OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint  ,provider='CPUExecutionProvider'      )
							A						   =   LMSDiscreteScheduler.from_config(pipe.scheduler.config      )
							pipe.set_progress_bar_config(disable=A_      )

							# warmup pass to apply optimizations
							A						   =   pipe(**self.get_dummy_inputs()      )

							A						   =   self.get_dummy_inputs()
							A						   =   pipe(**A_      ).images
							A						   =   image[0, -3:, -3:, -1]

							assert image.shape == (1, 128, 128, 3)
							A						   =   np.array([0.5_27_61, 0.5_99_77, 0.4_90_33, 0.4_96_19, 0.5_42_82, 0.5_03_11, 0.4_76_00, 0.4_09_18, 0.4_52_03]      )

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


						def 						_SCREAMING_SNAKE_CASE      ( self     :      int      )     ->   Optional[int]:
							A						   =   OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint  ,provider='CPUExecutionProvider'      )
							A						   =   EulerDiscreteScheduler.from_config(pipe.scheduler.config      )
							pipe.set_progress_bar_config(disable=A_      )

							A						   =   self.get_dummy_inputs()
							A						   =   pipe(**A_      ).images
							A						   =   image[0, -3:, -3:, -1]

							assert image.shape == (1, 128, 128, 3)
							A						   =   np.array([0.5_29_11, 0.6_00_04, 0.4_92_29, 0.4_98_05, 0.5_45_02, 0.5_06_80, 0.4_77_77, 0.4_10_28, 0.4_53_04]      )

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


						def 						_SCREAMING_SNAKE_CASE      ( self     :      List[str]      )     ->   Optional[int]:
							A						   =   OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint  ,provider='CPUExecutionProvider'      )
							A						   =   EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config      )
							pipe.set_progress_bar_config(disable=A_      )

							A						   =   self.get_dummy_inputs()
							A						   =   pipe(**A_      ).images
							A						   =   image[0, -3:, -3:, -1]

							assert image.shape == (1, 128, 128, 3)
							A						   =   np.array([0.5_29_11, 0.6_00_04, 0.4_92_29, 0.4_98_05, 0.5_45_02, 0.5_06_80, 0.4_77_77, 0.4_10_28, 0.4_53_04]      )

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




						def 						_SCREAMING_SNAKE_CASE      ( self     :      str      )     ->   Optional[Any]:
							A						   =   OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint  ,provider='CPUExecutionProvider'      )
							A						   =   DPMSolverMultistepScheduler.from_config(pipe.scheduler.config      )
							pipe.set_progress_bar_config(disable=A_      )

							A						   =   self.get_dummy_inputs()
							A						   =   pipe(**A_      ).images
							A						   =   image[0, -3:, -3:, -1]

							assert image.shape == (1, 128, 128, 3)
							A						   =   np.array([0.6_53_31, 0.5_82_77, 0.4_82_04, 0.5_60_59, 0.5_36_65, 0.5_62_35, 0.5_09_69, 0.4_00_09, 0.4_65_52]      )

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







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



						'''simple docstring'''


						@property
						def 						_SCREAMING_SNAKE_CASE      ( self     :      Any      )     ->   Union[str, Any]:
							return (
							    "CUDAExecutionProvider",
							    {
							        "gpu_mem_limit": "15000000000",  # 15GB
							        "arena_extend_strategy": "kSameAsRequested",
							    },
							)


						@property
						def 						_SCREAMING_SNAKE_CASE      ( self     :      Dict      )     ->   str:
							A						   =   ort.SessionOptions()
							A						   =   False
							return options


						def 						_SCREAMING_SNAKE_CASE      ( self     :      str      )     ->   Tuple:
							A						   =   load_image(
							    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
							    '/img2img/sketch-mountains-input.jpg'      )
							A						   =   init_image.resize((768, 512)      )
							# using the PNDM scheduler by default
							A						   =   OnnxStableDiffusionImgaImgPipeline.from_pretrained(
							    'CompVis/stable-diffusion-v1-4'  ,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 fantasy landscape, trending on artstation'

							A						   =   np.random.RandomState(0      )
							A						   =   pipe(
							    prompt=A_  ,image=A_  ,strength=0.75  ,guidance_scale=7.5  ,num_inference_steps=10  ,generator=A_  ,output_type='np'  ,)
							A						   =   output.images
							A						   =   images[0, 255:258, 383:386, -1]

							assert images.shape == (1, 512, 768, 3)
							A						   =   np.array([0.49_09, 0.50_59, 0.53_72, 0.46_23, 0.48_76, 0.50_49, 0.48_20, 0.49_56, 0.50_19]      )
							# TODO: lower the tolerance after finding the cause of onnxruntime reproducibility issues

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




						def 						_SCREAMING_SNAKE_CASE      ( self     :      Optional[Any]      )     ->   Any:
							A						   =   load_image(
							    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
							    '/img2img/sketch-mountains-input.jpg'      )
							A						   =   init_image.resize((768, 512)      )
							A						   =   LMSDiscreteScheduler.from_pretrained(
							    'runwayml/stable-diffusion-v1-5'  ,subfolder='scheduler'  ,revision='onnx'      )
							A						   =   OnnxStableDiffusionImgaImgPipeline.from_pretrained(
							    'runwayml/stable-diffusion-v1-5'  ,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 fantasy landscape, trending on artstation'

							A						   =   np.random.RandomState(0      )
							A						   =   pipe(
							    prompt=A_  ,image=A_  ,strength=0.75  ,guidance_scale=7.5  ,num_inference_steps=20  ,generator=A_  ,output_type='np'  ,)
							A						   =   output.images
							A						   =   images[0, 255:258, 383:386, -1]

							assert images.shape == (1, 512, 768, 3)
							A						   =   np.array([0.80_43, 0.9_26, 0.95_81, 0.81_19, 0.89_54, 0.9_13, 0.72_09, 0.74_63, 0.74_31]      )
							# TODO: lower the tolerance after finding the cause of onnxruntime reproducibility issues

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