import random
import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
							import torch

if is_vision_available():
							import PIL

							from transformers import FlavaImageProcessor
							from transformers.image_utils import PILImageResampling
							from transformers.models.flava.image_processing_flava import (
							    FLAVA_CODEBOOK_MEAN,
							    FLAVA_CODEBOOK_STD,
							    FLAVA_IMAGE_MEAN,
							    FLAVA_IMAGE_STD,
							)
else:
							_lowerCamelCase    :      Dict	 =						None


class   lowercase			(   unittest.TestCase   ):




							def __init__(  self      :    Optional[Any]		,							_UpperCamelCase      :    List[str]		,							_UpperCamelCase      :    List[Any]=7		,							_UpperCamelCase      :    Optional[int]=3		,							_UpperCamelCase      :    Dict=30		,							_UpperCamelCase      :    Union[str, Any]=400		,							_UpperCamelCase      :    List[Any]=True		,							_UpperCamelCase      :    Optional[Any]=None		,							_UpperCamelCase      :    Union[str, Any]=True		,							_UpperCamelCase      :    str=None		,							_UpperCamelCase      :    Optional[Any]=None		,							_UpperCamelCase      :    Union[str, Any]=True		,							_UpperCamelCase      :    Optional[Any]=1 / 255		,							_UpperCamelCase      :    Dict=True		,							_UpperCamelCase      :    Any=FLAVA_IMAGE_MEAN		,							_UpperCamelCase      :    Optional[Any]=FLAVA_IMAGE_STD		,							_UpperCamelCase      :    str=14		,							_UpperCamelCase      :    Dict=75		,							_UpperCamelCase      :    Union[str, Any]=None		,							_UpperCamelCase      :    str=16		,							_UpperCamelCase      :    Dict=0.3		,							_UpperCamelCase      :    str=None		,							_UpperCamelCase      :    Tuple=True		,							_UpperCamelCase      :    Union[str, Any]=None		,							_UpperCamelCase      :    Any=None		,							_UpperCamelCase      :    Union[str, Any]=True		,							_UpperCamelCase      :    Union[str, Any]=None		,							_UpperCamelCase      :    Optional[Any]=True		,							_UpperCamelCase      :    Optional[Any]=True		,							_UpperCamelCase      :    str=FLAVA_CODEBOOK_MEAN		,							_UpperCamelCase      :    Union[str, Any]=FLAVA_CODEBOOK_STD		,							)    -> List[Any]:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE				=				size if size is not None else {"height": 224, "width": 224}
												SCREAMING_SNAKE_CASE				=				crop_size if crop_size is not None else {"height": 224, "width": 224}
												SCREAMING_SNAKE_CASE				=				codebook_size if codebook_size is not None else {"height": 112, "width": 112}
												SCREAMING_SNAKE_CASE				=				codebook_crop_size if codebook_crop_size is not None else {"height": 112, "width": 112}

												SCREAMING_SNAKE_CASE				=				parent
												SCREAMING_SNAKE_CASE				=				batch_size
												SCREAMING_SNAKE_CASE				=				num_channels
												SCREAMING_SNAKE_CASE				=				do_resize
												SCREAMING_SNAKE_CASE				=				do_rescale
												SCREAMING_SNAKE_CASE				=				rescale_factor
												SCREAMING_SNAKE_CASE				=				min_resolution
												SCREAMING_SNAKE_CASE				=				max_resolution
												SCREAMING_SNAKE_CASE				=				size
												SCREAMING_SNAKE_CASE				=				resample if resample is not None else PILImageResampling.BICUBIC
												SCREAMING_SNAKE_CASE				=				do_normalize
												SCREAMING_SNAKE_CASE				=				image_mean
												SCREAMING_SNAKE_CASE				=				image_std
												SCREAMING_SNAKE_CASE				=				do_center_crop
												SCREAMING_SNAKE_CASE				=				crop_size

												SCREAMING_SNAKE_CASE				=				input_size_patches
												SCREAMING_SNAKE_CASE				=				total_mask_patches
												SCREAMING_SNAKE_CASE				=				mask_group_max_patches
												SCREAMING_SNAKE_CASE				=				mask_group_min_patches
												SCREAMING_SNAKE_CASE				=				mask_group_min_aspect_ratio
												SCREAMING_SNAKE_CASE				=				mask_group_max_aspect_ratio

												SCREAMING_SNAKE_CASE				=				codebook_do_resize
												SCREAMING_SNAKE_CASE				=				codebook_size
												SCREAMING_SNAKE_CASE				=				codebook_resample if codebook_resample is not None else PILImageResampling.LANCZOS
												SCREAMING_SNAKE_CASE				=				codebook_do_center_crop
												SCREAMING_SNAKE_CASE				=				codebook_crop_size
												SCREAMING_SNAKE_CASE				=				codebook_do_map_pixels
												SCREAMING_SNAKE_CASE				=				codebook_do_normalize
												SCREAMING_SNAKE_CASE				=				codebook_image_mean
												SCREAMING_SNAKE_CASE				=				codebook_image_std




							def 		__snake_case(  self      :    Optional[Any]					)    -> Union[str, Any]:



												'''simple docstring'''

												return {
												    "image_mean": self.image_mean,
												    "image_std": self.image_std,
												    "do_normalize": self.do_normalize,
												    "do_resize": self.do_resize,
												    "size": self.size,
												    "resample": self.resample,
												    "do_rescale": self.do_rescale,
												    "rescale_factor": self.rescale_factor,
												    "do_center_crop": self.do_center_crop,
												    "crop_size": self.crop_size,
												    "input_size_patches": self.input_size_patches,
												    "total_mask_patches": self.total_mask_patches,
												    "mask_group_max_patches": self.mask_group_max_patches,
												    "mask_group_min_patches": self.mask_group_min_patches,
												    "mask_group_min_aspect_ratio": self.mask_group_min_aspect_ratio,
												    "mask_group_max_aspect_ratio": self.mask_group_min_aspect_ratio,
												    "codebook_do_resize": self.codebook_do_resize,
												    "codebook_size": self.codebook_size,
												    "codebook_resample": self.codebook_resample,
												    "codebook_do_center_crop": self.codebook_do_center_crop,
												    "codebook_crop_size": self.codebook_crop_size,
												    "codebook_do_map_pixels": self.codebook_do_map_pixels,
												    "codebook_do_normalize": self.codebook_do_normalize,
												    "codebook_image_mean": self.codebook_image_mean,
												    "codebook_image_std": self.codebook_image_std,
												}




							def 		__snake_case(  self      :    Dict					)    -> Optional[Any]:



												'''simple docstring'''

												return (self.size["height"], self.size["width"])




							def 		__snake_case(  self      :    int					)    -> Dict:



												'''simple docstring'''

												return (
												    (self.input_size_patches, self.input_size_patches)
												    if not isinstance(self.input_size_patches		,							_UpperCamelCase					)
												    else self.input_size_patches
												)





							def 		__snake_case(  self      :    Any					)    -> List[str]:



												'''simple docstring'''

												return (self.codebook_size["height"], self.codebook_size["width"])



@require_torch
@require_vision
class   lowercase			(   a ,				unittest.TestCase   ):
							lowercase__  :				str									=							FlavaImageProcessor if is_vision_available() else None
							lowercase__  :				Union[str, Any]									=							None




							def 		__snake_case(  self      :    Any					)    -> int:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE				=				FlavaImageProcessingTester(self					)




							@property
							def 		__snake_case(  self      :    List[Any]					)    -> Union[str, Any]:



												'''simple docstring'''

												return self.image_processor_tester.prepare_image_processor_dict()




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



												'''simple docstring'''

												SCREAMING_SNAKE_CASE				=				self.image_processing_class(**self.image_processor_dict					)
												self.assertTrue(hasattr(_UpperCamelCase		,							"image_mean"					)					)
												self.assertTrue(hasattr(_UpperCamelCase		,							"image_std"					)					)
												self.assertTrue(hasattr(_UpperCamelCase		,							"do_normalize"					)					)
												self.assertTrue(hasattr(_UpperCamelCase		,							"do_resize"					)					)
												self.assertTrue(hasattr(_UpperCamelCase		,							"resample"					)					)
												self.assertTrue(hasattr(_UpperCamelCase		,							"crop_size"					)					)
												self.assertTrue(hasattr(_UpperCamelCase		,							"do_center_crop"					)					)
												self.assertTrue(hasattr(_UpperCamelCase		,							"do_rescale"					)					)
												self.assertTrue(hasattr(_UpperCamelCase		,							"rescale_factor"					)					)
												self.assertTrue(hasattr(_UpperCamelCase		,							"masking_generator"					)					)
												self.assertTrue(hasattr(_UpperCamelCase		,							"codebook_do_resize"					)					)
												self.assertTrue(hasattr(_UpperCamelCase		,							"codebook_size"					)					)
												self.assertTrue(hasattr(_UpperCamelCase		,							"codebook_resample"					)					)
												self.assertTrue(hasattr(_UpperCamelCase		,							"codebook_do_center_crop"					)					)
												self.assertTrue(hasattr(_UpperCamelCase		,							"codebook_crop_size"					)					)
												self.assertTrue(hasattr(_UpperCamelCase		,							"codebook_do_map_pixels"					)					)
												self.assertTrue(hasattr(_UpperCamelCase		,							"codebook_do_normalize"					)					)
												self.assertTrue(hasattr(_UpperCamelCase		,							"codebook_image_mean"					)					)
												self.assertTrue(hasattr(_UpperCamelCase		,							"codebook_image_std"					)					)




							def 		__snake_case(  self      :    Optional[Any]					)    -> Optional[int]:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE				=				self.image_processing_class.from_dict(self.image_processor_dict					)
												self.assertEqual(image_processor.size		,							{"height": 224, "width": 224}					)
												self.assertEqual(image_processor.crop_size		,							{"height": 224, "width": 224}					)
												self.assertEqual(image_processor.codebook_size		,							{"height": 112, "width": 112}					)
												self.assertEqual(image_processor.codebook_crop_size		,							{"height": 112, "width": 112}					)

												SCREAMING_SNAKE_CASE				=				self.image_processing_class.from_dict(
												    self.image_processor_dict		,							size=42		,							crop_size=84		,							codebook_size=33		,							codebook_crop_size=66					)
												self.assertEqual(image_processor.size		,							{"height": 42, "width": 42}					)
												self.assertEqual(image_processor.crop_size		,							{"height": 84, "width": 84}					)
												self.assertEqual(image_processor.codebook_size		,							{"height": 33, "width": 33}					)
												self.assertEqual(image_processor.codebook_crop_size		,							{"height": 66, "width": 66}					)




							def 		__snake_case(  self      :    List[str]					)    -> Optional[Any]:



												'''simple docstring'''

												pass




							def 		__snake_case(  self      :    Optional[Any]					)    -> Dict:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE				=				self.image_processing_class(**self.image_processor_dict					)
												# create random PIL images
												SCREAMING_SNAKE_CASE				=				prepare_image_inputs(self.image_processor_tester		,							equal_resolution=_UpperCamelCase					)
												for image in image_inputs:
																	self.assertIsInstance(_UpperCamelCase		,							PIL.Image.Image					)

												# Test not batched input
												SCREAMING_SNAKE_CASE				=				image_processing(image_inputs[0]		,							return_tensors="pt"					)

												# Test no bool masked pos
												self.assertFalse("bool_masked_pos" in encoded_images					)

												SCREAMING_SNAKE_CASE	,      SCREAMING_SNAKE_CASE				=				self.image_processor_tester.get_expected_image_size()

												self.assertEqual(
												    encoded_images.pixel_values.shape		,							(1, self.image_processor_tester.num_channels, expected_height, expected_width)		,							)

												# Test batched
												SCREAMING_SNAKE_CASE				=				image_processing(_UpperCamelCase		,							return_tensors="pt"					)
												SCREAMING_SNAKE_CASE	,      SCREAMING_SNAKE_CASE				=				self.image_processor_tester.get_expected_image_size()

												# Test no bool masked pos
												self.assertFalse("bool_masked_pos" in encoded_images					)

												self.assertEqual(
												    encoded_images.pixel_values.shape		,							(
												        self.image_processor_tester.batch_size,
												        self.image_processor_tester.num_channels,
												        expected_height,
												        expected_width,
												    )		,							)




							def 		__snake_case(  self      :    Union[str, Any]		,							_UpperCamelCase      :    Optional[int]		,							_UpperCamelCase      :    Optional[int]					)    -> Tuple:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE				=				self.image_processing_class(**self.image_processor_dict					)
												# create random tensors
												SCREAMING_SNAKE_CASE				=				prepare_image_inputs(self.image_processor_tester		,							equal_resolution=_UpperCamelCase		,							**_UpperCamelCase					)
												for image in image_inputs:
																	self.assertIsInstance(_UpperCamelCase		,							_UpperCamelCase					)

												# Test not batched input
												SCREAMING_SNAKE_CASE				=				image_processing(image_inputs[0]		,							return_tensors="pt"					)

												SCREAMING_SNAKE_CASE	,      SCREAMING_SNAKE_CASE				=				self.image_processor_tester.get_expected_image_size()
												self.assertEqual(
												    encoded_images.pixel_values.shape		,							(1, self.image_processor_tester.num_channels, expected_height, expected_width)		,							)

												SCREAMING_SNAKE_CASE				=				image_processing(_UpperCamelCase		,							return_image_mask=_UpperCamelCase		,							return_tensors="pt"					)

												SCREAMING_SNAKE_CASE	,      SCREAMING_SNAKE_CASE				=				self.image_processor_tester.get_expected_image_size()
												self.assertEqual(
												    encoded_images.pixel_values.shape		,							(
												        self.image_processor_tester.batch_size,
												        self.image_processor_tester.num_channels,
												        expected_height,
												        expected_width,
												    )		,							)

												SCREAMING_SNAKE_CASE	,      SCREAMING_SNAKE_CASE				=				self.image_processor_tester.get_expected_mask_size()
												self.assertEqual(
												    encoded_images.bool_masked_pos.shape		,							(
												        self.image_processor_tester.batch_size,
												        expected_height,
												        expected_width,
												    )		,							)

												# Test batched
												SCREAMING_SNAKE_CASE				=				image_processing(_UpperCamelCase		,							return_tensors="pt"					).pixel_values

												SCREAMING_SNAKE_CASE	,      SCREAMING_SNAKE_CASE				=				self.image_processor_tester.get_expected_image_size()
												self.assertEqual(
												    encoded_images.shape		,							(
												        self.image_processor_tester.batch_size,
												        self.image_processor_tester.num_channels,
												        expected_height,
												        expected_width,
												    )		,							)

												# Test masking
												SCREAMING_SNAKE_CASE				=				image_processing(_UpperCamelCase		,							return_image_mask=_UpperCamelCase		,							return_tensors="pt"					)

												SCREAMING_SNAKE_CASE	,      SCREAMING_SNAKE_CASE				=				self.image_processor_tester.get_expected_image_size()
												self.assertEqual(
												    encoded_images.pixel_values.shape		,							(
												        self.image_processor_tester.batch_size,
												        self.image_processor_tester.num_channels,
												        expected_height,
												        expected_width,
												    )		,							)

												SCREAMING_SNAKE_CASE	,      SCREAMING_SNAKE_CASE				=				self.image_processor_tester.get_expected_mask_size()
												self.assertEqual(
												    encoded_images.bool_masked_pos.shape		,							(
												        self.image_processor_tester.batch_size,
												        expected_height,
												        expected_width,
												    )		,							)




							def 		__snake_case(  self      :    List[Any]					)    -> Union[str, Any]:



												'''simple docstring'''

												self._test_call_framework(np.ndarray		,							prepare_kwargs={"numpify": True}					)




							def 		__snake_case(  self      :    Dict					)    -> List[str]:



												'''simple docstring'''

												self._test_call_framework(torch.Tensor		,							prepare_kwargs={"torchify": True}					)




							def 		__snake_case(  self      :    Dict					)    -> Any:



												'''simple docstring'''

												random.seed(1_234					)
												SCREAMING_SNAKE_CASE				=				self.image_processing_class(**self.image_processor_dict					)
												SCREAMING_SNAKE_CASE				=				prepare_image_inputs(self.image_processor_tester		,							equal_resolution=_UpperCamelCase		,							torchify=_UpperCamelCase					)

												# Test not batched input
												SCREAMING_SNAKE_CASE				=				image_processing(image_inputs[0]		,							return_image_mask=_UpperCamelCase		,							return_tensors="pt"					)
												self.assertEqual(encoded_images.bool_masked_pos.sum().item()		,							75					)





							def 		__snake_case(  self      :    Any					)    -> str:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE				=				self.image_processing_class(**self.image_processor_dict					)
												# create random PIL images
												SCREAMING_SNAKE_CASE				=				prepare_image_inputs(self.image_processor_tester		,							equal_resolution=_UpperCamelCase					)
												for image in image_inputs:
																	self.assertIsInstance(_UpperCamelCase		,							PIL.Image.Image					)

												# Test not batched input
												SCREAMING_SNAKE_CASE				=				image_processing(image_inputs[0]		,							return_codebook_pixels=_UpperCamelCase		,							return_tensors="pt"					)
												SCREAMING_SNAKE_CASE	,      SCREAMING_SNAKE_CASE				=				self.image_processor_tester.get_expected_codebook_image_size()
												self.assertEqual(
												    encoded_images.codebook_pixel_values.shape		,							(1, self.image_processor_tester.num_channels, expected_height, expected_width)		,							)

												# Test batched
												SCREAMING_SNAKE_CASE				=				image_processing(_UpperCamelCase		,							return_codebook_pixels=_UpperCamelCase		,							return_tensors="pt"					)
												SCREAMING_SNAKE_CASE	,      SCREAMING_SNAKE_CASE				=				self.image_processor_tester.get_expected_codebook_image_size()
												self.assertEqual(
												    encoded_images.codebook_pixel_values.shape		,							(
												        self.image_processor_tester.batch_size,
												        self.image_processor_tester.num_channels,
												        expected_height,
												        expected_width,
												    )		,							)





import gc
import unittest

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

from diffusers import (
    AutoencoderKL,
    DDIMParallelScheduler,
    DDPMParallelScheduler,
    StableDiffusionParadigmsPipeline,
    UNetaDConditionModel,
)
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import (
    enable_full_determinism,
    require_torch_gpu,
)

from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS
from ..test_pipelines_common import PipelineLatentTesterMixin, PipelineTesterMixin


enable_full_determinism()


class   lowercase			(   a ,				a ,				unittest.TestCase   ):
							lowercase__  :				Optional[Any]									=							StableDiffusionParadigmsPipeline
							lowercase__  :				Optional[Any]									=							TEXT_TO_IMAGE_PARAMS
							lowercase__  :				Union[str, Any]									=							TEXT_TO_IMAGE_BATCH_PARAMS
							lowercase__  :				int									=							TEXT_TO_IMAGE_IMAGE_PARAMS
							lowercase__  :				List[Any]									=							TEXT_TO_IMAGE_IMAGE_PARAMS




							def 		__snake_case(  self      :    Tuple					)    -> List[Any]:



												'''simple docstring'''

												torch.manual_seed(0					)
												SCREAMING_SNAKE_CASE				=				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		,							attention_head_dim=(2, 4)		,							use_linear_projection=_UpperCamelCase		,							)
												SCREAMING_SNAKE_CASE				=				DDIMParallelScheduler(
												    beta_start=0.0_0_0_8_5		,							beta_end=0.0_1_2		,							beta_schedule="scaled_linear"		,							clip_sample=_UpperCamelCase		,							set_alpha_to_one=_UpperCamelCase		,							)
												torch.manual_seed(0					)
												SCREAMING_SNAKE_CASE				=				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		,							sample_size=128		,							)
												torch.manual_seed(0					)
												SCREAMING_SNAKE_CASE				=				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=1_000		,							hidden_act="gelu"		,							projection_dim=512		,							)
												SCREAMING_SNAKE_CASE				=				CLIPTextModel(_UpperCamelCase					)
												SCREAMING_SNAKE_CASE				=				CLIPTokenizer.from_pretrained("hf-internal-testing/tiny-random-clip"					)

												SCREAMING_SNAKE_CASE				=				{
												    "unet": unet,
												    "scheduler": scheduler,
												    "vae": vae,
												    "text_encoder": text_encoder,
												    "tokenizer": tokenizer,
												    "safety_checker": None,
												    "feature_extractor": None,
												}
												return components




							def 		__snake_case(  self      :    Any		,							_UpperCamelCase      :    List[str]		,							_UpperCamelCase      :    Any=0					)    -> Optional[int]:



												'''simple docstring'''

												if str(_UpperCamelCase					).startswith("mps"					):
																	SCREAMING_SNAKE_CASE				=				torch.manual_seed(_UpperCamelCase					)
												else:
																	SCREAMING_SNAKE_CASE				=				torch.Generator(device=_UpperCamelCase					).manual_seed(_UpperCamelCase					)
												SCREAMING_SNAKE_CASE				=				{
												    "prompt": "a photograph of an astronaut riding a horse",
												    "generator": generator,
												    "num_inference_steps": 10,
												    "guidance_scale": 6.0,
												    "output_type": "numpy",
												    "parallel": 3,
												    "debug": True,
												}
												return inputs




							def 		__snake_case(  self      :    Optional[Any]					)    -> Optional[int]:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE				=				"cpu"  # ensure determinism for the device-dependent torch.Generator
												SCREAMING_SNAKE_CASE				=				self.get_dummy_components()
												SCREAMING_SNAKE_CASE				=				StableDiffusionParadigmsPipeline(**_UpperCamelCase					)
												SCREAMING_SNAKE_CASE				=				sd_pipe.to(_UpperCamelCase					)
												sd_pipe.set_progress_bar_config(disable=_UpperCamelCase					)

												SCREAMING_SNAKE_CASE				=				self.get_dummy_inputs(_UpperCamelCase					)
												SCREAMING_SNAKE_CASE				=				sd_pipe(**_UpperCamelCase					).images
												SCREAMING_SNAKE_CASE				=				image[0, -3:, -3:, -1]
												assert image.shape == (1, 64, 64, 3)

												SCREAMING_SNAKE_CASE				=				np.array([0.4_7_7_3, 0.5_4_1_7, 0.4_7_2_3, 0.4_9_2_5, 0.5_6_3_1, 0.4_7_5_2, 0.5_2_4_0, 0.4_9_3_5, 0.5_0_2_3]					)

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




							def 		__snake_case(  self      :    Optional[Any]					)    -> List[Any]:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE				=				"cpu"  # ensure determinism for the device-dependent torch.Generator
												SCREAMING_SNAKE_CASE				=				self.get_dummy_components()
												torch.manual_seed(0					)
												SCREAMING_SNAKE_CASE				=				DDPMParallelScheduler()
												torch.manual_seed(0					)
												SCREAMING_SNAKE_CASE				=				StableDiffusionParadigmsPipeline(**_UpperCamelCase					)
												SCREAMING_SNAKE_CASE				=				sd_pipe.to(_UpperCamelCase					)
												sd_pipe.set_progress_bar_config(disable=_UpperCamelCase					)

												SCREAMING_SNAKE_CASE				=				self.get_dummy_inputs(_UpperCamelCase					)
												SCREAMING_SNAKE_CASE				=				sd_pipe(**_UpperCamelCase					).images
												SCREAMING_SNAKE_CASE				=				image[0, -3:, -3:, -1]
												assert image.shape == (1, 64, 64, 3)

												SCREAMING_SNAKE_CASE				=				np.array([0.3_5_7_3, 0.4_4_2_0, 0.4_9_6_0, 0.4_7_9_9, 0.3_7_9_6, 0.3_8_7_9, 0.4_8_1_9, 0.4_3_6_5, 0.4_4_6_8]					)

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




							def 		__snake_case(  self      :    Tuple					)    -> int:



												'''simple docstring'''

												super().test_inference_batch_consistent(batch_sizes=[1, 2]					)




							def 		__snake_case(  self      :    List[Any]					)    -> Union[str, Any]:



												'''simple docstring'''

												super().test_inference_batch_single_identical(batch_size=2		,							expected_max_diff=3e-3					)





							def 		__snake_case(  self      :    List[Any]					)    -> str:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE				=				"cpu"  # ensure determinism for the device-dependent torch.Generator
												SCREAMING_SNAKE_CASE				=				self.get_dummy_components()
												SCREAMING_SNAKE_CASE				=				StableDiffusionParadigmsPipeline(**_UpperCamelCase					)
												SCREAMING_SNAKE_CASE				=				sd_pipe.to(_UpperCamelCase					)
												sd_pipe.set_progress_bar_config(disable=_UpperCamelCase					)

												SCREAMING_SNAKE_CASE				=				self.get_dummy_inputs(_UpperCamelCase					)
												SCREAMING_SNAKE_CASE				=				"french fries"
												SCREAMING_SNAKE_CASE				=				sd_pipe(**_UpperCamelCase		,							negative_prompt=_UpperCamelCase					)
												SCREAMING_SNAKE_CASE				=				output.images
												SCREAMING_SNAKE_CASE				=				image[0, -3:, -3:, -1]

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

												SCREAMING_SNAKE_CASE				=				np.array([0.4_7_7_1, 0.5_4_2_0, 0.4_6_8_3, 0.4_9_1_8, 0.5_6_3_6, 0.4_7_2_5, 0.5_2_3_0, 0.4_9_2_3, 0.5_0_1_5]					)

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



@slow
@require_torch_gpu
class   lowercase			(   unittest.TestCase   ):




							def 		__snake_case(  self      :    List[str]					)    -> List[Any]:



												'''simple docstring'''

												super().tearDown()
												gc.collect()
												torch.cuda.empty_cache()




							def 		__snake_case(  self      :    Optional[Any]		,							_UpperCamelCase      :    int=0					)    -> Tuple:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE				=				torch.Generator(device=_UpperCamelCase					).manual_seed(_UpperCamelCase					)
												SCREAMING_SNAKE_CASE				=				{
												    "prompt": "a photograph of an astronaut riding a horse",
												    "generator": generator,
												    "num_inference_steps": 10,
												    "guidance_scale": 7.5,
												    "output_type": "numpy",
												    "parallel": 3,
												    "debug": True,
												}
												return inputs





							def 		__snake_case(  self      :    Dict					)    -> str:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE				=				"stabilityai/stable-diffusion-2-base"
												SCREAMING_SNAKE_CASE				=				DDIMParallelScheduler.from_pretrained(_UpperCamelCase		,							subfolder="scheduler"					)
												SCREAMING_SNAKE_CASE				=				StableDiffusionParadigmsPipeline.from_pretrained(_UpperCamelCase		,							scheduler=_UpperCamelCase		,							safety_checker=_UpperCamelCase					)
												pipe.to(_UpperCamelCase					)
												pipe.set_progress_bar_config(disable=_UpperCamelCase					)
												pipe.enable_attention_slicing()

												SCREAMING_SNAKE_CASE				=				self.get_inputs()
												SCREAMING_SNAKE_CASE				=				pipe(**_UpperCamelCase					).images
												SCREAMING_SNAKE_CASE				=				image[0, -3:, -3:, -1].flatten()

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

												SCREAMING_SNAKE_CASE				=				np.array([0.9_6_2_2, 0.9_6_0_2, 0.9_7_4_8, 0.9_5_9_1, 0.9_6_3_0, 0.9_6_9_1, 0.9_6_6_1, 0.9_6_3_1, 0.9_7_4_1]					)

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




