



"""simple docstring"""







import gc
import importlib.metadata
import tempfile
import unittest

from packaging import version

from transformers import (
    AutoModel,
    AutoModelForCausalLM,
    AutoModelForSeqaSeqLM,
    AutoModelForSequenceClassification,
    AutoTokenizer,
    BitsAndBytesConfig,
    pipeline,
)
from transformers.testing_utils import (
    is_torch_available,
    require_accelerate,
    require_bitsandbytes,
    require_torch,
    require_torch_gpu,
    require_torch_multi_gpu,
    slow,
)

def   lowerCAmelCase__			(     lowerCamelCase__			) ->							Optional[Any]:
							if model.config.model_type == "gpt2":
														return model.transformer.h[0].mlp.c_fc
							return model.transformer.h[0].mlp.dense_ah_to_h


if is_torch_available():
							import torch
							import torch.nn as nn






							class      UpperCAmelCase__		(      nn.Module     ):



									def __init__( self  :    str      ,							snake_case  :    nn.Module      ,							snake_case  :    int				)			->						str:






																'''simple docstring'''

																super().__init__()
																A         =					module
																A         =					nn.Sequential(
																    nn.Linear(module.in_features      ,							snake_case      ,							bias=snake_case				)      ,							nn.Linear(snake_case      ,							module.out_features      ,							bias=snake_case				)      ,							)
																A         =					(2.0 / (5 * min(module.in_features      ,							module.out_features				))) ** 0.5
																nn.init.normal_(self.adapter[0].weight      ,							std=snake_case				)
																nn.init.zeros_(self.adapter[1].weight				)
																self.adapter.to(module.weight.device				)



									def 					A_		( self  :    Optional[Any]      ,							snake_case  :    List[Any]      ,							*snake_case  :    Optional[int]      ,							**snake_case  :    Dict				)			->						str:






																'''simple docstring'''

																return self.module(snake_case      ,							*snake_case      ,							**snake_case				) + self.adapter(snake_case				)






@require_bitsandbytes
@require_accelerate
@require_torch
@require_torch_gpu
@slow
class      UpperCAmelCase__		(      unittest.TestCase     ):
		# We keep the constants inside the init function and model loading inside setUp function

		# We need to test on relatively large models (aka >1b parameters otherwise the quantiztion may not work as expected)
		# Therefore here we use only bloom-1b3 to test our module
		lowerCAmelCase_       :	List[Any] 							=     """bigscience/bloom-1b7"""

		# Constant values
		lowerCAmelCase_       :	int 							=     2.109_6595_5269_2574

		lowerCAmelCase_       :	Optional[Any] 							=     """Hello my name is"""
		lowerCAmelCase_       :	Optional[int] 							=     set()
		EXPECTED_OUTPUTS.add("""Hello my name is John and I am a professional photographer. I"""     )
		EXPECTED_OUTPUTS.add("""Hello my name is John.\nI am a friend of your father.\n"""     )
		EXPECTED_OUTPUTS.add("""Hello my name is John Doe, I am a student at the University"""     )
		lowerCAmelCase_       :	Optional[int] 							=     10



		def 					A_		( self  :    Any				)			->						Dict:






									'''simple docstring'''

									A         =					AutoTokenizer.from_pretrained(self.model_name				)






class      UpperCAmelCase__		(      UpperCamelCase     ):



		def 					A_		( self  :    List[str]				)			->						int:






									'''simple docstring'''

									super().setUp()

									# Models and tokenizer
									A         =					AutoModelForCausalLM.from_pretrained(
									    self.model_name      ,							torch_dtype=torch.floataa      ,							device_map='auto'				)
									A         =					AutoModelForCausalLM.from_pretrained(self.model_name      ,							load_in_abit=snake_case      ,							device_map='auto'				)



		def 					A_		( self  :    Any				)			->						Tuple:






									'''simple docstring'''

									del self.model_fpaa
									del self.model_abit

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



		def 					A_		( self  :    str				)			->						Any:






									'''simple docstring'''

									A         =					self.model_abit.config

									self.assertTrue(hasattr(snake_case      ,							'quantization_config'				)				)

									A         =					config.to_dict()
									A         =					config.to_diff_dict()

									A         =					config.to_json_string()



		def 					A_		( self  :    str				)			->						Dict:






									'''simple docstring'''

									from bitsandbytes.nn import Paramsabit

									A         =					self.model_fpaa.get_memory_footprint()
									A         =					self.model_abit.get_memory_footprint()

									self.assertAlmostEqual(mem_fpaa / mem_abit      ,							self.EXPECTED_RELATIVE_DIFFERENCE				)
									A         =					get_some_linear_layer(self.model_abit				)
									self.assertTrue(linear.weight.__class__ == Paramsabit				)



		def 					A_		( self  :    Tuple				)			->						Any:






									'''simple docstring'''

									from transformers import TaPreTrainedModel

									self.model_fpaa.get_memory_footprint()
									self.model_abit.get_memory_footprint()

									for name, module in self.model_abit.named_modules():
																if isinstance(snake_case      ,							torch.nn.Linear				):
																							if name not in ["lm_head"] + TaPreTrainedModel._keep_in_fpaa_modules:
																														# 4-bit parameters are packed in uint8 variables
																														self.assertTrue(module.weight.dtype == torch.uinta				)



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






									'''simple docstring'''

									A         =					self.tokenizer(self.input_text      ,							return_tensors='pt'				)
									A         =					self.model_abit.generate(input_ids=encoded_input['input_ids'].to(0				)      ,							max_new_tokens=10				)

									self.assertIn(self.tokenizer.decode(output_sequences[0]      ,							skip_special_tokens=snake_case				)      ,							self.EXPECTED_OUTPUTS				)



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






									'''simple docstring'''

									A         =					BitsAndBytesConfig()
									A         =					True

									A         =					AutoModelForCausalLM.from_pretrained(
									    self.model_name      ,							quantization_config=snake_case      ,							device_map='auto'				)

									A         =					self.tokenizer(self.input_text      ,							return_tensors='pt'				)
									A         =					model_abit_from_config.generate(
									    input_ids=encoded_input['input_ids'].to(0				)      ,							max_new_tokens=10				)

									self.assertIn(self.tokenizer.decode(output_sequences[0]      ,							skip_special_tokens=snake_case				)      ,							self.EXPECTED_OUTPUTS				)



		def 					A_		( self  :    Any				)			->						List[str]:






									'''simple docstring'''

									with self.assertRaises(snake_case				), tempfile.TemporaryDirectory() as tmpdirname:
																self.model_abit.save_pretrained(snake_case				)



		def 					A_		( self  :    str				)			->						str:






									'''simple docstring'''

									A         =					BitsAndBytesConfig()

									with self.assertRaises(snake_case				):
																A         =					AutoModelForCausalLM.from_pretrained(
																    self.model_name      ,							quantization_config=snake_case      ,							load_in_abit=snake_case      ,							device_map='auto'      ,							bnb_abit_quant_type='nf4'      ,							)



		def 					A_		( self  :    List[str]				)			->						Dict:






									'''simple docstring'''

									with self.assertRaises(snake_case				):
																# Tries with `str`
																self.model_abit.to('cpu'				)

									with self.assertRaises(snake_case				):
																# Tries with a `dtype``
																self.model_abit.to(torch.floataa				)

									with self.assertRaises(snake_case				):
																# Tries with a `device`
																self.model_abit.to(torch.device('cuda:0'				)				)

									with self.assertRaises(snake_case				):
																# Tries with a `device`
																self.model_abit.float()

									with self.assertRaises(snake_case				):
																# Tries with a `device`
																self.model_abit.half()

									# Test if we did not break anything
									A         =					self.tokenizer(self.input_text      ,							return_tensors='pt'				)

									A         =					self.model_fpaa.to(torch.floataa				)
									A         =					self.model_fpaa.generate(input_ids=encoded_input['input_ids'].to(0				)      ,							max_new_tokens=10				)

									# Check this does not throw an error
									A         =					self.model_fpaa.to('cpu'				)

									# Check this does not throw an error
									A         =					self.model_fpaa.half()

									# Check this does not throw an error
									A         =					self.model_fpaa.float()



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






									'''simple docstring'''

									A         =					AutoModelForSeqaSeqLM.from_pretrained('t5-small'      ,							load_in_abit=snake_case      ,							device_map='auto'				)
									self.assertTrue(model.decoder.block[0].layer[2].DenseReluDense.wo.weight.dtype == torch.floataa				)






@require_bitsandbytes
@require_accelerate
@require_torch
@require_torch_gpu
@slow
class      UpperCAmelCase__		(      unittest.TestCase     ):



		@classmethod
		def 					A_		( cls  :    Dict				)			->						Any:






									'''simple docstring'''

									A         =					't5-small'
									A         =					'google/flan-t5-small'  # flan-t5 uses dense-act instead of dense-relu-dense
									A         =					AutoTokenizer.from_pretrained(cls.model_name				)
									A         =					'Translate in German: Hello, my dog is cute'



		def 					A_		( self  :    List[Any]				)			->						List[str]:






									'''simple docstring'''

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



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






									'''simple docstring'''

									from transformers import TaForConditionalGeneration

									A         =					TaForConditionalGeneration._keep_in_fpaa_modules
									A         =					None

									# test with `t5-small`
									A         =					TaForConditionalGeneration.from_pretrained(self.model_name      ,							load_in_abit=snake_case      ,							device_map='auto'				)
									A         =					self.tokenizer(self.input_text      ,							return_tensors='pt'				).to(0				)
									A         =					model.generate(**snake_case				)

									# test with `flan-t5-small`
									A         =					TaForConditionalGeneration.from_pretrained(
									    self.dense_act_model_name      ,							load_in_abit=snake_case      ,							device_map='auto'				)
									A         =					self.tokenizer(self.input_text      ,							return_tensors='pt'				).to(0				)
									A         =					model.generate(**snake_case				)
									A         =					modules



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






									'''simple docstring'''

									import bitsandbytes as bnb

									from transformers import TaForConditionalGeneration

									# test with `t5-small`
									A         =					TaForConditionalGeneration.from_pretrained(self.model_name      ,							load_in_abit=snake_case      ,							device_map='auto'				)

									# there was a bug with decoders - this test checks that it is fixed
									self.assertTrue(isinstance(model.decoder.block[0].layer[0].SelfAttention.q      ,							bnb.nn.Linearabit				)				)

									A         =					self.tokenizer(self.input_text      ,							return_tensors='pt'				).to(0				)
									A         =					model.generate(**snake_case				)

									# test with `flan-t5-small`
									A         =					TaForConditionalGeneration.from_pretrained(
									    self.dense_act_model_name      ,							load_in_abit=snake_case      ,							device_map='auto'				)
									A         =					self.tokenizer(self.input_text      ,							return_tensors='pt'				).to(0				)
									A         =					model.generate(**snake_case				)






class      UpperCAmelCase__		(      UpperCamelCase     ):



		def 					A_		( self  :    Optional[int]				)			->						Optional[int]:






									'''simple docstring'''

									super().setUp()
									# model_name
									A         =					'bigscience/bloom-560m'
									A         =					't5-small'

									# Different types of model

									A         =					AutoModel.from_pretrained(self.model_name      ,							load_in_abit=snake_case      ,							device_map='auto'				)
									# Sequence classification model
									A         =					AutoModelForSequenceClassification.from_pretrained(
									    self.model_name      ,							load_in_abit=snake_case      ,							device_map='auto'				)
									# CausalLM model
									A         =					AutoModelForCausalLM.from_pretrained(self.model_name      ,							load_in_abit=snake_case      ,							device_map='auto'				)
									# Seq2seq model
									A         =					AutoModelForSeqaSeqLM.from_pretrained(
									    self.seq_to_seq_name      ,							load_in_abit=snake_case      ,							device_map='auto'				)



		def 					A_		( self  :    int				)			->						str:






									'''simple docstring'''

									del self.base_model
									del self.sequence_model
									del self.model_abit
									del self.seq_to_seq_model

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



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






									'''simple docstring'''

									from bitsandbytes.nn import Paramsabit

									self.assertTrue(self.base_model.h[-1].mlp.dense_ah_to_h.weight.__class__ == Paramsabit				)

									# Other heads should be nn.Parameter
									self.assertTrue(self.model_abit.lm_head.weight.__class__ == torch.nn.Parameter				)
									self.assertTrue(self.sequence_model.score.weight.__class__ == torch.nn.Parameter				)
									self.assertTrue(self.seq_to_seq_model.lm_head.weight.__class__ == torch.nn.Parameter				)






class      UpperCAmelCase__		(      UpperCamelCase     ):



		def 					A_		( self  :    int				)			->						List[str]:






									'''simple docstring'''

									super().setUp()



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






									'''simple docstring'''

									del self.pipe

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



		def 					A_		( self  :    List[Any]				)			->						List[str]:






									'''simple docstring'''

									A         =					pipeline(
									    'text-generation'      ,							model=self.model_name      ,							model_kwargs={'device_map': 'auto', 'load_in_4bit': True, 'torch_dtype': torch.floataa}      ,							max_new_tokens=self.MAX_NEW_TOKENS      ,							)

									# Real second forward pass
									A         =					self.pipe(self.input_text				)
									self.assertIn(pipeline_output[0]['generated_text']      ,							self.EXPECTED_OUTPUTS				)






@require_torch_multi_gpu
class      UpperCAmelCase__		(      UpperCamelCase     ):



		def 					A_		( self  :    Dict				)			->						List[Any]:






									'''simple docstring'''

									super().setUp()



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






									'''simple docstring'''

									A         =					AutoModelForCausalLM.from_pretrained(
									    self.model_name      ,							load_in_abit=snake_case      ,							device_map='balanced'				)

									# Check correct device map
									self.assertEqual(set(model_parallel.hf_device_map.values()				)      ,							{0, 1}				)

									# Check that inference pass works on the model
									A         =					self.tokenizer(self.input_text      ,							return_tensors='pt'				)

									# Second real batch
									A         =					model_parallel.generate(input_ids=encoded_input['input_ids'].to(0				)      ,							max_new_tokens=10				)
									self.assertIn(self.tokenizer.decode(output_parallel[0]      ,							skip_special_tokens=snake_case				)      ,							self.EXPECTED_OUTPUTS				)






class      UpperCAmelCase__		(      UpperCamelCase     ):



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






									'''simple docstring'''

									A         =					'facebook/opt-350m'
									super().setUp()



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






									'''simple docstring'''

									if version.parse(importlib.metadata.version('bitsandbytes'				)				) < version.parse('0.37.0'				):
																return

									# Step 1: freeze all parameters
									A         =					AutoModelForCausalLM.from_pretrained(self.model_name      ,							load_in_abit=snake_case				)

									self.assertEqual(set(model.hf_device_map.values()				)      ,							{torch.cuda.current_device()}				)

									for param in model.parameters():
																A         =					False  # freeze the model - train adapters later
																if param.ndim == 1:
																							# cast the small parameters (e.g. layernorm) to fp32 for stability
																							A         =					param.data.to(torch.floataa				)

        # Step 2: add adapters
									for _, module in model.named_modules():
																if "OPTAttention" in repr(type(snake_case				)				):
																							A         =					LoRALayer(module.q_proj      ,							rank=16				)
																							A         =					LoRALayer(module.k_proj      ,							rank=16				)
																							A         =					LoRALayer(module.v_proj      ,							rank=16				)

        # Step 3: dummy batch
									A         =					self.tokenizer('Test batch '      ,							return_tensors='pt'				).to(0				)

									# Step 4: Check if the gradient is not None
									with torch.cuda.amp.autocast():
																A         =					model.forward(**snake_case				)
																out.logits.norm().backward()

									for module in model.modules():
																if isinstance(snake_case      ,							snake_case				):
																							self.assertTrue(module.adapter[1].weight.grad is not None				)
																							self.assertTrue(module.adapter[1].weight.grad.norm().item() > 0				)
																elif isinstance(snake_case      ,							nn.Embedding				):
																							self.assertTrue(module.weight.grad is None				)






class      UpperCAmelCase__		(      UpperCamelCase     ):
		lowerCAmelCase_       :	int 							=     """gpt2-xl"""
		lowerCAmelCase_       :	Union[str, Any] 							=     3.3191_8548_5415_2187








"""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      UpperCAmelCase__		(      UpperCamelCase   ,unittest.TestCase     ):
		# TODO: is there an appropriate internal test set?
		lowerCAmelCase_       :	Tuple 							=     """ssube/stable-diffusion-x4-upscaler-onnx"""



		def 					A_		( self  :    Any      ,							snake_case  :    Union[str, Any]=0				)			->						Dict:






									'''simple docstring'''

									A         =					floats_tensor((1, 3, 128, 128)      ,							rng=random.Random(snake_case				)				)
									A         =					torch.manual_seed(snake_case				)
									A         =					{
									    '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 					A_		( self  :    str				)			->						Optional[Any]:






									'''simple docstring'''

									A         =					OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint      ,							provider='CPUExecutionProvider'				)
									pipe.set_progress_bar_config(disable=snake_case				)

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

									# started as 128, should now be 512
									assert image.shape == (1, 512, 512, 3)
									A         =					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 					A_		( self  :    Union[str, Any]				)			->						Optional[int]:






									'''simple docstring'''

									A         =					OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint      ,							provider='CPUExecutionProvider'				)
									A         =					PNDMScheduler.from_config(pipe.scheduler.config      ,							skip_prk_steps=snake_case				)
									pipe.set_progress_bar_config(disable=snake_case				)

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

									assert image.shape == (1, 512, 512, 3)
									A         =					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 					A_		( self  :    List[str]				)			->						str:






									'''simple docstring'''

									A         =					OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint      ,							provider='CPUExecutionProvider'				)
									A         =					DPMSolverMultistepScheduler.from_config(pipe.scheduler.config				)
									pipe.set_progress_bar_config(disable=snake_case				)

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

									assert image.shape == (1, 512, 512, 3)
									A         =					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 					A_		( self  :    int				)			->						Optional[int]:






									'''simple docstring'''

									A         =					OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint      ,							provider='CPUExecutionProvider'				)
									A         =					EulerDiscreteScheduler.from_config(pipe.scheduler.config				)
									pipe.set_progress_bar_config(disable=snake_case				)

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

									assert image.shape == (1, 512, 512, 3)
									A         =					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 					A_		( self  :    Optional[int]				)			->						Optional[int]:






									'''simple docstring'''

									A         =					OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint      ,							provider='CPUExecutionProvider'				)
									A         =					EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config				)
									pipe.set_progress_bar_config(disable=snake_case				)

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

									assert image.shape == (1, 512, 512, 3)
									A         =					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      UpperCAmelCase__		(      unittest.TestCase     ):



		@property
		def 					A_		( self  :    Tuple				)			->						str:






									'''simple docstring'''

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



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






									'''simple docstring'''

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



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






									'''simple docstring'''

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

									A         =					'A fantasy landscape, trending on artstation'

									A         =					torch.manual_seed(0				)
									A         =					pipe(
									    prompt=snake_case      ,							image=snake_case      ,							guidance_scale=7.5      ,							num_inference_steps=10      ,							generator=snake_case      ,							output_type='np'      ,							)
									A         =					output.images
									A         =					images[0, 255:258, 383:386, -1]

									assert images.shape == (1, 512, 512, 3)
									A         =					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 					A_		( self  :    str				)			->						Union[str, Any]:






									'''simple docstring'''

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

									A         =					'A fantasy landscape, trending on artstation'

									A         =					torch.manual_seed(0				)
									A         =					pipe(
									    prompt=snake_case      ,							image=snake_case      ,							guidance_scale=7.5      ,							num_inference_steps=20      ,							generator=snake_case      ,							output_type='np'      ,							)
									A         =					output.images
									A         =					images[0, 255:258, 383:386, -1]

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



