


"""simple docstring"""



import inspect
import math
import tempfile
import unittest

import numpy as np

from transformers import ViTMAEConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
  import torch
  from torch import nn

  from transformers import ViTMAEForPreTraining, ViTMAEModel
  from transformers.models.vit.modeling_vit import VIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
  from PIL import Image

  from transformers import ViTImageProcessor







class _lowerCAmelCase				:







   def __init__(	self						,	UpperCamelCase__						,	UpperCamelCase__=13						,	UpperCamelCase__=30						,	UpperCamelCase__=2						,	UpperCamelCase__=3						,	UpperCamelCase__=True						,	UpperCamelCase__=True						,	UpperCamelCase__=32						,	UpperCamelCase__=5						,	UpperCamelCase__=4						,	UpperCamelCase__=37						,	UpperCamelCase__="gelu"						,	UpperCamelCase__=0.1						,	UpperCamelCase__=0.1						,	UpperCamelCase__=10						,	UpperCamelCase__=0.02						,	UpperCamelCase__=3						,	UpperCamelCase__=0.6						,	UpperCamelCase__=None						,	)	->		Optional[Any]:

       '''simple docstring'''




       snake_case    :      Any      					=    parent
       snake_case    :      List[Any]      					=    batch_size
       snake_case    :      Any      					=    image_size
       snake_case    :      Union[str, Any]      					=    patch_size
       snake_case    :      Any      					=    num_channels
       snake_case    :      Dict      					=    is_training
       snake_case    :      List[str]      					=    use_labels
       snake_case    :      int      					=    hidden_size
       snake_case    :      Union[str, Any]      					=    num_hidden_layers
       snake_case    :      Optional[int]      					=    num_attention_heads
       snake_case    :      Union[str, Any]      					=    intermediate_size
       snake_case    :      List[Any]      					=    hidden_act
       snake_case    :      int      					=    hidden_dropout_prob
       snake_case    :      Dict      					=    attention_probs_dropout_prob
       snake_case    :      List[str]      					=    type_sequence_label_size
       snake_case    :      Optional[Any]      					=    initializer_range
       snake_case    :      List[Any]      					=    mask_ratio
       snake_case    :      Dict      					=    scope

       # in ViTMAE, the expected sequence length = (num_patches + 1) * (1 - config.mask_ratio), rounded above
       # (we add 1 for the [CLS] token)
       snake_case    :      List[Any]      					=    (image_size // patch_size) ** 2
       snake_case    :      int      					=    int(math.ceil((1 - mask_ratio) * (num_patches + 1)						)						)







   def  lowerCamelCase		(	self						)	->		int:

       '''simple docstring'''




       snake_case    :      str      					=    floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

       snake_case    :      str      					=    None
       if self.use_labels:
           snake_case    :      Tuple      					=    ids_tensor([self.batch_size]						,	self.type_sequence_label_size						)

       snake_case    :      Optional[int]      					=    self.get_config()

       return config, pixel_values, labels







   def  lowerCamelCase		(	self						)	->		str:

       '''simple docstring'''




       return ViTMAEConfig(
           image_size=self.image_size						,	patch_size=self.patch_size						,	num_channels=self.num_channels						,	hidden_size=self.hidden_size						,	num_hidden_layers=self.num_hidden_layers						,	num_attention_heads=self.num_attention_heads						,	intermediate_size=self.intermediate_size						,	hidden_act=self.hidden_act						,	hidden_dropout_prob=self.hidden_dropout_prob						,	attention_probs_dropout_prob=self.attention_probs_dropout_prob						,	is_decoder=UpperCamelCase__						,	initializer_range=self.initializer_range						,	mask_ratio=self.mask_ratio						,	)







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

       '''simple docstring'''




       snake_case    :      Optional[int]      					=    ViTMAEModel(config=UpperCamelCase__						)
       model.to(UpperCamelCase__						)
       model.eval()
       snake_case    :      Dict      					=    model(UpperCamelCase__						)
       self.parent.assertEqual(result.last_hidden_state.shape						,	(self.batch_size, self.seq_length, self.hidden_size)						)







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

       '''simple docstring'''




       snake_case    :      Any      					=    ViTMAEForPreTraining(UpperCamelCase__						)
       model.to(UpperCamelCase__						)
       model.eval()
       snake_case    :      str      					=    model(UpperCamelCase__						)
       snake_case    :      Optional[int]      					=    (self.image_size // self.patch_size) ** 2
       snake_case    :      Any      					=    self.patch_size**2 * self.num_channels
       self.parent.assertEqual(result.logits.shape						,	(self.batch_size, num_patches, expected_num_channels)						)

       # test greyscale images
       snake_case    :      int      					=    1
       snake_case    :      int      					=    ViTMAEForPreTraining(UpperCamelCase__						)
       model.to(UpperCamelCase__						)
       model.eval()
       snake_case    :      Optional[int]      					=    floats_tensor([self.batch_size, 1, self.image_size, self.image_size]						)
       snake_case    :      int      					=    model(UpperCamelCase__						)
       snake_case    :      Union[str, Any]      					=    self.patch_size**2
       self.parent.assertEqual(result.logits.shape						,	(self.batch_size, num_patches, expected_num_channels)						)







   def  lowerCamelCase		(	self						)	->		Dict:

       '''simple docstring'''




       snake_case    :      Union[str, Any]      					=    self.prepare_config_and_inputs()
       snake_case					,snake_case					,snake_case    :      str      					=    config_and_inputs
       snake_case    :      Optional[Any]      					=    {"pixel_values": pixel_values}
       return config, inputs_dict







@require_torch
class _lowerCAmelCase				(      snake_case_    ,							snake_case_    ,							unittest.TestCase	):
   __UpperCAmelCase :       Tuple							  =  (ViTMAEModel, ViTMAEForPreTraining) if is_torch_available() else ()
   __UpperCAmelCase :       Any							  =  {'''feature-extraction''': ViTMAEModel} if is_torch_available() else {}

   __UpperCAmelCase :       Optional[Any]							  =  False
   __UpperCAmelCase :       List[str]							  =  False
   __UpperCAmelCase :       List[str]							  =  False
   __UpperCAmelCase :       Optional[Any]							  =  False







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

       '''simple docstring'''




       snake_case    :      Union[str, Any]      					=    ViTMAEModelTester(self						)
       snake_case    :      Union[str, Any]      					=    ConfigTester(self						,	config_class=UpperCamelCase__						,	has_text_modality=UpperCamelCase__						,	hidden_size=37						)







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

       '''simple docstring'''




       self.config_tester.run_common_tests()







   @unittest.skip(reason="ViTMAE does not use inputs_embeds"						)
   def  lowerCamelCase		(	self						)	->		Tuple:

       '''simple docstring'''




       pass







   def  lowerCamelCase		(	self						)	->		Any:

       '''simple docstring'''




       snake_case					,snake_case    :      List[str]      					=    self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
           snake_case    :      Union[str, Any]      					=    model_class(UpperCamelCase__						)
           self.assertIsInstance(model.get_input_embeddings()						,	(nn.Module)						)
           snake_case    :      Optional[Any]      					=    model.get_output_embeddings()
           self.assertTrue(x is None or isinstance(UpperCamelCase__						,	nn.Linear						)						)







   def  lowerCamelCase		(	self						)	->		int:

       '''simple docstring'''




       snake_case					,snake_case    :      List[Any]      					=    self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
           snake_case    :      int      					=    model_class(UpperCamelCase__						)
           snake_case    :      Optional[Any]      					=    inspect.signature(model.forward						)
           # signature.parameters is an OrderedDict => so arg_names order is deterministic
           snake_case    :      Dict      					=    [*signature.parameters.keys()]

           snake_case    :      List[str]      					=    ["pixel_values"]
           self.assertListEqual(arg_names[:1]						,	UpperCamelCase__						)







   def  lowerCamelCase		(	self						)	->		str:

       '''simple docstring'''




       snake_case    :      Tuple      					=    self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*UpperCamelCase__						)







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

       '''simple docstring'''




       snake_case    :      List[Any]      					=    self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_pretraining(*UpperCamelCase__						)







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

       '''simple docstring'''




       np.random.seed(2						)

       snake_case    :      Dict      					=    int((pt_model.config.image_size // pt_model.config.patch_size) ** 2						)
       snake_case    :      List[str]      					=    np.random.uniform(size=(self.model_tester.batch_size, num_patches)						)
       snake_case    :      Union[str, Any]      					=    torch.from_numpy(UpperCamelCase__						)

       # Add `noise` argument.
       # PT inputs will be prepared in `super().check_pt_tf_models()` with this added `noise` argument
       snake_case    :      List[str]      					=    pt_noise

       super().check_pt_tf_models(UpperCamelCase__						,	UpperCamelCase__						,	UpperCamelCase__						)







   def  lowerCamelCase		(	self						)	->		Tuple:

       '''simple docstring'''




       snake_case					,snake_case    :      Union[str, Any]      					=    self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
           snake_case    :      Tuple      					=    model_class(UpperCamelCase__						)
           model.to(UpperCamelCase__						)
           model.eval()
           # make random mask reproducible
           torch.manual_seed(2						)
           with torch.no_grad():
               snake_case    :      str      					=    model(**self._prepare_for_class(UpperCamelCase__						,	UpperCamelCase__						)						)

           snake_case    :      Tuple      					=    outputs[0].cpu().numpy()
           snake_case    :      Any      					=    0

           with tempfile.TemporaryDirectory() as tmpdirname:
               model.save_pretrained(UpperCamelCase__						)
               snake_case    :      List[str]      					=    model_class.from_pretrained(UpperCamelCase__						)
               model.to(UpperCamelCase__						)
               # make random mask reproducible
               torch.manual_seed(2						)
               with torch.no_grad():
                   snake_case    :      List[Any]      					=    model(**self._prepare_for_class(UpperCamelCase__						,	UpperCamelCase__						)						)

               # Make sure we don't have nans
               snake_case    :      int      					=    after_outputs[0].cpu().numpy()
               snake_case    :      Tuple      					=    0
               snake_case    :      List[Any]      					=    np.amax(np.abs(out_a - out_a						)						)
               self.assertLessEqual(UpperCamelCase__						,	1e-5						)







   @unittest.skip(
       reason="ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load\n    to get deterministic results."						)
   def  lowerCamelCase		(	self						)	->		int:

       '''simple docstring'''




       pass







   @unittest.skip(
       reason="ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load\n    to get deterministic results."						)
   def  lowerCamelCase		(	self						)	->		Optional[Any]:

       '''simple docstring'''




       pass







   @unittest.skip(
       reason="ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load\n    to get deterministic results."						)
   def  lowerCamelCase		(	self						)	->		Dict:

       '''simple docstring'''




       pass







   @unittest.skip(reason="ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load"						)
   def  lowerCamelCase		(	self						)	->		List[str]:

       '''simple docstring'''




       pass







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

       '''simple docstring'''




       pass







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

       '''simple docstring'''




       for model_name in VIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           snake_case    :      Optional[int]      					=    ViTMAEModel.from_pretrained(UpperCamelCase__						)
           self.assertIsNotNone(UpperCamelCase__						)







def   __lowerCAmelCase						(						)	->						List[str]:


    """simple docstring"""





    snake_case    :      Any      					=    Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png" )
    return image







@require_torch
@require_vision
class _lowerCAmelCase				(      unittest.TestCase	):







   @cached_property
   def  lowerCamelCase		(	self						)	->		int:

       '''simple docstring'''




       return ViTImageProcessor.from_pretrained("facebook/vit-mae-base"						) if is_vision_available() else None







   @slow
   def  lowerCamelCase		(	self						)	->		int:

       '''simple docstring'''




       np.random.seed(2						)

       snake_case    :      int      					=    ViTMAEForPreTraining.from_pretrained("facebook/vit-mae-base"						).to(UpperCamelCase__						)

       snake_case    :      int      					=    self.default_image_processor
       snake_case    :      int      					=    prepare_img()
       snake_case    :      Union[str, Any]      					=    image_processor(images=UpperCamelCase__						,	return_tensors="pt"						).to(UpperCamelCase__						)

       # prepare a noise vector that will be also used for testing the TF model
       # (this way we can ensure that the PT and TF models operate on the same inputs)
       snake_case    :      List[Any]      					=    ViTMAEConfig()
       snake_case    :      List[Any]      					=    int((vit_mae_config.image_size // vit_mae_config.patch_size) ** 2						)
       snake_case    :      str      					=    np.random.uniform(size=(1, num_patches)						)

       # forward pass
       with torch.no_grad():
           snake_case    :      List[Any]      					=    model(**UpperCamelCase__						,	noise=torch.from_numpy(UpperCamelCase__						).to(device=UpperCamelCase__						)						)

       # verify the logits
       snake_case    :      Optional[int]      					=    torch.Size((1, 196, 768)						)
       self.assertEqual(outputs.logits.shape						,	UpperCamelCase__						)

       snake_case    :      Optional[int]      					=    torch.tensor(
           [[-0.0548, -1.7023, -0.9325], [0.3721, -0.5670, -0.2233], [0.8235, -1.3878, -0.3524]]						)

       self.assertTrue(torch.allclose(outputs.logits[0, :3, :3]						,	expected_slice.to(UpperCamelCase__						)						,	atol=1e-4						)						)









"""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





