
"""simple docstring"""




import unittest

from parameterized import parameterized

from transformers import AutoTokenizer, GPTNeoXConfig, is_torch_available, set_seed
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, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch

							from transformers import (
							    GPTNeoXForCausalLM,
							    GPTNeoXForQuestionAnswering,
							    GPTNeoXForSequenceClassification,
							    GPTNeoXForTokenClassification,
							    GPTNeoXModel,
							)

class     _UpperCamelCase			:






			'''simple docstring'''

			def __init__(    self	:    Union[str, Any]  ,		snake_case_	:    int  ,		snake_case_	:    Any=13  ,		snake_case_	:    List[Any]=7  ,		snake_case_	:    Union[str, Any]=True  ,		snake_case_	:    Dict=True  ,		snake_case_	:    Optional[Any]=True  ,		snake_case_	:    str=True  ,		snake_case_	:    Any=99  ,		snake_case_	:    Optional[Any]=64  ,		snake_case_	:    str=5  ,		snake_case_	:    Optional[Any]=4  ,		snake_case_	:    Any=37  ,		snake_case_	:    Dict="gelu"  ,		snake_case_	:    List[str]=0.1  ,		snake_case_	:    Tuple=0.1  ,		snake_case_	:    List[Any]=512  ,		snake_case_	:    str=16  ,		snake_case_	:    Union[str, Any]=2  ,		snake_case_	:    Any=0.02  ,		snake_case_	:    str=3  ,		snake_case_	:    List[Any]=4  ,		snake_case_	:    List[Any]=None  ,		):
							UpperCamelCase_:							List[str]		=  parent
							UpperCamelCase_:							List[Any]		=  batch_size
							UpperCamelCase_:							List[str]		=  seq_length
							UpperCamelCase_:							Union[str, Any]		=  is_training
							UpperCamelCase_:							int		=  use_input_mask
							UpperCamelCase_:							Tuple		=  use_token_type_ids
							UpperCamelCase_:							List[Any]		=  use_labels
							UpperCamelCase_:							List[Any]		=  vocab_size
							UpperCamelCase_:							List[Any]		=  hidden_size
							UpperCamelCase_:							List[str]		=  num_hidden_layers
							UpperCamelCase_:							Optional[Any]		=  num_attention_heads
							UpperCamelCase_:							Optional[Any]		=  intermediate_size
							UpperCamelCase_:							int		=  hidden_act
							UpperCamelCase_:							Dict		=  hidden_dropout_prob
							UpperCamelCase_:							Optional[Any]		=  attention_probs_dropout_prob
							UpperCamelCase_:							Tuple		=  max_position_embeddings
							UpperCamelCase_:							Optional[int]		=  type_vocab_size
							UpperCamelCase_:							Dict		=  type_sequence_label_size
							UpperCamelCase_:							Tuple		=  initializer_range
							UpperCamelCase_:							Any		=  num_labels
							UpperCamelCase_:							List[Any]		=  num_choices
							UpperCamelCase_:							Optional[int]		=  scope
							UpperCamelCase_:							Tuple		=  vocab_size - 1

			def  lowerCAmelCase__		(    self	:    List[str] ):
							UpperCamelCase_:							Union[str, Any]		=  ids_tensor([self.batch_size, self.seq_length]  ,		self.vocab_size )

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

							UpperCamelCase_:							List[Any]		=  None
							if self.use_labels:
											UpperCamelCase_:							List[str]		=  ids_tensor([self.batch_size, self.seq_length]  ,		self.num_labels )

							UpperCamelCase_:							Dict		=  self.get_config()

							return config, input_ids, input_mask, token_labels

			def  lowerCAmelCase__		(    self	:    Tuple ):
							return GPTNeoXConfig(
							    vocab_size=self.vocab_size  ,		hidden_size=self.hidden_size  ,		num_hidden_layers=self.num_hidden_layers  ,		num_attention_heads=self.num_attention_heads  ,		intermediate_size=self.intermediate_size  ,		hidden_act=self.hidden_act  ,		hidden_dropout_prob=self.hidden_dropout_prob  ,		attention_probs_dropout_prob=self.attention_probs_dropout_prob  ,		max_position_embeddings=self.max_position_embeddings  ,		type_vocab_size=self.type_vocab_size  ,		is_decoder=snake_case_  ,		initializer_range=self.initializer_range  ,		pad_token_id=self.pad_token_id  ,		)

			def  lowerCAmelCase__		(    self	:    Union[str, Any] ):
							UpperCamelCase_:							Dict		=  self.prepare_config_and_inputs()

							UpperCamelCase_:							List[Any]		=  True

							return config, input_ids, input_mask, token_labels

			def  lowerCAmelCase__		(    self	:    Dict  ,		snake_case_	:    Any  ,		snake_case_	:    Optional[int]  ,		snake_case_	:    Tuple ):
							UpperCamelCase_:							Tuple		=  GPTNeoXModel(config=snake_case_ )
							model.to(snake_case_ )
							model.eval()
							UpperCamelCase_:							Any		=  model(snake_case_  ,		attention_mask=snake_case_ )
							UpperCamelCase_:							Optional[int]		=  model(snake_case_ )
							self.parent.assertEqual(result.last_hidden_state.shape  ,		(self.batch_size, self.seq_length, self.hidden_size) )

			def  lowerCAmelCase__		(    self	:    Any  ,		snake_case_	:    Dict  ,		snake_case_	:    Optional[Any]  ,		snake_case_	:    Dict ):
							UpperCamelCase_:							List[Any]		=  True
							UpperCamelCase_:							Optional[Any]		=  GPTNeoXModel(snake_case_ )
							model.to(snake_case_ )
							model.eval()
							UpperCamelCase_:							Dict		=  model(snake_case_  ,		attention_mask=snake_case_ )
							self.parent.assertEqual(result.last_hidden_state.shape  ,		(self.batch_size, self.seq_length, self.hidden_size) )

			def  lowerCAmelCase__		(    self	:    Any  ,		snake_case_	:    Optional[int]  ,		snake_case_	:    Dict  ,		snake_case_	:    Optional[Any]  ,		snake_case_	:    Dict ):
							UpperCamelCase_:							Optional[int]		=  GPTNeoXForCausalLM(config=snake_case_ )
							model.to(snake_case_ )
							model.eval()
							UpperCamelCase_:							Optional[int]		=  model(snake_case_  ,		attention_mask=snake_case_  ,		labels=snake_case_ )
							self.parent.assertEqual(result.logits.shape  ,		(self.batch_size, self.seq_length, self.vocab_size) )

			def  lowerCAmelCase__		(    self	:    Union[str, Any]  ,		snake_case_	:    int  ,		snake_case_	:    Optional[Any]  ,		snake_case_	:    List[Any]  ,		snake_case_	:    Optional[Any] ):
							UpperCamelCase_:							Optional[Any]		=  self.num_labels
							UpperCamelCase_:							Union[str, Any]		=  GPTNeoXForQuestionAnswering(snake_case_ )
							model.to(snake_case_ )
							model.eval()
							UpperCamelCase_:							Tuple		=  model(snake_case_  ,		attention_mask=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  lowerCAmelCase__		(    self	:    str  ,		snake_case_	:    Optional[Any]  ,		snake_case_	:    Tuple  ,		snake_case_	:    int  ,		snake_case_	:    Optional[int] ):
							UpperCamelCase_:							List[Any]		=  self.num_labels
							UpperCamelCase_:							List[str]		=  GPTNeoXForSequenceClassification(snake_case_ )
							model.to(snake_case_ )
							model.eval()
							UpperCamelCase_:							List[Any]		=  ids_tensor([self.batch_size]  ,		self.type_sequence_label_size )
							UpperCamelCase_:							Union[str, Any]		=  model(snake_case_  ,		attention_mask=snake_case_  ,		labels=snake_case_ )
							self.parent.assertEqual(result.logits.shape  ,		(self.batch_size, self.num_labels) )

			def  lowerCAmelCase__		(    self	:    Union[str, Any]  ,		snake_case_	:    Tuple  ,		snake_case_	:    Tuple  ,		snake_case_	:    List[str]  ,		snake_case_	:    int ):
							UpperCamelCase_:							List[Any]		=  self.num_labels
							UpperCamelCase_:							Tuple		=  GPTNeoXForTokenClassification(snake_case_ )
							model.to(snake_case_ )
							model.eval()
							UpperCamelCase_:							Dict		=  model(snake_case_  ,		attention_mask=snake_case_  ,		labels=snake_case_ )
							self.parent.assertEqual(result.logits.shape  ,		(self.batch_size, self.seq_length, self.num_labels) )

			def  lowerCAmelCase__		(    self	:    List[str]  ,		snake_case_	:    Optional[int]  ,		snake_case_	:    List[Any]  ,		snake_case_	:    List[Any] ):
							UpperCamelCase_:							int		=  True
							UpperCamelCase_:							Optional[Any]		=  GPTNeoXForCausalLM(config=snake_case_ )
							model.to(snake_case_ )
							model.eval()

							# first forward pass
							UpperCamelCase_:							List[str]		=  model(snake_case_  ,		attention_mask=snake_case_  ,		use_cache=snake_case_ )
							UpperCamelCase_:							Tuple		=  outputs.past_key_values

							# create hypothetical multiple next token and extent to next_input_ids
							UpperCamelCase_:							Optional[Any]		=  ids_tensor((self.batch_size, 3)  ,		config.vocab_size )
							UpperCamelCase_:							Any		=  ids_tensor((self.batch_size, 3)  ,		vocab_size=2 )

							# append to next input_ids and
							UpperCamelCase_:							Tuple		=  torch.cat([input_ids, next_tokens]  ,		dim=-1 )
							UpperCamelCase_:							Union[str, Any]		=  torch.cat([input_mask, next_mask]  ,		dim=-1 )

							UpperCamelCase_:							int		=  model(snake_case_  ,		attention_mask=snake_case_  ,		output_hidden_states=snake_case_ )
							UpperCamelCase_:							Any		=  output_from_no_past["""hidden_states"""][0]
							UpperCamelCase_:							List[Any]		=  model(
							    snake_case_  ,		attention_mask=snake_case_  ,		past_key_values=snake_case_  ,		output_hidden_states=snake_case_  ,		)["""hidden_states"""][0]

							# select random slice
							UpperCamelCase_:							List[Any]		=  ids_tensor((1,)  ,		output_from_past.shape[-1] ).item()
							UpperCamelCase_:							Optional[int]		=  output_from_no_past[:, -3:, random_slice_idx].detach()
							UpperCamelCase_:							Tuple		=  output_from_past[:, :, random_slice_idx].detach()

							self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1] )

							# test that outputs are equal for slice
							self.parent.assertTrue(torch.allclose(snake_case_  ,		snake_case_  ,		atol=1e-3 ) )




			def  lowerCAmelCase__		(    self	:    int ):
							UpperCamelCase_:							List[Any]		=  self.prepare_config_and_inputs()
							UpperCamelCase_:							Optional[Any]		=  config_and_inputs
							UpperCamelCase_:							Any		=  {"""input_ids""": input_ids, """attention_mask""": input_mask}
							return config, inputs_dict




@require_torch
class     _UpperCamelCase			(   _A       ,    _A       ,    _A       ,    unittest.TestCase					):






			'''simple docstring'''

			__UpperCamelCase :  int    =	(
			    (
			        GPTNeoXModel,
			        GPTNeoXForCausalLM,
			        GPTNeoXForQuestionAnswering,
			        GPTNeoXForSequenceClassification,
			        GPTNeoXForTokenClassification,
			    )
			    if is_torch_available()
			    else ()
			)
			__UpperCamelCase :  Dict    =	(GPTNeoXForCausalLM,) if is_torch_available() else ()
			__UpperCamelCase :  int    =	(
			    {
			        """feature-extraction""": GPTNeoXModel,
			        """question-answering""": GPTNeoXForQuestionAnswering,
			        """text-classification""": GPTNeoXForSequenceClassification,
			        """text-generation""": GPTNeoXForCausalLM,
			        """token-classification""": GPTNeoXForTokenClassification,
			        """zero-shot""": GPTNeoXForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)
			__UpperCamelCase :  Optional[Any]    =	False
			__UpperCamelCase :  Union[str, Any]    =	False
			__UpperCamelCase :  Optional[int]    =	False
			__UpperCamelCase :  Tuple    =	False

			def  lowerCAmelCase__		(    self	:    Optional[int] ):
							UpperCamelCase_:							Optional[int]		=  GPTNeoXModelTester(self )
							UpperCamelCase_:							Optional[Any]		=  ConfigTester(self  ,		config_class=snake_case_  ,		hidden_size=64  ,		num_attention_heads=8 )

			def  lowerCAmelCase__		(    self	:    int ):
							self.config_tester.run_common_tests()

			def  lowerCAmelCase__		(    self	:    str ):
							UpperCamelCase_:							Tuple		=  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(snake_case_  ,		snake_case_  ,		snake_case_ )

			def  lowerCAmelCase__		(    self	:    Optional[Any] ):
							UpperCamelCase_:							int		=  self.model_tester.prepare_config_and_inputs_for_decoder()
							self.model_tester.create_and_check_model_as_decoder(snake_case_  ,		snake_case_  ,		snake_case_ )

			def  lowerCAmelCase__		(    self	:    List[str] ):
							# This regression test was failing with PyTorch < 1.3
							UpperCamelCase_:							Optional[int]		=  self.model_tester.prepare_config_and_inputs_for_decoder()

							UpperCamelCase_:							Dict		=  None

							self.model_tester.create_and_check_model_as_decoder(snake_case_  ,		snake_case_  ,		snake_case_ )

			def  lowerCAmelCase__		(    self	:    List[str] ):
							UpperCamelCase_:							Any		=  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_decoder_model_past_large_inputs(snake_case_  ,		snake_case_  ,		snake_case_ )

			def  lowerCAmelCase__		(    self	:    List[str] ):
							UpperCamelCase_:							Optional[Any]		=  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_causal_lm(*snake_case_ )

			def  lowerCAmelCase__		(    self	:    Union[str, Any] ):
							UpperCamelCase_:							Optional[int]		=  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_question_answering(*snake_case_ )

			def  lowerCAmelCase__		(    self	:    Dict ):
							UpperCamelCase_:							Optional[int]		=  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_sequence_classification(*snake_case_ )

			def  lowerCAmelCase__		(    self	:    Optional[int] ):
							UpperCamelCase_:							Any		=  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_token_classification(*snake_case_ )

			@unittest.skip(reason="""Feed forward chunking is not implemented""" )
			def  lowerCAmelCase__		(    self	:    Optional[Any] ):
							pass




			@parameterized.expand([("""linear""",), ("""dynamic""",)] )
			def  lowerCAmelCase__		(    self	:    List[str]  ,		snake_case_	:    Any ):
							UpperCamelCase_:							Any		=  self.model_tester.prepare_config_and_inputs_for_common()
							UpperCamelCase_:							Optional[int]		=  ids_tensor([1, 10]  ,		config.vocab_size )
							UpperCamelCase_:							Dict		=  ids_tensor([1, int(config.max_position_embeddings * 1.5 )]  ,		config.vocab_size )

							set_seed(42 )  # Fixed seed at init time so the two models get the same random weights
							UpperCamelCase_:							List[Any]		=  GPTNeoXModel(snake_case_ )
							original_model.to(snake_case_ )
							original_model.eval()
							UpperCamelCase_:							List[Any]		=  original_model(snake_case_ ).last_hidden_state
							UpperCamelCase_:							List[Any]		=  original_model(snake_case_ ).last_hidden_state

							set_seed(42 )  # Fixed seed at init time so the two models get the same random weights
							UpperCamelCase_:							str		=  {"""type""": scaling_type, """factor""": 10.0}
							UpperCamelCase_:							Optional[int]		=  GPTNeoXModel(snake_case_ )
							scaled_model.to(snake_case_ )
							scaled_model.eval()
							UpperCamelCase_:							List[Any]		=  scaled_model(snake_case_ ).last_hidden_state
							UpperCamelCase_:							Dict		=  scaled_model(snake_case_ ).last_hidden_state

							# Dynamic scaling does not change the RoPE embeddings until it receives an input longer than the original
							# maximum sequence length, so the outputs for the short input should match.
							if scaling_type == "dynamic":
											self.assertTrue(torch.allclose(snake_case_  ,		snake_case_  ,		atol=1e-5 ) )
							else:
											self.assertFalse(torch.allclose(snake_case_  ,		snake_case_  ,		atol=1e-5 ) )

							# The output should be different for long inputs
							self.assertFalse(torch.allclose(snake_case_  ,		snake_case_  ,		atol=1e-5 ) )




@require_torch
class     _UpperCamelCase			(   unittest.TestCase					):






			'''simple docstring'''

			@slow
			def  lowerCAmelCase__		(    self	:    Optional[Any] ):
							UpperCamelCase_:							Optional[int]		=  AutoTokenizer.from_pretrained("""EleutherAI/pythia-410m-deduped""" )
							for checkpointing in [True, False]:
											UpperCamelCase_:							Dict		=  GPTNeoXForCausalLM.from_pretrained("""EleutherAI/pythia-410m-deduped""" )

											if checkpointing:
															model.gradient_checkpointing_enable()
											else:
															model.gradient_checkpointing_disable()
											model.to(snake_case_ )

											UpperCamelCase_:							Optional[int]		=  tokenizer("""My favorite food is"""  ,		return_tensors="""pt""" ).to(snake_case_ )
											# The hub repo. is updated on 2023-04-04, resulting in poor outputs.
											# See: https://github.com/huggingface/transformers/pull/24193
											UpperCamelCase_:							str		=  """My favorite food is a good old-fashioned, old-fashioned, old-fashioned.\n\nI'm not sure"""

											UpperCamelCase_:							Union[str, Any]		=  model.generate(**snake_case_  ,		do_sample=snake_case_  ,		max_new_tokens=20 )
											UpperCamelCase_:							Any		=  tokenizer.batch_decode(snake_case_ )[0]

											self.assertEqual(snake_case_  ,		snake_case_ )








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






