


import unittest

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

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
   import torch

   from transformers import (
       LiltForQuestionAnswering,
       LiltForSequenceClassification,
       LiltForTokenClassification,
       LiltModel,
   )
   from transformers.models.lilt.modeling_lilt import LILT_PRETRAINED_MODEL_ARCHIVE_LIST
class  SCREAMING_SNAKE_CASE__  :
      def __init__(       self				:       Tuple     ,							SCREAMING_SNAKE_CASE__				:       List[Any]     ,							SCREAMING_SNAKE_CASE__				:       str=1_3     ,							SCREAMING_SNAKE_CASE__				:       Optional[int]=7     ,							SCREAMING_SNAKE_CASE__				:       str=True     ,							SCREAMING_SNAKE_CASE__				:       int=True     ,							SCREAMING_SNAKE_CASE__				:       Dict=True     ,							SCREAMING_SNAKE_CASE__				:       str=True     ,							SCREAMING_SNAKE_CASE__				:       str=9_9     ,							SCREAMING_SNAKE_CASE__				:       str=2_4     ,							SCREAMING_SNAKE_CASE__				:       Union[str, Any]=2     ,							SCREAMING_SNAKE_CASE__				:       Optional[Any]=6     ,							SCREAMING_SNAKE_CASE__				:       Optional[int]=3_7     ,							SCREAMING_SNAKE_CASE__				:       List[Any]="gelu"     ,							SCREAMING_SNAKE_CASE__				:       str=0.1     ,							SCREAMING_SNAKE_CASE__				:       List[Any]=0.1     ,							SCREAMING_SNAKE_CASE__				:       List[str]=5_1_2     ,							SCREAMING_SNAKE_CASE__				:       List[str]=1_6     ,							SCREAMING_SNAKE_CASE__				:       Union[str, Any]=2     ,							SCREAMING_SNAKE_CASE__				:       int=0.02     ,							SCREAMING_SNAKE_CASE__				:       Optional[Any]=3     ,							SCREAMING_SNAKE_CASE__				:       Optional[int]=None     ,							SCREAMING_SNAKE_CASE__				:       Tuple=1_0_0_0     ,							)		->			str:
             a_					:		Optional[Any]							=  parent
             a_					:		List[str]							=  batch_size
             a_					:		List[str]							=  seq_length
             a_					:		str							=  is_training
             a_					:		str							=  use_input_mask
             a_					:		int							=  use_token_type_ids
             a_					:		List[str]							=  use_labels
             a_					:		Optional[int]							=  vocab_size
             a_					:		Any							=  hidden_size
             a_					:		int							=  num_hidden_layers
             a_					:		List[str]							=  num_attention_heads
             a_					:		str							=  intermediate_size
             a_					:		Union[str, Any]							=  hidden_act
             a_					:		List[str]							=  hidden_dropout_prob
             a_					:		int							=  attention_probs_dropout_prob
             a_					:		int							=  max_position_embeddings
             a_					:		Tuple							=  type_vocab_size
             a_					:		Optional[Any]							=  type_sequence_label_size
             a_					:		Tuple							=  initializer_range
             a_					:		Dict							=  num_labels
             a_					:		str							=  scope
             a_					:		Optional[int]							=  range_bbox
      def        SCREAMING_SNAKE_CASE							(       self				:       List[str]     )		->			int:
             a_					:		Dict							=  ids_tensor([self.batch_size, self.seq_length]     ,							self.vocab_size     )

             a_					:		Any							=  ids_tensor([self.batch_size, self.seq_length, 4]     ,							self.range_bbox     )
             # Ensure that bbox is legal
             for i in range(bbox.shape[0]     ):
                    for j in range(bbox.shape[1]     ):
                           if bbox[i, j, 3] < bbox[i, j, 1]:
                                  a_					:		int							=  bbox[i, j, 3]
                                  a_					:		str							=  bbox[i, j, 1]
                                  a_					:		List[str]							=  t
                           if bbox[i, j, 2] < bbox[i, j, 0]:
                                  a_					:		Tuple							=  bbox[i, j, 2]
                                  a_					:		List[str]							=  bbox[i, j, 0]
                                  a_					:		Union[str, Any]							=  t

             a_					:		List[Any]							=  None
             if self.use_input_mask:
                    a_					:		Dict							=  ids_tensor([self.batch_size, self.seq_length]     ,							vocab_size=2     )

             a_					:		List[Any]							=  None
             if self.use_token_type_ids:
                    a_					:		Optional[Any]							=  ids_tensor([self.batch_size, self.seq_length]     ,							self.type_vocab_size     )

             a_					:		int							=  None
             a_					:		Tuple							=  None
             if self.use_labels:
                    a_					:		List[Any]							=  ids_tensor([self.batch_size]     ,							self.type_sequence_label_size     )
                    a_					:		int							=  ids_tensor([self.batch_size, self.seq_length]     ,							self.num_labels     )

             a_					:		Optional[int]							=  self.get_config()

             return config, input_ids, bbox, token_type_ids, input_mask, sequence_labels, token_labels
      def        SCREAMING_SNAKE_CASE							(       self				:       Dict     )		->			int:
             return LiltConfig(
                 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     ,							initializer_range=self.initializer_range     ,							)
      def        SCREAMING_SNAKE_CASE							(       self				:       Optional[int]     ,							SCREAMING_SNAKE_CASE__				:       Dict     ,							SCREAMING_SNAKE_CASE__				:       Any     ,							SCREAMING_SNAKE_CASE__				:       Any     ,							SCREAMING_SNAKE_CASE__				:       Optional[int]     ,							SCREAMING_SNAKE_CASE__				:       int     ,							SCREAMING_SNAKE_CASE__				:       Union[str, Any]     ,							SCREAMING_SNAKE_CASE__				:       Optional[Any]     ,							)		->			str:
             a_					:		Any							=  LiltModel(config=SCREAMING_SNAKE_CASE__     )
             model.to(SCREAMING_SNAKE_CASE__     )
             model.eval()
             a_					:		Any							=  model(SCREAMING_SNAKE_CASE__     ,							bbox=SCREAMING_SNAKE_CASE__     ,							attention_mask=SCREAMING_SNAKE_CASE__     ,							token_type_ids=SCREAMING_SNAKE_CASE__     )
             a_					:		Optional[int]							=  model(SCREAMING_SNAKE_CASE__     ,							bbox=SCREAMING_SNAKE_CASE__     ,							token_type_ids=SCREAMING_SNAKE_CASE__     )
             a_					:		List[Any]							=  model(SCREAMING_SNAKE_CASE__     ,							bbox=SCREAMING_SNAKE_CASE__     )

             self.parent.assertEqual(result.last_hidden_state.shape     ,							(self.batch_size, self.seq_length, self.hidden_size)     )
             self.parent.assertEqual(result.pooler_output.shape     ,							(self.batch_size, self.hidden_size)     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Tuple     ,							SCREAMING_SNAKE_CASE__				:       str     ,							SCREAMING_SNAKE_CASE__				:       int     ,							SCREAMING_SNAKE_CASE__				:       int     ,							SCREAMING_SNAKE_CASE__				:       Union[str, Any]     ,							SCREAMING_SNAKE_CASE__				:       Optional[int]     ,							SCREAMING_SNAKE_CASE__				:       Any     ,							SCREAMING_SNAKE_CASE__				:       Optional[Any]     ,							)		->			int:
             a_					:		Any							=  self.num_labels
             a_					:		str							=  LiltForTokenClassification(config=SCREAMING_SNAKE_CASE__     )
             model.to(SCREAMING_SNAKE_CASE__     )
             model.eval()
             a_					:		str							=  model(
                 SCREAMING_SNAKE_CASE__     ,							bbox=SCREAMING_SNAKE_CASE__     ,							attention_mask=SCREAMING_SNAKE_CASE__     ,							token_type_ids=SCREAMING_SNAKE_CASE__     ,							labels=SCREAMING_SNAKE_CASE__     )
             self.parent.assertEqual(result.logits.shape     ,							(self.batch_size, self.seq_length, self.num_labels)     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Any     ,							SCREAMING_SNAKE_CASE__				:       Tuple     ,							SCREAMING_SNAKE_CASE__				:       List[str]     ,							SCREAMING_SNAKE_CASE__				:       List[str]     ,							SCREAMING_SNAKE_CASE__				:       int     ,							SCREAMING_SNAKE_CASE__				:       Any     ,							SCREAMING_SNAKE_CASE__				:       Dict     ,							SCREAMING_SNAKE_CASE__				:       Union[str, Any]     ,							)		->			str:
             a_					:		Union[str, Any]							=  LiltForQuestionAnswering(config=SCREAMING_SNAKE_CASE__     )
             model.to(SCREAMING_SNAKE_CASE__     )
             model.eval()
             a_					:		List[str]							=  model(
                 SCREAMING_SNAKE_CASE__     ,							bbox=SCREAMING_SNAKE_CASE__     ,							attention_mask=SCREAMING_SNAKE_CASE__     ,							token_type_ids=SCREAMING_SNAKE_CASE__     ,							start_positions=SCREAMING_SNAKE_CASE__     ,							end_positions=SCREAMING_SNAKE_CASE__     ,							)
             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        SCREAMING_SNAKE_CASE							(       self				:       int     )		->			List[str]:
             a_					:		int							=  self.prepare_config_and_inputs()
             (
                 (
                 a_
             )							,		(
                 a_
             )							,		(
                 a_
             )							,		(
                 a_
             )							,		(
                 a_
             )							,		(
                 a_
             )							,		(
                 a_
             )							,		
             )					:		List[Any]							=  config_and_inputs
             a_					:		Optional[int]							=  {
                 'input_ids': input_ids,
                 'bbox': bbox,
                 'token_type_ids': token_type_ids,
                 'attention_mask': input_mask,
             }
             return config, inputs_dict
@require_torch
class  SCREAMING_SNAKE_CASE__  (				lowercase__						,    lowercase__						,    lowercase__						,    unittest.TestCase			):
      snake_case__				:     Union[str, Any]        =						(
          (
              LiltModel,
              LiltForSequenceClassification,
              LiltForTokenClassification,
              LiltForQuestionAnswering,
          )
          if is_torch_available()
          else ()
      )
      snake_case__				:     str        =						(
          {
              '''feature-extraction''': LiltModel,
              '''question-answering''': LiltForQuestionAnswering,
              '''text-classification''': LiltForSequenceClassification,
              '''token-classification''': LiltForTokenClassification,
              '''zero-shot''': LiltForSequenceClassification,
          }
          if is_torch_available()
          else {}
      )
      snake_case__				:     List[str]        =						False
      snake_case__				:     str        =						False
      def        SCREAMING_SNAKE_CASE							(       self				:       Dict     ,							SCREAMING_SNAKE_CASE__				:       str     ,							SCREAMING_SNAKE_CASE__				:       Tuple     ,							SCREAMING_SNAKE_CASE__				:       List[str]     ,							SCREAMING_SNAKE_CASE__				:       Optional[int]     ,							SCREAMING_SNAKE_CASE__				:       int     )		->			int:
             return True
      def        SCREAMING_SNAKE_CASE							(       self				:       Optional[Any]     )		->			Tuple:
             a_					:		str							=  LiltModelTester(self     )
             a_					:		List[Any]							=  ConfigTester(self     ,							config_class=SCREAMING_SNAKE_CASE__     ,							hidden_size=3_7     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Dict     )		->			List[Any]:
             self.config_tester.run_common_tests()
      def        SCREAMING_SNAKE_CASE							(       self				:       Optional[int]     )		->			str:
             a_					:		Dict							=  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE__     )
      def        SCREAMING_SNAKE_CASE							(       self				:       Dict     )		->			Optional[int]:
             a_					:		Tuple							=  self.model_tester.prepare_config_and_inputs()
             for type in ["absolute", "relative_key", "relative_key_query"]:
                    a_					:		List[str]							=  type
                    self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE__     )
      def        SCREAMING_SNAKE_CASE							(       self				:       int     )		->			Optional[Any]:
             a_					:		List[Any]							=  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_token_classification(*SCREAMING_SNAKE_CASE__     )
      def        SCREAMING_SNAKE_CASE							(       self				:       List[str]     )		->			List[str]:
             a_					:		Optional[Any]							=  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_question_answering(*SCREAMING_SNAKE_CASE__     )

      @slow
      def        SCREAMING_SNAKE_CASE							(       self				:       str     )		->			Union[str, Any]:
             for model_name in LILT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                    a_					:		List[Any]							=  LiltModel.from_pretrained(SCREAMING_SNAKE_CASE__     )
                    self.assertIsNotNone(SCREAMING_SNAKE_CASE__     )
@require_torch
@slow
class  SCREAMING_SNAKE_CASE__  (				unittest.TestCase			):
      def        SCREAMING_SNAKE_CASE							(       self				:       Union[str, Any]     )		->			Union[str, Any]:
             a_					:		List[str]							=  LiltModel.from_pretrained('SCUT-DLVCLab/lilt-roberta-en-base'     ).to(SCREAMING_SNAKE_CASE__     )

             a_					:		str							=  torch.tensor([[1, 2]]     ,							device=SCREAMING_SNAKE_CASE__     )
             a_					:		List[Any]							=  torch.tensor([[[1, 2, 3, 4], [5, 6, 7, 8]]]     ,							device=SCREAMING_SNAKE_CASE__     )

             # forward pass
             with torch.no_grad():
                    a_					:		str							=  model(input_ids=SCREAMING_SNAKE_CASE__     ,							bbox=SCREAMING_SNAKE_CASE__     )

             a_					:		Optional[int]							=  torch.Size([1, 2, 7_6_8]     )
             a_					:		int							=  torch.tensor(
                 [[-0.0653, 0.0950, -0.0061], [-0.0545, 0.0926, -0.0324]]     ,							device=SCREAMING_SNAKE_CASE__     ,							)

             self.assertTrue(outputs.last_hidden_state.shape     ,							SCREAMING_SNAKE_CASE__     )
             self.assertTrue(torch.allclose(outputs.last_hidden_state[0, :, :3]     ,							SCREAMING_SNAKE_CASE__     ,							atol=1E-3     )     )





"""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




