




'''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









'''simple docstring'''




import random
import unittest

import numpy as np
import torch

from diffusers import DDIMScheduler, LDMSuperResolutionPipeline, UNetaDModel, VQModel
from diffusers.utils import PIL_INTERPOLATION, floats_tensor, load_image, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch


enable_full_determinism()






class     UpperCamelCase_     (unittest.TestCase     ):







						"""simple docstring"""


						@property
						def       _a    (     self      :       int    ):





											"""simple docstring"""







											A_ :     Dict =							1
											A_ :     Any =							3
											A_ :     Any =							(32, 32)

											A_ :     Dict =							floats_tensor((batch_size, num_channels) + sizes							, rng=random.Random(0    )    ).to(_lowerCamelCase    )
											return image







						@property
						def       _a    (     self      :       Dict    ):





											"""simple docstring"""







											torch.manual_seed(0    )
											A_ :     Optional[int] =							UNetaDModel(
											    block_out_channels=(32, 64)							, layers_per_block=2							, sample_size=32							, in_channels=6							, out_channels=3							, down_block_types=('''DownBlock2D''', '''AttnDownBlock2D''')							, up_block_types=('''AttnUpBlock2D''', '''UpBlock2D''')							, )
											return model







						@property
						def       _a    (     self      :       Any    ):





											"""simple docstring"""







											torch.manual_seed(0    )
											A_ :     Dict =							VQModel(
											    block_out_channels=[32, 64]							, in_channels=3							, out_channels=3							, down_block_types=['''DownEncoderBlock2D''', '''DownEncoderBlock2D''']							, up_block_types=['''UpDecoderBlock2D''', '''UpDecoderBlock2D''']							, latent_channels=3							, )
											return model







						def       _a    (     self      :       List[Any]    ):





											"""simple docstring"""







											A_ :     Any =							'''cpu'''
											A_ :     Optional[Any] =							self.dummy_uncond_unet
											A_ :     str =							DDIMScheduler()
											A_ :     Optional[int] =							self.dummy_vq_model

											A_ :     Optional[Any] =							LDMSuperResolutionPipeline(unet=_lowerCamelCase							, vqvae=_lowerCamelCase							, scheduler=_lowerCamelCase    )
											ldm.to(_lowerCamelCase    )
											ldm.set_progress_bar_config(disable=_lowerCamelCase    )

											A_ :     Any =							self.dummy_image.to(_lowerCamelCase    )

											A_ :     str =							torch.Generator(device=_lowerCamelCase    ).manual_seed(0    )
											A_ :     List[Any] =							ldm(image=_lowerCamelCase							, generator=_lowerCamelCase							, num_inference_steps=2							, output_type='''numpy'''    ).images

											A_ :     str =							image[0, -3:, -3:, -1]

											assert image.shape == (1, 64, 64, 3)
											A_ :     List[Any] =							np.array([0.86_78, 0.82_45, 0.63_81, 0.68_30, 0.43_85, 0.55_99, 0.46_41, 0.62_01, 0.51_50]    )

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







						@unittest.skipIf(torch_device != '''cuda'''							, '''This test requires a GPU'''    )
						def       _a    (     self      :       Optional[int]    ):





											"""simple docstring"""







											A_ :     Tuple =							self.dummy_uncond_unet
											A_ :     List[str] =							DDIMScheduler()
											A_ :     str =							self.dummy_vq_model

											# put models in fp16
											A_ :     List[Any] =							unet.half()
											A_ :     Optional[int] =							vqvae.half()

											A_ :     Optional[Any] =							LDMSuperResolutionPipeline(unet=_lowerCamelCase							, vqvae=_lowerCamelCase							, scheduler=_lowerCamelCase    )
											ldm.to(_lowerCamelCase    )
											ldm.set_progress_bar_config(disable=_lowerCamelCase    )

											A_ :     Optional[Any] =							self.dummy_image.to(_lowerCamelCase    )

											A_ :     Optional[Any] =							ldm(_lowerCamelCase							, num_inference_steps=2							, output_type='''numpy'''    ).images

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






@slow
@require_torch
class     UpperCamelCase_     (unittest.TestCase     ):







						"""simple docstring"""


						def       _a    (     self      :       int    ):





											"""simple docstring"""







											A_ :     Optional[int] =							load_image(
											    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'''
											    '''/vq_diffusion/teddy_bear_pool.png'''    )
											A_ :     List[str] =							init_image.resize((64, 64)							, resample=PIL_INTERPOLATION['''lanczos''']    )

											A_ :     List[str] =							LDMSuperResolutionPipeline.from_pretrained('''duongna/ldm-super-resolution'''							, device_map='''auto'''    )
											ldm.set_progress_bar_config(disable=_lowerCamelCase    )

											A_ :     List[str] =							torch.manual_seed(0    )
											A_ :     str =							ldm(image=_lowerCamelCase							, generator=_lowerCamelCase							, num_inference_steps=20							, output_type='''numpy'''    ).images

											A_ :     str =							image[0, -3:, -3:, -1]

											assert image.shape == (1, 256, 256, 3)
											A_ :     Optional[Any] =							np.array([0.76_44, 0.76_79, 0.76_42, 0.76_33, 0.76_66, 0.75_60, 0.74_25, 0.72_57, 0.69_07]    )

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



