






import itertools
import os
import random
import tempfile
import unittest

import numpy as np
from datasets import load_dataset

from transformers import is_speech_available
from transformers.testing_utils import check_json_file_has_correct_format, require_torch, require_torchaudio
from transformers.utils.import_utils import is_torch_available

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


if is_speech_available():
       from transformers import WhisperFeatureExtractor

if is_torch_available():
       import torch

a		:       int			     = random.Random()






def 				lowerCamelCase__      (    __lowerCamelCase			:     Union[str, Any]  ,		__lowerCamelCase			:     Union[str, Any]=1.0  ,		__lowerCamelCase			:     Union[str, Any]=None  ,		__lowerCamelCase			:     Tuple=None		):
  if rng is None:
    __UpperCAmelCase							:	List[str]           =  global_rng

  __UpperCAmelCase							:	Union[str, Any]           =  []
  for batch_idx in range(shape[0]		):
    values.append([]		)
    for _ in range(shape[1]		):
      values[-1].append(rng.random() * scale		)

  return values
@require_torch
@require_torchaudio
class     a    ( unittest.TestCase   ):



      """simple docstring"""


      def __init__(      self					:			List[Any]		,      __lowercase					:			Optional[int]		,      __lowercase					:			List[str]=7		,      __lowercase					:			Tuple=400		,      __lowercase					:			List[Any]=2000		,      __lowercase					:			Optional[int]=10		,      __lowercase					:			Union[str, Any]=160		,      __lowercase					:			Tuple=8		,      __lowercase					:			Any=0.0		,      __lowercase					:			Optional[int]=4000		,      __lowercase					:			List[Any]=False		,      __lowercase					:			Optional[Any]=True		,      )							->      Tuple:
        __UpperCAmelCase							:	Any           =  parent
        __UpperCAmelCase							:	Optional[int]           =  batch_size
        __UpperCAmelCase							:	List[Any]           =  min_seq_length
        __UpperCAmelCase							:	Union[str, Any]           =  max_seq_length
        __UpperCAmelCase							:	str           =  (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
        __UpperCAmelCase							:	Union[str, Any]           =  padding_value
        __UpperCAmelCase							:	Union[str, Any]           =  sampling_rate
        __UpperCAmelCase							:	List[Any]           =  return_attention_mask
        __UpperCAmelCase							:	Optional[Any]           =  do_normalize
        __UpperCAmelCase							:	Tuple           =  feature_size
        __UpperCAmelCase							:	Union[str, Any]           =  chunk_length
        __UpperCAmelCase							:	Union[str, Any]           =  hop_length
      def 	UpperCAmelCase      (      self					:			Any					)							->      Dict:
        return {
            "feature_size": self.feature_size,
            "hop_length": self.hop_length,
            "chunk_length": self.chunk_length,
            "padding_value": self.padding_value,
            "sampling_rate": self.sampling_rate,
            "return_attention_mask": self.return_attention_mask,
            "do_normalize": self.do_normalize,
        }




      def 	UpperCAmelCase      (      self					:			Union[str, Any]		,      __lowercase					:			Any=False		,      __lowercase					:			Optional[Any]=False					)							->      List[Any]:
        def _flatten(__lowercase					:			Union[str, Any]					):
          return list(itertools.chain(*__lowercase					)					)

        if equal_length:
          __UpperCAmelCase							:	int           =  [floats_list((self.max_seq_length, self.feature_size)					) for _ in range(self.batch_size					)]
        else:
          # make sure that inputs increase in size
          __UpperCAmelCase							:	List[Any]           =  [
              floats_list((x, self.feature_size)					)
              for x in range(self.min_seq_length		,      self.max_seq_length		,      self.seq_length_diff					)
          ]
        if numpify:
          __UpperCAmelCase							:	Tuple           =  [np.asarray(__lowercase					) for x in speech_inputs]
        return speech_inputs


@require_torch
@require_torchaudio
class     a    ( lowercase__							,       unittest.TestCase   ):



      """simple docstring"""


      a  : List[str]							       =	WhisperFeatureExtractor if is_speech_available() else None
      def 	UpperCAmelCase      (      self					:			List[str]					)							->      Union[str, Any]:
        __UpperCAmelCase							:	Optional[Any]           =  WhisperFeatureExtractionTester(self					)
      def 	UpperCAmelCase      (      self					:			List[Any]					)							->      Optional[Any]:
        __UpperCAmelCase							:	Dict           =  self.feature_extraction_class(**self.feat_extract_dict					)

        with tempfile.TemporaryDirectory() as tmpdirname:
          __UpperCAmelCase							:	Union[str, Any]           =  feat_extract_first.save_pretrained(__lowercase					)[0]
          check_json_file_has_correct_format(__lowercase					)
          __UpperCAmelCase							:	Optional[Any]           =  self.feature_extraction_class.from_pretrained(__lowercase					)

        __UpperCAmelCase							:	Optional[Any]           =  feat_extract_first.to_dict()
        __UpperCAmelCase							:	List[str]           =  feat_extract_second.to_dict()
        __UpperCAmelCase							:	List[Any]           =  feat_extract_first.mel_filters
        __UpperCAmelCase							:	List[str]           =  feat_extract_second.mel_filters
        self.assertTrue(np.allclose(__lowercase		,      __lowercase					)					)
        self.assertEqual(__lowercase		,      __lowercase					)
      def 	UpperCAmelCase      (      self					:			List[str]					)							->      Dict:
        __UpperCAmelCase							:	Union[str, Any]           =  self.feature_extraction_class(**self.feat_extract_dict					)

        with tempfile.TemporaryDirectory() as tmpdirname:
          __UpperCAmelCase							:	Optional[Any]           =  os.path.join(__lowercase		,      """feat_extract.json"""					)
          feat_extract_first.to_json_file(__lowercase					)
          __UpperCAmelCase							:	List[Any]           =  self.feature_extraction_class.from_json_file(__lowercase					)

        __UpperCAmelCase							:	Union[str, Any]           =  feat_extract_first.to_dict()
        __UpperCAmelCase							:	Tuple           =  feat_extract_second.to_dict()
        __UpperCAmelCase							:	Any           =  feat_extract_first.mel_filters
        __UpperCAmelCase							:	str           =  feat_extract_second.mel_filters
        self.assertTrue(np.allclose(__lowercase		,      __lowercase					)					)
        self.assertEqual(__lowercase		,      __lowercase					)
      def 	UpperCAmelCase      (      self					:			str					)							->      Optional[Any]:
        # Tests that all call wrap to encode_plus and batch_encode_plus
        __UpperCAmelCase							:	Any           =  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()					)
        # create three inputs of length 800, 1000, and 1200
        __UpperCAmelCase							:	int           =  [floats_list((1, x)					)[0] for x in range(800		,      1400		,      200					)]
        __UpperCAmelCase							:	Dict           =  [np.asarray(__lowercase					) for speech_input in speech_inputs]

        # Test feature size
        __UpperCAmelCase							:	Dict           =  feature_extractor(__lowercase		,      padding="""max_length"""		,      return_tensors="""np"""					).input_features
        self.assertTrue(input_features.ndim == 3					)
        self.assertTrue(input_features.shape[-1] == feature_extractor.nb_max_frames					)
        self.assertTrue(input_features.shape[-2] == feature_extractor.feature_size					)

        # Test not batched input
        __UpperCAmelCase							:	Any           =  feature_extractor(speech_inputs[0]		,      return_tensors="""np"""					).input_features
        __UpperCAmelCase							:	Optional[int]           =  feature_extractor(np_speech_inputs[0]		,      return_tensors="""np"""					).input_features
        self.assertTrue(np.allclose(__lowercase		,      __lowercase		,      atol=1e-3					)					)

        # Test batched
        __UpperCAmelCase							:	str           =  feature_extractor(__lowercase		,      return_tensors="""np"""					).input_features
        __UpperCAmelCase							:	Any           =  feature_extractor(__lowercase		,      return_tensors="""np"""					).input_features
        for enc_seq_a, enc_seq_a in zip(__lowercase		,      __lowercase					):
          self.assertTrue(np.allclose(__lowercase		,      __lowercase		,      atol=1e-3					)					)

        # Test 2-D numpy arrays are batched.
        __UpperCAmelCase							:	Tuple           =  [floats_list((1, x)					)[0] for x in (800, 800, 800)]
        __UpperCAmelCase							:	Tuple           =  np.asarray(__lowercase					)
        __UpperCAmelCase							:	Union[str, Any]           =  feature_extractor(__lowercase		,      return_tensors="""np"""					).input_features
        __UpperCAmelCase							:	List[Any]           =  feature_extractor(__lowercase		,      return_tensors="""np"""					).input_features
        for enc_seq_a, enc_seq_a in zip(__lowercase		,      __lowercase					):
          self.assertTrue(np.allclose(__lowercase		,      __lowercase		,      atol=1e-3					)					)

        # Test truncation required
        __UpperCAmelCase							:	Optional[int]           =  [floats_list((1, x)					)[0] for x in range(200		,      (feature_extractor.n_samples + 500)		,      200					)]
        __UpperCAmelCase							:	str           =  [np.asarray(__lowercase					) for speech_input in speech_inputs]

        __UpperCAmelCase							:	int           =  [x[: feature_extractor.n_samples] for x in speech_inputs]
        __UpperCAmelCase							:	Any           =  [np.asarray(__lowercase					) for speech_input in speech_inputs_truncated]

        __UpperCAmelCase							:	str           =  feature_extractor(__lowercase		,      return_tensors="""np"""					).input_features
        __UpperCAmelCase							:	Any           =  feature_extractor(__lowercase		,      return_tensors="""np"""					).input_features
        for enc_seq_a, enc_seq_a in zip(__lowercase		,      __lowercase					):
          self.assertTrue(np.allclose(__lowercase		,      __lowercase		,      atol=1e-3					)					)
      def 	UpperCAmelCase      (      self					:			Dict					)							->      List[str]:
        import torch

        __UpperCAmelCase							:	int           =  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()					)
        __UpperCAmelCase							:	List[Any]           =  np.random.rand(100		,      32					).astype(np.floataa					)
        __UpperCAmelCase							:	List[str]           =  np_speech_inputs.tolist()

        for inputs in [py_speech_inputs, np_speech_inputs]:
          __UpperCAmelCase							:	Optional[Any]           =  feature_extractor.pad([{"""input_features""": inputs}]		,      return_tensors="""np"""					)
          self.assertTrue(np_processed.input_features.dtype == np.floataa					)
          __UpperCAmelCase							:	Dict           =  feature_extractor.pad([{"""input_features""": inputs}]		,      return_tensors="""pt"""					)
          self.assertTrue(pt_processed.input_features.dtype == torch.floataa					)
      def 	UpperCAmelCase      (      self					:			Tuple		,      __lowercase					:			List[str]					)							->      List[str]:
        __UpperCAmelCase							:	Optional[Any]           =  load_dataset("""hf-internal-testing/librispeech_asr_dummy"""		,      """clean"""		,      split="""validation"""					)
        # automatic decoding with librispeech
        __UpperCAmelCase							:	Union[str, Any]           =  ds.sort("""id"""					).select(range(__lowercase					)					)[:num_samples]["""audio"""]

        return [x["array"] for x in speech_samples]
      def 	UpperCAmelCase      (      self					:			Optional[int]					)							->      List[str]:
        # fmt: off
        __UpperCAmelCase							:	int           =  torch.tensor(
            [
                0.1_193, -0.0_946, -0.1_098, -0.0_196, 0.0_225, -0.0_690, -0.1_736, 0.0_951,
                0.0_971, -0.0_817, -0.0_702, 0.0_162, 0.0_260, 0.0_017, -0.0_192, -0.1_678,
                0.0_709, -0.1_867, -0.0_655, -0.0_274, -0.0_234, -0.1_884, -0.0_516, -0.0_554,
                -0.0_274, -0.1_425, -0.1_423, 0.0_837, 0.0_377, -0.0_854
            ]					)
        # fmt: on

        __UpperCAmelCase							:	Optional[Any]           =  self._load_datasamples(1					)
        __UpperCAmelCase							:	str           =  WhisperFeatureExtractor()
        __UpperCAmelCase							:	Union[str, Any]           =  feature_extractor(__lowercase		,      return_tensors="""pt"""					).input_features
        self.assertEqual(input_features.shape		,      (1, 80, 3000)					)
        self.assertTrue(torch.allclose(input_features[0, 0, :30]		,      __lowercase		,      atol=1e-4					)					)




      def 	UpperCAmelCase      (      self					:			Optional[int]					)							->      Tuple:
        __UpperCAmelCase							:	Optional[int]           =  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()					)
        __UpperCAmelCase							:	Tuple           =  self._load_datasamples(1					)[0]
        __UpperCAmelCase							:	Optional[int]           =  ((audio - audio.min()) / (audio.max() - audio.min())) * 65535  # Rescale to [0, 65535] to show issue
        __UpperCAmelCase							:	str           =  feat_extract.zero_mean_unit_var_norm([audio]		,      attention_mask=__lowercase					)[0]

        self.assertTrue(np.all(np.mean(__lowercase					) < 1e-3					)					)
        self.assertTrue(np.all(np.abs(np.var(__lowercase					) - 1					) < 1e-3					)					)










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     a    ( lowercase__							,       unittest.TestCase   ):



      """simple docstring"""


      a  : int							       =	'hf-internal-testing/tiny-random-OnnxStableDiffusionPipeline'
      def 	UpperCAmelCase      (      self					:			List[str]		,      __lowercase					:			Optional[Any]=0					)							->      Any:
        __UpperCAmelCase							:	Any           =  floats_tensor((1, 3, 128, 128)		,      rng=random.Random(__lowercase					)					)
        __UpperCAmelCase							:	int           =  np.random.RandomState(__lowercase					)
        __UpperCAmelCase							:	Optional[Any]           =  {
            """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 	UpperCAmelCase      (      self					:			Optional[int]					)							->      Optional[Any]:
        __UpperCAmelCase							:	List[Any]           =  OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint		,      provider="""CPUExecutionProvider"""					)
        pipe.set_progress_bar_config(disable=__lowercase					)

        __UpperCAmelCase							:	int           =  self.get_dummy_inputs()
        __UpperCAmelCase							:	Optional[Any]           =  pipe(**__lowercase					).images
        __UpperCAmelCase							:	Union[str, Any]           =  image[0, -3:, -3:, -1].flatten()

        assert image.shape == (1, 128, 128, 3)
        __UpperCAmelCase							:	List[str]           =  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 	UpperCAmelCase      (      self					:			Optional[Any]					)							->      List[str]:
        __UpperCAmelCase							:	Dict           =  OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint		,      provider="""CPUExecutionProvider"""					)
        __UpperCAmelCase							:	int           =  PNDMScheduler.from_config(pipe.scheduler.config		,      skip_prk_steps=__lowercase					)
        pipe.set_progress_bar_config(disable=__lowercase					)

        __UpperCAmelCase							:	Any           =  self.get_dummy_inputs()
        __UpperCAmelCase							:	Tuple           =  pipe(**__lowercase					).images
        __UpperCAmelCase							:	Dict           =  image[0, -3:, -3:, -1]

        assert image.shape == (1, 128, 128, 3)
        __UpperCAmelCase							:	str           =  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 	UpperCAmelCase      (      self					:			str					)							->      Tuple:
        __UpperCAmelCase							:	Tuple           =  OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint		,      provider="""CPUExecutionProvider"""					)
        __UpperCAmelCase							:	int           =  LMSDiscreteScheduler.from_config(pipe.scheduler.config					)
        pipe.set_progress_bar_config(disable=__lowercase					)

        # warmup pass to apply optimizations
        __UpperCAmelCase							:	Optional[int]           =  pipe(**self.get_dummy_inputs()					)

        __UpperCAmelCase							:	Tuple           =  self.get_dummy_inputs()
        __UpperCAmelCase							:	Any           =  pipe(**__lowercase					).images
        __UpperCAmelCase							:	List[Any]           =  image[0, -3:, -3:, -1]

        assert image.shape == (1, 128, 128, 3)
        __UpperCAmelCase							:	Optional[int]           =  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 	UpperCAmelCase      (      self					:			Optional[Any]					)							->      str:
        __UpperCAmelCase							:	int           =  OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint		,      provider="""CPUExecutionProvider"""					)
        __UpperCAmelCase							:	Union[str, Any]           =  EulerDiscreteScheduler.from_config(pipe.scheduler.config					)
        pipe.set_progress_bar_config(disable=__lowercase					)

        __UpperCAmelCase							:	List[str]           =  self.get_dummy_inputs()
        __UpperCAmelCase							:	int           =  pipe(**__lowercase					).images
        __UpperCAmelCase							:	Dict           =  image[0, -3:, -3:, -1]

        assert image.shape == (1, 128, 128, 3)
        __UpperCAmelCase							:	Tuple           =  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 	UpperCAmelCase      (      self					:			int					)							->      Any:
        __UpperCAmelCase							:	Any           =  OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint		,      provider="""CPUExecutionProvider"""					)
        __UpperCAmelCase							:	List[Any]           =  EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config					)
        pipe.set_progress_bar_config(disable=__lowercase					)

        __UpperCAmelCase							:	Union[str, Any]           =  self.get_dummy_inputs()
        __UpperCAmelCase							:	int           =  pipe(**__lowercase					).images
        __UpperCAmelCase							:	List[Any]           =  image[0, -3:, -3:, -1]

        assert image.shape == (1, 128, 128, 3)
        __UpperCAmelCase							:	List[str]           =  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 	UpperCAmelCase      (      self					:			Tuple					)							->      str:
        __UpperCAmelCase							:	Dict           =  OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint		,      provider="""CPUExecutionProvider"""					)
        __UpperCAmelCase							:	str           =  DPMSolverMultistepScheduler.from_config(pipe.scheduler.config					)
        pipe.set_progress_bar_config(disable=__lowercase					)

        __UpperCAmelCase							:	Optional[Any]           =  self.get_dummy_inputs()
        __UpperCAmelCase							:	int           =  pipe(**__lowercase					).images
        __UpperCAmelCase							:	List[Any]           =  image[0, -3:, -3:, -1]

        assert image.shape == (1, 128, 128, 3)
        __UpperCAmelCase							:	Union[str, Any]           =  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     a    ( unittest.TestCase   ):



      """simple docstring"""


      @property
      def 	UpperCAmelCase      (      self					:			Dict					)							->      List[Any]:
        return (
            "CUDAExecutionProvider",
            {
                "gpu_mem_limit": "15000000000",  # 15GB
                "arena_extend_strategy": "kSameAsRequested",
            },
        )
      @property
      def 	UpperCAmelCase      (      self					:			Tuple					)							->      Tuple:
        __UpperCAmelCase							:	Optional[int]           =  ort.SessionOptions()
        __UpperCAmelCase							:	List[Any]           =  False
        return options
      def 	UpperCAmelCase      (      self					:			List[str]					)							->      Tuple:
        __UpperCAmelCase							:	List[Any]           =  load_image(
            """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"""
            """/img2img/sketch-mountains-input.jpg"""					)
        __UpperCAmelCase							:	Dict           =  init_image.resize((768, 512)					)
        # using the PNDM scheduler by default
        __UpperCAmelCase							:	Any           =  OnnxStableDiffusionImgaImgPipeline.from_pretrained(
            """CompVis/stable-diffusion-v1-4"""		,      revision="""onnx"""		,      safety_checker=__lowercase		,      feature_extractor=__lowercase		,      provider=self.gpu_provider		,      sess_options=self.gpu_options		,      )
        pipe.set_progress_bar_config(disable=__lowercase					)

        __UpperCAmelCase							:	Dict           =  """A fantasy landscape, trending on artstation"""

        __UpperCAmelCase							:	str           =  np.random.RandomState(0					)
        __UpperCAmelCase							:	Optional[Any]           =  pipe(
            prompt=__lowercase		,      image=__lowercase		,      strength=0.75		,      guidance_scale=7.5		,      num_inference_steps=10		,      generator=__lowercase		,      output_type="""np"""		,      )
        __UpperCAmelCase							:	str           =  output.images
        __UpperCAmelCase							:	int           =  images[0, 255:258, 383:386, -1]

        assert images.shape == (1, 512, 768, 3)
        __UpperCAmelCase							:	Union[str, Any]           =  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 	UpperCAmelCase      (      self					:			Optional[Any]					)							->      str:
        __UpperCAmelCase							:	Tuple           =  load_image(
            """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"""
            """/img2img/sketch-mountains-input.jpg"""					)
        __UpperCAmelCase							:	int           =  init_image.resize((768, 512)					)
        __UpperCAmelCase							:	Tuple           =  LMSDiscreteScheduler.from_pretrained(
            """runwayml/stable-diffusion-v1-5"""		,      subfolder="""scheduler"""		,      revision="""onnx"""					)
        __UpperCAmelCase							:	Tuple           =  OnnxStableDiffusionImgaImgPipeline.from_pretrained(
            """runwayml/stable-diffusion-v1-5"""		,      revision="""onnx"""		,      scheduler=__lowercase		,      safety_checker=__lowercase		,      feature_extractor=__lowercase		,      provider=self.gpu_provider		,      sess_options=self.gpu_options		,      )
        pipe.set_progress_bar_config(disable=__lowercase					)

        __UpperCAmelCase							:	Dict           =  """A fantasy landscape, trending on artstation"""

        __UpperCAmelCase							:	int           =  np.random.RandomState(0					)
        __UpperCAmelCase							:	Optional[int]           =  pipe(
            prompt=__lowercase		,      image=__lowercase		,      strength=0.75		,      guidance_scale=7.5		,      num_inference_steps=20		,      generator=__lowercase		,      output_type="""np"""		,      )
        __UpperCAmelCase							:	Union[str, Any]           =  output.images
        __UpperCAmelCase							:	Union[str, Any]           =  images[0, 255:258, 383:386, -1]

        assert images.shape == (1, 512, 768, 3)
        __UpperCAmelCase							:	str           =  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


