


"""simple docstring"""



import gc
import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    PNDMScheduler,
    StableDiffusionLDMaDPipeline,
    UNetaDConditionModel,
)
from diffusers.utils import nightly, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu

from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS


enable_full_determinism()







class _lowerCAmelCase				(      unittest.TestCase	):
   __UpperCAmelCase :       Tuple							  =  StableDiffusionLDMaDPipeline
   __UpperCAmelCase :       List[Any]							  =  TEXT_TO_IMAGE_PARAMS
   __UpperCAmelCase :       Optional[int]							  =  TEXT_TO_IMAGE_BATCH_PARAMS
   __UpperCAmelCase :       int							  =  TEXT_TO_IMAGE_IMAGE_PARAMS







   def  lowerCamelCase		(	self						)	->		Tuple:

       '''simple docstring'''




       torch.manual_seed(0						)
       snake_case    :      int      					=    UNetaDConditionModel(
           block_out_channels=(32, 64)						,	layers_per_block=2						,	sample_size=32						,	in_channels=4						,	out_channels=4						,	down_block_types=("DownBlock2D", "CrossAttnDownBlock2D")						,	up_block_types=("CrossAttnUpBlock2D", "UpBlock2D")						,	cross_attention_dim=32						,	)
       snake_case    :      Tuple      					=    DDIMScheduler(
           beta_start=0.00085						,	beta_end=0.012						,	beta_schedule="scaled_linear"						,	clip_sample=UpperCamelCase__						,	set_alpha_to_one=UpperCamelCase__						,	)
       torch.manual_seed(0						)
       snake_case    :      Tuple      					=    AutoencoderKL(
           block_out_channels=[32, 64]						,	in_channels=6						,	out_channels=6						,	down_block_types=["DownEncoderBlock2D", "DownEncoderBlock2D"]						,	up_block_types=["UpDecoderBlock2D", "UpDecoderBlock2D"]						,	latent_channels=4						,	)
       torch.manual_seed(0						)
       snake_case    :      Tuple      					=    CLIPTextConfig(
           bos_token_id=0						,	eos_token_id=2						,	hidden_size=32						,	intermediate_size=37						,	layer_norm_eps=1e-05						,	num_attention_heads=4						,	num_hidden_layers=5						,	pad_token_id=1						,	vocab_size=1000						,	)
       snake_case    :      str      					=    CLIPTextModel(UpperCamelCase__						)
       snake_case    :      str      					=    CLIPTokenizer.from_pretrained("hf-internal-testing/tiny-random-clip"						)

       snake_case    :      int      					=    {
           "unet": unet,
           "scheduler": scheduler,
           "vae": vae,
           "text_encoder": text_encoder,
           "tokenizer": tokenizer,
           "safety_checker": None,
           "feature_extractor": None,
       }
       return components







   def  lowerCamelCase		(	self						,	UpperCamelCase__						,	UpperCamelCase__=0						)	->		int:

       '''simple docstring'''




       if str(UpperCamelCase__						).startswith("mps"						):
           snake_case    :      List[Any]      					=    torch.manual_seed(UpperCamelCase__						)
       else:
           snake_case    :      Any      					=    torch.Generator(device=UpperCamelCase__						).manual_seed(UpperCamelCase__						)
       snake_case    :      int      					=    {
           "prompt": "A painting of a squirrel eating a burger",
           "generator": generator,
           "num_inference_steps": 2,
           "guidance_scale": 6.0,
           "output_type": "numpy",
       }
       return inputs







   def  lowerCamelCase		(	self						)	->		List[str]:

       '''simple docstring'''




       snake_case    :      List[Any]      					=    "cpu"  # ensure determinism for the device-dependent torch.Generator

       snake_case    :      int      					=    self.get_dummy_components()
       snake_case    :      int      					=    StableDiffusionLDMaDPipeline(**UpperCamelCase__						)
       snake_case    :      Optional[int]      					=    ldmad_pipe.to(UpperCamelCase__						)
       ldmad_pipe.set_progress_bar_config(disable=UpperCamelCase__						)

       snake_case    :      Any      					=    self.get_dummy_inputs(UpperCamelCase__						)
       snake_case    :      Any      					=    ldmad_pipe(**UpperCamelCase__						)
       snake_case					,snake_case    :      Dict      					=    output.rgb, output.depth

       snake_case    :      Any      					=    rgb[0, -3:, -3:, -1]
       snake_case    :      str      					=    depth[0, -3:, -1]

       assert rgb.shape == (1, 64, 64, 3)
       assert depth.shape == (1, 64, 64)

       snake_case    :      str      					=    np.array(
           [0.37338176, 0.70247, 0.74203193, 0.51643604, 0.58256793, 0.60932136, 0.4181095, 0.48355877, 0.46535262]						)
       snake_case    :      Optional[Any]      					=    np.array([103.46727, 85.812004, 87.849236]						)

       assert np.abs(image_slice_rgb.flatten() - expected_slice_rgb						).max() < 1e-2
       assert np.abs(image_slice_depth.flatten() - expected_slice_depth						).max() < 1e-2







   def  lowerCamelCase		(	self						)	->		List[Any]:

       '''simple docstring'''




       snake_case    :      Optional[Any]      					=    self.get_dummy_components()
       snake_case    :      List[str]      					=    StableDiffusionLDMaDPipeline(**UpperCamelCase__						)
       snake_case    :      int      					=    ldmad_pipe.to(UpperCamelCase__						)
       ldmad_pipe.set_progress_bar_config(disable=UpperCamelCase__						)

       snake_case    :      Optional[int]      					=    self.get_dummy_inputs(UpperCamelCase__						)
       snake_case    :      Dict      					=    3 * [inputs["prompt"]]

       # forward
       snake_case    :      str      					=    ldmad_pipe(**UpperCamelCase__						)
       snake_case					,snake_case    :      Any      					=    output.rgb, output.depth
       snake_case    :      str      					=    rgb_slice_a[0, -3:, -3:, -1]
       snake_case    :      Tuple      					=    depth_slice_a[0, -3:, -1]

       snake_case    :      str      					=    self.get_dummy_inputs(UpperCamelCase__						)
       snake_case    :      Optional[Any]      					=    3 * [inputs.pop("prompt"						)]

       snake_case    :      List[str]      					=    ldmad_pipe.tokenizer(
           UpperCamelCase__						,	padding="max_length"						,	max_length=ldmad_pipe.tokenizer.model_max_length						,	truncation=UpperCamelCase__						,	return_tensors="pt"						,	)
       snake_case    :      str      					=    text_inputs["input_ids"].to(UpperCamelCase__						)

       snake_case    :      Tuple      					=    ldmad_pipe.text_encoder(UpperCamelCase__						)[0]

       snake_case    :      str      					=    prompt_embeds

       # forward
       snake_case    :      List[str]      					=    ldmad_pipe(**UpperCamelCase__						)
       snake_case					,snake_case    :      str      					=    output.rgb, output.depth
       snake_case    :      Optional[Any]      					=    rgb_slice_a[0, -3:, -3:, -1]
       snake_case    :      Optional[int]      					=    depth_slice_a[0, -3:, -1]

       assert np.abs(rgb_slice_a.flatten() - rgb_slice_a.flatten()						).max() < 1e-4
       assert np.abs(depth_slice_a.flatten() - depth_slice_a.flatten()						).max() < 1e-4







   def  lowerCamelCase		(	self						)	->		Tuple:

       '''simple docstring'''




       snake_case    :      List[str]      					=    "cpu"  # ensure determinism for the device-dependent torch.Generator
       snake_case    :      Optional[int]      					=    self.get_dummy_components()
       snake_case    :      List[str]      					=    PNDMScheduler(skip_prk_steps=UpperCamelCase__						)
       snake_case    :      Optional[Any]      					=    StableDiffusionLDMaDPipeline(**UpperCamelCase__						)
       snake_case    :      Tuple      					=    ldmad_pipe.to(UpperCamelCase__						)
       ldmad_pipe.set_progress_bar_config(disable=UpperCamelCase__						)

       snake_case    :      Any      					=    self.get_dummy_inputs(UpperCamelCase__						)
       snake_case    :      str      					=    "french fries"
       snake_case    :      Union[str, Any]      					=    ldmad_pipe(**UpperCamelCase__						,	negative_prompt=UpperCamelCase__						)

       snake_case					,snake_case    :      str      					=    output.rgb, output.depth
       snake_case    :      List[Any]      					=    rgb[0, -3:, -3:, -1]
       snake_case    :      Tuple      					=    depth[0, -3:, -1]

       assert rgb.shape == (1, 64, 64, 3)
       assert depth.shape == (1, 64, 64)

       snake_case    :      List[Any]      					=    np.array(
           [0.37044, 0.71811503, 0.7223251, 0.48603675, 0.5638391, 0.6364948, 0.42833704, 0.4901315, 0.47926217]						)
       snake_case    :      str      					=    np.array([107.84738, 84.62802, 89.962135]						)
       assert np.abs(rgb_slice.flatten() - expected_slice_rgb						).max() < 1e-2
       assert np.abs(depth_slice.flatten() - expected_slice_depth						).max() < 1e-2







@slow
@require_torch_gpu
class _lowerCAmelCase				(      unittest.TestCase	):







   def  lowerCamelCase		(	self						)	->		str:

       '''simple docstring'''




       super().tearDown()
       gc.collect()
       torch.cuda.empty_cache()







   def  lowerCamelCase		(	self						,	UpperCamelCase__						,	UpperCamelCase__="cpu"						,	UpperCamelCase__=torch.floataa						,	UpperCamelCase__=0						)	->		List[str]:

       '''simple docstring'''




       snake_case    :      Any      					=    torch.Generator(device=UpperCamelCase__						).manual_seed(UpperCamelCase__						)
       snake_case    :      Dict      					=    np.random.RandomState(UpperCamelCase__						).standard_normal((1, 4, 64, 64)						)
       snake_case    :      Any      					=    torch.from_numpy(UpperCamelCase__						).to(device=UpperCamelCase__						,	dtype=UpperCamelCase__						)
       snake_case    :      List[Any]      					=    {
           "prompt": "a photograph of an astronaut riding a horse",
           "latents": latents,
           "generator": generator,
           "num_inference_steps": 3,
           "guidance_scale": 7.5,
           "output_type": "numpy",
       }
       return inputs







   def  lowerCamelCase		(	self						)	->		List[Any]:

       '''simple docstring'''




       snake_case    :      Tuple      					=    StableDiffusionLDMaDPipeline.from_pretrained("Intel/ldm3d"						)
       snake_case    :      List[Any]      					=    ldmad_pipe.to(UpperCamelCase__						)
       ldmad_pipe.set_progress_bar_config(disable=UpperCamelCase__						)

       snake_case    :      int      					=    self.get_inputs(UpperCamelCase__						)
       snake_case    :      Any      					=    ldmad_pipe(**UpperCamelCase__						)
       snake_case					,snake_case    :      Optional[Any]      					=    output.rgb, output.depth
       snake_case    :      List[str]      					=    rgb[0, -3:, -3:, -1].flatten()
       snake_case    :      Optional[int]      					=    rgb[0, -3:, -1].flatten()

       assert rgb.shape == (1, 512, 512, 3)
       assert depth.shape == (1, 512, 512)

       snake_case    :      str      					=    np.array(
           [0.53805465, 0.56707305, 0.5486515, 0.57012236, 0.5814511, 0.56253487, 0.54843014, 0.55092263, 0.6459706]						)
       snake_case    :      List[Any]      					=    np.array(
           [0.9263781, 0.6678672, 0.5486515, 0.92202145, 0.67831135, 0.56253487, 0.9241694, 0.7551478, 0.6459706]						)
       assert np.abs(rgb_slice - expected_slice_rgb						).max() < 3e-3
       assert np.abs(depth_slice - expected_slice_depth						).max() < 3e-3







@nightly
@require_torch_gpu
class _lowerCAmelCase				(      unittest.TestCase	):







   def  lowerCamelCase		(	self						)	->		str:

       '''simple docstring'''




       super().tearDown()
       gc.collect()
       torch.cuda.empty_cache()







   def  lowerCamelCase		(	self						,	UpperCamelCase__						,	UpperCamelCase__="cpu"						,	UpperCamelCase__=torch.floataa						,	UpperCamelCase__=0						)	->		Optional[Any]:

       '''simple docstring'''




       snake_case    :      Tuple      					=    torch.Generator(device=UpperCamelCase__						).manual_seed(UpperCamelCase__						)
       snake_case    :      List[Any]      					=    np.random.RandomState(UpperCamelCase__						).standard_normal((1, 4, 64, 64)						)
       snake_case    :      int      					=    torch.from_numpy(UpperCamelCase__						).to(device=UpperCamelCase__						,	dtype=UpperCamelCase__						)
       snake_case    :      Optional[int]      					=    {
           "prompt": "a photograph of an astronaut riding a horse",
           "latents": latents,
           "generator": generator,
           "num_inference_steps": 50,
           "guidance_scale": 7.5,
           "output_type": "numpy",
       }
       return inputs







   def  lowerCamelCase		(	self						)	->		Any:

       '''simple docstring'''




       snake_case    :      Union[str, Any]      					=    StableDiffusionLDMaDPipeline.from_pretrained("Intel/ldm3d"						).to(UpperCamelCase__						)
       ldmad_pipe.set_progress_bar_config(disable=UpperCamelCase__						)

       snake_case    :      Any      					=    self.get_inputs(UpperCamelCase__						)
       snake_case    :      List[str]      					=    ldmad_pipe(**UpperCamelCase__						)
       snake_case					,snake_case    :      List[Any]      					=    output.rgb, output.depth

       snake_case    :      int      					=    0.495586
       snake_case    :      Optional[Any]      					=    0.33795515
       snake_case    :      List[str]      					=    112.48518
       snake_case    :      List[Any]      					=    98.489746
       assert np.abs(expected_rgb_mean - rgb.mean()						) < 1e-3
       assert np.abs(expected_rgb_std - rgb.std()						) < 1e-3
       assert np.abs(expected_depth_mean - depth.mean()						) < 1e-3
       assert np.abs(expected_depth_std - depth.std()						) < 1e-3







   def  lowerCamelCase		(	self						)	->		List[Any]:

       '''simple docstring'''




       snake_case    :      Tuple      					=    StableDiffusionLDMaDPipeline.from_pretrained("Intel/ldm3d-4c"						).to(UpperCamelCase__						)
       ldmad_pipe.set_progress_bar_config(disable=UpperCamelCase__						)

       snake_case    :      int      					=    self.get_inputs(UpperCamelCase__						)
       snake_case    :      str      					=    ldmad_pipe(**UpperCamelCase__						)
       snake_case					,snake_case    :      Any      					=    output.rgb, output.depth

       snake_case    :      Any      					=    0.4194127
       snake_case    :      str      					=    0.35375586
       snake_case    :      Dict      					=    0.5638502
       snake_case    :      int      					=    0.34686103

       assert rgb.shape == (1, 512, 512, 3)
       assert depth.shape == (1, 512, 512, 1)
       assert np.abs(expected_rgb_mean - rgb.mean()						) < 1e-3
       assert np.abs(expected_rgb_std - rgb.std()						) < 1e-3
       assert np.abs(expected_depth_mean - depth.mean()						) < 1e-3
       assert np.abs(expected_depth_std - depth.std()						) < 1e-3









"""simple docstring"""



import random
import unittest

import numpy as np
import torch

from diffusers import (
    DPMSolverMultistepScheduler,
    EulerAncestralDiscreteScheduler,
    EulerDiscreteScheduler,
    LMSDiscreteScheduler,
    OnnxStableDiffusionUpscalePipeline,
    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				(      snake_case_    ,							unittest.TestCase	):
   # TODO: is there an appropriate internal test set?
   __UpperCAmelCase :       Optional[Any]							  =  '''ssube/stable-diffusion-x4-upscaler-onnx'''







   def  lowerCamelCase		(	self						,	UpperCamelCase__=0						)	->		Tuple:

       '''simple docstring'''




       snake_case    :      Union[str, Any]      					=    floats_tensor((1, 3, 128, 128)						,	rng=random.Random(UpperCamelCase__						)						)
       snake_case    :      Any      					=    torch.manual_seed(UpperCamelCase__						)
       snake_case    :      List[str]      					=    {
           "prompt": "A painting of a squirrel eating a burger",
           "image": image,
           "generator": generator,
           "num_inference_steps": 3,
           "guidance_scale": 7.5,
           "output_type": "numpy",
       }
       return inputs







   def  lowerCamelCase		(	self						)	->		Tuple:

       '''simple docstring'''




       snake_case    :      Optional[Any]      					=    OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint						,	provider="CPUExecutionProvider"						)
       pipe.set_progress_bar_config(disable=UpperCamelCase__						)

       snake_case    :      Tuple      					=    self.get_dummy_inputs()
       snake_case    :      int      					=    pipe(**UpperCamelCase__						).images
       snake_case    :      Tuple      					=    image[0, -3:, -3:, -1].flatten()

       # started as 128, should now be 512
       assert image.shape == (1, 512, 512, 3)
       snake_case    :      Optional[int]      					=    np.array(
           [0.6974782, 0.68902093, 0.70135885, 0.7583618, 0.7804545, 0.7854912, 0.78667426, 0.78743863, 0.78070223]						)
       assert np.abs(image_slice - expected_slice						).max() < 1e-1







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

       '''simple docstring'''




       snake_case    :      Tuple      					=    OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint						,	provider="CPUExecutionProvider"						)
       snake_case    :      Optional[Any]      					=    PNDMScheduler.from_config(pipe.scheduler.config						,	skip_prk_steps=UpperCamelCase__						)
       pipe.set_progress_bar_config(disable=UpperCamelCase__						)

       snake_case    :      Tuple      					=    self.get_dummy_inputs()
       snake_case    :      Optional[Any]      					=    pipe(**UpperCamelCase__						).images
       snake_case    :      List[str]      					=    image[0, -3:, -3:, -1]

       assert image.shape == (1, 512, 512, 3)
       snake_case    :      Dict      					=    np.array(
           [0.6898892, 0.59240556, 0.52499527, 0.58866215, 0.52258235, 0.52572715, 0.62414473, 0.6174387, 0.6214964]						)
       assert np.abs(image_slice.flatten() - expected_slice						).max() < 1e-1







   def  lowerCamelCase		(	self						)	->		Any:

       '''simple docstring'''




       snake_case    :      Optional[int]      					=    OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint						,	provider="CPUExecutionProvider"						)
       snake_case    :      Optional[Any]      					=    DPMSolverMultistepScheduler.from_config(pipe.scheduler.config						)
       pipe.set_progress_bar_config(disable=UpperCamelCase__						)

       snake_case    :      Any      					=    self.get_dummy_inputs()
       snake_case    :      List[Any]      					=    pipe(**UpperCamelCase__						).images
       snake_case    :      List[str]      					=    image[0, -3:, -3:, -1]

       assert image.shape == (1, 512, 512, 3)
       snake_case    :      Optional[Any]      					=    np.array(
           [0.7659278, 0.76437664, 0.75579107, 0.7691116, 0.77666986, 0.7727672, 0.7758664, 0.7812226, 0.76942515]						)

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







   def  lowerCamelCase		(	self						)	->		Any:

       '''simple docstring'''




       snake_case    :      Union[str, Any]      					=    OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint						,	provider="CPUExecutionProvider"						)
       snake_case    :      Any      					=    EulerDiscreteScheduler.from_config(pipe.scheduler.config						)
       pipe.set_progress_bar_config(disable=UpperCamelCase__						)

       snake_case    :      Dict      					=    self.get_dummy_inputs()
       snake_case    :      Union[str, Any]      					=    pipe(**UpperCamelCase__						).images
       snake_case    :      str      					=    image[0, -3:, -3:, -1]

       assert image.shape == (1, 512, 512, 3)
       snake_case    :      Union[str, Any]      					=    np.array(
           [0.6974782, 0.68902093, 0.70135885, 0.7583618, 0.7804545, 0.7854912, 0.78667426, 0.78743863, 0.78070223]						)
       assert np.abs(image_slice.flatten() - expected_slice						).max() < 1e-1







   def  lowerCamelCase		(	self						)	->		str:

       '''simple docstring'''




       snake_case    :      Optional[Any]      					=    OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint						,	provider="CPUExecutionProvider"						)
       snake_case    :      Optional[Any]      					=    EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config						)
       pipe.set_progress_bar_config(disable=UpperCamelCase__						)

       snake_case    :      Any      					=    self.get_dummy_inputs()
       snake_case    :      int      					=    pipe(**UpperCamelCase__						).images
       snake_case    :      List[Any]      					=    image[0, -3:, -3:, -1]

       assert image.shape == (1, 512, 512, 3)
       snake_case    :      Union[str, Any]      					=    np.array(
           [0.77424496, 0.773601, 0.7645288, 0.7769598, 0.7772739, 0.7738688, 0.78187233, 0.77879584, 0.767043]						)

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







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







   @property
   def  lowerCamelCase		(	self						)	->		Tuple:

       '''simple docstring'''




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







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

       '''simple docstring'''




       snake_case    :      List[Any]      					=    ort.SessionOptions()
       snake_case    :      str      					=    False
       return options







   def  lowerCamelCase		(	self						)	->		List[Any]:

       '''simple docstring'''




       snake_case    :      str      					=    load_image(
           "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
           "/img2img/sketch-mountains-input.jpg"						)
       snake_case    :      Tuple      					=    init_image.resize((128, 128)						)
       # using the PNDM scheduler by default
       snake_case    :      Tuple      					=    OnnxStableDiffusionUpscalePipeline.from_pretrained(
           "ssube/stable-diffusion-x4-upscaler-onnx"						,	provider=self.gpu_provider						,	sess_options=self.gpu_options						,	)
       pipe.set_progress_bar_config(disable=UpperCamelCase__						)

       snake_case    :      List[Any]      					=    "A fantasy landscape, trending on artstation"

       snake_case    :      Union[str, Any]      					=    torch.manual_seed(0						)
       snake_case    :      int      					=    pipe(
           prompt=UpperCamelCase__						,	image=UpperCamelCase__						,	guidance_scale=7.5						,	num_inference_steps=10						,	generator=UpperCamelCase__						,	output_type="np"						,	)
       snake_case    :      str      					=    output.images
       snake_case    :      Tuple      					=    images[0, 255:258, 383:386, -1]

       assert images.shape == (1, 512, 512, 3)
       snake_case    :      int      					=    np.array([0.4883, 0.4947, 0.4980, 0.4975, 0.4982, 0.4980, 0.5000, 0.5006, 0.4972]						)
       # TODO: lower the tolerance after finding the cause of onnxruntime reproducibility issues

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







   def  lowerCamelCase		(	self						)	->		Optional[Any]:

       '''simple docstring'''




       snake_case    :      Tuple      					=    load_image(
           "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
           "/img2img/sketch-mountains-input.jpg"						)
       snake_case    :      Optional[Any]      					=    init_image.resize((128, 128)						)
       snake_case    :      Union[str, Any]      					=    LMSDiscreteScheduler.from_pretrained(
           "ssube/stable-diffusion-x4-upscaler-onnx"						,	subfolder="scheduler"						)
       snake_case    :      List[Any]      					=    OnnxStableDiffusionUpscalePipeline.from_pretrained(
           "ssube/stable-diffusion-x4-upscaler-onnx"						,	scheduler=UpperCamelCase__						,	provider=self.gpu_provider						,	sess_options=self.gpu_options						,	)
       pipe.set_progress_bar_config(disable=UpperCamelCase__						)

       snake_case    :      Union[str, Any]      					=    "A fantasy landscape, trending on artstation"

       snake_case    :      Tuple      					=    torch.manual_seed(0						)
       snake_case    :      str      					=    pipe(
           prompt=UpperCamelCase__						,	image=UpperCamelCase__						,	guidance_scale=7.5						,	num_inference_steps=20						,	generator=UpperCamelCase__						,	output_type="np"						,	)
       snake_case    :      List[Any]      					=    output.images
       snake_case    :      List[Any]      					=    images[0, 255:258, 383:386, -1]

       assert images.shape == (1, 512, 512, 3)
       snake_case    :      int      					=    np.array(
           [0.50173753, 0.50223356, 0.502039, 0.50233036, 0.5023725, 0.5022601, 0.5018758, 0.50234085, 0.50241566]						)
       # TODO: lower the tolerance after finding the cause of onnxruntime reproducibility issues

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





