






"""simple docstring"""





import gc
import unittest

from transformers import CTRLConfig, 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, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch

							from transformers import (
							    CTRL_PRETRAINED_MODEL_ARCHIVE_LIST,
							    CTRLForSequenceClassification,
							    CTRLLMHeadModel,
							    CTRLModel,
							)



class       __A		:

					def __init__(			self  :      Optional[int]     ,		__snake_case  :      int     ,		__snake_case  :      str=1_4     ,		__snake_case  :      Any=7     ,		__snake_case  :      Dict=True     ,		__snake_case  :      Union[str, Any]=True     ,		__snake_case  :      List[str]=True     ,		__snake_case  :      Any=True     ,		__snake_case  :      Dict=True     ,		__snake_case  :      int=9_9     ,		__snake_case  :      Tuple=3_2     ,		__snake_case  :      List[str]=5     ,		__snake_case  :      Optional[Any]=4     ,		__snake_case  :      Optional[int]=3_7     ,		__snake_case  :      Optional[int]="gelu"     ,		__snake_case  :      Tuple=0.1     ,		__snake_case  :      Optional[int]=0.1     ,		__snake_case  :      Optional[int]=5_1_2     ,		__snake_case  :      List[Any]=1_6     ,		__snake_case  :      Tuple=2     ,		__snake_case  :      str=0.02     ,		__snake_case  :      str=3     ,		__snake_case  :      int=4     ,		__snake_case  :      Dict=None     ,		)			->							List[str]:
											__magic_name__:	Tuple							=       parent
											__magic_name__:	int							=       batch_size
											__magic_name__:	str							=       seq_length
											__magic_name__:	Optional[int]							=       is_training
											__magic_name__:	Dict							=       use_token_type_ids
											__magic_name__:	str							=       use_input_mask
											__magic_name__:	int							=       use_labels
											__magic_name__:	Union[str, Any]							=       use_mc_token_ids
											__magic_name__:	str							=       vocab_size
											__magic_name__:	List[str]							=       hidden_size
											__magic_name__:	Any							=       num_hidden_layers
											__magic_name__:	int							=       num_attention_heads
											__magic_name__:	Dict							=       intermediate_size
											__magic_name__:	Optional[Any]							=       hidden_act
											__magic_name__:	Any							=       hidden_dropout_prob
											__magic_name__:	Dict							=       attention_probs_dropout_prob
											__magic_name__:	List[Any]							=       max_position_embeddings
											__magic_name__:	List[str]							=       type_vocab_size
											__magic_name__:	int							=       type_sequence_label_size
											__magic_name__:	Optional[int]							=       initializer_range
											__magic_name__:	Optional[int]							=       num_labels
											__magic_name__:	str							=       num_choices
											__magic_name__:	Optional[Any]							=       scope
											__magic_name__:	Union[str, Any]							=       self.vocab_size - 1

					def   lowerCamelCase__   (			self  :      Optional[int]					)			->							List[Any]:
											__magic_name__:	Union[str, Any]							=       ids_tensor([self.batch_size, self.seq_length]     ,		self.vocab_size					)

											__magic_name__:	Dict							=       None
											if self.use_input_mask:
																	__magic_name__:	Any							=       random_attention_mask([self.batch_size, self.seq_length]					)

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

											__magic_name__:	Dict							=       None
											if self.use_mc_token_ids:
																	__magic_name__:	Any							=       ids_tensor([self.batch_size, self.num_choices]     ,		self.seq_length					)

											__magic_name__:	List[Any]							=       None
											__magic_name__:	Any							=       None
											__magic_name__:	List[Any]							=       None
											if self.use_labels:
																	__magic_name__:	List[str]							=       ids_tensor([self.batch_size]     ,		self.type_sequence_label_size					)
																	__magic_name__:	Union[str, Any]							=       ids_tensor([self.batch_size, self.seq_length]     ,		self.num_labels					)
																	__magic_name__:	Dict							=       ids_tensor([self.batch_size]     ,		self.num_choices					)

											__magic_name__:	Tuple							=       self.get_config()

											__magic_name__:	Optional[int]							=       ids_tensor([self.num_hidden_layers, self.num_attention_heads]     ,		2					)

											return (
											    config,
											    input_ids,
											    input_mask,
											    head_mask,
											    token_type_ids,
											    mc_token_ids,
											    sequence_labels,
											    token_labels,
											    choice_labels,
											)

					def   lowerCamelCase__   (			self  :      Any					)			->							Optional[Any]:
											return CTRLConfig(
											    vocab_size=self.vocab_size     ,		n_embd=self.hidden_size     ,		n_layer=self.num_hidden_layers     ,		n_head=self.num_attention_heads     ,		n_positions=self.max_position_embeddings     ,		pad_token_id=self.pad_token_id     ,		)

					def   lowerCamelCase__   (			self  :      Any     ,		__snake_case  :      int     ,		__snake_case  :      int     ,		__snake_case  :      int     ,		__snake_case  :      List[Any]     ,		__snake_case  :      Optional[int]     ,		*__snake_case  :      Dict					)			->							Any:
											__magic_name__:	Any							=       CTRLModel(config=__snake_case					)
											model.to(__snake_case					)
											model.eval()

											model(__snake_case     ,		token_type_ids=__snake_case     ,		head_mask=__snake_case					)
											model(__snake_case     ,		token_type_ids=__snake_case					)
											__magic_name__:	List[Any]							=       model(__snake_case					)
											self.parent.assertEqual(result.last_hidden_state.shape     ,		(self.batch_size, self.seq_length, self.hidden_size)					)
											self.parent.assertEqual(len(result.past_key_values					)     ,		config.n_layer					)

					def   lowerCamelCase__   (			self  :      Union[str, Any]     ,		__snake_case  :      str     ,		__snake_case  :      int     ,		__snake_case  :      Any     ,		__snake_case  :      Optional[Any]     ,		__snake_case  :      Dict     ,		*__snake_case  :      Any					)			->							Union[str, Any]:
											__magic_name__:	List[Any]							=       CTRLLMHeadModel(__snake_case					)
											model.to(__snake_case					)
											model.eval()

											__magic_name__:	Optional[Any]							=       model(__snake_case     ,		token_type_ids=__snake_case     ,		labels=__snake_case					)
											self.parent.assertEqual(result.loss.shape     ,		()					)
											self.parent.assertEqual(result.logits.shape     ,		(self.batch_size, self.seq_length, self.vocab_size)					)

					def   lowerCamelCase__   (			self  :      Dict					)			->							Optional[int]:
											__magic_name__:	List[str]							=       self.prepare_config_and_inputs()

											(
											    (
											    __magic_name__
											),			(
											    __magic_name__
											),			(
											    __magic_name__
											),			(
											    __magic_name__
											),			(
											    __magic_name__
											),			(
											    __magic_name__
											),			(
											    __magic_name__
											),			(
											    __magic_name__
											),			(
											    __magic_name__
											),			
											):	int							=       config_and_inputs

											__magic_name__:	int							=       {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """head_mask""": head_mask}

											return config, inputs_dict






					def   lowerCamelCase__   (			self  :      List[str]     ,		__snake_case  :      List[Any]     ,		__snake_case  :      str     ,		__snake_case  :      str     ,		__snake_case  :      Optional[int]     ,		*__snake_case  :      Union[str, Any]					)			->							str:
											__magic_name__:	int							=       self.num_labels
											__magic_name__:	int							=       CTRLForSequenceClassification(__snake_case					)
											model.to(__snake_case					)
											model.eval()
											__magic_name__:	str							=       ids_tensor([self.batch_size]     ,		self.type_sequence_label_size					)
											__magic_name__:	int							=       model(__snake_case     ,		token_type_ids=__snake_case     ,		labels=__snake_case					)
											self.parent.assertEqual(result.logits.shape     ,		(self.batch_size, self.num_labels)					)



@require_torch
class       __A		(   SCREAMING_SNAKE_CASE_     ,SCREAMING_SNAKE_CASE_     ,SCREAMING_SNAKE_CASE_     ,unittest.TestCase			):
					UpperCAmelCase__								=				(CTRLModel, CTRLLMHeadModel, CTRLForSequenceClassification) if is_torch_available() else ()
					UpperCAmelCase__								=				(CTRLLMHeadModel,) if is_torch_available() else ()
					UpperCAmelCase__								=				(
					    {
					        "feature-extraction": CTRLModel,
					        "text-classification": CTRLForSequenceClassification,
					        "text-generation": CTRLLMHeadModel,
					        "zero-shot": CTRLForSequenceClassification,
					    }
					    if is_torch_available()
					    else {}
					)
					UpperCAmelCase__								=				True
					UpperCAmelCase__								=				False
					UpperCAmelCase__								=				False

					def   lowerCamelCase__   (			self  :      Optional[Any]     ,		__snake_case  :      Optional[int]     ,		__snake_case  :      Tuple     ,		__snake_case  :      List[str]     ,		__snake_case  :      int     ,		__snake_case  :      Optional[int]					)			->							Dict:
											if pipeline_test_casse_name == "ZeroShotClassificationPipelineTests":
																	# Get `tokenizer does not have a padding token` error for both fast/slow tokenizers.
																	# `CTRLConfig` was never used in pipeline tests, either because of a missing checkpoint or because a tiny
																	# config could not be created.
																	return True

											return False

					def   lowerCamelCase__   (			self  :      Union[str, Any]					)			->							Union[str, Any]:
											__magic_name__:	str							=       CTRLModelTester(self					)
											__magic_name__:	Optional[int]							=       ConfigTester(self     ,		config_class=__snake_case     ,		n_embd=3_7					)

					def   lowerCamelCase__   (			self  :      List[str]					)			->							Optional[int]:
											super().tearDown()
											# clean-up as much as possible GPU memory occupied by PyTorch
											gc.collect()
											torch.cuda.empty_cache()

					def   lowerCamelCase__   (			self  :      Tuple					)			->							List[str]:
											self.config_tester.run_common_tests()

					def   lowerCamelCase__   (			self  :      List[str]					)			->							List[Any]:
											__magic_name__:	Optional[Any]							=       self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_ctrl_model(*__snake_case					)

					def   lowerCamelCase__   (			self  :      Any					)			->							Tuple:
											__magic_name__:	Optional[Any]							=       self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_lm_head_model(*__snake_case					)

					@unittest.skip("""Will be fixed soon by reducing the size of the model used for common tests."""					)
					def   lowerCamelCase__   (			self  :      Tuple					)			->							Dict:
											pass

					@slow
					def   lowerCamelCase__   (			self  :      Dict					)			->							Optional[Any]:
											for model_name in CTRL_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	__magic_name__:	Union[str, Any]							=       CTRLModel.from_pretrained(__snake_case					)
																	self.assertIsNotNone(__snake_case					)






					@unittest.skip("""The model doesn't support left padding"""					)  # and it's not used enough to be worth fixing :)
					def   lowerCamelCase__   (			self  :      Optional[int]					)			->							List[Any]:
											pass



@require_torch
class       __A		(   unittest.TestCase			):

					def   lowerCamelCase__   (			self  :      Tuple					)			->							str:
											super().tearDown()
											# clean-up as much as possible GPU memory occupied by PyTorch
											gc.collect()
											torch.cuda.empty_cache()






					@slow
					def   lowerCamelCase__   (			self  :      Optional[int]					)			->							List[Any]:
											__magic_name__:	Optional[Any]							=       CTRLLMHeadModel.from_pretrained("""ctrl"""					)
											model.to(__snake_case					)
											__magic_name__:	List[str]							=       torch.tensor(
											    [[1_1_8_5_9, 0, 1_6_1_1, 8]]     ,		dtype=torch.long     ,		device=__snake_case					)  # Legal the president is
											__magic_name__:	List[Any]							=       [
											    1_1_8_5_9,
											    0,
											    1_6_1_1,
											    8,
											    5,
											    1_5_0,
											    2_6_4_4_9,
											    2,
											    1_9,
											    3_4_8,
											    4_6_9,
											    3,
											    2_5_9_5,
											    4_8,
											    2_0_7_4_0,
											    2_4_6_5_3_3,
											    2_4_6_5_3_3,
											    1_9,
											    3_0,
											    5,
											]  # Legal the president is a good guy and I don't want to lose my job. \n \n I have a

											__magic_name__:	Optional[int]							=       model.generate(__snake_case     ,		do_sample=__snake_case					)
											self.assertListEqual(output_ids[0].tolist()     ,		__snake_case					)







import tempfile
import unittest

import numpy as np

from diffusers import (
    DDIMScheduler,
    DPMSolverMultistepScheduler,
    EulerAncestralDiscreteScheduler,
    EulerDiscreteScheduler,
    LMSDiscreteScheduler,
    OnnxStableDiffusionPipeline,
    PNDMScheduler,
)
from diffusers.utils.testing_utils import is_onnx_available, nightly, require_onnxruntime, require_torch_gpu

from ..test_pipelines_onnx_common import OnnxPipelineTesterMixin


if is_onnx_available():
 import onnxruntime as ort






class _lowerCamelCase(		_a,					unittest.TestCase  ):
       lowercase_					:      Optional[int]       					=     """hf-internal-testing/tiny-random-OnnxStableDiffusionPipeline"""
       def      UpperCamelCase	(   self, lowerCamelCase=0)			->  str:




           """simple docstring"""

           _lowercase			:				Optional[int] 						=						np.random.RandomState(lowerCamelCase)
           _lowercase			:				Union[str, Any] 						=						{
               'prompt': 'A painting of a squirrel eating a burger',
               'generator': generator,
               'num_inference_steps': 2,
               'guidance_scale': 7.5,
               'output_type': 'numpy',
           }
           return inputs
       def      UpperCamelCase	(   self)			->  List[str]:




           """simple docstring"""

           _lowercase			:				int 						=						OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint, provider='CPUExecutionProvider')
           pipe.set_progress_bar_config(disable=lowerCamelCase)

           _lowercase			:				List[str] 						=						self.get_dummy_inputs()
           _lowercase			:				Tuple 						=						pipe(**lowerCamelCase).images
           _lowercase			:				Optional[Any] 						=						image[0, -3:, -3:, -1]

           assert image.shape == (1, 1_28, 1_28, 3)
           _lowercase			:				List[Any] 						=						np.array([0.6_5_0_7_2, 0.5_8_4_9_2, 0.4_8_2_1_9, 0.5_5_5_2_1, 0.5_3_1_8_0, 0.5_5_9_3_9, 0.5_0_6_9_7, 0.3_9_8_0_0, 0.4_6_4_5_5])

           assert np.abs(image_slice.flatten() - expected_slice).max() < 1E-2
       def      UpperCamelCase	(   self)			->  List[Any]:




           """simple docstring"""

           _lowercase			:				str 						=						OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint, provider='CPUExecutionProvider')
           _lowercase			:				List[Any] 						=						PNDMScheduler.from_config(pipe.scheduler.config, skip_prk_steps=lowerCamelCase)
           pipe.set_progress_bar_config(disable=lowerCamelCase)

           _lowercase			:				Dict 						=						self.get_dummy_inputs()
           _lowercase			:				Optional[int] 						=						pipe(**lowerCamelCase).images
           _lowercase			:				Dict 						=						image[0, -3:, -3:, -1]

           assert image.shape == (1, 1_28, 1_28, 3)
           _lowercase			:				List[Any] 						=						np.array([0.6_5_8_6_3, 0.5_9_4_2_5, 0.4_9_3_2_6, 0.5_6_3_1_3, 0.5_3_8_7_5, 0.5_6_6_2_7, 0.5_1_0_6_5, 0.3_9_7_7_7, 0.4_6_3_3_0])

           assert np.abs(image_slice.flatten() - expected_slice).max() < 1E-2
       def      UpperCamelCase	(   self)			->  str:




           """simple docstring"""

           _lowercase			:				Optional[int] 						=						OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint, provider='CPUExecutionProvider')
           _lowercase			:				Optional[int] 						=						LMSDiscreteScheduler.from_config(pipe.scheduler.config)
           pipe.set_progress_bar_config(disable=lowerCamelCase)

           _lowercase			:				Dict 						=						self.get_dummy_inputs()
           _lowercase			:				Union[str, Any] 						=						pipe(**lowerCamelCase).images
           _lowercase			:				str 						=						image[0, -3:, -3:, -1]

           assert image.shape == (1, 1_28, 1_28, 3)
           _lowercase			:				Union[str, Any] 						=						np.array([0.5_3_7_5_5, 0.6_0_7_8_6, 0.4_7_4_0_2, 0.4_9_4_8_8, 0.5_1_8_6_9, 0.4_9_8_1_9, 0.4_7_9_8_5, 0.3_8_9_5_7, 0.4_4_2_7_9])

           assert np.abs(image_slice.flatten() - expected_slice).max() < 1E-2
       def      UpperCamelCase	(   self)			->  Optional[int]:




           """simple docstring"""

           _lowercase			:				Union[str, Any] 						=						OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint, provider='CPUExecutionProvider')
           _lowercase			:				Any 						=						EulerDiscreteScheduler.from_config(pipe.scheduler.config)
           pipe.set_progress_bar_config(disable=lowerCamelCase)

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

           assert image.shape == (1, 1_28, 1_28, 3)
           _lowercase			:				Union[str, Any] 						=						np.array([0.5_3_7_5_5, 0.6_0_7_8_6, 0.4_7_4_0_2, 0.4_9_4_8_8, 0.5_1_8_6_9, 0.4_9_8_1_9, 0.4_7_9_8_5, 0.3_8_9_5_7, 0.4_4_2_7_9])

           assert np.abs(image_slice.flatten() - expected_slice).max() < 1E-2
       def      UpperCamelCase	(   self)			->  Dict:




           """simple docstring"""

           _lowercase			:				List[str] 						=						OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint, provider='CPUExecutionProvider')
           _lowercase			:				Optional[int] 						=						EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
           pipe.set_progress_bar_config(disable=lowerCamelCase)

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

           assert image.shape == (1, 1_28, 1_28, 3)
           _lowercase			:				List[str] 						=						np.array([0.5_3_8_1_7, 0.6_0_8_1_2, 0.4_7_3_8_4, 0.4_9_5_3_0, 0.5_1_8_9_4, 0.4_9_8_1_4, 0.4_7_9_8_4, 0.3_8_9_5_8, 0.4_4_2_7_1])

           assert np.abs(image_slice.flatten() - expected_slice).max() < 1E-2
       def      UpperCamelCase	(   self)			->  List[Any]:




           """simple docstring"""

           _lowercase			:				List[Any] 						=						OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint, provider='CPUExecutionProvider')
           _lowercase			:				Any 						=						DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
           pipe.set_progress_bar_config(disable=lowerCamelCase)

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

           assert image.shape == (1, 1_28, 1_28, 3)
           _lowercase			:				Any 						=						np.array([0.5_3_8_9_5, 0.6_0_8_0_8, 0.4_7_9_3_3, 0.4_9_6_0_8, 0.5_1_8_8_6, 0.4_9_9_5_0, 0.4_8_0_5_3, 0.3_8_9_5_7, 0.4_4_2_0_0])

           assert np.abs(image_slice.flatten() - expected_slice).max() < 1E-2
       def      UpperCamelCase	(   self)			->  int:




           """simple docstring"""

           _lowercase			:				Dict 						=						OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint, provider='CPUExecutionProvider')
           pipe.set_progress_bar_config(disable=lowerCamelCase)

           _lowercase			:				str 						=						self.get_dummy_inputs()
           _lowercase			:				Any 						=						3 * [inputs['prompt']]

           # forward
           _lowercase			:				int 						=						pipe(**lowerCamelCase)
           _lowercase			:				Optional[int] 						=						output.images[0, -3:, -3:, -1]

           _lowercase			:				int 						=						self.get_dummy_inputs()
           _lowercase			:				Union[str, Any] 						=						3 * [inputs.pop('prompt')]

           _lowercase			:				Union[str, Any] 						=						pipe.tokenizer(
               lowerCamelCase, padding='max_length', max_length=pipe.tokenizer.model_max_length, truncation=lowerCamelCase, return_tensors='np', )
           _lowercase			:				Tuple 						=						text_inputs['input_ids']

           _lowercase			:				Any 						=						pipe.text_encoder(input_ids=text_inputs.astype(np.intaa))[0]

           _lowercase			:				List[Any] 						=						prompt_embeds

           # forward
           _lowercase			:				Union[str, Any] 						=						pipe(**lowerCamelCase)
           _lowercase			:				Union[str, Any] 						=						output.images[0, -3:, -3:, -1]

           assert np.abs(image_slice_a.flatten() - image_slice_a.flatten()).max() < 1E-4




       def      UpperCamelCase	(   self)			->  Optional[int]:




           """simple docstring"""

           _lowercase			:				Optional[Any] 						=						OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint, provider='CPUExecutionProvider')
           pipe.set_progress_bar_config(disable=lowerCamelCase)

           _lowercase			:				Optional[Any] 						=						self.get_dummy_inputs()
           _lowercase			:				Any 						=						3 * ['this is a negative prompt']
           _lowercase			:				str 						=						negative_prompt
           _lowercase			:				Optional[int] 						=						3 * [inputs['prompt']]

           # forward
           _lowercase			:				int 						=						pipe(**lowerCamelCase)
           _lowercase			:				str 						=						output.images[0, -3:, -3:, -1]

           _lowercase			:				Union[str, Any] 						=						self.get_dummy_inputs()
           _lowercase			:				str 						=						3 * [inputs.pop('prompt')]

           _lowercase			:				Optional[int] 						=						[]
           for p in [prompt, negative_prompt]:
               _lowercase			:				Tuple 						=						pipe.tokenizer(
                   lowerCamelCase, padding='max_length', max_length=pipe.tokenizer.model_max_length, truncation=lowerCamelCase, return_tensors='np', )
               _lowercase			:				Dict 						=						text_inputs['input_ids']

               embeds.append(pipe.text_encoder(input_ids=text_inputs.astype(np.intaa))[0])

           _lowercase						,							_lowercase			:				str 						=						embeds

           # forward
           _lowercase			:				Dict 						=						pipe(**lowerCamelCase)
           _lowercase			:				Tuple 						=						output.images[0, -3:, -3:, -1]

           assert np.abs(image_slice_a.flatten() - image_slice_a.flatten()).max() < 1E-4






@nightly
@require_onnxruntime
@require_torch_gpu
class _lowerCamelCase(		unittest.TestCase  ):
       @property
       def      UpperCamelCase	(   self)			->  Union[str, Any]:




           """simple docstring"""

           return (
               "CUDAExecutionProvider",
               {
                   "gpu_mem_limit": "15000000000",  # 15GB
                   "arena_extend_strategy": "kSameAsRequested",
               },
           )
       @property
       def      UpperCamelCase	(   self)			->  str:




           """simple docstring"""

           _lowercase			:				int 						=						ort.SessionOptions()
           _lowercase			:				str 						=						False
           return options
       def      UpperCamelCase	(   self)			->  Optional[Any]:




           """simple docstring"""

           _lowercase			:				Optional[int] 						=						OnnxStableDiffusionPipeline.from_pretrained(
               'CompVis/stable-diffusion-v1-4', revision='onnx', safety_checker=lowerCamelCase, feature_extractor=lowerCamelCase, provider=self.gpu_provider, sess_options=self.gpu_options, )
           sd_pipe.set_progress_bar_config(disable=lowerCamelCase)

           _lowercase			:				List[Any] 						=						'A painting of a squirrel eating a burger'
           np.random.seed(0)
           _lowercase			:				Union[str, Any] 						=						sd_pipe([prompt], guidance_scale=6.0, num_inference_steps=10, output_type='np')
           _lowercase			:				Optional[Any] 						=						output.images

           _lowercase			:				Optional[int] 						=						image[0, -3:, -3:, -1]

           assert image.shape == (1, 5_12, 5_12, 3)
           _lowercase			:				Union[str, Any] 						=						np.array([0.0_4_5_2, 0.0_3_9_0, 0.0_0_8_7, 0.0_3_5_0, 0.0_6_1_7, 0.0_3_6_4, 0.0_5_4_4, 0.0_5_2_3, 0.0_7_2_0])

           assert np.abs(image_slice.flatten() - expected_slice).max() < 1E-3
       def      UpperCamelCase	(   self)			->  Optional[int]:




           """simple docstring"""

           _lowercase			:				str 						=						DDIMScheduler.from_pretrained(
               'runwayml/stable-diffusion-v1-5', subfolder='scheduler', revision='onnx')
           _lowercase			:				str 						=						OnnxStableDiffusionPipeline.from_pretrained(
               'runwayml/stable-diffusion-v1-5', revision='onnx', scheduler=lowerCamelCase, safety_checker=lowerCamelCase, feature_extractor=lowerCamelCase, provider=self.gpu_provider, sess_options=self.gpu_options, )
           sd_pipe.set_progress_bar_config(disable=lowerCamelCase)

           _lowercase			:				List[Any] 						=						'open neural network exchange'
           _lowercase			:				List[Any] 						=						np.random.RandomState(0)
           _lowercase			:				Optional[Any] 						=						sd_pipe([prompt], guidance_scale=7.5, num_inference_steps=10, generator=lowerCamelCase, output_type='np')
           _lowercase			:				Optional[Any] 						=						output.images
           _lowercase			:				List[Any] 						=						image[0, -3:, -3:, -1]

           assert image.shape == (1, 5_12, 5_12, 3)
           _lowercase			:				Optional[int] 						=						np.array([0.2_8_6_7, 0.1_9_7_4, 0.1_4_8_1, 0.7_2_9_4, 0.7_2_5_1, 0.6_6_6_7, 0.4_1_9_4, 0.5_6_4_2, 0.6_4_8_6])

           assert np.abs(image_slice.flatten() - expected_slice).max() < 1E-3
       def      UpperCamelCase	(   self)			->  List[str]:




           """simple docstring"""

           _lowercase			:				Dict 						=						LMSDiscreteScheduler.from_pretrained(
               'runwayml/stable-diffusion-v1-5', subfolder='scheduler', revision='onnx')
           _lowercase			:				Dict 						=						OnnxStableDiffusionPipeline.from_pretrained(
               'runwayml/stable-diffusion-v1-5', revision='onnx', scheduler=lowerCamelCase, safety_checker=lowerCamelCase, feature_extractor=lowerCamelCase, provider=self.gpu_provider, sess_options=self.gpu_options, )
           sd_pipe.set_progress_bar_config(disable=lowerCamelCase)

           _lowercase			:				Tuple 						=						'open neural network exchange'
           _lowercase			:				str 						=						np.random.RandomState(0)
           _lowercase			:				Dict 						=						sd_pipe([prompt], guidance_scale=7.5, num_inference_steps=10, generator=lowerCamelCase, output_type='np')
           _lowercase			:				Optional[Any] 						=						output.images
           _lowercase			:				int 						=						image[0, -3:, -3:, -1]

           assert image.shape == (1, 5_12, 5_12, 3)
           _lowercase			:				Optional[Any] 						=						np.array([0.2_3_0_6, 0.1_9_5_9, 0.1_5_9_3, 0.6_5_4_9, 0.6_3_9_4, 0.5_4_0_8, 0.5_0_6_5, 0.6_0_1_0, 0.6_1_6_1])

           assert np.abs(image_slice.flatten() - expected_slice).max() < 1E-3
       def      UpperCamelCase	(   self)			->  int:




           """simple docstring"""

           _lowercase			:				List[Any] 						=						0

           def test_callback_fn(lowerCamelCase, lowerCamelCase, lowerCamelCase) -> None:
               _lowercase			:				List[str] 						=						True
               nonlocal number_of_steps
               number_of_steps += 1
               if step == 0:
                   assert latents.shape == (1, 4, 64, 64)
                   _lowercase			:				Any 						=						latents[0, -3:, -3:, -1]
                   _lowercase			:				Tuple 						=						np.array(
                       [-0.6_7_7_2, -0.3_8_3_5, -1.2_4_5_6, 0.1_9_0_5, -1.0_9_7_4, 0.6_9_6_7, -1.9_3_5_3, 0.0_1_7_8, 1.0_1_6_7])

                   assert np.abs(latents_slice.flatten() - expected_slice).max() < 1E-3
               elif step == 5:
                   assert latents.shape == (1, 4, 64, 64)
                   _lowercase			:				List[Any] 						=						latents[0, -3:, -3:, -1]
                   _lowercase			:				str 						=						np.array(
                       [-0.3_3_5_1, 0.2_2_4_1, -0.1_8_3_7, -0.2_3_2_5, -0.6_5_7_7, 0.3_3_9_3, -0.0_2_4_1, 0.5_8_9_9, 1.3_8_7_5])

                   assert np.abs(latents_slice.flatten() - expected_slice).max() < 1E-3

           _lowercase			:				Any 						=						False

           _lowercase			:				int 						=						OnnxStableDiffusionPipeline.from_pretrained(
               'runwayml/stable-diffusion-v1-5', revision='onnx', safety_checker=lowerCamelCase, feature_extractor=lowerCamelCase, provider=self.gpu_provider, sess_options=self.gpu_options, )
           pipe.set_progress_bar_config(disable=lowerCamelCase)

           _lowercase			:				Any 						=						'Andromeda galaxy in a bottle'

           _lowercase			:				str 						=						np.random.RandomState(0)
           pipe(
               prompt=lowerCamelCase, num_inference_steps=5, guidance_scale=7.5, generator=lowerCamelCase, callback=lowerCamelCase, callback_steps=1, )
           assert test_callback_fn.has_been_called
           assert number_of_steps == 6




       def      UpperCamelCase	(   self)			->  Tuple:




           """simple docstring"""

           _lowercase			:				List[str] 						=						OnnxStableDiffusionPipeline.from_pretrained(
               'runwayml/stable-diffusion-v1-5', revision='onnx', safety_checker=lowerCamelCase, feature_extractor=lowerCamelCase, provider=self.gpu_provider, sess_options=self.gpu_options, )
           assert isinstance(lowerCamelCase, lowerCamelCase)
           assert pipe.safety_checker is None

           _lowercase			:				Optional[int] 						=						pipe('example prompt', num_inference_steps=2).images[0]
           assert image is not None

           # check that there's no error when saving a pipeline with one of the models being None
           with tempfile.TemporaryDirectory() as tmpdirname:
               pipe.save_pretrained(lowerCamelCase)
               _lowercase			:				Any 						=						OnnxStableDiffusionPipeline.from_pretrained(lowerCamelCase)

           # sanity check that the pipeline still works
           assert pipe.safety_checker is None
           _lowercase			:				List[str] 						=						pipe('example prompt', num_inference_steps=2).images[0]
           assert image is not None


