



"""simple docstring"""







from collections import OrderedDict
from typing import Any, Mapping, Optional

from ... import PreTrainedTokenizer
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig, OnnxConfigWithPast, OnnxSeqaSeqConfigWithPast
from ...onnx.utils import compute_effective_axis_dimension
from ...utils import TensorType, is_torch_available, logging


lowercase__		:				List[Any]          =	logging.get_logger(__name__)

lowercase__		:				int          =	{
    'Helsinki-NLP/opus-mt-en-de': 'https://huggingface.co/Helsinki-NLP/opus-mt-en-de/resolve/main/config.json',
    # See all Marian models at https://huggingface.co/models?filter=marian
}







class       UpperCamelCase__   (	lowercase_  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE  				=     """marian"""
      _SCREAMING_SNAKE_CASE  				=     ["""past_key_values"""]
      _SCREAMING_SNAKE_CASE  				=     {"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}



      def __init__(      self				:      int    ,			SCREAMING_SNAKE_CASE_				:      Any=5_8_1_0_1    ,			SCREAMING_SNAKE_CASE_				:      int=None    ,			SCREAMING_SNAKE_CASE_				:      Union[str, Any]=1_0_2_4    ,			SCREAMING_SNAKE_CASE_				:      Union[str, Any]=1_2    ,			SCREAMING_SNAKE_CASE_				:      str=4_0_9_6    ,			SCREAMING_SNAKE_CASE_				:      int=1_6    ,			SCREAMING_SNAKE_CASE_				:      int=1_2    ,			SCREAMING_SNAKE_CASE_				:      Optional[Any]=4_0_9_6    ,			SCREAMING_SNAKE_CASE_				:      Optional[Any]=1_6    ,			SCREAMING_SNAKE_CASE_				:      Dict=0.0    ,			SCREAMING_SNAKE_CASE_				:      Dict=0.0    ,			SCREAMING_SNAKE_CASE_				:      str=True    ,			SCREAMING_SNAKE_CASE_				:      Optional[int]=True    ,			SCREAMING_SNAKE_CASE_				:      Any="gelu"    ,			SCREAMING_SNAKE_CASE_				:      Any=1_0_2_4    ,			SCREAMING_SNAKE_CASE_				:      List[Any]=0.1    ,			SCREAMING_SNAKE_CASE_				:      Optional[Any]=0.0    ,			SCREAMING_SNAKE_CASE_				:      Union[str, Any]=0.0    ,			SCREAMING_SNAKE_CASE_				:      Tuple=0.02    ,			SCREAMING_SNAKE_CASE_				:      List[str]=5_8_1_0_0    ,			SCREAMING_SNAKE_CASE_				:      str=False    ,			SCREAMING_SNAKE_CASE_				:      Optional[int]=5_8_1_0_0    ,			SCREAMING_SNAKE_CASE_				:      List[Any]=0    ,			SCREAMING_SNAKE_CASE_				:      List[str]=0    ,			SCREAMING_SNAKE_CASE_				:      Dict=True    ,			**SCREAMING_SNAKE_CASE_				:      Tuple    ,			):
        lowerCAmelCase_   :				Tuple								= vocab_size
        lowerCAmelCase_   :				int								= decoder_vocab_size or vocab_size
        lowerCAmelCase_   :				Dict								= max_position_embeddings
        lowerCAmelCase_   :				Optional[int]								= d_model
        lowerCAmelCase_   :				int								= encoder_ffn_dim
        lowerCAmelCase_   :				Any								= encoder_layers
        lowerCAmelCase_   :				Optional[Any]								= encoder_attention_heads
        lowerCAmelCase_   :				Optional[Any]								= decoder_ffn_dim
        lowerCAmelCase_   :				List[Any]								= decoder_layers
        lowerCAmelCase_   :				Union[str, Any]								= decoder_attention_heads
        lowerCAmelCase_   :				List[str]								= dropout
        lowerCAmelCase_   :				Optional[int]								= attention_dropout
        lowerCAmelCase_   :				Optional[int]								= activation_dropout
        lowerCAmelCase_   :				Any								= activation_function
        lowerCAmelCase_   :				Tuple								= init_std
        lowerCAmelCase_   :				Optional[Any]								= encoder_layerdrop
        lowerCAmelCase_   :				Union[str, Any]								= decoder_layerdrop
        lowerCAmelCase_   :				Optional[int]								= use_cache
        lowerCAmelCase_   :				List[str]								= encoder_layers
        lowerCAmelCase_   :				str								= scale_embedding  # scale factor will be sqrt(d_model) if True
        lowerCAmelCase_   :				str								= share_encoder_decoder_embeddings
        super().__init__(
            pad_token_id=__UpperCamelCase    ,			eos_token_id=__UpperCamelCase    ,			is_encoder_decoder=__UpperCamelCase    ,			decoder_start_token_id=__UpperCamelCase    ,			forced_eos_token_id=__UpperCamelCase    ,			**__UpperCamelCase    ,			)







class       UpperCamelCase__   (	lowercase_  ):




      """simple docstring"""




      @property
      # Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.inputs
      def      SCREAMING_SNAKE_CASE__ (      self				:      List[str]       ):
        if self.task in ["default", "seq2seq-lm"]:
          lowerCAmelCase_   :				List[Any]								= OrderedDict(
              [
                  ('input_ids', {0: 'batch', 1: 'encoder_sequence'}),
                  ('attention_mask', {0: 'batch', 1: 'encoder_sequence'}),
              ]       )

          if self.use_past:
            lowerCAmelCase_   :				Tuple								= {0: 'batch'}
            lowerCAmelCase_   :				Tuple								= {0: 'batch', 1: 'past_decoder_sequence + sequence'}
          else:
            lowerCAmelCase_   :				str								= {0: 'batch', 1: 'decoder_sequence'}
            lowerCAmelCase_   :				Optional[Any]								= {0: 'batch', 1: 'decoder_sequence'}

          if self.use_past:
            self.fill_with_past_key_values_(__UpperCamelCase    ,			direction='inputs'       )
        elif self.task == "causal-lm":
          # TODO: figure this case out.
          lowerCAmelCase_   :				Union[str, Any]								= OrderedDict(
              [
                  ('input_ids', {0: 'batch', 1: 'encoder_sequence'}),
                  ('attention_mask', {0: 'batch', 1: 'encoder_sequence'}),
              ]       )
          if self.use_past:
            lowerCAmelCase_						,lowerCAmelCase_   :				str								= self.num_layers
            for i in range(__UpperCamelCase       ):
              lowerCAmelCase_   :				Optional[int]								= {0: 'batch', 2: 'past_sequence + sequence'}
              lowerCAmelCase_   :				Dict								= {0: 'batch', 2: 'past_sequence + sequence'}
        else:
          lowerCAmelCase_   :				Union[str, Any]								= OrderedDict(
              [
                  ('input_ids', {0: 'batch', 1: 'encoder_sequence'}),
                  ('attention_mask', {0: 'batch', 1: 'encoder_sequence'}),
                  ('decoder_input_ids', {0: 'batch', 1: 'decoder_sequence'}),
                  ('decoder_attention_mask', {0: 'batch', 1: 'decoder_sequence'}),
              ]       )

        return common_inputs



      @property
      # Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.outputs
      def      SCREAMING_SNAKE_CASE__ (      self				:      List[str]       ):
        if self.task in ["default", "seq2seq-lm"]:
          lowerCAmelCase_   :				List[Any]								= super().outputs
        else:
          lowerCAmelCase_   :				Union[str, Any]								= super(__UpperCamelCase    ,			self       ).outputs
          if self.use_past:
            lowerCAmelCase_						,lowerCAmelCase_   :				Optional[int]								= self.num_layers
            for i in range(__UpperCamelCase       ):
              lowerCAmelCase_   :				int								= {0: 'batch', 2: 'past_sequence + sequence'}
              lowerCAmelCase_   :				int								= {0: 'batch', 2: 'past_sequence + sequence'}
        return common_outputs



      def      SCREAMING_SNAKE_CASE__ (      self				:      Optional[int]    ,			SCREAMING_SNAKE_CASE_				:      PreTrainedTokenizer    ,			SCREAMING_SNAKE_CASE_				:      int = -1    ,			SCREAMING_SNAKE_CASE_				:      int = -1    ,			SCREAMING_SNAKE_CASE_				:      bool = False    ,			SCREAMING_SNAKE_CASE_				:      Optional[TensorType] = None    ,			):
        lowerCAmelCase_   :				List[Any]								= self._generate_dummy_inputs_for_encoder_and_decoder(
            __UpperCamelCase    ,			__UpperCamelCase    ,			__UpperCamelCase    ,			__UpperCamelCase    ,			__UpperCamelCase       )

        # Generate decoder inputs
        lowerCAmelCase_   :				Union[str, Any]								= seq_length if not self.use_past else 1
        lowerCAmelCase_   :				Tuple								= self._generate_dummy_inputs_for_encoder_and_decoder(
            __UpperCamelCase    ,			__UpperCamelCase    ,			__UpperCamelCase    ,			__UpperCamelCase    ,			__UpperCamelCase       )
        lowerCAmelCase_   :				List[Any]								= {F"decoder_{name}": tensor for name, tensor in decoder_inputs.items()}
        lowerCAmelCase_   :				Any								= dict(**__UpperCamelCase    ,			**__UpperCamelCase       )

        if self.use_past:
          if not is_torch_available():
            raise ValueError('Cannot generate dummy past_keys inputs without PyTorch installed.'       )
          else:
            import torch
          lowerCAmelCase_						,lowerCAmelCase_   :				Union[str, Any]								= common_inputs['input_ids'].shape
          lowerCAmelCase_   :				List[str]								= common_inputs['decoder_input_ids'].shape[1]
          lowerCAmelCase_						,lowerCAmelCase_   :				Any								= self.num_attention_heads
          lowerCAmelCase_   :				Tuple								= (
              batch,
              num_encoder_attention_heads,
              encoder_seq_length,
              self._config.hidden_size // num_encoder_attention_heads,
          )
          lowerCAmelCase_   :				Union[str, Any]								= decoder_seq_length + 3
          lowerCAmelCase_   :				str								= (
              batch,
              num_decoder_attention_heads,
              decoder_past_length,
              self._config.hidden_size // num_decoder_attention_heads,
          )

          lowerCAmelCase_   :				int								= torch.cat(
              [common_inputs['decoder_attention_mask'], torch.ones(__UpperCamelCase    ,			__UpperCamelCase       )]    ,			dim=1       )

          lowerCAmelCase_   :				Union[str, Any]								= []
          # If the number of encoder and decoder layers are present in the model configuration, both are considered
          lowerCAmelCase_						,lowerCAmelCase_   :				Tuple								= self.num_layers
          lowerCAmelCase_   :				str								= min(__UpperCamelCase    ,			__UpperCamelCase       )
          lowerCAmelCase_   :				Dict								= max(__UpperCamelCase    ,			__UpperCamelCase       ) - min_num_layers
          lowerCAmelCase_   :				Optional[int]								= 'encoder' if num_encoder_layers > num_decoder_layers else 'decoder'

          for _ in range(__UpperCamelCase       ):
            common_inputs["past_key_values"].append(
                (
                    torch.zeros(__UpperCamelCase       ),
                    torch.zeros(__UpperCamelCase       ),
                    torch.zeros(__UpperCamelCase       ),
                    torch.zeros(__UpperCamelCase       ),
                )       )
          # TODO: test this.
          lowerCAmelCase_   :				Optional[Any]								= encoder_shape if remaining_side_name == 'encoder' else decoder_shape
          for _ in range(__UpperCamelCase    ,			__UpperCamelCase       ):
            common_inputs["past_key_values"].append((torch.zeros(__UpperCamelCase       ), torch.zeros(__UpperCamelCase       ))       )
        return common_inputs



      def      SCREAMING_SNAKE_CASE__ (      self				:      Optional[int]    ,			SCREAMING_SNAKE_CASE_				:      PreTrainedTokenizer    ,			SCREAMING_SNAKE_CASE_				:      int = -1    ,			SCREAMING_SNAKE_CASE_				:      int = -1    ,			SCREAMING_SNAKE_CASE_				:      bool = False    ,			SCREAMING_SNAKE_CASE_				:      Optional[TensorType] = None    ,			):
        lowerCAmelCase_   :				List[str]								= self._generate_dummy_inputs_for_encoder_and_decoder(
            __UpperCamelCase    ,			__UpperCamelCase    ,			__UpperCamelCase    ,			__UpperCamelCase    ,			__UpperCamelCase       )

        if self.use_past:
          if not is_torch_available():
            raise ValueError('Cannot generate dummy past_keys inputs without PyTorch installed.'       )
          else:
            import torch
          lowerCAmelCase_						,lowerCAmelCase_   :				Tuple								= common_inputs['input_ids'].shape
          # Not using the same length for past_key_values
          lowerCAmelCase_   :				Union[str, Any]								= seqlen + 2
          lowerCAmelCase_						,lowerCAmelCase_   :				int								= self.num_layers
          lowerCAmelCase_						,lowerCAmelCase_   :				List[Any]								= self.num_attention_heads
          lowerCAmelCase_   :				Any								= (
              batch,
              num_encoder_attention_heads,
              past_key_values_length,
              self._config.hidden_size // num_encoder_attention_heads,
          )

          lowerCAmelCase_   :				Tuple								= common_inputs['attention_mask'].dtype
          lowerCAmelCase_   :				Tuple								= torch.cat(
              [common_inputs['attention_mask'], torch.ones(__UpperCamelCase    ,			__UpperCamelCase    ,			dtype=__UpperCamelCase       )]    ,			dim=1       )
          lowerCAmelCase_   :				List[Any]								= [
              (torch.zeros(__UpperCamelCase       ), torch.zeros(__UpperCamelCase       )) for _ in range(__UpperCamelCase       )
          ]
        return common_inputs



      def      SCREAMING_SNAKE_CASE__ (      self				:      Tuple    ,			SCREAMING_SNAKE_CASE_				:      PreTrainedTokenizer    ,			SCREAMING_SNAKE_CASE_				:      int = -1    ,			SCREAMING_SNAKE_CASE_				:      int = -1    ,			SCREAMING_SNAKE_CASE_				:      bool = False    ,			SCREAMING_SNAKE_CASE_				:      Optional[TensorType] = None    ,			):
        # Copied from OnnxConfig.generate_dummy_inputs
        # Did not use super(OnnxConfigWithPast, self).generate_dummy_inputs for code clarity.
        # If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
        lowerCAmelCase_   :				List[Any]								= compute_effective_axis_dimension(
            __UpperCamelCase    ,			fixed_dimension=OnnxConfig.default_fixed_batch    ,			num_token_to_add=0       )

        # If dynamic axis (-1) we forward with a fixed dimension of 8 tokens to avoid optimizations made by ONNX
        lowerCAmelCase_   :				Union[str, Any]								= tokenizer.num_special_tokens_to_add(__UpperCamelCase       )
        lowerCAmelCase_   :				int								= compute_effective_axis_dimension(
            __UpperCamelCase    ,			fixed_dimension=OnnxConfig.default_fixed_sequence    ,			num_token_to_add=__UpperCamelCase       )

        # Generate dummy inputs according to compute batch and sequence
        lowerCAmelCase_   :				Any								= [' '.join([tokenizer.unk_token]       ) * seq_length] * batch_size
        lowerCAmelCase_   :				int								= dict(tokenizer(__UpperCamelCase    ,			return_tensors=__UpperCamelCase       )       )
        return common_inputs



      def      SCREAMING_SNAKE_CASE__ (      self				:      List[Any]    ,			SCREAMING_SNAKE_CASE_				:      PreTrainedTokenizer    ,			SCREAMING_SNAKE_CASE_				:      int = -1    ,			SCREAMING_SNAKE_CASE_				:      int = -1    ,			SCREAMING_SNAKE_CASE_				:      bool = False    ,			SCREAMING_SNAKE_CASE_				:      Optional[TensorType] = None    ,			):
        if self.task in ["default", "seq2seq-lm"]:
          lowerCAmelCase_   :				List[Any]								= self._generate_dummy_inputs_for_default_and_seqaseq_lm(
              __UpperCamelCase    ,			batch_size=__UpperCamelCase    ,			seq_length=__UpperCamelCase    ,			is_pair=__UpperCamelCase    ,			framework=__UpperCamelCase       )

        else:
          lowerCAmelCase_   :				Tuple								= self._generate_dummy_inputs_for_causal_lm(
              __UpperCamelCase    ,			batch_size=__UpperCamelCase    ,			seq_length=__UpperCamelCase    ,			is_pair=__UpperCamelCase    ,			framework=__UpperCamelCase       )

        return common_inputs



      def      SCREAMING_SNAKE_CASE__ (      self				:      List[Any]    ,			SCREAMING_SNAKE_CASE_				:      Tuple    ,			SCREAMING_SNAKE_CASE_				:      List[str]    ,			SCREAMING_SNAKE_CASE_				:      str    ,			SCREAMING_SNAKE_CASE_				:      str       ):
        if self.task in ["default", "seq2seq-lm"]:
          lowerCAmelCase_   :				List[Any]								= super()._flatten_past_key_values_(__UpperCamelCase    ,			__UpperCamelCase    ,			__UpperCamelCase    ,			__UpperCamelCase       )
        else:
          lowerCAmelCase_   :				Tuple								= super(__UpperCamelCase    ,			self       )._flatten_past_key_values_(
              __UpperCamelCase    ,			__UpperCamelCase    ,			__UpperCamelCase    ,			__UpperCamelCase       )





      @property
      def      SCREAMING_SNAKE_CASE__ (      self				:      List[str]       ):
        return 1E-4












"""simple docstring"""
import random
import unittest

import numpy as np

from diffusers import (
    DPMSolverMultistepScheduler,
    EulerAncestralDiscreteScheduler,
    EulerDiscreteScheduler,
    LMSDiscreteScheduler,
    OnnxStableDiffusionImgaImgPipeline,
    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   (	lowercase_     ,							unittest.TestCase ):
					UpperCamelCase      =							'''hf-internal-testing/tiny-random-OnnxStableDiffusionPipeline'''


					def 	lowerCamelCase       (					self			:Optional[int]     ,       __UpperCamelCase			:Union[str, Any]=0		):
												A		=  floats_tensor((1, 3, 1_28, 1_28)     ,       rng=random.Random(__UpperCamelCase		)		)
												A		=  np.random.RandomState(__UpperCamelCase		)
												A		=  {
												    "prompt": "A painting of a squirrel eating a burger",
												    "image": image,
												    "generator": generator,
												    "num_inference_steps": 3,
												    "strength": 0.75,
												    "guidance_scale": 7.5,
												    "output_type": "numpy",
												}
												return inputs


					def 	lowerCamelCase       (					self			:Any		):
												A		=  OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint     ,       provider="CPUExecutionProvider"		)
												pipe.set_progress_bar_config(disable=__UpperCamelCase		)

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

												assert image.shape == (1, 1_28, 1_28, 3)
												A		=  np.array([0.69_643, 0.58_484, 0.50_314, 0.58_760, 0.55_368, 0.59_643, 0.51_529, 0.41_217, 0.49_087]		)
												assert np.abs(image_slice - expected_slice		).max() < 1e-1


					def 	lowerCamelCase       (					self			:Dict		):
												A		=  OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint     ,       provider="CPUExecutionProvider"		)
												A		=  PNDMScheduler.from_config(pipe.scheduler.config     ,       skip_prk_steps=__UpperCamelCase		)
												pipe.set_progress_bar_config(disable=__UpperCamelCase		)

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

												assert image.shape == (1, 1_28, 1_28, 3)
												A		=  np.array([0.61_737, 0.54_642, 0.53_183, 0.54_465, 0.52_742, 0.60_525, 0.49_969, 0.40_655, 0.48_154]		)

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


					def 	lowerCamelCase       (					self			:Optional[Any]		):
												A		=  OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint     ,       provider="CPUExecutionProvider"		)
												A		=  LMSDiscreteScheduler.from_config(pipe.scheduler.config		)
												pipe.set_progress_bar_config(disable=__UpperCamelCase		)

												# warmup pass to apply optimizations
												A		=  pipe(**self.get_dummy_inputs()		)

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

												assert image.shape == (1, 1_28, 1_28, 3)
												A		=  np.array([0.52_761, 0.59_977, 0.49_033, 0.49_619, 0.54_282, 0.50_311, 0.47_600, 0.40_918, 0.45_203]		)

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


					def 	lowerCamelCase       (					self			:Dict		):
												A		=  OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint     ,       provider="CPUExecutionProvider"		)
												A		=  EulerDiscreteScheduler.from_config(pipe.scheduler.config		)
												pipe.set_progress_bar_config(disable=__UpperCamelCase		)

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

												assert image.shape == (1, 1_28, 1_28, 3)
												A		=  np.array([0.52_911, 0.60_004, 0.49_229, 0.49_805, 0.54_502, 0.50_680, 0.47_777, 0.41_028, 0.45_304]		)

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


					def 	lowerCamelCase       (					self			:Optional[Any]		):
												A		=  OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint     ,       provider="CPUExecutionProvider"		)
												A		=  EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config		)
												pipe.set_progress_bar_config(disable=__UpperCamelCase		)

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

												assert image.shape == (1, 1_28, 1_28, 3)
												A		=  np.array([0.52_911, 0.60_004, 0.49_229, 0.49_805, 0.54_502, 0.50_680, 0.47_777, 0.41_028, 0.45_304]		)

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


					def 	lowerCamelCase       (					self			:Union[str, Any]		):
												A		=  OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint     ,       provider="CPUExecutionProvider"		)
												A		=  DPMSolverMultistepScheduler.from_config(pipe.scheduler.config		)
												pipe.set_progress_bar_config(disable=__UpperCamelCase		)

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

												assert image.shape == (1, 1_28, 1_28, 3)
												A		=  np.array([0.65_331, 0.58_277, 0.48_204, 0.56_059, 0.53_665, 0.56_235, 0.50_969, 0.40_009, 0.46_552]		)

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







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


					@property
					def 	lowerCamelCase       (					self			:Optional[Any]		):
												return (
												    "CUDAExecutionProvider",
												    {
												        "gpu_mem_limit": "15000000000",  # 15GB
												        "arena_extend_strategy": "kSameAsRequested",
												    },
												)


					@property
					def 	lowerCamelCase       (					self			:Optional[int]		):
												A		=  ort.SessionOptions()
												A		=  False
												return options


					def 	lowerCamelCase       (					self			:Dict		):
												A		=  load_image(
												    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
												    "/img2img/sketch-mountains-input.jpg"		)
												A		=  init_image.resize((7_68, 5_12)		)
												# using the PNDM scheduler by default
												A		=  OnnxStableDiffusionImgaImgPipeline.from_pretrained(
												    "CompVis/stable-diffusion-v1-4"     ,       revision="onnx"     ,       safety_checker=__UpperCamelCase     ,       feature_extractor=__UpperCamelCase     ,       provider=self.gpu_provider     ,       sess_options=self.gpu_options     ,       )
												pipe.set_progress_bar_config(disable=__UpperCamelCase		)

												A		=  "A fantasy landscape, trending on artstation"

												A		=  np.random.RandomState(0		)
												A		=  pipe(
												    prompt=__UpperCamelCase     ,       image=__UpperCamelCase     ,       strength=0.75     ,       guidance_scale=7.5     ,       num_inference_steps=10     ,       generator=__UpperCamelCase     ,       output_type="np"     ,       )
												A		=  output.images
												A		=  images[0, 2_55:2_58, 3_83:3_86, -1]

												assert images.shape == (1, 5_12, 7_68, 3)
												A		=  np.array([0.4_909, 0.5_059, 0.5_372, 0.4_623, 0.4_876, 0.5_049, 0.4_820, 0.4_956, 0.5_019]		)
												# 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			:Any		):
												A		=  load_image(
												    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
												    "/img2img/sketch-mountains-input.jpg"		)
												A		=  init_image.resize((7_68, 5_12)		)
												A		=  LMSDiscreteScheduler.from_pretrained(
												    "runwayml/stable-diffusion-v1-5"     ,       subfolder="scheduler"     ,       revision="onnx"		)
												A		=  OnnxStableDiffusionImgaImgPipeline.from_pretrained(
												    "runwayml/stable-diffusion-v1-5"     ,       revision="onnx"     ,       scheduler=__UpperCamelCase     ,       safety_checker=__UpperCamelCase     ,       feature_extractor=__UpperCamelCase     ,       provider=self.gpu_provider     ,       sess_options=self.gpu_options     ,       )
												pipe.set_progress_bar_config(disable=__UpperCamelCase		)

												A		=  "A fantasy landscape, trending on artstation"

												A		=  np.random.RandomState(0		)
												A		=  pipe(
												    prompt=__UpperCamelCase     ,       image=__UpperCamelCase     ,       strength=0.75     ,       guidance_scale=7.5     ,       num_inference_steps=20     ,       generator=__UpperCamelCase     ,       output_type="np"     ,       )
												A		=  output.images
												A		=  images[0, 2_55:2_58, 3_83:3_86, -1]

												assert images.shape == (1, 5_12, 7_68, 3)
												A		=  np.array([0.8_043, 0.926, 0.9_581, 0.8_119, 0.8_954, 0.913, 0.7_209, 0.7_463, 0.7_431]		)
												# TODO: lower the tolerance after finding the cause of onnxruntime reproducibility issues

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


