






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        _SCREAMING_SNAKE_CASE			(     unittest.TestCase ):





	def 		_A					(						self							:   Dict      ):
		super().tearDown()
		gc.collect()
		torch.cuda.empty_cache()





	@property
	def 		_A					(						self							:   Tuple      ):
		UpperCamelCase	:List[str]		=      1
		UpperCamelCase	:Optional[Any]		=      3
		UpperCamelCase	:List[Any]		=      (32, 32)

		UpperCamelCase	:Tuple		=      floats_tensor((batch_size, num_channels) + sizes					,    rng=random.Random(0      )      ).to(__lowerCamelCase      )
		return image





	@property
	def 		_A					(						self							:   Any      ):
		torch.manual_seed(0      )
		UpperCamelCase	: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 		_A					(						self							:   Dict      ):
		torch.manual_seed(0      )
		UpperCamelCase	:List[Any]		=      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 		_A					(						self							:   Union[str, Any]      ):
		torch.manual_seed(0      )
		UpperCamelCase	:Union[str, Any]		=      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					,    )
		return CLIPTextModel(__lowerCamelCase      )





	@property
	def 		_A					(						self							:   Dict      ):
		def extract(*__lowerCamelCase							:   Dict					,    **__lowerCamelCase							:   Dict      ):

			class        _SCREAMING_SNAKE_CASE			:





				def __init__(						self							:   Optional[int]      ):
					UpperCamelCase	:List[Any]		=      torch.ones([0]      )





				def 		_A					(						self							:   Dict					,    __lowerCamelCase							:   Any      ):
					self.pixel_values.to(__lowerCamelCase      )
					return self
			return Out()

		return extract





	def 		_A					(						self							:   Optional[int]      ):
		UpperCamelCase	:int		=      """cpu"""  # ensure determinism for the device-dependent torch.Generator
		UpperCamelCase	:Tuple		=      self.dummy_cond_unet
		UpperCamelCase	:str		=      DDIMScheduler(
		    beta_start=0.00085					,    beta_end=0.012					,    beta_schedule="""scaled_linear"""					,    clip_sample=__lowerCamelCase					,    set_alpha_to_one=__lowerCamelCase					,    )

		UpperCamelCase	:Dict		=      self.dummy_vae
		UpperCamelCase	:Dict		=      self.dummy_text_encoder
		UpperCamelCase	:Tuple		=      CLIPTokenizer.from_pretrained("""hf-internal-testing/tiny-random-clip"""      )

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

		UpperCamelCase	:Any		=      """A painting of a squirrel eating a burger"""

		UpperCamelCase	:Any		=      torch.Generator(device=__lowerCamelCase      ).manual_seed(0      )
		UpperCamelCase	:int		=      sd_pipe([prompt]					,    generator=__lowerCamelCase					,    guidance_scale=6.0					,    num_inference_steps=2					,    output_type="""np"""      )
		UpperCamelCase	:str		=      output.images

		UpperCamelCase	:Optional[int]		=      torch.Generator(device=__lowerCamelCase      ).manual_seed(0      )
		UpperCamelCase	:List[Any]		=      sd_pipe(
		    [prompt]					,    generator=__lowerCamelCase					,    guidance_scale=6.0					,    num_inference_steps=2					,    output_type="""np"""					,    return_dict=__lowerCamelCase					,    )[0]

		UpperCamelCase	:int		=      image[0, -3:, -3:, -1]
		UpperCamelCase	:Optional[Any]		=      image_from_tuple[0, -3:, -3:, -1]

		assert image.shape == (1, 64, 64, 3)
		UpperCamelCase	:str		=      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 		_A					(						self							:   Union[str, Any]      ):
		UpperCamelCase	:Optional[Any]		=      """cpu"""  # ensure determinism for the device-dependent torch.Generator
		UpperCamelCase	:Dict		=      self.dummy_cond_unet
		UpperCamelCase	:Any		=      PNDMScheduler(skip_prk_steps=__lowerCamelCase      )
		UpperCamelCase	:int		=      self.dummy_vae
		UpperCamelCase	:Dict		=      self.dummy_text_encoder
		UpperCamelCase	:Dict		=      CLIPTokenizer.from_pretrained("""hf-internal-testing/tiny-random-clip"""      )

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

		UpperCamelCase	:Union[str, Any]		=      """A painting of a squirrel eating a burger"""
		UpperCamelCase	:Optional[Any]		=      torch.Generator(device=__lowerCamelCase      ).manual_seed(0      )
		UpperCamelCase	:Any		=      sd_pipe([prompt]					,    generator=__lowerCamelCase					,    guidance_scale=6.0					,    num_inference_steps=2					,    output_type="""np"""      )

		UpperCamelCase	:List[str]		=      output.images

		UpperCamelCase	:int		=      torch.Generator(device=__lowerCamelCase      ).manual_seed(0      )
		UpperCamelCase	:Any		=      sd_pipe(
		    [prompt]					,    generator=__lowerCamelCase					,    guidance_scale=6.0					,    num_inference_steps=2					,    output_type="""np"""					,    return_dict=__lowerCamelCase					,    )[0]

		UpperCamelCase	:List[Any]		=      image[0, -3:, -3:, -1]
		UpperCamelCase	:Any		=      image_from_tuple[0, -3:, -3:, -1]

		assert image.shape == (1, 64, 64, 3)
		UpperCamelCase	:List[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 		_A					(						self							:   Tuple      ):
		UpperCamelCase	:List[Any]		=      StableDiffusionPipeline.from_pretrained(
		    """hf-internal-testing/tiny-stable-diffusion-lms-pipe"""					,    safety_checker=__lowerCamelCase      )
		assert isinstance(__lowerCamelCase					,    __lowerCamelCase      )
		assert isinstance(pipe.scheduler					,    __lowerCamelCase      )
		assert pipe.safety_checker is None

		UpperCamelCase	: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      )
			UpperCamelCase	:Optional[Any]		=      StableDiffusionPipeline.from_pretrained(__lowerCamelCase      )

		# sanity check that the pipeline still works
		assert pipe.safety_checker is None
		UpperCamelCase	:Any		=      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 		_A					(						self							:   Any      ):
		UpperCamelCase	:int		=      self.dummy_cond_unet
		UpperCamelCase	:Union[str, Any]		=      PNDMScheduler(skip_prk_steps=__lowerCamelCase      )
		UpperCamelCase	:Dict		=      self.dummy_vae
		UpperCamelCase	:Dict		=      self.dummy_text_encoder
		UpperCamelCase	:List[Any]		=      CLIPTokenizer.from_pretrained("""hf-internal-testing/tiny-random-clip"""      )

		# put models in fp16
		UpperCamelCase	:Optional[Any]		=      unet.half()
		UpperCamelCase	:List[Any]		=      vae.half()
		UpperCamelCase	:List[str]		=      bert.half()

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

		UpperCamelCase	:Optional[Any]		=      """A painting of a squirrel eating a burger"""
		UpperCamelCase	:List[str]		=      sd_pipe([prompt]					,    num_inference_steps=2					,    output_type="""np"""      ).images

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

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





	def 		_A					(						self							:   Any      ):
		super().tearDown()
		gc.collect()
		torch.cuda.empty_cache()





	def 		_A					(						self							:   str      ):
		UpperCamelCase	:str		=      """cuda"""
		UpperCamelCase	:Any		=      StableDiffusionPipeline.from_pretrained("""runwayml/stable-diffusion-v1-5"""      )
		UpperCamelCase	:List[Any]		=      pipe.to(__lowerCamelCase      )
		pipe.set_progress_bar_config(disable=__lowerCamelCase      )

		UpperCamelCase	:Dict		=      """a photo of a cat"""
		UpperCamelCase	: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,
		}

		UpperCamelCase	:Any		=      3
		UpperCamelCase	:Optional[int]		=      7

		# no sega enabled
		UpperCamelCase	:Optional[Any]		=      torch.Generator(__lowerCamelCase      )
		generator.manual_seed(__lowerCamelCase      )
		UpperCamelCase	:Union[str, Any]		=      pipe(
		    [prompt]					,    generator=__lowerCamelCase					,    guidance_scale=__lowerCamelCase					,    num_inference_steps=50					,    output_type="""np"""					,    width=512					,    height=512					,    )

		UpperCamelCase	:Dict		=      output.images
		UpperCamelCase	:List[Any]		=      image[0, -3:, -3:, -1]
		UpperCamelCase	:Dict		=      [
		    0.34673113,
		    0.38492733,
		    0.37597352,
		    0.34086335,
		    0.35650748,
		    0.35579205,
		    0.3384763,
		    0.34340236,
		    0.3573271,
		]

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

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

		# with sega enabled
		# generator = torch.manual_seed(seed)
		generator.manual_seed(__lowerCamelCase      )
		UpperCamelCase	:Dict		=      pipe(
		    [prompt]					,    generator=__lowerCamelCase					,    guidance_scale=__lowerCamelCase					,    num_inference_steps=50					,    output_type="""np"""					,    width=512					,    height=512					,    **__lowerCamelCase					,    )

		UpperCamelCase	:Dict		=      output.images
		UpperCamelCase	:List[Any]		=      image[0, -3:, -3:, -1]
		UpperCamelCase	:int		=      [
		    0.41887826,
		    0.37728766,
		    0.30138272,
		    0.41416335,
		    0.41664985,
		    0.36283392,
		    0.36191246,
		    0.43364465,
		    0.43001732,
		]

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

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





	def 		_A					(						self							:   Dict      ):
		UpperCamelCase	:Union[str, Any]		=      """cuda"""
		UpperCamelCase	:List[Any]		=      StableDiffusionPipeline.from_pretrained("""runwayml/stable-diffusion-v1-5"""      )
		UpperCamelCase	:Optional[int]		=      pipe.to(__lowerCamelCase      )
		pipe.set_progress_bar_config(disable=__lowerCamelCase      )

		UpperCamelCase	:List[Any]		=      """an image of a crowded boulevard, realistic, 4k"""
		UpperCamelCase	:str		=      {
		    """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,
		}

		UpperCamelCase	:List[Any]		=      9
		UpperCamelCase	:Optional[int]		=      7

		# no sega enabled
		UpperCamelCase	:List[Any]		=      torch.Generator(__lowerCamelCase      )
		generator.manual_seed(__lowerCamelCase      )
		UpperCamelCase	:str		=      pipe(
		    [prompt]					,    generator=__lowerCamelCase					,    guidance_scale=__lowerCamelCase					,    num_inference_steps=50					,    output_type="""np"""					,    width=512					,    height=512					,    )

		UpperCamelCase	:str		=      output.images
		UpperCamelCase	:Dict		=      image[0, -3:, -3:, -1]
		UpperCamelCase	:str		=      [
		    0.43497998,
		    0.91814065,
		    0.7540739,
		    0.55580205,
		    0.8467265,
		    0.5389691,
		    0.62574506,
		    0.58897763,
		    0.50926757,
		]

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

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

		# with sega enabled
		# generator = torch.manual_seed(seed)
		generator.manual_seed(__lowerCamelCase      )
		UpperCamelCase	:List[str]		=      pipe(
		    [prompt]					,    generator=__lowerCamelCase					,    guidance_scale=__lowerCamelCase					,    num_inference_steps=50					,    output_type="""np"""					,    width=512					,    height=512					,    **__lowerCamelCase					,    )

		UpperCamelCase	:Tuple		=      output.images
		UpperCamelCase	:Tuple		=      image[0, -3:, -3:, -1]
		UpperCamelCase	:str		=      [
		    0.3089719,
		    0.30500144,
		    0.29016042,
		    0.30630964,
		    0.325687,
		    0.29419225,
		    0.2908091,
		    0.28723598,
		    0.27696294,
		]

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

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





	def 		_A					(						self							:   Any      ):
		UpperCamelCase	:Tuple		=      """cuda"""
		UpperCamelCase	:Tuple		=      StableDiffusionPipeline.from_pretrained("""runwayml/stable-diffusion-v1-5"""      )
		UpperCamelCase	:str		=      pipe.to(__lowerCamelCase      )
		pipe.set_progress_bar_config(disable=__lowerCamelCase      )

		UpperCamelCase	:str		=      """a castle next to a river"""
		UpperCamelCase	:List[Any]		=      {
		    """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,
		}

		UpperCamelCase	:Optional[Any]		=      48
		UpperCamelCase	:Any		=      7

		# no sega enabled
		UpperCamelCase	:Tuple		=      torch.Generator(__lowerCamelCase      )
		generator.manual_seed(__lowerCamelCase      )
		UpperCamelCase	:List[Any]		=      pipe(
		    [prompt]					,    generator=__lowerCamelCase					,    guidance_scale=__lowerCamelCase					,    num_inference_steps=50					,    output_type="""np"""					,    width=512					,    height=512					,    )

		UpperCamelCase	:Optional[int]		=      output.images
		UpperCamelCase	:List[Any]		=      image[0, -3:, -3:, -1]
		UpperCamelCase	:List[Any]		=      [
		    0.75163555,
		    0.76037145,
		    0.61785,
		    0.9189673,
		    0.8627701,
		    0.85189694,
		    0.8512813,
		    0.87012076,
		    0.8312857,
		]

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

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

		# with sega enabled
		# generator = torch.manual_seed(seed)
		generator.manual_seed(__lowerCamelCase      )
		UpperCamelCase	:Any		=      pipe(
		    [prompt]					,    generator=__lowerCamelCase					,    guidance_scale=__lowerCamelCase					,    num_inference_steps=50					,    output_type="""np"""					,    width=512					,    height=512					,    **__lowerCamelCase					,    )

		UpperCamelCase	:Dict		=      output.images
		UpperCamelCase	:Union[str, Any]		=      image[0, -3:, -3:, -1]
		UpperCamelCase	:List[str]		=      [
		    0.73553365,
		    0.7537271,
		    0.74341905,
		    0.66480356,
		    0.6472925,
		    0.63039416,
		    0.64812905,
		    0.6749717,
		    0.6517102,
		]

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

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





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

		UpperCamelCase	:int		=      """a photo of a cat"""
		UpperCamelCase	:Tuple		=      {
		    """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,
		}

		UpperCamelCase	:List[Any]		=      3
		UpperCamelCase	:List[str]		=      7

		# no sega enabled
		UpperCamelCase	:Dict		=      torch.Generator(__lowerCamelCase      )
		generator.manual_seed(__lowerCamelCase      )
		UpperCamelCase	:Union[str, Any]		=      pipe(
		    [prompt]					,    generator=__lowerCamelCase					,    guidance_scale=__lowerCamelCase					,    num_inference_steps=50					,    output_type="""np"""					,    width=512					,    height=512					,    )

		UpperCamelCase	:Any		=      output.images
		UpperCamelCase	:List[str]		=      image[0, -3:, -3:, -1]
		UpperCamelCase	:Dict		=      [
		    0.34887695,
		    0.3876953,
		    0.375,
		    0.34423828,
		    0.3581543,
		    0.35717773,
		    0.3383789,
		    0.34570312,
		    0.359375,
		]

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

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

		# with sega enabled
		# generator = torch.manual_seed(seed)
		generator.manual_seed(__lowerCamelCase      )
		UpperCamelCase	:Tuple		=      pipe(
		    [prompt]					,    generator=__lowerCamelCase					,    guidance_scale=__lowerCamelCase					,    num_inference_steps=50					,    output_type="""np"""					,    width=512					,    height=512					,    **__lowerCamelCase					,    )

		UpperCamelCase	:Optional[Any]		=      output.images
		UpperCamelCase	:Optional[Any]		=      image[0, -3:, -3:, -1]
		UpperCamelCase	:Dict		=      [
		    0.42285156,
		    0.36914062,
		    0.29077148,
		    0.42041016,
		    0.41918945,
		    0.35498047,
		    0.3618164,
		    0.4423828,
		    0.43115234,
		]

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

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






import random
import unittest

import numpy as np
import torch
from PIL import Image
from torch import nn
from transformers import (
    CLIPImageProcessor,
    CLIPTextConfig,
    CLIPTextModelWithProjection,
    CLIPTokenizer,
    CLIPVisionConfig,
    CLIPVisionModelWithProjection,
)

from diffusers import KandinskyVaaPriorEmbaEmbPipeline, PriorTransformer, UnCLIPScheduler
from diffusers.utils import floats_tensor, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, skip_mps

from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()







class 		__UpperCAmelCase(		lowercase__							,						unittest.TestCase			):





     """simple docstring"""



     __UpperCAmelCase						:			Optional[int]							=     KandinskyVaaPriorEmbaEmbPipeline
     __UpperCAmelCase						:			str							=     ["""prompt""", """image"""]
     __UpperCAmelCase						:			Dict							=     ["""prompt""", """image"""]
     __UpperCAmelCase						:			Optional[Any]							=     [
         """num_images_per_prompt""",
         """strength""",
         """generator""",
         """num_inference_steps""",
         """latents""",
         """negative_prompt""",
         """guidance_scale""",
         """output_type""",
         """return_dict""",
     ]
     __UpperCAmelCase						:			Dict							=     False

     @property
     def 					__SCREAMING_SNAKE_CASE		(   self			:							Any     )      ->      int:






         """simple docstring"""
         return 32

     @property
     def 					__SCREAMING_SNAKE_CASE		(   self			:							Optional[Any]     )      ->      Any:






         """simple docstring"""
         return 32

     @property
     def 					__SCREAMING_SNAKE_CASE		(   self			:							Tuple     )      ->      int:






         """simple docstring"""
         return self.time_input_dim

     @property
     def 					__SCREAMING_SNAKE_CASE		(   self			:							int     )      ->      List[Any]:






         """simple docstring"""
         return self.time_input_dim * 4

     @property
     def 					__SCREAMING_SNAKE_CASE		(   self			:							Optional[int]     )      ->      Tuple:






         """simple docstring"""
         return 1_00

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






         """simple docstring"""
         a__  			=							CLIPTokenizer.from_pretrained("""hf-internal-testing/tiny-random-clip"""     )
         return tokenizer

     @property
     def 					__SCREAMING_SNAKE_CASE		(   self			:							int     )      ->      Optional[int]:






         """simple docstring"""
         torch.manual_seed(0     )
         a__  			=							CLIPTextConfig(
             bos_token_id=0    ,					eos_token_id=2    ,					hidden_size=self.text_embedder_hidden_size    ,					projection_dim=self.text_embedder_hidden_size    ,					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 CLIPTextModelWithProjection(A     )

     @property
     def 					__SCREAMING_SNAKE_CASE		(   self			:							Dict     )      ->      List[Any]:






         """simple docstring"""
         torch.manual_seed(0     )

         a__  			=							{
             """num_attention_heads""": 2,
             """attention_head_dim""": 12,
             """embedding_dim""": self.text_embedder_hidden_size,
             """num_layers""": 1,
         }

         a__  			=							PriorTransformer(**A     )
         # clip_std and clip_mean is initialized to be 0 so PriorTransformer.post_process_latents will always return 0 - set clip_std to be 1 so it won't return 0
         a__  			=							nn.Parameter(torch.ones(model.clip_std.shape     )     )
         return model

     @property
     def 					__SCREAMING_SNAKE_CASE		(   self			:							Dict     )      ->      Optional[int]:






         """simple docstring"""
         torch.manual_seed(0     )
         a__  			=							CLIPVisionConfig(
             hidden_size=self.text_embedder_hidden_size    ,					image_size=2_24    ,					projection_dim=self.text_embedder_hidden_size    ,					intermediate_size=37    ,					num_attention_heads=4    ,					num_channels=3    ,					num_hidden_layers=5    ,					patch_size=14    ,					)

         a__  			=							CLIPVisionModelWithProjection(A     )
         return model

     @property
     def 					__SCREAMING_SNAKE_CASE		(   self			:							int     )      ->      List[str]:






         """simple docstring"""
         a__  			=							CLIPImageProcessor(
             crop_size=2_24    ,					do_center_crop=A    ,					do_normalize=A    ,					do_resize=A    ,					image_mean=[0.4_8_1_4_5_4_6_6, 0.4_5_7_8_2_7_5, 0.4_0_8_2_1_0_7_3]    ,					image_std=[0.2_6_8_6_2_9_5_4, 0.2_6_1_3_0_2_5_8, 0.2_7_5_7_7_7_1_1]    ,					resample=3    ,					size=2_24    ,					)

         return image_processor

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






         """simple docstring"""
         a__  			=							self.dummy_prior
         a__  			=							self.dummy_image_encoder
         a__  			=							self.dummy_text_encoder
         a__  			=							self.dummy_tokenizer
         a__  			=							self.dummy_image_processor

         a__  			=							UnCLIPScheduler(
             variance_type="""fixed_small_log"""    ,					prediction_type="""sample"""    ,					num_train_timesteps=10_00    ,					clip_sample=A    ,					clip_sample_range=1_0.0    ,					)

         a__  			=							{
             """prior""": prior,
             """image_encoder""": image_encoder,
             """text_encoder""": text_encoder,
             """tokenizer""": tokenizer,
             """scheduler""": scheduler,
             """image_processor""": image_processor,
         }

         return components

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






         """simple docstring"""
         if str(A     ).startswith("""mps"""     ):
             a__  			=							torch.manual_seed(A     )
         else:
             a__  			=							torch.Generator(device=A     ).manual_seed(A     )

         a__  			=							floats_tensor((1, 3, 64, 64)    ,					rng=random.Random(A     )     ).to(A     )
         a__  			=							image.cpu().permute(0    ,					2    ,					3    ,					1     )[0]
         a__  			=							Image.fromarray(np.uinta(A     )     ).convert("""RGB"""     ).resize((2_56, 2_56)     )

         a__  			=							{
             """prompt""": """horse""",
             """image""": init_image,
             """strength""": 0.5,
             """generator""": generator,
             """guidance_scale""": 4.0,
             """num_inference_steps""": 2,
             """output_type""": """np""",
         }
         return inputs

     def 					__SCREAMING_SNAKE_CASE		(   self			:							Dict     )      ->      Optional[int]:






         """simple docstring"""
         a__  			=							"""cpu"""

         a__  			=							self.get_dummy_components()

         a__  			=							self.pipeline_class(**A     )
         a__  			=							pipe.to(A     )

         pipe.set_progress_bar_config(disable=A     )

         a__  			=							pipe(**self.get_dummy_inputs(A     )     )
         a__  			=							output.image_embeds

         a__  			=							pipe(
             **self.get_dummy_inputs(A     )    ,					return_dict=A    ,					)[0]

         a__  			=							image[0, -10:]
         a__  			=							image_from_tuple[0, -10:]

         assert image.shape == (1, 32)

         a__  			=							np.array(
             [
                 0.1_0_7_1_2_8_4,
                 1.3_3_3_0_2_7_1,
                 0.6_1_2_6_0_2_2_3,
                 -0.6_6_9_1_0_6_5,
                 -0.3_8_4_6_8_5_2,
                 -1.0_3_0_3_6_6_1,
                 0.2_2_7_1_6_1_1_1,
                 0.0_3_3_4_8_9_0_1,
                 0.3_0_0_4_0_6_7_5,
                 -0.2_4_8_0_5_0_2_9,
             ]     )

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

     @skip_mps
     def 					__SCREAMING_SNAKE_CASE		(   self			:							str     )      ->      Optional[Any]:






         """simple docstring"""
         a__  			=							torch_device == """cpu"""
         a__  			=							True
         a__  			=							False

         self._test_inference_batch_single_identical(
             test_max_difference=A    ,					relax_max_difference=A    ,					test_mean_pixel_difference=A    ,					)






     @skip_mps
     def 					__SCREAMING_SNAKE_CASE		(   self			:							Tuple     )      ->      Union[str, Any]:






         """simple docstring"""
         a__  			=							torch_device == """cpu"""
         a__  			=							False

         self._test_attention_slicing_forward_pass(
             test_max_difference=A    ,					test_mean_pixel_difference=A    ,					)






