
'''simple docstring'''







import random
import unittest

import numpy as np

import transformers
from transformers import is_flax_available, is_torch_available
from transformers.testing_utils import is_pt_flax_cross_test, require_flax


if is_flax_available():
						import os

						import jax.numpy as jnp
						from jax import jit

						from transformers import AutoTokenizer, FlaxAutoModelForCausalLM
						from transformers.modeling_flax_pytorch_utils import load_flax_weights_in_pytorch_model

						_snake_case				:   Optional[int]     =				"""0.12"""  # assumed parallelism: 8


if is_torch_available():
						import torch



def 			_a		(	a		:   List[str]	,			a		:   Dict	,			a		:   Optional[int]=None  ):
						if rng is None:
												_SCREAMING_SNAKE_CASE				= random.Random()

						_SCREAMING_SNAKE_CASE				= 1
						for dim in shape:
												total_dims *= dim

						_SCREAMING_SNAKE_CASE				= []
						for _ in range(_SCREAMING_SNAKE_CASE  ):
												values.append(rng.randint(0	,			vocab_size - 1  )  )

						_SCREAMING_SNAKE_CASE				= np.array(_SCREAMING_SNAKE_CASE	,			dtype=jnp.intaa  ).reshape(_SCREAMING_SNAKE_CASE  )

						return output



def 			_a		(	a		:   List[str]	,			a		:   Any=None  ):
						_SCREAMING_SNAKE_CASE				= ids_tensor(_SCREAMING_SNAKE_CASE	,			vocab_size=2	,			rng=_SCREAMING_SNAKE_CASE  )
						# make sure that at least one token is attended to for each batch
						_SCREAMING_SNAKE_CASE				= 1
						return attn_mask


@require_flax
class 			lowerCAmelCase :
		a							:					Union[str, Any]       =					None
		a							:					Optional[Any]       =					()




		def     lowercase       (				self      ):
								_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE				= self.model_tester.prepare_config_and_inputs_for_common()

								# cut to half length & take max batch_size 3
								_SCREAMING_SNAKE_CASE				= 2
								_SCREAMING_SNAKE_CASE				= inputs["input_ids"].shape[-1] // 2
								_SCREAMING_SNAKE_CASE				= inputs["input_ids"][:max_batch_size, :sequence_length]

								_SCREAMING_SNAKE_CASE				= jnp.ones_like(UpperCamelCase      )
								_SCREAMING_SNAKE_CASE				= attention_mask[:max_batch_size, :sequence_length]

								# generate max 5 tokens
								_SCREAMING_SNAKE_CASE				= input_ids.shape[-1] + 5
								if config.eos_token_id is not None and config.pad_token_id is None:
														# hack to allow generate for models such as GPT2 as is done in `generate()`
														_SCREAMING_SNAKE_CASE				= config.eos_token_id
								return config, input_ids, attention_mask, max_length




		@is_pt_flax_cross_test
		def     lowercase       (				self      ):
								_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE				= self._get_input_ids_and_config()
								_SCREAMING_SNAKE_CASE				= False
								_SCREAMING_SNAKE_CASE				= max_length
								_SCREAMING_SNAKE_CASE				= 0

								for model_class in self.all_generative_model_classes:
														_SCREAMING_SNAKE_CASE				= model_class(UpperCamelCase      )

														_SCREAMING_SNAKE_CASE				= model_class.__name__[4:]  # Skip the "Flax" at the beginning
														_SCREAMING_SNAKE_CASE				= getattr(UpperCamelCase					,						UpperCamelCase      )
														_SCREAMING_SNAKE_CASE				= pt_model_class(UpperCamelCase      ).eval()
														_SCREAMING_SNAKE_CASE				= load_flax_weights_in_pytorch_model(UpperCamelCase					,						flax_model.params      )

														_SCREAMING_SNAKE_CASE				= flax_model.generate(UpperCamelCase      ).sequences
														_SCREAMING_SNAKE_CASE				= pt_model.generate(torch.tensor(UpperCamelCase					,						dtype=torch.long      )      )

														if flax_generation_outputs.shape[-1] > pt_generation_outputs.shape[-1]:
																				_SCREAMING_SNAKE_CASE				= flax_generation_outputs[:, : pt_generation_outputs.shape[-1]]

														self.assertListEqual(pt_generation_outputs.numpy().tolist()					,						flax_generation_outputs.tolist()      )




		def     lowercase       (				self      ):
								_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE				= self._get_input_ids_and_config()
								_SCREAMING_SNAKE_CASE				= False
								_SCREAMING_SNAKE_CASE				= max_length

								for model_class in self.all_generative_model_classes:
														_SCREAMING_SNAKE_CASE				= model_class(UpperCamelCase      )

														_SCREAMING_SNAKE_CASE				= model.generate(UpperCamelCase      ).sequences
														self.assertEqual(generation_outputs.shape[-1]					,						UpperCamelCase      )

														_SCREAMING_SNAKE_CASE				= jit(model.generate      )
														_SCREAMING_SNAKE_CASE				= jit_generate(UpperCamelCase      ).sequences

														self.assertListEqual(generation_outputs.tolist()					,						jit_generation_outputs.tolist()      )




		def     lowercase       (				self      ):
								_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE				= self._get_input_ids_and_config()
								_SCREAMING_SNAKE_CASE				= True
								_SCREAMING_SNAKE_CASE				= max_length

								for model_class in self.all_generative_model_classes:
														_SCREAMING_SNAKE_CASE				= model_class(UpperCamelCase      )

														_SCREAMING_SNAKE_CASE				= model.generate(UpperCamelCase      ).sequences
														self.assertEqual(generation_outputs.shape[-1]					,						UpperCamelCase      )

														_SCREAMING_SNAKE_CASE				= jit(model.generate      )
														_SCREAMING_SNAKE_CASE				= jit_generate(UpperCamelCase      ).sequences

														self.assertListEqual(generation_outputs.tolist()					,						jit_generation_outputs.tolist()      )




		def     lowercase       (				self      ):
								_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE				= self._get_input_ids_and_config()
								_SCREAMING_SNAKE_CASE				= False
								_SCREAMING_SNAKE_CASE				= max_length
								_SCREAMING_SNAKE_CASE				= 2

								for model_class in self.all_generative_model_classes:
														_SCREAMING_SNAKE_CASE				= model_class(UpperCamelCase      )

														_SCREAMING_SNAKE_CASE				= model.generate(UpperCamelCase      ).sequences
														self.assertEqual(generation_outputs.shape[-1]					,						UpperCamelCase      )

														_SCREAMING_SNAKE_CASE				= jit(model.generate      )
														_SCREAMING_SNAKE_CASE				= jit_generate(UpperCamelCase      ).sequences

														self.assertListEqual(generation_outputs.tolist()					,						jit_generation_outputs.tolist()      )




		def     lowercase       (				self      ):
								_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE				= self._get_input_ids_and_config()
								_SCREAMING_SNAKE_CASE				= False
								_SCREAMING_SNAKE_CASE				= max_length
								_SCREAMING_SNAKE_CASE				= 2
								_SCREAMING_SNAKE_CASE				= 2

								for model_class in self.all_generative_model_classes:
														_SCREAMING_SNAKE_CASE				= model_class(UpperCamelCase      )

														_SCREAMING_SNAKE_CASE				= model.generate(UpperCamelCase      ).sequences
														self.assertEqual(generation_outputs.shape[0]					,						input_ids.shape[0] * config.num_return_sequences      )




		def     lowercase       (				self      ):
								_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE				= self._get_input_ids_and_config()
								_SCREAMING_SNAKE_CASE				= True
								_SCREAMING_SNAKE_CASE				= max_length
								_SCREAMING_SNAKE_CASE				= 0.8
								_SCREAMING_SNAKE_CASE				= 10
								_SCREAMING_SNAKE_CASE				= 0.3
								_SCREAMING_SNAKE_CASE				= 1
								_SCREAMING_SNAKE_CASE				= 8
								_SCREAMING_SNAKE_CASE				= 9

								for model_class in self.all_generative_model_classes:
														_SCREAMING_SNAKE_CASE				= model_class(UpperCamelCase      )

														_SCREAMING_SNAKE_CASE				= model.generate(UpperCamelCase      ).sequences
														self.assertEqual(generation_outputs.shape[-1]					,						UpperCamelCase      )

														_SCREAMING_SNAKE_CASE				= jit(model.generate      )
														_SCREAMING_SNAKE_CASE				= jit_generate(UpperCamelCase      ).sequences

														self.assertListEqual(generation_outputs.tolist()					,						jit_generation_outputs.tolist()      )




		def     lowercase       (				self      ):
								_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE				= self._get_input_ids_and_config()
								_SCREAMING_SNAKE_CASE				= max_length
								_SCREAMING_SNAKE_CASE				= 1
								_SCREAMING_SNAKE_CASE				= 8
								_SCREAMING_SNAKE_CASE				= 9

								for model_class in self.all_generative_model_classes:
														_SCREAMING_SNAKE_CASE				= model_class(UpperCamelCase      )

														_SCREAMING_SNAKE_CASE				= model.generate(UpperCamelCase      ).sequences
														self.assertEqual(generation_outputs.shape[-1]					,						UpperCamelCase      )

														_SCREAMING_SNAKE_CASE				= jit(model.generate      )
														_SCREAMING_SNAKE_CASE				= jit_generate(UpperCamelCase      ).sequences

														self.assertListEqual(generation_outputs.tolist()					,						jit_generation_outputs.tolist()      )




		def     lowercase       (				self      ):
								_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE				= self._get_input_ids_and_config()
								_SCREAMING_SNAKE_CASE				= max_length
								_SCREAMING_SNAKE_CASE				= 2
								_SCREAMING_SNAKE_CASE				= 1
								_SCREAMING_SNAKE_CASE				= 8
								_SCREAMING_SNAKE_CASE				= 9

								for model_class in self.all_generative_model_classes:
														_SCREAMING_SNAKE_CASE				= model_class(UpperCamelCase      )

														_SCREAMING_SNAKE_CASE				= model.generate(UpperCamelCase      ).sequences
														self.assertEqual(generation_outputs.shape[-1]					,						UpperCamelCase      )

														_SCREAMING_SNAKE_CASE				= jit(model.generate      )
														_SCREAMING_SNAKE_CASE				= jit_generate(UpperCamelCase      ).sequences

														self.assertListEqual(generation_outputs.tolist()					,						jit_generation_outputs.tolist()      )




		def     lowercase       (				self      ):
								_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE				= self._get_input_ids_and_config()

								# pad attention mask on the left
								_SCREAMING_SNAKE_CASE				= attention_mask.at[(0, 0)].set(0      )

								_SCREAMING_SNAKE_CASE				= False
								_SCREAMING_SNAKE_CASE				= max_length

								for model_class in self.all_generative_model_classes:
														_SCREAMING_SNAKE_CASE				= model_class(UpperCamelCase      )

														_SCREAMING_SNAKE_CASE				= model.generate(UpperCamelCase					,						attention_mask=UpperCamelCase      ).sequences
														self.assertEqual(generation_outputs.shape[-1]					,						UpperCamelCase      )

														_SCREAMING_SNAKE_CASE				= jit(model.generate      )
														_SCREAMING_SNAKE_CASE				= jit_generate(UpperCamelCase					,						attention_mask=UpperCamelCase      ).sequences

														self.assertListEqual(generation_outputs.tolist()					,						jit_generation_outputs.tolist()      )




		def     lowercase       (				self      ):
								_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE				= self._get_input_ids_and_config()

								# pad attention mask on the left
								_SCREAMING_SNAKE_CASE				= attention_mask.at[(0, 0)].set(0      )

								_SCREAMING_SNAKE_CASE				= True
								_SCREAMING_SNAKE_CASE				= max_length

								for model_class in self.all_generative_model_classes:
														_SCREAMING_SNAKE_CASE				= model_class(UpperCamelCase      )

														_SCREAMING_SNAKE_CASE				= model.generate(UpperCamelCase					,						attention_mask=UpperCamelCase      ).sequences
														self.assertEqual(generation_outputs.shape[-1]					,						UpperCamelCase      )

														_SCREAMING_SNAKE_CASE				= jit(model.generate      )
														_SCREAMING_SNAKE_CASE				= jit_generate(UpperCamelCase					,						attention_mask=UpperCamelCase      ).sequences

														self.assertListEqual(generation_outputs.tolist()					,						jit_generation_outputs.tolist()      )




		def     lowercase       (				self      ):
								_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE				= self._get_input_ids_and_config()

								# pad attention mask on the left
								_SCREAMING_SNAKE_CASE				= attention_mask.at[(0, 0)].set(0      )

								_SCREAMING_SNAKE_CASE				= 2
								_SCREAMING_SNAKE_CASE				= max_length

								for model_class in self.all_generative_model_classes:
														_SCREAMING_SNAKE_CASE				= model_class(UpperCamelCase      )

														_SCREAMING_SNAKE_CASE				= model.generate(UpperCamelCase					,						attention_mask=UpperCamelCase      ).sequences
														self.assertEqual(generation_outputs.shape[-1]					,						UpperCamelCase      )

														_SCREAMING_SNAKE_CASE				= jit(model.generate      )
														_SCREAMING_SNAKE_CASE				= jit_generate(UpperCamelCase					,						attention_mask=UpperCamelCase      ).sequences

														self.assertListEqual(generation_outputs.tolist()					,						jit_generation_outputs.tolist()      )


@require_flax
class 			lowerCAmelCase (				unittest.TestCase			):




		def     lowercase       (				self      ):
								_SCREAMING_SNAKE_CASE				= AutoTokenizer.from_pretrained("hf-internal-testing/tiny-bert"      )
								_SCREAMING_SNAKE_CASE				= FlaxAutoModelForCausalLM.from_pretrained("hf-internal-testing/tiny-bert-flax-only"      )

								_SCREAMING_SNAKE_CASE				= "Hello world"
								_SCREAMING_SNAKE_CASE				= tokenizer(UpperCamelCase					,						return_tensors="np"      ).input_ids

								# typos are quickly detected (the correct argument is `do_sample`)
								with self.assertRaisesRegex(UpperCamelCase					,						"do_samples"      ):
														model.generate(UpperCamelCase					,						do_samples=UpperCamelCase      )

								# arbitrary arguments that will not be used anywhere are also not accepted
								with self.assertRaisesRegex(UpperCamelCase					,						"foo"      ):
														_SCREAMING_SNAKE_CASE				= {"foo": "bar"}
														model.generate(UpperCamelCase					,						**UpperCamelCase      )

'''simple docstring'''







import tempfile

import numpy as np
import torch
from transformers import AutoTokenizer, TaEncoderModel

from diffusers import DDPMScheduler, UNetaDConditionModel
from diffusers.models.attention_processor import AttnAddedKVProcessor
from diffusers.pipelines.deepfloyd_if import IFWatermarker
from diffusers.utils.testing_utils import torch_device

from ..test_pipelines_common import to_np


class 			lowerCAmelCase :




		def     lowercase       (				self      ):
								torch.manual_seed(0      )
								_SCREAMING_SNAKE_CASE				= TaEncoderModel.from_pretrained("hf-internal-testing/tiny-random-t5"      )

								torch.manual_seed(0      )
								_SCREAMING_SNAKE_CASE				= AutoTokenizer.from_pretrained("hf-internal-testing/tiny-random-t5"      )

								torch.manual_seed(0      )
								_SCREAMING_SNAKE_CASE				= UNetaDConditionModel(
								    sample_size=32					,						layers_per_block=1					,						block_out_channels=[32, 64]					,						down_block_types=[
								        "ResnetDownsampleBlock2D",
								        "SimpleCrossAttnDownBlock2D",
								    ]					,						mid_block_type="UNetMidBlock2DSimpleCrossAttn"					,						up_block_types=["SimpleCrossAttnUpBlock2D", "ResnetUpsampleBlock2D"]					,						in_channels=3					,						out_channels=6					,						cross_attention_dim=32					,						encoder_hid_dim=32					,						attention_head_dim=8					,						addition_embed_type="text"					,						addition_embed_type_num_heads=2					,						cross_attention_norm="group_norm"					,						resnet_time_scale_shift="scale_shift"					,						act_fn="gelu"					,						)
								unet.set_attn_processor(AttnAddedKVProcessor()      )  # For reproducibility tests

								torch.manual_seed(0      )
								_SCREAMING_SNAKE_CASE				= DDPMScheduler(
								    num_train_timesteps=1_000					,						beta_schedule="squaredcos_cap_v2"					,						beta_start=0.00_01					,						beta_end=0.02					,						thresholding=UpperCamelCase					,						dynamic_thresholding_ratio=0.95					,						sample_max_value=1.0					,						prediction_type="epsilon"					,						variance_type="learned_range"					,						)

								torch.manual_seed(0      )
								_SCREAMING_SNAKE_CASE				= IFWatermarker()

								return {
								    "text_encoder": text_encoder,
								    "tokenizer": tokenizer,
								    "unet": unet,
								    "scheduler": scheduler,
								    "watermarker": watermarker,
								    "safety_checker": None,
								    "feature_extractor": None,
								}




		def     lowercase       (				self      ):
								torch.manual_seed(0      )
								_SCREAMING_SNAKE_CASE				= TaEncoderModel.from_pretrained("hf-internal-testing/tiny-random-t5"      )

								torch.manual_seed(0      )
								_SCREAMING_SNAKE_CASE				= AutoTokenizer.from_pretrained("hf-internal-testing/tiny-random-t5"      )

								torch.manual_seed(0      )
								_SCREAMING_SNAKE_CASE				= UNetaDConditionModel(
								    sample_size=32					,						layers_per_block=[1, 2]					,						block_out_channels=[32, 64]					,						down_block_types=[
								        "ResnetDownsampleBlock2D",
								        "SimpleCrossAttnDownBlock2D",
								    ]					,						mid_block_type="UNetMidBlock2DSimpleCrossAttn"					,						up_block_types=["SimpleCrossAttnUpBlock2D", "ResnetUpsampleBlock2D"]					,						in_channels=6					,						out_channels=6					,						cross_attention_dim=32					,						encoder_hid_dim=32					,						attention_head_dim=8					,						addition_embed_type="text"					,						addition_embed_type_num_heads=2					,						cross_attention_norm="group_norm"					,						resnet_time_scale_shift="scale_shift"					,						act_fn="gelu"					,						class_embed_type="timestep"					,						mid_block_scale_factor=1.4_14					,						time_embedding_act_fn="gelu"					,						time_embedding_dim=32					,						)
								unet.set_attn_processor(AttnAddedKVProcessor()      )  # For reproducibility tests

								torch.manual_seed(0      )
								_SCREAMING_SNAKE_CASE				= DDPMScheduler(
								    num_train_timesteps=1_000					,						beta_schedule="squaredcos_cap_v2"					,						beta_start=0.00_01					,						beta_end=0.02					,						thresholding=UpperCamelCase					,						dynamic_thresholding_ratio=0.95					,						sample_max_value=1.0					,						prediction_type="epsilon"					,						variance_type="learned_range"					,						)

								torch.manual_seed(0      )
								_SCREAMING_SNAKE_CASE				= DDPMScheduler(
								    num_train_timesteps=1_000					,						beta_schedule="squaredcos_cap_v2"					,						beta_start=0.00_01					,						beta_end=0.02					,						)

								torch.manual_seed(0      )
								_SCREAMING_SNAKE_CASE				= IFWatermarker()

								return {
								    "text_encoder": text_encoder,
								    "tokenizer": tokenizer,
								    "unet": unet,
								    "scheduler": scheduler,
								    "image_noising_scheduler": image_noising_scheduler,
								    "watermarker": watermarker,
								    "safety_checker": None,
								    "feature_extractor": None,
								}




		def     lowercase       (				self      ):
								_SCREAMING_SNAKE_CASE				= self.get_dummy_components()
								_SCREAMING_SNAKE_CASE				= self.pipeline_class(**UpperCamelCase      )
								pipe.to(UpperCamelCase      )
								pipe.set_progress_bar_config(disable=UpperCamelCase      )

								_SCREAMING_SNAKE_CASE				= self.get_dummy_inputs(UpperCamelCase      )

								_SCREAMING_SNAKE_CASE				= inputs["prompt"]
								_SCREAMING_SNAKE_CASE				= inputs["generator"]
								_SCREAMING_SNAKE_CASE				= inputs["num_inference_steps"]
								_SCREAMING_SNAKE_CASE				= inputs["output_type"]

								if "image" in inputs:
														_SCREAMING_SNAKE_CASE				= inputs["image"]
								else:
														_SCREAMING_SNAKE_CASE				= None

								if "mask_image" in inputs:
														_SCREAMING_SNAKE_CASE				= inputs["mask_image"]
								else:
														_SCREAMING_SNAKE_CASE				= None

								if "original_image" in inputs:
														_SCREAMING_SNAKE_CASE				= inputs["original_image"]
								else:
														_SCREAMING_SNAKE_CASE				= None

								_SCREAMING_SNAKE_CASE,							_SCREAMING_SNAKE_CASE				= pipe.encode_prompt(UpperCamelCase      )

								# inputs with prompt converted to embeddings
								_SCREAMING_SNAKE_CASE				= {
								    "prompt_embeds": prompt_embeds,
								    "negative_prompt_embeds": negative_prompt_embeds,
								    "generator": generator,
								    "num_inference_steps": num_inference_steps,
								    "output_type": output_type,
								}

								if image is not None:
														_SCREAMING_SNAKE_CASE				= image

								if mask_image is not None:
														_SCREAMING_SNAKE_CASE				= mask_image

								if original_image is not None:
														_SCREAMING_SNAKE_CASE				= original_image

								# set all optional components to None
								for optional_component in pipe._optional_components:
														setattr(UpperCamelCase					,						UpperCamelCase					,						UpperCamelCase      )

								_SCREAMING_SNAKE_CASE				= pipe(**UpperCamelCase      )[0]

								with tempfile.TemporaryDirectory() as tmpdir:
														pipe.save_pretrained(UpperCamelCase      )
														_SCREAMING_SNAKE_CASE				= self.pipeline_class.from_pretrained(UpperCamelCase      )
														pipe_loaded.to(UpperCamelCase      )
														pipe_loaded.set_progress_bar_config(disable=UpperCamelCase      )

								pipe_loaded.unet.set_attn_processor(AttnAddedKVProcessor()      )  # For reproducibility tests

								for optional_component in pipe._optional_components:
														self.assertTrue(
														    getattr(UpperCamelCase					,						UpperCamelCase      ) is None					,						F'`{optional_component}` did not stay set to None after loading.'					,						)

								_SCREAMING_SNAKE_CASE				= self.get_dummy_inputs(UpperCamelCase      )

								_SCREAMING_SNAKE_CASE				= inputs["generator"]
								_SCREAMING_SNAKE_CASE				= inputs["num_inference_steps"]
								_SCREAMING_SNAKE_CASE				= inputs["output_type"]

								# inputs with prompt converted to embeddings
								_SCREAMING_SNAKE_CASE				= {
								    "prompt_embeds": prompt_embeds,
								    "negative_prompt_embeds": negative_prompt_embeds,
								    "generator": generator,
								    "num_inference_steps": num_inference_steps,
								    "output_type": output_type,
								}

								if image is not None:
														_SCREAMING_SNAKE_CASE				= image

								if mask_image is not None:
														_SCREAMING_SNAKE_CASE				= mask_image

								if original_image is not None:
														_SCREAMING_SNAKE_CASE				= original_image

								_SCREAMING_SNAKE_CASE				= pipe_loaded(**UpperCamelCase      )[0]

								_SCREAMING_SNAKE_CASE				= np.abs(to_np(UpperCamelCase      ) - to_np(UpperCamelCase      )      ).max()
								self.assertLess(UpperCamelCase					,						1e-4      )




		def     lowercase       (				self      ):
								_SCREAMING_SNAKE_CASE				= self.get_dummy_components()
								_SCREAMING_SNAKE_CASE				= self.pipeline_class(**UpperCamelCase      )
								pipe.to(UpperCamelCase      )
								pipe.set_progress_bar_config(disable=UpperCamelCase      )

								_SCREAMING_SNAKE_CASE				= self.get_dummy_inputs(UpperCamelCase      )
								_SCREAMING_SNAKE_CASE				= pipe(**UpperCamelCase      )[0]

								with tempfile.TemporaryDirectory() as tmpdir:
														pipe.save_pretrained(UpperCamelCase      )
														_SCREAMING_SNAKE_CASE				= self.pipeline_class.from_pretrained(UpperCamelCase      )
														pipe_loaded.to(UpperCamelCase      )
														pipe_loaded.set_progress_bar_config(disable=UpperCamelCase      )

								pipe_loaded.unet.set_attn_processor(AttnAddedKVProcessor()      )  # For reproducibility tests

								_SCREAMING_SNAKE_CASE				= self.get_dummy_inputs(UpperCamelCase      )
								_SCREAMING_SNAKE_CASE				= pipe_loaded(**UpperCamelCase      )[0]

								_SCREAMING_SNAKE_CASE				= np.abs(to_np(UpperCamelCase      ) - to_np(UpperCamelCase      )      ).max()
								self.assertLess(UpperCamelCase					,						1e-4      )