

"""simple docstring"""





import unittest

from transformers import MraConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_torch_available():
   import torch

   from transformers import (
       MraForMaskedLM,
       MraForMultipleChoice,
       MraForQuestionAnswering,
       MraForSequenceClassification,
       MraForTokenClassification,
       MraModel,
   )
   from transformers.models.mra.modeling_mra import MRA_PRETRAINED_MODEL_ARCHIVE_LIST




class 					_lowerCAmelCase  :







 """simple docstring"""







 def __init__(			self							:			str,					UpperCAmelCase__							:			Tuple,					UpperCAmelCase__							:			List[str]=2,					UpperCAmelCase__							:			str=8,					UpperCAmelCase__							:			int=True,					UpperCAmelCase__							:			str=True,					UpperCAmelCase__							:			Optional[int]=True,					UpperCAmelCase__							:			Any=True,					UpperCAmelCase__							:			Tuple=9_9,					UpperCAmelCase__							:			Dict=1_6,					UpperCAmelCase__							:			Optional[int]=5,					UpperCAmelCase__							:			Any=2,					UpperCAmelCase__							:			int=3_6,					UpperCAmelCase__							:			List[Any]="gelu",					UpperCAmelCase__							:			str=0.0,					UpperCAmelCase__							:			Dict=0.0,					UpperCAmelCase__							:			List[str]=5_1_2,					UpperCAmelCase__							:			Optional[int]=1_6,					UpperCAmelCase__							:			Tuple=2,					UpperCAmelCase__							:			Tuple=0.02,					UpperCAmelCase__							:			int=3,					UpperCAmelCase__							:			Tuple=4,					UpperCAmelCase__							:			List[Any]=None,					):
    __lowercase								=						parent
    __lowercase								=						batch_size
    __lowercase								=						seq_length
    __lowercase								=						is_training
    __lowercase								=						use_input_mask
    __lowercase								=						use_token_type_ids
    __lowercase								=						use_labels
    __lowercase								=						vocab_size
    __lowercase								=						hidden_size
    __lowercase								=						num_hidden_layers
    __lowercase								=						num_attention_heads
    __lowercase								=						intermediate_size
    __lowercase								=						hidden_act
    __lowercase								=						hidden_dropout_prob
    __lowercase								=						attention_probs_dropout_prob
    __lowercase								=						max_position_embeddings
    __lowercase								=						type_vocab_size
    __lowercase								=						type_sequence_label_size
    __lowercase								=						initializer_range
    __lowercase								=						num_labels
    __lowercase								=						num_choices
    __lowercase								=						scope


 def 					_lowercase (			self							:			str	):
    __lowercase								=						ids_tensor([self.batch_size, self.seq_length],					self.vocab_size	)

    __lowercase								=						None
    if self.use_input_mask:
       __lowercase								=						random_attention_mask([self.batch_size, self.seq_length]	)

    __lowercase								=						None
    if self.use_token_type_ids:
       __lowercase								=						ids_tensor([self.batch_size, self.seq_length],					self.type_vocab_size	)

    __lowercase								=						None
    __lowercase								=						None
    __lowercase								=						None
    if self.use_labels:
       __lowercase								=						ids_tensor([self.batch_size],					self.type_sequence_label_size	)
       __lowercase								=						ids_tensor([self.batch_size, self.seq_length],					self.num_labels	)
       __lowercase								=						ids_tensor([self.batch_size],					self.num_choices	)

    __lowercase								=						self.get_config()

    return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels


 def 					_lowercase (			self							:			Optional[Any]	):
    return MraConfig(
        vocab_size=self.vocab_size,					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,					max_position_embeddings=self.max_position_embeddings,					type_vocab_size=self.type_vocab_size,					is_decoder=UpperCAmelCase__,					initializer_range=self.initializer_range,					)


 def 					_lowercase (			self							:			Union[str, Any]	):
    __lowercase								=						self.get_config()
    __lowercase								=						3_0_0
    return config


 def 					_lowercase (			self							:			List[str]	):
    (
        (
        __lowercase
    )		,(
        __lowercase
    )		,(
        __lowercase
    )		,(
        __lowercase
    )		,(
        __lowercase
    )		,(
        __lowercase
    )		,(
        __lowercase
    )		,
    )								=						self.prepare_config_and_inputs()

    __lowercase								=						True
    __lowercase								=						floats_tensor([self.batch_size, self.seq_length, self.hidden_size]	)
    __lowercase								=						ids_tensor([self.batch_size, self.seq_length],					vocab_size=2	)

    return (
        config,
        input_ids,
        token_type_ids,
        input_mask,
        sequence_labels,
        token_labels,
        choice_labels,
        encoder_hidden_states,
        encoder_attention_mask,
    )


 def 					_lowercase (			self							:			List[Any],					UpperCAmelCase__							:			Dict,					UpperCAmelCase__							:			Optional[int],					UpperCAmelCase__							:			List[Any],					UpperCAmelCase__							:			Tuple,					UpperCAmelCase__							:			Dict,					UpperCAmelCase__							:			Dict,					UpperCAmelCase__							:			Dict	):
    __lowercase								=						MraModel(config=UpperCAmelCase__	)
    model.to(UpperCAmelCase__	)
    model.eval()
    __lowercase								=						model(UpperCAmelCase__,					attention_mask=UpperCAmelCase__,					token_type_ids=UpperCAmelCase__	)
    __lowercase								=						model(UpperCAmelCase__,					token_type_ids=UpperCAmelCase__	)
    __lowercase								=						model(UpperCAmelCase__	)
    self.parent.assertEqual(result.last_hidden_state.shape,					(self.batch_size, self.seq_length, self.hidden_size)	)


 def 					_lowercase (			self							:			Tuple,					UpperCAmelCase__							:			Union[str, Any],					UpperCAmelCase__							:			Any,					UpperCAmelCase__							:			List[Any],					UpperCAmelCase__							:			Union[str, Any],					UpperCAmelCase__							:			Optional[Any],					UpperCAmelCase__							:			Optional[Any],					UpperCAmelCase__							:			Tuple,					UpperCAmelCase__							:			Tuple,					UpperCAmelCase__							:			Optional[Any],					):
    __lowercase								=						True
    __lowercase								=						MraModel(UpperCAmelCase__	)
    model.to(UpperCAmelCase__	)
    model.eval()
    __lowercase								=						model(
        UpperCAmelCase__,					attention_mask=UpperCAmelCase__,					token_type_ids=UpperCAmelCase__,					encoder_hidden_states=UpperCAmelCase__,					encoder_attention_mask=UpperCAmelCase__,					)
    __lowercase								=						model(
        UpperCAmelCase__,					attention_mask=UpperCAmelCase__,					token_type_ids=UpperCAmelCase__,					encoder_hidden_states=UpperCAmelCase__,					)
    __lowercase								=						model(UpperCAmelCase__,					attention_mask=UpperCAmelCase__,					token_type_ids=UpperCAmelCase__	)
    self.parent.assertEqual(result.last_hidden_state.shape,					(self.batch_size, self.seq_length, self.hidden_size)	)


 def 					_lowercase (			self							:			Dict,					UpperCAmelCase__							:			Union[str, Any],					UpperCAmelCase__							:			str,					UpperCAmelCase__							:			Dict,					UpperCAmelCase__							:			int,					UpperCAmelCase__							:			Dict,					UpperCAmelCase__							:			str,					UpperCAmelCase__							:			int	):
    __lowercase								=						MraForMaskedLM(config=UpperCAmelCase__	)
    model.to(UpperCAmelCase__	)
    model.eval()
    __lowercase								=						model(UpperCAmelCase__,					attention_mask=UpperCAmelCase__,					token_type_ids=UpperCAmelCase__,					labels=UpperCAmelCase__	)
    self.parent.assertEqual(result.logits.shape,					(self.batch_size, self.seq_length, self.vocab_size)	)


 def 					_lowercase (			self							:			str,					UpperCAmelCase__							:			Dict,					UpperCAmelCase__							:			Any,					UpperCAmelCase__							:			Optional[Any],					UpperCAmelCase__							:			int,					UpperCAmelCase__							:			Tuple,					UpperCAmelCase__							:			str,					UpperCAmelCase__							:			List[str]	):
    __lowercase								=						MraForQuestionAnswering(config=UpperCAmelCase__	)
    model.to(UpperCAmelCase__	)
    model.eval()
    __lowercase								=						model(
        UpperCAmelCase__,					attention_mask=UpperCAmelCase__,					token_type_ids=UpperCAmelCase__,					start_positions=UpperCAmelCase__,					end_positions=UpperCAmelCase__,					)
    self.parent.assertEqual(result.start_logits.shape,					(self.batch_size, self.seq_length)	)
    self.parent.assertEqual(result.end_logits.shape,					(self.batch_size, self.seq_length)	)


 def 					_lowercase (			self							:			str,					UpperCAmelCase__							:			Optional[int],					UpperCAmelCase__							:			Any,					UpperCAmelCase__							:			List[str],					UpperCAmelCase__							:			List[Any],					UpperCAmelCase__							:			Union[str, Any],					UpperCAmelCase__							:			Optional[int],					UpperCAmelCase__							:			Tuple	):
    __lowercase								=						self.num_labels
    __lowercase								=						MraForSequenceClassification(UpperCAmelCase__	)
    model.to(UpperCAmelCase__	)
    model.eval()
    __lowercase								=						model(UpperCAmelCase__,					attention_mask=UpperCAmelCase__,					token_type_ids=UpperCAmelCase__,					labels=UpperCAmelCase__	)
    self.parent.assertEqual(result.logits.shape,					(self.batch_size, self.num_labels)	)


 def 					_lowercase (			self							:			Optional[int],					UpperCAmelCase__							:			int,					UpperCAmelCase__							:			Tuple,					UpperCAmelCase__							:			List[Any],					UpperCAmelCase__							:			List[Any],					UpperCAmelCase__							:			List[str],					UpperCAmelCase__							:			Optional[int],					UpperCAmelCase__							:			Optional[Any]	):
    __lowercase								=						self.num_labels
    __lowercase								=						MraForTokenClassification(config=UpperCAmelCase__	)
    model.to(UpperCAmelCase__	)
    model.eval()
    __lowercase								=						model(UpperCAmelCase__,					attention_mask=UpperCAmelCase__,					token_type_ids=UpperCAmelCase__,					labels=UpperCAmelCase__	)
    self.parent.assertEqual(result.logits.shape,					(self.batch_size, self.seq_length, self.num_labels)	)


 def 					_lowercase (			self							:			Optional[Any],					UpperCAmelCase__							:			Any,					UpperCAmelCase__							:			int,					UpperCAmelCase__							:			Dict,					UpperCAmelCase__							:			int,					UpperCAmelCase__							:			Union[str, Any],					UpperCAmelCase__							:			Tuple,					UpperCAmelCase__							:			Tuple	):
    __lowercase								=						self.num_choices
    __lowercase								=						MraForMultipleChoice(config=UpperCAmelCase__	)
    model.to(UpperCAmelCase__	)
    model.eval()
    __lowercase								=						input_ids.unsqueeze(1	).expand(-1,					self.num_choices,					-1	).contiguous()
    __lowercase								=						token_type_ids.unsqueeze(1	).expand(-1,					self.num_choices,					-1	).contiguous()
    __lowercase								=						input_mask.unsqueeze(1	).expand(-1,					self.num_choices,					-1	).contiguous()
    __lowercase								=						model(
        UpperCAmelCase__,					attention_mask=UpperCAmelCase__,					token_type_ids=UpperCAmelCase__,					labels=UpperCAmelCase__,					)
    self.parent.assertEqual(result.logits.shape,					(self.batch_size, self.num_choices)	)



 def 					_lowercase (			self							:			Union[str, Any]	):
    __lowercase								=						self.prepare_config_and_inputs()
    (
        (
        __lowercase
    )		,(
        __lowercase
    )		,(
        __lowercase
    )		,(
        __lowercase
    )		,(
        __lowercase
    )		,(
        __lowercase
    )		,(
        __lowercase
    )		,
    )								=						config_and_inputs
    __lowercase								=						{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
    return config, inputs_dict







@require_torch
class 					_lowerCAmelCase  (	lowercase     ,unittest.TestCase   ):







 """simple docstring"""







 __UpperCAmelCase	:					Optional[int]   		=	(
     (
         MraModel,
         MraForMaskedLM,
         MraForMultipleChoice,
         MraForQuestionAnswering,
         MraForSequenceClassification,
         MraForTokenClassification,
     )
     if is_torch_available()
     else ()
 )
 __UpperCAmelCase	:					Any   		=	False
 __UpperCAmelCase	:					List[Any]   		=	False
 __UpperCAmelCase	:					Union[str, Any]   		=	False
 __UpperCAmelCase	:					List[Any]   		=	False

 __UpperCAmelCase	:					List[Any]   		=	()


 def 					_lowercase (			self							:			List[Any]	):
    __lowercase								=						MraModelTester(self	)
    __lowercase								=						ConfigTester(self,					config_class=UpperCAmelCase__,					hidden_size=3_7	)


 def 					_lowercase (			self							:			Any	):
    self.config_tester.run_common_tests()


 def 					_lowercase (			self							:			Union[str, Any]	):
    __lowercase								=						self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_model(*UpperCAmelCase__	)


 def 					_lowercase (			self							:			int	):
    __lowercase								=						self.model_tester.prepare_config_and_inputs()
    for type in ["absolute", "relative_key", "relative_key_query"]:
       __lowercase								=						type
       self.model_tester.create_and_check_model(*UpperCAmelCase__	)


 def 					_lowercase (			self							:			Tuple	):
    __lowercase								=						self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_masked_lm(*UpperCAmelCase__	)


 def 					_lowercase (			self							:			Tuple	):
    __lowercase								=						self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_multiple_choice(*UpperCAmelCase__	)


 def 					_lowercase (			self							:			Tuple	):
    __lowercase								=						self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_question_answering(*UpperCAmelCase__	)


 def 					_lowercase (			self							:			List[str]	):
    __lowercase								=						self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_sequence_classification(*UpperCAmelCase__	)


 def 					_lowercase (			self							:			int	):
    __lowercase								=						self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_token_classification(*UpperCAmelCase__	)


 @slow
 def 					_lowercase (			self							:			Any	):
    for model_name in MRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       __lowercase								=						MraModel.from_pretrained(UpperCAmelCase__	)
       self.assertIsNotNone(UpperCAmelCase__	)



 @unittest.skip(reason="MRA does not output attentions"	)
 def 					_lowercase (			self							:			Union[str, Any]	):
    return







@require_torch
class 					_lowerCAmelCase  (	unittest.TestCase   ):







 """simple docstring"""







 @slow
 def 					_lowercase (			self							:			Tuple	):
    __lowercase								=						MraModel.from_pretrained("uw-madison/mra-base-512-4"	)
    __lowercase								=						torch.arange(2_5_6	).unsqueeze(0	)

    with torch.no_grad():
       __lowercase								=						model(UpperCAmelCase__	)[0]

    __lowercase								=						torch.Size((1, 2_5_6, 7_6_8)	)
    self.assertEqual(output.shape,					UpperCAmelCase__	)

    __lowercase								=						torch.tensor(
        [[[-0.0_140, 0.0_830, -0.0_381], [0.1_546, 0.1_402, 0.0_220], [0.1_162, 0.0_851, 0.0_165]]]	)

    self.assertTrue(torch.allclose(output[:, :3, :3],					UpperCAmelCase__,					atol=1E-4	)	)


 @slow
 def 					_lowercase (			self							:			Union[str, Any]	):
    __lowercase								=						MraForMaskedLM.from_pretrained("uw-madison/mra-base-512-4"	)
    __lowercase								=						torch.arange(2_5_6	).unsqueeze(0	)

    with torch.no_grad():
       __lowercase								=						model(UpperCAmelCase__	)[0]

    __lowercase								=						5_0_2_6_5

    __lowercase								=						torch.Size((1, 2_5_6, vocab_size)	)
    self.assertEqual(output.shape,					UpperCAmelCase__	)

    __lowercase								=						torch.tensor(
        [[[9.2_595, -3.6_038, 11.8_819], [9.3_869, -3.2_693, 11.0_956], [11.8_524, -3.4_938, 13.1_210]]]	)

    self.assertTrue(torch.allclose(output[:, :3, :3],					UpperCAmelCase__,					atol=1E-4	)	)



 @slow
 def 					_lowercase (			self							:			Tuple	):
    __lowercase								=						MraForMaskedLM.from_pretrained("uw-madison/mra-base-4096-8-d3"	)
    __lowercase								=						torch.arange(4_0_9_6	).unsqueeze(0	)

    with torch.no_grad():
       __lowercase								=						model(UpperCAmelCase__	)[0]

    __lowercase								=						5_0_2_6_5

    __lowercase								=						torch.Size((1, 4_0_9_6, vocab_size)	)
    self.assertEqual(output.shape,					UpperCAmelCase__	)

    __lowercase								=						torch.tensor(
        [[[5.4_789, -2.3_564, 7.5_064], [7.9_067, -1.3_369, 9.9_668], [9.0_712, -1.8_106, 7.0_380]]]	)

    self.assertTrue(torch.allclose(output[:, :3, :3],					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  (	lowercase     ,unittest.TestCase   ):







 """simple docstring"""







 __UpperCAmelCase	:					str   		=	"ssube/stable-diffusion-x4-upscaler-onnx"


 def 					_lowercase (			self							:			Union[str, Any],					UpperCAmelCase__							:			List[str]=0	):
    __lowercase								=						floats_tensor((1, 3, 1_2_8, 1_2_8),					rng=random.Random(UpperCAmelCase__	)	)
    __lowercase								=						torch.manual_seed(UpperCAmelCase__	)
    __lowercase								=						{
        "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 					_lowercase (			self							:			Any	):
    __lowercase								=						OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint,					provider="CPUExecutionProvider"	)
    pipe.set_progress_bar_config(disable=UpperCAmelCase__	)

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

    # started as 128, should now be 512
    assert image.shape == (1, 5_1_2, 5_1_2, 3)
    __lowercase								=						np.array(
        [0.6_974_782, 0.68_902_093, 0.70_135_885, 0.7_583_618, 0.7_804_545, 0.7_854_912, 0.78_667_426, 0.78_743_863, 0.78_070_223]	)
    assert np.abs(image_slice - expected_slice	).max() < 1E-1


 def 					_lowercase (			self							:			Optional[Any]	):
    __lowercase								=						OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint,					provider="CPUExecutionProvider"	)
    __lowercase								=						PNDMScheduler.from_config(pipe.scheduler.config,					skip_prk_steps=UpperCAmelCase__	)
    pipe.set_progress_bar_config(disable=UpperCAmelCase__	)

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

    assert image.shape == (1, 5_1_2, 5_1_2, 3)
    __lowercase								=						np.array(
        [0.6_898_892, 0.59_240_556, 0.52_499_527, 0.58_866_215, 0.52_258_235, 0.52_572_715, 0.62_414_473, 0.6_174_387, 0.6_214_964]	)
    assert np.abs(image_slice.flatten() - expected_slice	).max() < 1E-1


 def 					_lowercase (			self							:			int	):
    __lowercase								=						OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint,					provider="CPUExecutionProvider"	)
    __lowercase								=						DPMSolverMultistepScheduler.from_config(pipe.scheduler.config	)
    pipe.set_progress_bar_config(disable=UpperCAmelCase__	)

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

    assert image.shape == (1, 5_1_2, 5_1_2, 3)
    __lowercase								=						np.array(
        [0.7_659_278, 0.76_437_664, 0.75_579_107, 0.7_691_116, 0.77_666_986, 0.7_727_672, 0.7_758_664, 0.7_812_226, 0.76_942_515]	)

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


 def 					_lowercase (			self							:			str	):
    __lowercase								=						OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint,					provider="CPUExecutionProvider"	)
    __lowercase								=						EulerDiscreteScheduler.from_config(pipe.scheduler.config	)
    pipe.set_progress_bar_config(disable=UpperCAmelCase__	)

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

    assert image.shape == (1, 5_1_2, 5_1_2, 3)
    __lowercase								=						np.array(
        [0.6_974_782, 0.68_902_093, 0.70_135_885, 0.7_583_618, 0.7_804_545, 0.7_854_912, 0.78_667_426, 0.78_743_863, 0.78_070_223]	)
    assert np.abs(image_slice.flatten() - expected_slice	).max() < 1E-1



 def 					_lowercase (			self							:			Any	):
    __lowercase								=						OnnxStableDiffusionUpscalePipeline.from_pretrained(self.hub_checkpoint,					provider="CPUExecutionProvider"	)
    __lowercase								=						EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config	)
    pipe.set_progress_bar_config(disable=UpperCAmelCase__	)

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

    assert image.shape == (1, 5_1_2, 5_1_2, 3)
    __lowercase								=						np.array(
        [0.77_424_496, 0.773_601, 0.7_645_288, 0.7_769_598, 0.7_772_739, 0.7_738_688, 0.78_187_233, 0.77_879_584, 0.767_043]	)

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







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







 """simple docstring"""







 @property
 def 					_lowercase (			self							:			Tuple	):
    return (
        "CUDAExecutionProvider",
        {
            "gpu_mem_limit": "15000000000",  # 15GB
            "arena_extend_strategy": "kSameAsRequested",
        },
    )


 @property
 def 					_lowercase (			self							:			Dict	):
    __lowercase								=						ort.SessionOptions()
    __lowercase								=						False
    return options


 def 					_lowercase (			self							:			Dict	):
    __lowercase								=						load_image(
        "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
        "/img2img/sketch-mountains-input.jpg"	)
    __lowercase								=						init_image.resize((1_2_8, 1_2_8)	)
    # using the PNDM scheduler by default
    __lowercase								=						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__	)

    __lowercase								=						"A fantasy landscape, trending on artstation"

    __lowercase								=						torch.manual_seed(0	)
    __lowercase								=						pipe(
        prompt=UpperCAmelCase__,					image=UpperCAmelCase__,					guidance_scale=7.5,					num_inference_steps=1_0,					generator=UpperCAmelCase__,					output_type="np",					)
    __lowercase								=						output.images
    __lowercase								=						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)
    __lowercase								=						np.array([0.4_883, 0.4_947, 0.4_980, 0.4_975, 0.4_982, 0.4_980, 0.5_000, 0.5_006, 0.4_972]	)
    # TODO: lower the tolerance after finding the cause of onnxruntime reproducibility issues

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



 def 					_lowercase (			self							:			str	):
    __lowercase								=						load_image(
        "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
        "/img2img/sketch-mountains-input.jpg"	)
    __lowercase								=						init_image.resize((1_2_8, 1_2_8)	)
    __lowercase								=						LMSDiscreteScheduler.from_pretrained(
        "ssube/stable-diffusion-x4-upscaler-onnx",					subfolder="scheduler"	)
    __lowercase								=						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__	)

    __lowercase								=						"A fantasy landscape, trending on artstation"

    __lowercase								=						torch.manual_seed(0	)
    __lowercase								=						pipe(
        prompt=UpperCAmelCase__,					image=UpperCAmelCase__,					guidance_scale=7.5,					num_inference_steps=2_0,					generator=UpperCAmelCase__,					output_type="np",					)
    __lowercase								=						output.images
    __lowercase								=						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)
    __lowercase								=						np.array(
        [0.50_173_753, 0.50_223_356, 0.502_039, 0.50_233_036, 0.5_023_725, 0.5_022_601, 0.5_018_758, 0.50_234_085, 0.50_241_566]	)
    # TODO: lower the tolerance after finding the cause of onnxruntime reproducibility issues

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




