
"""simple docstring"""




import torch
from torch import nn

class     _UpperCamelCase			(   nn.Module					):






			'''simple docstring'''

			def __init__(    self	:    List[Any]  ,		snake_case_	:    List[Any]  ,		snake_case_	:    Optional[int]  ,		snake_case_	:    List[Any]  ,		snake_case_	:    Any  ,		snake_case_	:    str=1  ,		snake_case_	:    List[str]=False ):
							super().__init__()

							UpperCamelCase_:							List[str]		=  n_token
							UpperCamelCase_:							Optional[Any]		=  d_embed
							UpperCamelCase_:							Dict		=  d_proj

							UpperCamelCase_:							Optional[int]		=  cutoffs + [n_token]
							UpperCamelCase_:							Any		=  [0] + self.cutoffs
							UpperCamelCase_:							List[str]		=  div_val

							UpperCamelCase_:							str		=  self.cutoffs[0]
							UpperCamelCase_:							Union[str, Any]		=  len(self.cutoffs ) - 1
							UpperCamelCase_:							Optional[int]		=  self.shortlist_size + self.n_clusters

							if self.n_clusters > 0:
											UpperCamelCase_:							Dict		=  nn.Parameter(torch.zeros(self.n_clusters  ,		self.d_embed ) )
											UpperCamelCase_:							Tuple		=  nn.Parameter(torch.zeros(self.n_clusters ) )

							UpperCamelCase_:							Tuple		=  nn.ModuleList()
							UpperCamelCase_:							Optional[int]		=  nn.ParameterList()

							if div_val == 1:
											for i in range(len(self.cutoffs ) ):
															if d_proj != d_embed:
																			self.out_projs.append(nn.Parameter(torch.FloatTensor(_SCREAMING_SNAKE_CASE  ,		_SCREAMING_SNAKE_CASE ) ) )
															else:
																			self.out_projs.append(_SCREAMING_SNAKE_CASE )

											self.out_layers.append(nn.Linear(_SCREAMING_SNAKE_CASE  ,		_SCREAMING_SNAKE_CASE ) )
							else:
											for i in range(len(self.cutoffs ) ):
															UpperCamelCase_:							Optional[int]		=  self.cutoff_ends[i], self.cutoff_ends[i + 1]
															UpperCamelCase_:							List[str]		=  d_embed // (div_val**i)

															self.out_projs.append(nn.Parameter(torch.FloatTensor(_SCREAMING_SNAKE_CASE  ,		_SCREAMING_SNAKE_CASE ) ) )

															self.out_layers.append(nn.Linear(_SCREAMING_SNAKE_CASE  ,		r_idx - l_idx ) )

							UpperCamelCase_:							List[str]		=  keep_order

			def  lowerCAmelCase__		(    self	:    Optional[int]  ,		snake_case_	:    Any  ,		snake_case_	:    List[Any]  ,		snake_case_	:    Optional[int]  ,		snake_case_	:    Union[str, Any] ):





							if proj is None:
											UpperCamelCase_:							Optional[int]		=  nn.functional.linear(_SCREAMING_SNAKE_CASE  ,		_SCREAMING_SNAKE_CASE  ,		bias=_SCREAMING_SNAKE_CASE )
							else:
											# if CUDA_MAJOR <= 9 and CUDA_MINOR <= 1:
											UpperCamelCase_:							Optional[Any]		=  nn.functional.linear(_SCREAMING_SNAKE_CASE  ,		proj.t().contiguous() )
											UpperCamelCase_:							Optional[int]		=  nn.functional.linear(_SCREAMING_SNAKE_CASE  ,		_SCREAMING_SNAKE_CASE  ,		bias=_SCREAMING_SNAKE_CASE )
											# else:
											#     logit = torch.einsum('bd,de,ev->bv', (hidden, proj, weight.t()))
											#     if bias is not None:
											#         logit = logit + bias

							return logit

			def  lowerCAmelCase__		(    self	:    str  ,		snake_case_	:    Dict  ,		snake_case_	:    Optional[Any]=None  ,		snake_case_	:    Any=False ):





							if labels is not None:
											# Shift so that tokens < n predict n
											UpperCamelCase_:							Optional[int]		=  hidden[..., :-1, :].contiguous()
											UpperCamelCase_:							Union[str, Any]		=  labels[..., 1:].contiguous()
											UpperCamelCase_:							Union[str, Any]		=  hidden.view(-1  ,		hidden.size(-1 ) )
											UpperCamelCase_:							str		=  labels.view(-1 )
											if hidden.size(0 ) != labels.size(0 ):
															raise RuntimeError("""Input and labels should have the same size in the batch dimension.""" )
							else:
											UpperCamelCase_:							Tuple		=  hidden.view(-1  ,		hidden.size(-1 ) )

							if self.n_clusters == 0:
											UpperCamelCase_:							str		=  self._compute_logit(_SCREAMING_SNAKE_CASE  ,		self.out_layers[0].weight  ,		self.out_layers[0].bias  ,		self.out_projs[0] )
											if labels is not None:
															UpperCamelCase_:							Union[str, Any]		=  labels != -100
															UpperCamelCase_:							str		=  torch.zeros_like(_SCREAMING_SNAKE_CASE  ,		dtype=hidden.dtype  ,		device=hidden.device )
															UpperCamelCase_:							Union[str, Any]		=  (
															    -nn.functional.log_softmax(_SCREAMING_SNAKE_CASE  ,		dim=-1 )[mask].gather(1  ,		labels[mask].unsqueeze(1 ) ).squeeze(1 )
															)
											else:
															UpperCamelCase_:							List[str]		=  nn.functional.log_softmax(_SCREAMING_SNAKE_CASE  ,		dim=-1 )
							else:
											# construct weights and biases
											UpperCamelCase_:							List[Any]		=  [], []
											for i in range(len(self.cutoffs ) ):
															if self.div_val == 1:
																			UpperCamelCase_:							Union[str, Any]		=  self.cutoff_ends[i], self.cutoff_ends[i + 1]
																			UpperCamelCase_:							Tuple		=  self.out_layers[0].weight[l_idx:r_idx]
																			UpperCamelCase_:							str		=  self.out_layers[0].bias[l_idx:r_idx]
															else:
																			UpperCamelCase_:							Optional[Any]		=  self.out_layers[i].weight
																			UpperCamelCase_:							str		=  self.out_layers[i].bias

															if i == 0:
																			UpperCamelCase_:							List[str]		=  torch.cat([weight_i, self.cluster_weight]  ,		dim=0 )
																			UpperCamelCase_:							List[str]		=  torch.cat([bias_i, self.cluster_bias]  ,		dim=0 )

															weights.append(_SCREAMING_SNAKE_CASE )
															biases.append(_SCREAMING_SNAKE_CASE )

											UpperCamelCase_:							Optional[int]		=  weights[0], biases[0], self.out_projs[0]

											UpperCamelCase_:							Union[str, Any]		=  self._compute_logit(_SCREAMING_SNAKE_CASE  ,		_SCREAMING_SNAKE_CASE  ,		_SCREAMING_SNAKE_CASE  ,		_SCREAMING_SNAKE_CASE )
											UpperCamelCase_:							Optional[int]		=  nn.functional.log_softmax(_SCREAMING_SNAKE_CASE  ,		dim=1 )

											if labels is None:
															UpperCamelCase_:							str		=  hidden.new_empty((head_logit.size(0 ), self.n_token) )
											else:
															UpperCamelCase_:							Tuple		=  torch.zeros_like(_SCREAMING_SNAKE_CASE  ,		dtype=hidden.dtype  ,		device=hidden.device )

											UpperCamelCase_:							Any		=  0
											UpperCamelCase_:							Union[str, Any]		=  [0] + self.cutoffs
											for i in range(len(_SCREAMING_SNAKE_CASE ) - 1 ):
															UpperCamelCase_:							Any		=  cutoff_values[i], cutoff_values[i + 1]

															if labels is not None:
																			UpperCamelCase_:							int		=  (labels >= l_idx) & (labels < r_idx)
																			UpperCamelCase_:							Union[str, Any]		=  mask_i.nonzero().squeeze()

																			if indices_i.numel() == 0:
																							continue

																			UpperCamelCase_:							Tuple		=  labels.index_select(0  ,		_SCREAMING_SNAKE_CASE ) - l_idx
																			UpperCamelCase_:							List[str]		=  head_logprob.index_select(0  ,		_SCREAMING_SNAKE_CASE )
																			UpperCamelCase_:							Optional[int]		=  hidden.index_select(0  ,		_SCREAMING_SNAKE_CASE )
															else:
																			UpperCamelCase_:							Optional[Any]		=  hidden

															if i == 0:
																			if labels is not None:
																							UpperCamelCase_:							Tuple		=  head_logprob_i.gather(1  ,		target_i[:, None] ).squeeze(1 )
																			else:
																							UpperCamelCase_:							Optional[int]		=  head_logprob[:, : self.cutoffs[0]]
															else:
																			UpperCamelCase_:							Any		=  weights[i], biases[i], self.out_projs[i]

																			UpperCamelCase_:							str		=  self._compute_logit(_SCREAMING_SNAKE_CASE  ,		_SCREAMING_SNAKE_CASE  ,		_SCREAMING_SNAKE_CASE  ,		_SCREAMING_SNAKE_CASE )
																			UpperCamelCase_:							List[str]		=  nn.functional.log_softmax(_SCREAMING_SNAKE_CASE  ,		dim=1 )
																			UpperCamelCase_:							Optional[int]		=  self.cutoffs[0] + i - 1  # No probability for the head cluster
																			if labels is not None:
																							UpperCamelCase_:							Optional[Any]		=  head_logprob_i[:, cluster_prob_idx] + tail_logprob_i.gather(
																							    1  ,		target_i[:, None] ).squeeze(1 )
																			else:
																							UpperCamelCase_:							Union[str, Any]		=  head_logprob[:, cluster_prob_idx, None] + tail_logprob_i
																							UpperCamelCase_:							Optional[Any]		=  logprob_i

															if labels is not None:
																			if (hasattr(self  ,		"""keep_order""" ) and self.keep_order) or keep_order:
																							out.index_copy_(0  ,		_SCREAMING_SNAKE_CASE  ,		-logprob_i )
																			else:
																							out[offset : offset + logprob_i.size(0 )].copy_(-logprob_i )
																			offset += logprob_i.size(0 )

							return out




			def  lowerCAmelCase__		(    self	:    Any  ,		snake_case_	:    Optional[Any] ):





							if self.n_clusters == 0:
											UpperCamelCase_:							Optional[int]		=  self._compute_logit(_SCREAMING_SNAKE_CASE  ,		self.out_layers[0].weight  ,		self.out_layers[0].bias  ,		self.out_projs[0] )
											return nn.functional.log_softmax(_SCREAMING_SNAKE_CASE  ,		dim=-1 )
							else:
											# construct weights and biases
											UpperCamelCase_:							Any		=  [], []
											for i in range(len(self.cutoffs ) ):
															if self.div_val == 1:
																			UpperCamelCase_:							Optional[int]		=  self.cutoff_ends[i], self.cutoff_ends[i + 1]
																			UpperCamelCase_:							Tuple		=  self.out_layers[0].weight[l_idx:r_idx]
																			UpperCamelCase_:							List[str]		=  self.out_layers[0].bias[l_idx:r_idx]
															else:
																			UpperCamelCase_:							str		=  self.out_layers[i].weight
																			UpperCamelCase_:							int		=  self.out_layers[i].bias

															if i == 0:
																			UpperCamelCase_:							Optional[int]		=  torch.cat([weight_i, self.cluster_weight]  ,		dim=0 )
																			UpperCamelCase_:							Optional[int]		=  torch.cat([bias_i, self.cluster_bias]  ,		dim=0 )

															weights.append(_SCREAMING_SNAKE_CASE )
															biases.append(_SCREAMING_SNAKE_CASE )

											UpperCamelCase_:							str		=  weights[0], biases[0], self.out_projs[0]
											UpperCamelCase_:							str		=  self._compute_logit(_SCREAMING_SNAKE_CASE  ,		_SCREAMING_SNAKE_CASE  ,		_SCREAMING_SNAKE_CASE  ,		_SCREAMING_SNAKE_CASE )

											UpperCamelCase_:							int		=  hidden.new_empty((head_logit.size(0 ), self.n_token) )
											UpperCamelCase_:							Union[str, Any]		=  nn.functional.log_softmax(_SCREAMING_SNAKE_CASE  ,		dim=1 )

											UpperCamelCase_:							Any		=  [0] + self.cutoffs
											for i in range(len(_SCREAMING_SNAKE_CASE ) - 1 ):
															UpperCamelCase_:							Union[str, Any]		=  cutoff_values[i], cutoff_values[i + 1]

															if i == 0:
																			UpperCamelCase_:							List[str]		=  head_logprob[:, : self.cutoffs[0]]
															else:
																			UpperCamelCase_:							Optional[Any]		=  weights[i], biases[i], self.out_projs[i]

																			UpperCamelCase_:							Tuple		=  self._compute_logit(_SCREAMING_SNAKE_CASE  ,		_SCREAMING_SNAKE_CASE  ,		_SCREAMING_SNAKE_CASE  ,		_SCREAMING_SNAKE_CASE )
																			UpperCamelCase_:							Tuple		=  nn.functional.log_softmax(_SCREAMING_SNAKE_CASE  ,		dim=1 )

																			UpperCamelCase_:							int		=  head_logprob[:, -i] + tail_logprob_i
																			UpperCamelCase_:							List[Any]		=  logprob_i

											return out








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






			'''simple docstring'''

			__UpperCamelCase :  Optional[Any]    =	"""hf-internal-testing/tiny-random-OnnxStableDiffusionPipeline"""

			def  lowerCAmelCase__		(    self	:    List[str]  ,		snake_case_	:    Optional[int]=0 ):
							UpperCamelCase_:							str		=  floats_tensor((1, 3, 128, 128)  ,		rng=random.Random(snake_case_ ) )
							UpperCamelCase_:							Optional[int]		=  np.random.RandomState(snake_case_ )
							UpperCamelCase_:							Dict		=  {
							    """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 ):
							UpperCamelCase_:							Any		=  OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint  ,		provider="""CPUExecutionProvider""" )
							pipe.set_progress_bar_config(disable=snake_case_ )

							UpperCamelCase_:							str		=  self.get_dummy_inputs()
							UpperCamelCase_:							Any		=  pipe(**snake_case_ ).images
							UpperCamelCase_:							Any		=  image[0, -3:, -3:, -1].flatten()

							assert image.shape == (1, 128, 128, 3)
							UpperCamelCase_:							str		=  np.array([0.6_9643, 0.5_8484, 0.5_0314, 0.5_8760, 0.5_5368, 0.5_9643, 0.5_1529, 0.4_1217, 0.4_9087] )
							assert np.abs(image_slice - expected_slice ).max() < 1e-1

			def  lowerCAmelCase__		(    self	:    List[str] ):
							UpperCamelCase_:							int		=  OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint  ,		provider="""CPUExecutionProvider""" )
							UpperCamelCase_:							Tuple		=  PNDMScheduler.from_config(pipe.scheduler.config  ,		skip_prk_steps=snake_case_ )
							pipe.set_progress_bar_config(disable=snake_case_ )

							UpperCamelCase_:							str		=  self.get_dummy_inputs()
							UpperCamelCase_:							Dict		=  pipe(**snake_case_ ).images
							UpperCamelCase_:							Optional[Any]		=  image[0, -3:, -3:, -1]

							assert image.shape == (1, 128, 128, 3)
							UpperCamelCase_:							Any		=  np.array([0.6_1737, 0.5_4642, 0.5_3183, 0.5_4465, 0.5_2742, 0.6_0525, 0.4_9969, 0.4_0655, 0.4_8154] )

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

			def  lowerCAmelCase__		(    self	:    str ):
							UpperCamelCase_:							str		=  OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint  ,		provider="""CPUExecutionProvider""" )
							UpperCamelCase_:							List[Any]		=  LMSDiscreteScheduler.from_config(pipe.scheduler.config )
							pipe.set_progress_bar_config(disable=snake_case_ )

							# warmup pass to apply optimizations
							UpperCamelCase_:							Union[str, Any]		=  pipe(**self.get_dummy_inputs() )

							UpperCamelCase_:							Tuple		=  self.get_dummy_inputs()
							UpperCamelCase_:							Optional[int]		=  pipe(**snake_case_ ).images
							UpperCamelCase_:							str		=  image[0, -3:, -3:, -1]

							assert image.shape == (1, 128, 128, 3)
							UpperCamelCase_:							Optional[int]		=  np.array([0.5_2761, 0.5_9977, 0.4_9033, 0.4_9619, 0.5_4282, 0.5_0311, 0.4_7600, 0.4_0918, 0.4_5203] )

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

			def  lowerCAmelCase__		(    self	:    Union[str, Any] ):
							UpperCamelCase_:							List[str]		=  OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint  ,		provider="""CPUExecutionProvider""" )
							UpperCamelCase_:							Optional[int]		=  EulerDiscreteScheduler.from_config(pipe.scheduler.config )
							pipe.set_progress_bar_config(disable=snake_case_ )

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

							assert image.shape == (1, 128, 128, 3)
							UpperCamelCase_:							List[str]		=  np.array([0.5_2911, 0.6_0004, 0.4_9229, 0.4_9805, 0.5_4502, 0.5_0680, 0.4_7777, 0.4_1028, 0.4_5304] )

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

			def  lowerCAmelCase__		(    self	:    Optional[int] ):
							UpperCamelCase_:							List[Any]		=  OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint  ,		provider="""CPUExecutionProvider""" )
							UpperCamelCase_:							List[Any]		=  EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config )
							pipe.set_progress_bar_config(disable=snake_case_ )

							UpperCamelCase_:							List[str]		=  self.get_dummy_inputs()
							UpperCamelCase_:							Any		=  pipe(**snake_case_ ).images
							UpperCamelCase_:							Any		=  image[0, -3:, -3:, -1]

							assert image.shape == (1, 128, 128, 3)
							UpperCamelCase_:							Tuple		=  np.array([0.5_2911, 0.6_0004, 0.4_9229, 0.4_9805, 0.5_4502, 0.5_0680, 0.4_7777, 0.4_1028, 0.4_5304] )

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




			def  lowerCAmelCase__		(    self	:    Union[str, Any] ):
							UpperCamelCase_:							Optional[Any]		=  OnnxStableDiffusionImgaImgPipeline.from_pretrained(self.hub_checkpoint  ,		provider="""CPUExecutionProvider""" )
							UpperCamelCase_:							str		=  DPMSolverMultistepScheduler.from_config(pipe.scheduler.config )
							pipe.set_progress_bar_config(disable=snake_case_ )

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

							assert image.shape == (1, 128, 128, 3)
							UpperCamelCase_:							Tuple		=  np.array([0.6_5331, 0.5_8277, 0.4_8204, 0.5_6059, 0.5_3665, 0.5_6235, 0.5_0969, 0.4_0009, 0.4_6552] )

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




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






			'''simple docstring'''

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

			@property
			def  lowerCAmelCase__		(    self	:    List[Any] ):
							UpperCamelCase_:							Dict		=  ort.SessionOptions()
							UpperCamelCase_:							Optional[int]		=  False
							return options

			def  lowerCAmelCase__		(    self	:    Tuple ):
							UpperCamelCase_:							Optional[int]		=  load_image(
							    """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"""
							    """/img2img/sketch-mountains-input.jpg""" )
							UpperCamelCase_:							Union[str, Any]		=  init_image.resize((768, 512) )
							# using the PNDM scheduler by default
							UpperCamelCase_:							int		=  OnnxStableDiffusionImgaImgPipeline.from_pretrained(
							    """CompVis/stable-diffusion-v1-4"""  ,		revision="""onnx"""  ,		safety_checker=snake_case_  ,		feature_extractor=snake_case_  ,		provider=self.gpu_provider  ,		sess_options=self.gpu_options  ,		)
							pipe.set_progress_bar_config(disable=snake_case_ )

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

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

							assert images.shape == (1, 512, 768, 3)
							UpperCamelCase_:							Tuple		=  np.array([0.4909, 0.5059, 0.5372, 0.4623, 0.4876, 0.5049, 0.4820, 0.4956, 0.5019] )
							# 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	:    Optional[Any] ):
							UpperCamelCase_:							Union[str, Any]		=  load_image(
							    """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"""
							    """/img2img/sketch-mountains-input.jpg""" )
							UpperCamelCase_:							List[Any]		=  init_image.resize((768, 512) )
							UpperCamelCase_:							Union[str, Any]		=  LMSDiscreteScheduler.from_pretrained(
							    """runwayml/stable-diffusion-v1-5"""  ,		subfolder="""scheduler"""  ,		revision="""onnx""" )
							UpperCamelCase_:							Dict		=  OnnxStableDiffusionImgaImgPipeline.from_pretrained(
							    """runwayml/stable-diffusion-v1-5"""  ,		revision="""onnx"""  ,		scheduler=snake_case_  ,		safety_checker=snake_case_  ,		feature_extractor=snake_case_  ,		provider=self.gpu_provider  ,		sess_options=self.gpu_options  ,		)
							pipe.set_progress_bar_config(disable=snake_case_ )

							UpperCamelCase_:							Any		=  """A fantasy landscape, trending on artstation"""

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

							assert images.shape == (1, 512, 768, 3)
							UpperCamelCase_:							Optional[int]		=  np.array([0.8043, 0.926, 0.9581, 0.8119, 0.8954, 0.913, 0.7209, 0.7463, 0.7431] )
							# TODO: lower the tolerance after finding the cause of onnxruntime reproducibility issues

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






