
"""simple docstring"""







import gc
import random
import tempfile
import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer

from diffusers import AutoencoderKL, DDIMScheduler, LMSDiscreteScheduler, PNDMScheduler, UNetaDConditionModel
from diffusers.pipelines.semantic_stable_diffusion import SemanticStableDiffusionPipeline as StableDiffusionPipeline
from diffusers.utils import floats_tensor, nightly, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()




class 					A__			(      unittest.TestCase):

		def 				__lowerCamelCase				( self					):
			# clean up the VRAM after each test
			super().tearDown()
			gc.collect()
			torch.cuda.empty_cache()

		@property
		def 				__lowerCamelCase				( self					):
			__lowerCAmelCase     :		List[str]		     = 1
			__lowerCAmelCase     :		List[str]		     = 3
			__lowerCAmelCase     :		Tuple		     = (32, 32)

			__lowerCAmelCase     :		Optional[Any]		     = floats_tensor((batch_size, num_channels) + sizes			,						rng=random.Random(0					)					).to(_SCREAMING_SNAKE_CASE					)
			return image

		@property
		def 				__lowerCamelCase				( self					):
			torch.manual_seed(0					)
			__lowerCAmelCase     :		int		     = UNetaDConditionModel(
			    block_out_channels=(32, 64)			,						layers_per_block=2			,						sample_size=32			,						in_channels=4			,						out_channels=4			,						down_block_types=('DownBlock2D', 'CrossAttnDownBlock2D')			,						up_block_types=('CrossAttnUpBlock2D', 'UpBlock2D')			,						cross_attention_dim=32			,						)
			return model

		@property
		def 				__lowerCamelCase				( self					):
			torch.manual_seed(0					)
			__lowerCAmelCase     :		int		     = AutoencoderKL(
			    block_out_channels=[32, 64]			,						in_channels=3			,						out_channels=3			,						down_block_types=['DownEncoderBlock2D', 'DownEncoderBlock2D']			,						up_block_types=['UpDecoderBlock2D', 'UpDecoderBlock2D']			,						latent_channels=4			,						)
			return model

		@property
		def 				__lowerCamelCase				( self					):
			torch.manual_seed(0					)
			__lowerCAmelCase     :		int		     = CLIPTextConfig(
			    bos_token_id=0			,						eos_token_id=2			,						hidden_size=32			,						intermediate_size=37			,						layer_norm_eps=1E-05			,						num_attention_heads=4			,						num_hidden_layers=5			,						pad_token_id=1			,						vocab_size=10_00			,						)
			return CLIPTextModel(_SCREAMING_SNAKE_CASE					)

		@property
		def 				__lowerCamelCase				( self					):
			def extract(*_SCREAMING_SNAKE_CASE			,						**_SCREAMING_SNAKE_CASE					):




				class 					A__			:

						def __init__( self					):
							__lowerCAmelCase     :		Optional[int]		     = torch.ones([0]					)







						def 				__lowerCamelCase				( self			,						_SCREAMING_SNAKE_CASE					):
							self.pixel_values.to(_SCREAMING_SNAKE_CASE					)
							return self



				return Out()

			return extract

		def 				__lowerCamelCase				( self					):
			__lowerCAmelCase     :		List[str]		     = 'cpu'  # ensure determinism for the device-dependent torch.Generator
			__lowerCAmelCase     :		Optional[Any]		     = self.dummy_cond_unet
			__lowerCAmelCase     :		List[Any]		     = DDIMScheduler(
			    beta_start=0.0_0085			,						beta_end=0.012			,						beta_schedule='scaled_linear'			,						clip_sample=_SCREAMING_SNAKE_CASE			,						set_alpha_to_one=_SCREAMING_SNAKE_CASE			,						)

			__lowerCAmelCase     :		int		     = self.dummy_vae
			__lowerCAmelCase     :		Dict		     = self.dummy_text_encoder
			__lowerCAmelCase     :		Optional[Any]		     = CLIPTokenizer.from_pretrained('hf-internal-testing/tiny-random-clip'					)

			# make sure here that pndm scheduler skips prk
			__lowerCAmelCase     :		str		     = StableDiffusionPipeline(
			    unet=_SCREAMING_SNAKE_CASE			,						scheduler=_SCREAMING_SNAKE_CASE			,						vae=_SCREAMING_SNAKE_CASE			,						text_encoder=_SCREAMING_SNAKE_CASE			,						tokenizer=_SCREAMING_SNAKE_CASE			,						safety_checker=_SCREAMING_SNAKE_CASE			,						feature_extractor=self.dummy_extractor			,						)
			__lowerCAmelCase     :		Dict		     = sd_pipe.to(_SCREAMING_SNAKE_CASE					)
			sd_pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE					)

			__lowerCAmelCase     :		Dict		     = 'A painting of a squirrel eating a burger'

			__lowerCAmelCase     :		Tuple		     = torch.Generator(device=_SCREAMING_SNAKE_CASE					).manual_seed(0					)
			__lowerCAmelCase     :		str		     = sd_pipe([prompt]			,						generator=_SCREAMING_SNAKE_CASE			,						guidance_scale=6.0			,						num_inference_steps=2			,						output_type='np'					)
			__lowerCAmelCase     :		Optional[int]		     = output.images

			__lowerCAmelCase     :		Optional[Any]		     = torch.Generator(device=_SCREAMING_SNAKE_CASE					).manual_seed(0					)
			__lowerCAmelCase     :		Tuple		     = sd_pipe(
			    [prompt]			,						generator=_SCREAMING_SNAKE_CASE			,						guidance_scale=6.0			,						num_inference_steps=2			,						output_type='np'			,						return_dict=_SCREAMING_SNAKE_CASE			,						)[0]

			__lowerCAmelCase     :		str		     = image[0, -3:, -3:, -1]
			__lowerCAmelCase     :		Dict		     = image_from_tuple[0, -3:, -3:, -1]

			assert image.shape == (1, 64, 64, 3)
			__lowerCAmelCase     :		List[Any]		     = np.array([0.5753, 0.6114, 0.5001, 0.5034, 0.5470, 0.4729, 0.4971, 0.4867, 0.4867]					)

			assert np.abs(image_slice.flatten() - expected_slice					).max() < 1E-2
			assert np.abs(image_from_tuple_slice.flatten() - expected_slice					).max() < 1E-2

		def 				__lowerCamelCase				( self					):
			__lowerCAmelCase     :		Any		     = 'cpu'  # ensure determinism for the device-dependent torch.Generator
			__lowerCAmelCase     :		List[Any]		     = self.dummy_cond_unet
			__lowerCAmelCase     :		str		     = PNDMScheduler(skip_prk_steps=_SCREAMING_SNAKE_CASE					)
			__lowerCAmelCase     :		Tuple		     = self.dummy_vae
			__lowerCAmelCase     :		Optional[Any]		     = self.dummy_text_encoder
			__lowerCAmelCase     :		Tuple		     = CLIPTokenizer.from_pretrained('hf-internal-testing/tiny-random-clip'					)

			# make sure here that pndm scheduler skips prk
			__lowerCAmelCase     :		Dict		     = StableDiffusionPipeline(
			    unet=_SCREAMING_SNAKE_CASE			,						scheduler=_SCREAMING_SNAKE_CASE			,						vae=_SCREAMING_SNAKE_CASE			,						text_encoder=_SCREAMING_SNAKE_CASE			,						tokenizer=_SCREAMING_SNAKE_CASE			,						safety_checker=_SCREAMING_SNAKE_CASE			,						feature_extractor=self.dummy_extractor			,						)
			__lowerCAmelCase     :		Optional[int]		     = sd_pipe.to(_SCREAMING_SNAKE_CASE					)
			sd_pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE					)

			__lowerCAmelCase     :		int		     = 'A painting of a squirrel eating a burger'
			__lowerCAmelCase     :		Dict		     = torch.Generator(device=_SCREAMING_SNAKE_CASE					).manual_seed(0					)
			__lowerCAmelCase     :		Tuple		     = sd_pipe([prompt]			,						generator=_SCREAMING_SNAKE_CASE			,						guidance_scale=6.0			,						num_inference_steps=2			,						output_type='np'					)

			__lowerCAmelCase     :		int		     = output.images

			__lowerCAmelCase     :		List[str]		     = torch.Generator(device=_SCREAMING_SNAKE_CASE					).manual_seed(0					)
			__lowerCAmelCase     :		Tuple		     = sd_pipe(
			    [prompt]			,						generator=_SCREAMING_SNAKE_CASE			,						guidance_scale=6.0			,						num_inference_steps=2			,						output_type='np'			,						return_dict=_SCREAMING_SNAKE_CASE			,						)[0]

			__lowerCAmelCase     :		str		     = image[0, -3:, -3:, -1]
			__lowerCAmelCase     :		Optional[int]		     = image_from_tuple[0, -3:, -3:, -1]

			assert image.shape == (1, 64, 64, 3)
			__lowerCAmelCase     :		str		     = np.array([0.5122, 0.5712, 0.4825, 0.5053, 0.5646, 0.4769, 0.5179, 0.4894, 0.4994]					)

			assert np.abs(image_slice.flatten() - expected_slice					).max() < 1E-2
			assert np.abs(image_from_tuple_slice.flatten() - expected_slice					).max() < 1E-2

		def 				__lowerCamelCase				( self					):
			__lowerCAmelCase     :		List[Any]		     = StableDiffusionPipeline.from_pretrained(
			    'hf-internal-testing/tiny-stable-diffusion-lms-pipe'			,						safety_checker=_SCREAMING_SNAKE_CASE					)
			assert isinstance(_SCREAMING_SNAKE_CASE			,						_SCREAMING_SNAKE_CASE					)
			assert isinstance(pipe.scheduler			,						_SCREAMING_SNAKE_CASE					)
			assert pipe.safety_checker is None

			__lowerCAmelCase     :		Optional[Any]		     = 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(_SCREAMING_SNAKE_CASE					)
				__lowerCAmelCase     :		Dict		     = StableDiffusionPipeline.from_pretrained(_SCREAMING_SNAKE_CASE					)

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







		@unittest.skipIf(torch_device != 'cuda'			,						'This test requires a GPU'					)
		def 				__lowerCamelCase				( self					):
			__lowerCAmelCase     :		Union[str, Any]		     = self.dummy_cond_unet
			__lowerCAmelCase     :		Optional[int]		     = PNDMScheduler(skip_prk_steps=_SCREAMING_SNAKE_CASE					)
			__lowerCAmelCase     :		List[str]		     = self.dummy_vae
			__lowerCAmelCase     :		Tuple		     = self.dummy_text_encoder
			__lowerCAmelCase     :		Dict		     = CLIPTokenizer.from_pretrained('hf-internal-testing/tiny-random-clip'					)

			# put models in fp16
			__lowerCAmelCase     :		Tuple		     = unet.half()
			__lowerCAmelCase     :		Tuple		     = vae.half()
			__lowerCAmelCase     :		Union[str, Any]		     = bert.half()

			# make sure here that pndm scheduler skips prk
			__lowerCAmelCase     :		List[str]		     = StableDiffusionPipeline(
			    unet=_SCREAMING_SNAKE_CASE			,						scheduler=_SCREAMING_SNAKE_CASE			,						vae=_SCREAMING_SNAKE_CASE			,						text_encoder=_SCREAMING_SNAKE_CASE			,						tokenizer=_SCREAMING_SNAKE_CASE			,						safety_checker=_SCREAMING_SNAKE_CASE			,						feature_extractor=self.dummy_extractor			,						)
			__lowerCAmelCase     :		Any		     = sd_pipe.to(_SCREAMING_SNAKE_CASE					)
			sd_pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE					)

			__lowerCAmelCase     :		Optional[int]		     = 'A painting of a squirrel eating a burger'
			__lowerCAmelCase     :		Optional[int]		     = sd_pipe([prompt]			,						num_inference_steps=2			,						output_type='np'					).images

			assert image.shape == (1, 64, 64, 3)




@nightly
@require_torch_gpu
class 					A__			(      unittest.TestCase):

		def 				__lowerCamelCase				( self					):
			# clean up the VRAM after each test
			super().tearDown()
			gc.collect()
			torch.cuda.empty_cache()

		def 				__lowerCamelCase				( self					):
			__lowerCAmelCase     :		Union[str, Any]		     = 'cuda'
			__lowerCAmelCase     :		Optional[int]		     = StableDiffusionPipeline.from_pretrained('runwayml/stable-diffusion-v1-5'					)
			__lowerCAmelCase     :		Union[str, Any]		     = pipe.to(_SCREAMING_SNAKE_CASE					)
			pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE					)

			__lowerCAmelCase     :		Any		     = 'a photo of a cat'
			__lowerCAmelCase     :		List[str]		     = {
			    'editing_prompt': ['sunglasses'],
			    'reverse_editing_direction': [False],
			    'edit_warmup_steps': 10,
			    'edit_guidance_scale': 6,
			    'edit_threshold': 0.95,
			    'edit_momentum_scale': 0.5,
			    'edit_mom_beta': 0.6,
			}

			__lowerCAmelCase     :		int		     = 3
			__lowerCAmelCase     :		Union[str, Any]		     = 7

			# no sega enabled
			__lowerCAmelCase     :		List[str]		     = torch.Generator(_SCREAMING_SNAKE_CASE					)
			generator.manual_seed(_SCREAMING_SNAKE_CASE					)
			__lowerCAmelCase     :		int		     = pipe(
			    [prompt]			,						generator=_SCREAMING_SNAKE_CASE			,						guidance_scale=_SCREAMING_SNAKE_CASE			,						num_inference_steps=50			,						output_type='np'			,						width=5_12			,						height=5_12			,						)

			__lowerCAmelCase     :		Union[str, Any]		     = output.images
			__lowerCAmelCase     :		Optional[int]		     = image[0, -3:, -3:, -1]
			__lowerCAmelCase     :		List[str]		     = [
			    0.3467_3113,
			    0.3849_2733,
			    0.3759_7352,
			    0.3408_6335,
			    0.3565_0748,
			    0.3557_9205,
			    0.338_4763,
			    0.3434_0236,
			    0.357_3271,
			]

			assert image.shape == (1, 5_12, 5_12, 3)

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

			# with sega enabled
			# generator = torch.manual_seed(seed)
			generator.manual_seed(_SCREAMING_SNAKE_CASE					)
			__lowerCAmelCase     :		Optional[Any]		     = pipe(
			    [prompt]			,						generator=_SCREAMING_SNAKE_CASE			,						guidance_scale=_SCREAMING_SNAKE_CASE			,						num_inference_steps=50			,						output_type='np'			,						width=5_12			,						height=5_12			,						**_SCREAMING_SNAKE_CASE			,						)

			__lowerCAmelCase     :		Dict		     = output.images
			__lowerCAmelCase     :		int		     = image[0, -3:, -3:, -1]
			__lowerCAmelCase     :		Optional[Any]		     = [
			    0.4188_7826,
			    0.3772_8766,
			    0.3013_8272,
			    0.4141_6335,
			    0.4166_4985,
			    0.3628_3392,
			    0.3619_1246,
			    0.4336_4465,
			    0.4300_1732,
			]

			assert image.shape == (1, 5_12, 5_12, 3)

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

		def 				__lowerCamelCase				( self					):
			__lowerCAmelCase     :		Dict		     = 'cuda'
			__lowerCAmelCase     :		str		     = StableDiffusionPipeline.from_pretrained('runwayml/stable-diffusion-v1-5'					)
			__lowerCAmelCase     :		Optional[int]		     = pipe.to(_SCREAMING_SNAKE_CASE					)
			pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE					)

			__lowerCAmelCase     :		List[Any]		     = 'an image of a crowded boulevard, realistic, 4k'
			__lowerCAmelCase     :		Optional[Any]		     = {
			    'editing_prompt': 'crowd, crowded, people',
			    'reverse_editing_direction': True,
			    'edit_warmup_steps': 10,
			    'edit_guidance_scale': 8.3,
			    'edit_threshold': 0.9,
			    'edit_momentum_scale': 0.5,
			    'edit_mom_beta': 0.6,
			}

			__lowerCAmelCase     :		int		     = 9
			__lowerCAmelCase     :		Any		     = 7

			# no sega enabled
			__lowerCAmelCase     :		Union[str, Any]		     = torch.Generator(_SCREAMING_SNAKE_CASE					)
			generator.manual_seed(_SCREAMING_SNAKE_CASE					)
			__lowerCAmelCase     :		List[str]		     = pipe(
			    [prompt]			,						generator=_SCREAMING_SNAKE_CASE			,						guidance_scale=_SCREAMING_SNAKE_CASE			,						num_inference_steps=50			,						output_type='np'			,						width=5_12			,						height=5_12			,						)

			__lowerCAmelCase     :		List[Any]		     = output.images
			__lowerCAmelCase     :		Optional[int]		     = image[0, -3:, -3:, -1]
			__lowerCAmelCase     :		Any		     = [
			    0.4349_7998,
			    0.9181_4065,
			    0.754_0739,
			    0.5558_0205,
			    0.846_7265,
			    0.538_9691,
			    0.6257_4506,
			    0.5889_7763,
			    0.5092_6757,
			]

			assert image.shape == (1, 5_12, 5_12, 3)

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

			# with sega enabled
			# generator = torch.manual_seed(seed)
			generator.manual_seed(_SCREAMING_SNAKE_CASE					)
			__lowerCAmelCase     :		Dict		     = pipe(
			    [prompt]			,						generator=_SCREAMING_SNAKE_CASE			,						guidance_scale=_SCREAMING_SNAKE_CASE			,						num_inference_steps=50			,						output_type='np'			,						width=5_12			,						height=5_12			,						**_SCREAMING_SNAKE_CASE			,						)

			__lowerCAmelCase     :		Tuple		     = output.images
			__lowerCAmelCase     :		Optional[Any]		     = image[0, -3:, -3:, -1]
			__lowerCAmelCase     :		List[Any]		     = [
			    0.308_9719,
			    0.3050_0144,
			    0.2901_6042,
			    0.3063_0964,
			    0.32_5687,
			    0.2941_9225,
			    0.290_8091,
			    0.2872_3598,
			    0.2769_6294,
			]

			assert image.shape == (1, 5_12, 5_12, 3)

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

		def 				__lowerCamelCase				( self					):
			__lowerCAmelCase     :		Dict		     = 'cuda'
			__lowerCAmelCase     :		Any		     = StableDiffusionPipeline.from_pretrained('runwayml/stable-diffusion-v1-5'					)
			__lowerCAmelCase     :		Tuple		     = pipe.to(_SCREAMING_SNAKE_CASE					)
			pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE					)

			__lowerCAmelCase     :		int		     = 'a castle next to a river'
			__lowerCAmelCase     :		List[str]		     = {
			    'editing_prompt': ['boat on a river, boat', 'monet, impression, sunrise'],
			    'reverse_editing_direction': False,
			    'edit_warmup_steps': [15, 18],
			    'edit_guidance_scale': 6,
			    'edit_threshold': [0.9, 0.8],
			    'edit_momentum_scale': 0.5,
			    'edit_mom_beta': 0.6,
			}

			__lowerCAmelCase     :		List[str]		     = 48
			__lowerCAmelCase     :		int		     = 7

			# no sega enabled
			__lowerCAmelCase     :		Any		     = torch.Generator(_SCREAMING_SNAKE_CASE					)
			generator.manual_seed(_SCREAMING_SNAKE_CASE					)
			__lowerCAmelCase     :		Optional[Any]		     = pipe(
			    [prompt]			,						generator=_SCREAMING_SNAKE_CASE			,						guidance_scale=_SCREAMING_SNAKE_CASE			,						num_inference_steps=50			,						output_type='np'			,						width=5_12			,						height=5_12			,						)

			__lowerCAmelCase     :		List[str]		     = output.images
			__lowerCAmelCase     :		Optional[Any]		     = image[0, -3:, -3:, -1]
			__lowerCAmelCase     :		Union[str, Any]		     = [
			    0.7516_3555,
			    0.7603_7145,
			    0.6_1785,
			    0.918_9673,
			    0.862_7701,
			    0.8518_9694,
			    0.851_2813,
			    0.8701_2076,
			    0.831_2857,
			]

			assert image.shape == (1, 5_12, 5_12, 3)

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

			# with sega enabled
			# generator = torch.manual_seed(seed)
			generator.manual_seed(_SCREAMING_SNAKE_CASE					)
			__lowerCAmelCase     :		Optional[int]		     = pipe(
			    [prompt]			,						generator=_SCREAMING_SNAKE_CASE			,						guidance_scale=_SCREAMING_SNAKE_CASE			,						num_inference_steps=50			,						output_type='np'			,						width=5_12			,						height=5_12			,						**_SCREAMING_SNAKE_CASE			,						)

			__lowerCAmelCase     :		Tuple		     = output.images
			__lowerCAmelCase     :		Optional[Any]		     = image[0, -3:, -3:, -1]
			__lowerCAmelCase     :		Dict		     = [
			    0.7355_3365,
			    0.753_7271,
			    0.7434_1905,
			    0.6648_0356,
			    0.647_2925,
			    0.6303_9416,
			    0.6481_2905,
			    0.674_9717,
			    0.651_7102,
			]

			assert image.shape == (1, 5_12, 5_12, 3)

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







		def 				__lowerCamelCase				( self					):
			__lowerCAmelCase     :		Dict		     = 'cuda'
			__lowerCAmelCase     :		Union[str, Any]		     = StableDiffusionPipeline.from_pretrained('runwayml/stable-diffusion-v1-5'			,						torch_dtype=torch.floataa					)
			__lowerCAmelCase     :		Tuple		     = pipe.to(_SCREAMING_SNAKE_CASE					)
			pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE					)

			__lowerCAmelCase     :		Optional[int]		     = 'a photo of a cat'
			__lowerCAmelCase     :		Dict		     = {
			    'editing_prompt': ['sunglasses'],
			    'reverse_editing_direction': [False],
			    'edit_warmup_steps': 10,
			    'edit_guidance_scale': 6,
			    'edit_threshold': 0.95,
			    'edit_momentum_scale': 0.5,
			    'edit_mom_beta': 0.6,
			}

			__lowerCAmelCase     :		Tuple		     = 3
			__lowerCAmelCase     :		Optional[int]		     = 7

			# no sega enabled
			__lowerCAmelCase     :		Dict		     = torch.Generator(_SCREAMING_SNAKE_CASE					)
			generator.manual_seed(_SCREAMING_SNAKE_CASE					)
			__lowerCAmelCase     :		Optional[Any]		     = pipe(
			    [prompt]			,						generator=_SCREAMING_SNAKE_CASE			,						guidance_scale=_SCREAMING_SNAKE_CASE			,						num_inference_steps=50			,						output_type='np'			,						width=5_12			,						height=5_12			,						)

			__lowerCAmelCase     :		Optional[Any]		     = output.images
			__lowerCAmelCase     :		Dict		     = image[0, -3:, -3:, -1]
			__lowerCAmelCase     :		Optional[Any]		     = [
			    0.3488_7695,
			    0.387_6953,
			    0.375,
			    0.3442_3828,
			    0.358_1543,
			    0.3571_7773,
			    0.338_3789,
			    0.3457_0312,
			    0.35_9375,
			]

			assert image.shape == (1, 5_12, 5_12, 3)

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

			# with sega enabled
			# generator = torch.manual_seed(seed)
			generator.manual_seed(_SCREAMING_SNAKE_CASE					)
			__lowerCAmelCase     :		List[str]		     = pipe(
			    [prompt]			,						generator=_SCREAMING_SNAKE_CASE			,						guidance_scale=_SCREAMING_SNAKE_CASE			,						num_inference_steps=50			,						output_type='np'			,						width=5_12			,						height=5_12			,						**_SCREAMING_SNAKE_CASE			,						)

			__lowerCAmelCase     :		List[str]		     = output.images
			__lowerCAmelCase     :		Union[str, Any]		     = image[0, -3:, -3:, -1]
			__lowerCAmelCase     :		Optional[Any]		     = [
			    0.4228_5156,
			    0.3691_4062,
			    0.2907_7148,
			    0.4204_1016,
			    0.4191_8945,
			    0.3549_8047,
			    0.361_8164,
			    0.442_3828,
			    0.4311_5234,
			]

			assert image.shape == (1, 5_12, 5_12, 3)

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

"""simple docstring"""







from ..utils import (
    OptionalDependencyNotAvailable,
    is_flax_available,
    is_invisible_watermark_available,
    is_k_diffusion_available,
    is_librosa_available,
    is_note_seq_available,
    is_onnx_available,
    is_torch_available,
    is_transformers_available,
)


try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from ..utils.dummy_pt_objects import *  # noqa F403
else:
							from .consistency_models import ConsistencyModelPipeline
							from .dance_diffusion import DanceDiffusionPipeline
							from .ddim import DDIMPipeline
							from .ddpm import DDPMPipeline
							from .dit import DiTPipeline
							from .latent_diffusion import LDMSuperResolutionPipeline
							from .latent_diffusion_uncond import LDMPipeline
							from .pipeline_utils import AudioPipelineOutput, DiffusionPipeline, ImagePipelineOutput
							from .pndm import PNDMPipeline
							from .repaint import RePaintPipeline
							from .score_sde_ve import ScoreSdeVePipeline
							from .stochastic_karras_ve import KarrasVePipeline

try:
							if not (is_torch_available() and is_librosa_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from ..utils.dummy_torch_and_librosa_objects import *  # noqa F403
else:
							from .audio_diffusion import AudioDiffusionPipeline, Mel

try:
							if not (is_torch_available() and is_transformers_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from ..utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
							from .alt_diffusion import AltDiffusionImgaImgPipeline, AltDiffusionPipeline
							from .audioldm import AudioLDMPipeline
							from .controlnet import (
							    StableDiffusionControlNetImgaImgPipeline,
							    StableDiffusionControlNetInpaintPipeline,
							    StableDiffusionControlNetPipeline,
							)
							from .deepfloyd_if import (
							    IFImgaImgPipeline,
							    IFImgaImgSuperResolutionPipeline,
							    IFInpaintingPipeline,
							    IFInpaintingSuperResolutionPipeline,
							    IFPipeline,
							    IFSuperResolutionPipeline,
							)
							from .kandinsky import (
							    KandinskyImgaImgPipeline,
							    KandinskyInpaintPipeline,
							    KandinskyPipeline,
							    KandinskyPriorPipeline,
							)
							from .kandinskya_a import (
							    KandinskyVaaControlnetImgaImgPipeline,
							    KandinskyVaaControlnetPipeline,
							    KandinskyVaaImgaImgPipeline,
							    KandinskyVaaInpaintPipeline,
							    KandinskyVaaPipeline,
							    KandinskyVaaPriorEmbaEmbPipeline,
							    KandinskyVaaPriorPipeline,
							)
							from .latent_diffusion import LDMTextToImagePipeline
							from .paint_by_example import PaintByExamplePipeline
							from .semantic_stable_diffusion import SemanticStableDiffusionPipeline
							from .shap_e import ShapEImgaImgPipeline, ShapEPipeline
							from .stable_diffusion import (
							    CycleDiffusionPipeline,
							    StableDiffusionAttendAndExcitePipeline,
							    StableDiffusionDepthaImgPipeline,
							    StableDiffusionDiffEditPipeline,
							    StableDiffusionImageVariationPipeline,
							    StableDiffusionImgaImgPipeline,
							    StableDiffusionInpaintPipeline,
							    StableDiffusionInpaintPipelineLegacy,
							    StableDiffusionInstructPixaPixPipeline,
							    StableDiffusionLatentUpscalePipeline,
							    StableDiffusionLDMaDPipeline,
							    StableDiffusionModelEditingPipeline,
							    StableDiffusionPanoramaPipeline,
							    StableDiffusionParadigmsPipeline,
							    StableDiffusionPipeline,
							    StableDiffusionPixaPixZeroPipeline,
							    StableDiffusionSAGPipeline,
							    StableDiffusionUpscalePipeline,
							    StableUnCLIPImgaImgPipeline,
							    StableUnCLIPPipeline,
							)
							from .stable_diffusion_safe import StableDiffusionPipelineSafe
							from .text_to_video_synthesis import TextToVideoSDPipeline, TextToVideoZeroPipeline, VideoToVideoSDPipeline
							from .unclip import UnCLIPImageVariationPipeline, UnCLIPPipeline
							from .unidiffuser import ImageTextPipelineOutput, UniDiffuserModel, UniDiffuserPipeline, UniDiffuserTextDecoder
							from .versatile_diffusion import (
							    VersatileDiffusionDualGuidedPipeline,
							    VersatileDiffusionImageVariationPipeline,
							    VersatileDiffusionPipeline,
							    VersatileDiffusionTextToImagePipeline,
							)
							from .vq_diffusion import VQDiffusionPipeline


try:
							if not (is_torch_available() and is_transformers_available() and is_invisible_watermark_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from ..utils.dummy_torch_and_transformers_and_invisible_watermark_objects import *  # noqa F403
else:
							from .stable_diffusion_xl import StableDiffusionXLImgaImgPipeline, StableDiffusionXLPipeline

try:
							if not is_onnx_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from ..utils.dummy_onnx_objects import *  # noqa F403
else:
							from .onnx_utils import OnnxRuntimeModel

try:
							if not (is_torch_available() and is_transformers_available() and is_onnx_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from ..utils.dummy_torch_and_transformers_and_onnx_objects import *  # noqa F403
else:
							from .stable_diffusion import (
							    OnnxStableDiffusionImgaImgPipeline,
							    OnnxStableDiffusionInpaintPipeline,
							    OnnxStableDiffusionInpaintPipelineLegacy,
							    OnnxStableDiffusionPipeline,
							    OnnxStableDiffusionUpscalePipeline,
							    StableDiffusionOnnxPipeline,
							)

try:
							if not (is_torch_available() and is_transformers_available() and is_k_diffusion_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from ..utils.dummy_torch_and_transformers_and_k_diffusion_objects import *  # noqa F403
else:
							from .stable_diffusion import StableDiffusionKDiffusionPipeline

try:
							if not is_flax_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from ..utils.dummy_flax_objects import *  # noqa F403
else:
							from .pipeline_flax_utils import FlaxDiffusionPipeline


try:
							if not (is_flax_available() and is_transformers_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from ..utils.dummy_flax_and_transformers_objects import *  # noqa F403
else:
							from .controlnet import FlaxStableDiffusionControlNetPipeline
							from .stable_diffusion import (
							    FlaxStableDiffusionImgaImgPipeline,
							    FlaxStableDiffusionInpaintPipeline,
							    FlaxStableDiffusionPipeline,
							)
try:
							if not (is_transformers_available() and is_torch_available() and is_note_seq_available()):
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							from ..utils.dummy_transformers_and_torch_and_note_seq_objects import *  # noqa F403
else:
							from .spectrogram_diffusion import MidiProcessor, SpectrogramDiffusionPipeline