


from __future__ import annotations

import os
import tempfile
import unittest

import numpy as np
from huggingface_hub import hf_hub_download

from transformers import is_tensorflow_text_available, is_tf_available
from transformers.testing_utils import require_tensorflow_text, require_tf, slow

from ..test_modeling_tf_common import floats_tensor
from .test_framework_agnostic import GenerationIntegrationTestsMixin


if is_tf_available():
	import tensorflow as tf

	from transformers import (
	    AutoTokenizer,
	    TFAutoModelForCausalLM,
	    TFAutoModelForSeqaSeqLM,
	    TFAutoModelForSpeechSeqaSeq,
	    TFAutoModelForVisionaSeq,
	    TFBartForConditionalGeneration,
	    TFLogitsProcessorList,
	    TFMinLengthLogitsProcessor,
	    tf_top_k_top_p_filtering,
	)

if is_tensorflow_text_available():
	import tensorflow_text as text






@require_tf
class     UpperCamelCase(  unittest.TestCase   ):


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




											'''simple docstring'''

											__snake_case				=		tf.convert_to_tensor(
											    [
											        [
											            8.2220991,  # 3rd highest value; idx. 0
											            -0.5620044,
											            5.23229752,
											            4.0386393,
											            -6.8798378,
											            -0.54785802,
											            -3.2012153,
											            2.92777176,
											            1.88171953,
											            7.35341276,  # 5th highest value; idx. 9
											            8.43207833,  # 2nd highest value; idx. 10
											            -9.85711836,
											            -5.96209236,
											            -1.13039161,
											            -7.1115294,
											            -0.8369633,
											            -5.3186408,
											            7.06427407,
											            0.81369344,
											            -0.82023817,
											            -5.9179796,
											            0.58813443,
											            -6.99778438,
											            4.71551189,
											            -0.18771637,
											            7.44020759,  # 4th highest value; idx. 25
											            9.38450987,  # 1st highest value; idx. 26
											            2.12662941,
											            -9.32562038,
											            2.35652522,
											        ],  # cummulative prob of 5 highest values <= 0.6
											        [
											            0.58425518,
											            4.53139238,
											            -5.57510464,
											            -6.28030699,
											            -7.19529503,
											            -4.02122551,
											            1.39337037,
											            -6.06707057,
											            1.59480517,
											            -9.643119,
											            0.03907799,
											            0.67231762,
											            -8.88206726,
											            6.27115922,  # 4th highest value; idx. 13
											            2.28520723,
											            4.82767506,
											            4.30421368,
											            8.8275313,  # 2nd highest value; idx. 17
											            5.44029958,  # 5th highest value; idx. 18
											            -4.4735794,
											            7.38579536,  # 3rd highest value; idx. 20
											            -2.91051663,
											            2.61946077,
											            -2.5674762,
											            -9.48959302,
											            -4.02922645,
											            -1.35416918,
											            9.67702323,  # 1st highest value; idx. 27
											            -5.89478553,
											            1.85370467,
											        ],  # cummulative prob of 5 highest values <= 0.6
											    ]     ,    dtype=tf.floataa     ,    )

											__snake_case				=		tf.convert_to_tensor(
											    [[0, 0], [0, 9], [0, 1_0], [0, 2_5], [0, 2_6], [1, 1_3], [1, 1_7], [1, 1_8], [1, 2_0], [1, 2_7]]     ,    dtype=tf.intaa     ,    )  # expected non filtered idx as noted above

											__snake_case				=		tf.convert_to_tensor(
											    [8.222099, 7.3534126, 8.432078, 7.4402075, 9.38451, 6.271159, 8.827531, 5.4402995, 7.3857956, 9.677023]     ,    dtype=tf.floataa     ,    )  # expected non filtered values as noted above

											__snake_case				=		tf_top_k_top_p_filtering(SCREAMING_SNAKE_CASE     ,    top_k=1_0     ,    top_p=0.6     ,    min_tokens_to_keep=4						)

											__snake_case				=		output[output != -float("inf"						)]
											__snake_case				=		tf.cast(
											    tf.where(tf.not_equal(SCREAMING_SNAKE_CASE     ,    tf.constant(-float("inf"						)     ,    dtype=tf.floataa						)						)						)     ,    dtype=tf.intaa     ,    )

											tf.debugging.assert_near(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE     ,    rtol=1e-1_2						)
											tf.debugging.assert_equal(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE						)






@require_tf
class     UpperCamelCase(  unittest.TestCase     ,							_a   ):
					# setting framework_dependent_parameters needs to be gated, just like its contents' imports
					if is_tf_available():
										snake_case_		:				List[Any]										=	{
										    """AutoModelForCausalLM""": TFAutoModelForCausalLM,
										    """AutoModelForSpeechSeq2Seq""": TFAutoModelForSpeechSeqaSeq,
										    """AutoModelForSeq2SeqLM""": TFAutoModelForSeqaSeqLM,
										    """AutoModelForVision2Seq""": TFAutoModelForVisionaSeq,
										    """LogitsProcessorList""": TFLogitsProcessorList,
										    """MinLengthLogitsProcessor""": TFMinLengthLogitsProcessor,
										    """create_tensor_fn""": tf.convert_to_tensor,
										    """floats_tensor""": floats_tensor,
										    """return_tensors""": """tf""",
										}


					@slow
					def 							SCREAMING_SNAKE_CASE_  (						self	:		Optional[int]						)			->	Optional[int]:




											'''simple docstring'''

											__snake_case				=		TFAutoModelForCausalLM.from_pretrained("hf-internal-testing/tiny-random-gpt2"						)
											__snake_case				=		2
											__snake_case				=		2






											class     UpperCamelCase(  tf.Module   ):


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




																						'''simple docstring'''

																						super(SCREAMING_SNAKE_CASE     ,    self						).__init__()
																						__snake_case				=		model






																@tf.function(
																    input_signature=(
																        tf.TensorSpec((None, input_length)     ,    tf.intaa     ,    name="input_ids"						),
																        tf.TensorSpec((None, input_length)     ,    tf.intaa     ,    name="attention_mask"						),
																    )     ,    jit_compile=SCREAMING_SNAKE_CASE     ,    )
																def 							SCREAMING_SNAKE_CASE_  (						self	:		Optional[Any]     ,    SCREAMING_SNAKE_CASE	:		List[Any]     ,    SCREAMING_SNAKE_CASE	:		Optional[Any]						)			->	Optional[Any]:




																						'''simple docstring'''

																						__snake_case				=		self.model.generate(
																						    input_ids=SCREAMING_SNAKE_CASE     ,    attention_mask=SCREAMING_SNAKE_CASE     ,    max_new_tokens=SCREAMING_SNAKE_CASE     ,    return_dict_in_generate=SCREAMING_SNAKE_CASE     ,    )
																						return {"sequences": outputs["sequences"]}




											__snake_case				=		[[2, 0], [1_0_2, 1_0_3]]
											__snake_case				=		[[1, 0], [1, 1]]
											__snake_case				=		DummyModel(model=SCREAMING_SNAKE_CASE						)
											with tempfile.TemporaryDirectory() as tmp_dir:
																	tf.saved_model.save(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE     ,    signatures={"serving_default": dummy_model.serving}						)
																	__snake_case				=		tf.saved_model.load(SCREAMING_SNAKE_CASE						).signatures["serving_default"]
																	for batch_size in range(1     ,    len(SCREAMING_SNAKE_CASE						) + 1						):
																							__snake_case				=		{
																							    "input_ids": tf.constant(dummy_input_ids[:batch_size]						),
																							    "attention_mask": tf.constant(dummy_attention_masks[:batch_size]						),
																							}
																							__snake_case				=		serving_func(**SCREAMING_SNAKE_CASE						)["sequences"]
																							__snake_case				=		test_model.generate(**SCREAMING_SNAKE_CASE     ,    max_new_tokens=SCREAMING_SNAKE_CASE						)
																							tf.debugging.assert_equal(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE						)


					@slow
					def 							SCREAMING_SNAKE_CASE_  (						self	:		Dict						)			->	Optional[Any]:




											'''simple docstring'''

											__snake_case				=		TFAutoModelForCausalLM.from_pretrained("hf-internal-testing/tiny-random-gpt2"						)
											__snake_case				=		1
											__snake_case				=		2






											class     UpperCamelCase(  tf.Module   ):


																def __init__(						self	:		Optional[Any]     ,    SCREAMING_SNAKE_CASE	:		str						)			->	Optional[Any]:




																						'''simple docstring'''

																						super(SCREAMING_SNAKE_CASE     ,    self						).__init__()
																						__snake_case				=		model






																@tf.function(
																    input_signature=(
																        tf.TensorSpec((batch_size, None)     ,    tf.intaa     ,    name="input_ids"						),
																        tf.TensorSpec((batch_size, None)     ,    tf.intaa     ,    name="attention_mask"						),
																    )     ,    jit_compile=SCREAMING_SNAKE_CASE     ,    )
																def 							SCREAMING_SNAKE_CASE_  (						self	:		int     ,    SCREAMING_SNAKE_CASE	:		int     ,    SCREAMING_SNAKE_CASE	:		Optional[Any]						)			->	List[Any]:




																						'''simple docstring'''

																						__snake_case				=		self.model.generate(
																						    input_ids=SCREAMING_SNAKE_CASE     ,    attention_mask=SCREAMING_SNAKE_CASE     ,    max_new_tokens=SCREAMING_SNAKE_CASE     ,    return_dict_in_generate=SCREAMING_SNAKE_CASE     ,    )
																						return {"sequences": outputs["sequences"]}




											__snake_case				=		[[2], [1_0_2, 1_0_3]]
											__snake_case				=		[[1], [1, 1]]
											__snake_case				=		DummyModel(model=SCREAMING_SNAKE_CASE						)
											with tempfile.TemporaryDirectory() as tmp_dir:
																	tf.saved_model.save(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE     ,    signatures={"serving_default": dummy_model.serving}						)
																	__snake_case				=		tf.saved_model.load(SCREAMING_SNAKE_CASE						).signatures["serving_default"]
																	for input_row in range(len(SCREAMING_SNAKE_CASE						)						):
																							__snake_case				=		{
																							    "input_ids": tf.constant([dummy_input_ids[input_row]]						),
																							    "attention_mask": tf.constant([dummy_attention_masks[input_row]]						),
																							}
																							__snake_case				=		serving_func(**SCREAMING_SNAKE_CASE						)["sequences"]
																							__snake_case				=		test_model.generate(**SCREAMING_SNAKE_CASE     ,    max_new_tokens=SCREAMING_SNAKE_CASE						)
																							tf.debugging.assert_equal(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE						)


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




											'''simple docstring'''

											with tempfile.TemporaryDirectory() as tmp_dir:
																	# file needed to load the TF tokenizer
																	hf_hub_download(repo_id="google/flan-t5-small"     ,    filename="spiece.model"     ,    local_dir=SCREAMING_SNAKE_CASE						)






																	class     UpperCamelCase(  tf.keras.layers.Layer   ):


																						def __init__(						self	:		Any						)			->	Optional[int]:




																												'''simple docstring'''

																												super().__init__()
																												__snake_case				=		text.SentencepieceTokenizer(
																												    model=tf.io.gfile.GFile(os.path.join(SCREAMING_SNAKE_CASE     ,    "spiece.model"						)     ,    "rb"						).read()						)
																												__snake_case				=		TFAutoModelForSeqaSeqLM.from_pretrained("hf-internal-testing/tiny-random-t5"						)






																						def 							SCREAMING_SNAKE_CASE_  (						self	:		Tuple     ,    SCREAMING_SNAKE_CASE	:		List[Any]     ,    *SCREAMING_SNAKE_CASE	:		int     ,    **SCREAMING_SNAKE_CASE	:		str						)			->	List[Any]:




																												'''simple docstring'''

																												__snake_case				=		self.tokenizer.tokenize(SCREAMING_SNAKE_CASE						)
																												__snake_case		,					__snake_case				=		text.pad_model_inputs(
																												    SCREAMING_SNAKE_CASE     ,    max_seq_length=6_4     ,    pad_value=self.model.config.pad_token_id						)
																												__snake_case				=		self.model.generate(input_ids=SCREAMING_SNAKE_CASE     ,    attention_mask=SCREAMING_SNAKE_CASE						)
																												return self.tokenizer.detokenize(SCREAMING_SNAKE_CASE						)




																	__snake_case				=		CompleteSentenceTransformer()
																	__snake_case				=		tf.keras.layers.Input(shape=(1,)     ,    dtype=tf.string     ,    name="inputs"						)
																	__snake_case				=		complete_model(SCREAMING_SNAKE_CASE						)
																	__snake_case				=		tf.keras.Model(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE						)
																	keras_model.save(SCREAMING_SNAKE_CASE						)


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Any						)			->	Dict:




											'''simple docstring'''

											__snake_case				=		{
											    "do_sample": True,
											    "num_beams": 1,
											    "top_p": 0.7,
											    "top_k": 1_0,
											    "temperature": 0.7,
											}
											__snake_case				=		1_4

											__snake_case				=		AutoTokenizer.from_pretrained("hf-internal-testing/tiny-random-gpt2"						)
											__snake_case				=		"Hello, my dog is cute and"
											__snake_case				=		tokenizer(SCREAMING_SNAKE_CASE     ,    return_tensors="tf"						)
											__snake_case				=		TFAutoModelForCausalLM.from_pretrained("hf-internal-testing/tiny-random-gpt2"						)

											__snake_case				=		6_3_8
											# forces the generation to happen on CPU, to avoid GPU-related quirks
											with tf.device(":/CPU:0"						):
																	tf.random.set_seed(0						)
																	__snake_case				=		model.generate(**SCREAMING_SNAKE_CASE     ,    eos_token_id=SCREAMING_SNAKE_CASE     ,    **SCREAMING_SNAKE_CASE						)
											self.assertTrue(expectation == len(generated_tokens[0]						)						)

											__snake_case				=		[6_3_8, 1_9_8]
											with tf.device(":/CPU:0"						):
																	tf.random.set_seed(0						)
																	__snake_case				=		model.generate(**SCREAMING_SNAKE_CASE     ,    eos_token_id=SCREAMING_SNAKE_CASE     ,    **SCREAMING_SNAKE_CASE						)
											self.assertTrue(expectation == len(generated_tokens[0]						)						)






					def 							SCREAMING_SNAKE_CASE_  (						self	:		int						)			->	int:




											'''simple docstring'''

											__snake_case				=		AutoTokenizer.from_pretrained("hf-internal-testing/tiny-random-bart"						)
											__snake_case				=		"Hugging Face is a technology company based in New York and Paris."
											__snake_case				=		bart_tokenizer(SCREAMING_SNAKE_CASE     ,    return_tensors="tf"						).input_ids
											__snake_case				=		TFBartForConditionalGeneration.from_pretrained("hf-internal-testing/tiny-random-bart"						)
											__snake_case				=		bart_model.generate(SCREAMING_SNAKE_CASE						).numpy()






											class     UpperCamelCase(  _a   ):


																def 							SCREAMING_SNAKE_CASE_  (						self	:		Optional[int]     ,    SCREAMING_SNAKE_CASE	:		Tuple     ,    SCREAMING_SNAKE_CASE	:		Tuple=None     ,    **SCREAMING_SNAKE_CASE	:		List[str]						)			->	Tuple:




																						'''simple docstring'''

																						return super().call(SCREAMING_SNAKE_CASE     ,    **SCREAMING_SNAKE_CASE						)




											__snake_case				=		FakeBart.from_pretrained("hf-internal-testing/tiny-random-bart"						)
											__snake_case				=		bart_model.generate(SCREAMING_SNAKE_CASE     ,    foo="bar"						).numpy()
											self.assertTrue(np.array_equal(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE						)						)






											class     UpperCamelCase(  bart_model.model.encoder.__class__   ):


																def 							SCREAMING_SNAKE_CASE_  (						self	:		List[str]     ,    SCREAMING_SNAKE_CASE	:		Optional[Any]     ,    **SCREAMING_SNAKE_CASE	:		Any						)			->	List[str]:




																						'''simple docstring'''

																						return super().call(SCREAMING_SNAKE_CASE     ,    **SCREAMING_SNAKE_CASE						)




											__snake_case				=		FakeEncoder(bart_model.config     ,    bart_model.model.shared						)
											__snake_case				=		fake_encoder

											# Normal generation still works (the output will be different because the encoder weights are different)
											__snake_case				=		bart_model.generate(SCREAMING_SNAKE_CASE						).numpy()
											with self.assertRaises(SCREAMING_SNAKE_CASE						):
																	# FakeEncoder.call() accepts **kwargs -> no filtering -> value error due to unexpected input "foo"
																	bart_model.generate(SCREAMING_SNAKE_CASE     ,    foo="bar"						)









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


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Dict     ,    SCREAMING_SNAKE_CASE	:		List[str]=0						)			->	Union[str, Any]:




											'''simple docstring'''

											__snake_case				=		floats_tensor((1, 3, 1_2_8, 1_2_8)     ,    rng=random.Random(SCREAMING_SNAKE_CASE						)						)
											__snake_case				=		torch.manual_seed(SCREAMING_SNAKE_CASE						)
											__snake_case				=		{
											    "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 							SCREAMING_SNAKE_CASE_  (						self	:		List[str]						)			->	List[str]:




											'''simple docstring'''

											__snake_case				=		OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint     ,    provider="CPUExecutionProvider"						)
											pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE						)

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

											# started as 128, should now be 512
											assert image.shape == (1, 5_1_2, 5_1_2, 3)
											__snake_case				=		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 							SCREAMING_SNAKE_CASE_  (						self	:		List[str]						)			->	Optional[Any]:




											'''simple docstring'''

											__snake_case				=		OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint     ,    provider="CPUExecutionProvider"						)
											__snake_case				=		PNDMScheduler.from_config(pipe.scheduler.config     ,    skip_prk_steps=SCREAMING_SNAKE_CASE						)
											pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE						)

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

											assert image.shape == (1, 5_1_2, 5_1_2, 3)
											__snake_case				=		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 							SCREAMING_SNAKE_CASE_  (						self	:		Any						)			->	Optional[int]:




											'''simple docstring'''

											__snake_case				=		OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint     ,    provider="CPUExecutionProvider"						)
											__snake_case				=		DPMSolverMultistepScheduler.from_config(pipe.scheduler.config						)
											pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE						)

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

											assert image.shape == (1, 5_1_2, 5_1_2, 3)
											__snake_case				=		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 							SCREAMING_SNAKE_CASE_  (						self	:		Dict						)			->	Dict:




											'''simple docstring'''

											__snake_case				=		OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint     ,    provider="CPUExecutionProvider"						)
											__snake_case				=		EulerDiscreteScheduler.from_config(pipe.scheduler.config						)
											pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE						)

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

											assert image.shape == (1, 5_1_2, 5_1_2, 3)
											__snake_case				=		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 							SCREAMING_SNAKE_CASE_  (						self	:		List[Any]						)			->	List[str]:




											'''simple docstring'''

											__snake_case				=		OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint     ,    provider="CPUExecutionProvider"						)
											__snake_case				=		EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config						)
											pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE						)

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

											assert image.shape == (1, 5_1_2, 5_1_2, 3)
											__snake_case				=		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 							SCREAMING_SNAKE_CASE_  (						self	:		str						)			->	List[Any]:




											'''simple docstring'''

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


					@property
					def 							SCREAMING_SNAKE_CASE_  (						self	:		Tuple						)			->	Tuple:




											'''simple docstring'''

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


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




											'''simple docstring'''

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

											__snake_case				=		"A fantasy landscape, trending on artstation"

											__snake_case				=		torch.manual_seed(0						)
											__snake_case				=		pipe(
											    prompt=SCREAMING_SNAKE_CASE     ,    image=SCREAMING_SNAKE_CASE     ,    guidance_scale=7.5     ,    num_inference_steps=1_0     ,    generator=SCREAMING_SNAKE_CASE     ,    output_type="np"     ,    )
											__snake_case				=		output.images
											__snake_case				=		images[0, 2_5_5:2_5_8, 3_8_3:3_8_6, -1]

											assert images.shape == (1, 5_1_2, 5_1_2, 3)
											__snake_case				=		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 							SCREAMING_SNAKE_CASE_  (						self	:		Tuple						)			->	Optional[int]:




											'''simple docstring'''

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

											__snake_case				=		"A fantasy landscape, trending on artstation"

											__snake_case				=		torch.manual_seed(0						)
											__snake_case				=		pipe(
											    prompt=SCREAMING_SNAKE_CASE     ,    image=SCREAMING_SNAKE_CASE     ,    guidance_scale=7.5     ,    num_inference_steps=2_0     ,    generator=SCREAMING_SNAKE_CASE     ,    output_type="np"     ,    )
											__snake_case				=		output.images
											__snake_case				=		images[0, 2_5_5:2_5_8, 3_8_3:3_8_6, -1]

											assert images.shape == (1, 5_1_2, 5_1_2, 3)
											__snake_case				=		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





