






UpperCamelCase			    =     '''0.18.2'''

from .configuration_utils import ConfigMixin
from .utils import (
    OptionalDependencyNotAvailable,
    is_flax_available,
    is_inflect_available,
    is_invisible_watermark_available,
    is_k_diffusion_available,
    is_k_diffusion_version,
    is_librosa_available,
    is_note_seq_available,
    is_onnx_available,
    is_scipy_available,
    is_torch_available,
    is_torchsde_available,
    is_transformers_available,
    is_transformers_version,
    is_unidecode_available,
    logging,
)


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

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		from .utils.dummy_pt_objects import *  # noqa F403
else:
		from .models import (
		    AutoencoderKL,
		    ControlNetModel,
		    ModelMixin,
		    PriorTransformer,
		    TaFilmDecoder,
		    TransformeraDModel,
		    UNetaDModel,
		    UNetaDConditionModel,
		    UNetaDModel,
		    UNetaDConditionModel,
		    VQModel,
		)
		from .optimization import (
		    get_constant_schedule,
		    get_constant_schedule_with_warmup,
		    get_cosine_schedule_with_warmup,
		    get_cosine_with_hard_restarts_schedule_with_warmup,
		    get_linear_schedule_with_warmup,
		    get_polynomial_decay_schedule_with_warmup,
		    get_scheduler,
		)
		from .pipelines import (
		    AudioPipelineOutput,
		    ConsistencyModelPipeline,
		    DanceDiffusionPipeline,
		    DDIMPipeline,
		    DDPMPipeline,
		    DiffusionPipeline,
		    DiTPipeline,
		    ImagePipelineOutput,
		    KarrasVePipeline,
		    LDMPipeline,
		    LDMSuperResolutionPipeline,
		    PNDMPipeline,
		    RePaintPipeline,
		    ScoreSdeVePipeline,
		)
		from .schedulers import (
		    CMStochasticIterativeScheduler,
		    DDIMInverseScheduler,
		    DDIMParallelScheduler,
		    DDIMScheduler,
		    DDPMParallelScheduler,
		    DDPMScheduler,
		    DEISMultistepScheduler,
		    DPMSolverMultistepInverseScheduler,
		    DPMSolverMultistepScheduler,
		    DPMSolverSinglestepScheduler,
		    EulerAncestralDiscreteScheduler,
		    EulerDiscreteScheduler,
		    HeunDiscreteScheduler,
		    IPNDMScheduler,
		    KarrasVeScheduler,
		    KDPMaAncestralDiscreteScheduler,
		    KDPMaDiscreteScheduler,
		    PNDMScheduler,
		    RePaintScheduler,
		    SchedulerMixin,
		    ScoreSdeVeScheduler,
		    UnCLIPScheduler,
		    UniPCMultistepScheduler,
		    VQDiffusionScheduler,
		)
		from .training_utils import EMAModel

try:
		if not (is_torch_available() and is_scipy_available()):
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		from .utils.dummy_torch_and_scipy_objects import *  # noqa F403
else:
		from .schedulers import LMSDiscreteScheduler

try:
		if not (is_torch_available() and is_torchsde_available()):
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		from .utils.dummy_torch_and_torchsde_objects import *  # noqa F403
else:
		from .schedulers import DPMSolverSDEScheduler

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 .pipelines import (
		    AltDiffusionImgaImgPipeline,
		    AltDiffusionPipeline,
		    AudioLDMPipeline,
		    CycleDiffusionPipeline,
		    IFImgaImgPipeline,
		    IFImgaImgSuperResolutionPipeline,
		    IFInpaintingPipeline,
		    IFInpaintingSuperResolutionPipeline,
		    IFPipeline,
		    IFSuperResolutionPipeline,
		    ImageTextPipelineOutput,
		    KandinskyImgaImgPipeline,
		    KandinskyInpaintPipeline,
		    KandinskyPipeline,
		    KandinskyPriorPipeline,
		    KandinskyVaaControlnetImgaImgPipeline,
		    KandinskyVaaControlnetPipeline,
		    KandinskyVaaImgaImgPipeline,
		    KandinskyVaaInpaintPipeline,
		    KandinskyVaaPipeline,
		    KandinskyVaaPriorEmbaEmbPipeline,
		    KandinskyVaaPriorPipeline,
		    LDMTextToImagePipeline,
		    PaintByExamplePipeline,
		    SemanticStableDiffusionPipeline,
		    ShapEImgaImgPipeline,
		    ShapEPipeline,
		    StableDiffusionAttendAndExcitePipeline,
		    StableDiffusionControlNetImgaImgPipeline,
		    StableDiffusionControlNetInpaintPipeline,
		    StableDiffusionControlNetPipeline,
		    StableDiffusionDepthaImgPipeline,
		    StableDiffusionDiffEditPipeline,
		    StableDiffusionImageVariationPipeline,
		    StableDiffusionImgaImgPipeline,
		    StableDiffusionInpaintPipeline,
		    StableDiffusionInpaintPipelineLegacy,
		    StableDiffusionInstructPixaPixPipeline,
		    StableDiffusionLatentUpscalePipeline,
		    StableDiffusionLDMaDPipeline,
		    StableDiffusionModelEditingPipeline,
		    StableDiffusionPanoramaPipeline,
		    StableDiffusionParadigmsPipeline,
		    StableDiffusionPipeline,
		    StableDiffusionPipelineSafe,
		    StableDiffusionPixaPixZeroPipeline,
		    StableDiffusionSAGPipeline,
		    StableDiffusionUpscalePipeline,
		    StableUnCLIPImgaImgPipeline,
		    StableUnCLIPPipeline,
		    TextToVideoSDPipeline,
		    TextToVideoZeroPipeline,
		    UnCLIPImageVariationPipeline,
		    UnCLIPPipeline,
		    UniDiffuserModel,
		    UniDiffuserPipeline,
		    UniDiffuserTextDecoder,
		    VersatileDiffusionDualGuidedPipeline,
		    VersatileDiffusionImageVariationPipeline,
		    VersatileDiffusionPipeline,
		    VersatileDiffusionTextToImagePipeline,
		    VideoToVideoSDPipeline,
		    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 .pipelines import StableDiffusionXLImgaImgPipeline, StableDiffusionXLPipeline

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 .pipelines import StableDiffusionKDiffusionPipeline

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 .pipelines import (
		    OnnxStableDiffusionImgaImgPipeline,
		    OnnxStableDiffusionInpaintPipeline,
		    OnnxStableDiffusionInpaintPipelineLegacy,
		    OnnxStableDiffusionPipeline,
		    OnnxStableDiffusionUpscalePipeline,
		    StableDiffusionOnnxPipeline,
		)

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 .pipelines import AudioDiffusionPipeline, Mel

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 .pipelines import SpectrogramDiffusionPipeline

try:
		if not is_flax_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		from .utils.dummy_flax_objects import *  # noqa F403
else:
		from .models.controlnet_flax import FlaxControlNetModel
		from .models.modeling_flax_utils import FlaxModelMixin
		from .models.unet_ad_condition_flax import FlaxUNetaDConditionModel
		from .models.vae_flax import FlaxAutoencoderKL
		from .pipelines import FlaxDiffusionPipeline
		from .schedulers import (
		    FlaxDDIMScheduler,
		    FlaxDDPMScheduler,
		    FlaxDPMSolverMultistepScheduler,
		    FlaxKarrasVeScheduler,
		    FlaxLMSDiscreteScheduler,
		    FlaxPNDMScheduler,
		    FlaxSchedulerMixin,
		    FlaxScoreSdeVeScheduler,
		)


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 .pipelines import (
		    FlaxStableDiffusionControlNetPipeline,
		    FlaxStableDiffusionImgaImgPipeline,
		    FlaxStableDiffusionInpaintPipeline,
		    FlaxStableDiffusionPipeline,
		)

try:
		if not (is_note_seq_available()):
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		from .utils.dummy_note_seq_objects import *  # noqa F403
else:
		from .pipelines import MidiProcessor









import torch

from diffusers import UnCLIPScheduler

from .test_schedulers import SchedulerCommonTest



class 				__UpperCAmelCase		(_UpperCAmelCase   ):
			__snake_case    :				Optional[Any]									=							(UnCLIPScheduler,)







			def 							UpperCamelCase				(     self:  int				,     **UpperCAmelCase_:  Dict					):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  {
									    """num_train_timesteps""": 1_000,
									    """variance_type""": """fixed_small_log""",
									    """clip_sample""": True,
									    """clip_sample_range""": 1.0,
									    """prediction_type""": """epsilon""",
									}

									config.update(**UpperCAmelCase_					)
									return config







			def 							UpperCamelCase				(     self:  Optional[Any]					):







									'''simple docstring'''




									for timesteps in [1, 5, 100, 1_000]:
															self.check_over_configs(num_train_timesteps=UpperCAmelCase_					)







			def 							UpperCamelCase				(     self:  Any					):







									'''simple docstring'''




									for variance in ["fixed_small_log", "learned_range"]:
															self.check_over_configs(variance_type=UpperCAmelCase_					)







			def 							UpperCamelCase				(     self:  List[Any]					):







									'''simple docstring'''




									for clip_sample in [True, False]:
															self.check_over_configs(clip_sample=UpperCAmelCase_					)







			def 							UpperCamelCase				(     self:  Optional[int]					):







									'''simple docstring'''




									for clip_sample_range in [1, 5, 10, 20]:
															self.check_over_configs(clip_sample_range=UpperCAmelCase_					)







			def 							UpperCamelCase				(     self:  Union[str, Any]					):







									'''simple docstring'''




									for prediction_type in ["epsilon", "sample"]:
															self.check_over_configs(prediction_type=UpperCAmelCase_					)







			def 							UpperCamelCase				(     self:  Optional[Any]					):







									'''simple docstring'''




									for time_step in [0, 500, 999]:
															for prev_timestep in [None, 5, 100, 250, 500, 750]:
																					if prev_timestep is not None and prev_timestep >= time_step:
																											continue

																					self.check_over_forward(time_step=UpperCAmelCase_				,     prev_timestep=UpperCAmelCase_					)







			def 							UpperCamelCase				(     self:  Any					):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  self.scheduler_classes[0]
									_SCREAMING_SNAKE_CASE     				=  self.get_scheduler_config(variance_type="""fixed_small_log"""					)
									_SCREAMING_SNAKE_CASE     				=  scheduler_class(**UpperCAmelCase_					)

									assert torch.sum(torch.abs(scheduler._get_variance(0					) - 1.0_000E-10					)					) < 1E-5
									assert torch.sum(torch.abs(scheduler._get_variance(487					) - 0.0_54_96_25					)					) < 1E-5
									assert torch.sum(torch.abs(scheduler._get_variance(999					) - 0.9_99_49_87					)					) < 1E-5







			def 							UpperCamelCase				(     self:  int					):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  self.scheduler_classes[0]
									_SCREAMING_SNAKE_CASE     				=  self.get_scheduler_config(variance_type="""learned_range"""					)
									_SCREAMING_SNAKE_CASE     				=  scheduler_class(**UpperCAmelCase_					)

									_SCREAMING_SNAKE_CASE     				=  0.5

									assert scheduler._get_variance(1				,     predicted_variance=UpperCAmelCase_					) - -10.1_71_27_90 < 1E-5
									assert scheduler._get_variance(487				,     predicted_variance=UpperCAmelCase_					) - -5.7_99_80_52 < 1E-5
									assert scheduler._get_variance(999				,     predicted_variance=UpperCAmelCase_					) - -0.0_01_00_11 < 1E-5







			def 							UpperCamelCase				(     self:  List[Any]					):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  self.scheduler_classes[0]
									_SCREAMING_SNAKE_CASE     				=  self.get_scheduler_config()
									_SCREAMING_SNAKE_CASE     				=  scheduler_class(**UpperCAmelCase_					)

									_SCREAMING_SNAKE_CASE     				=  scheduler.timesteps

									_SCREAMING_SNAKE_CASE     				=  self.dummy_model()
									_SCREAMING_SNAKE_CASE     				=  self.dummy_sample_deter
									_SCREAMING_SNAKE_CASE     				=  torch.manual_seed(0					)

									for i, t in enumerate(UpperCAmelCase_					):
															# 1. predict noise residual
															_SCREAMING_SNAKE_CASE     				=  model(UpperCAmelCase_				,     UpperCAmelCase_					)

															# 2. predict previous mean of sample x_t-1
															_SCREAMING_SNAKE_CASE     				=  scheduler.step(UpperCAmelCase_				,     UpperCAmelCase_				,     UpperCAmelCase_				,     generator=UpperCAmelCase_					).prev_sample

															_SCREAMING_SNAKE_CASE     				=  pred_prev_sample

									_SCREAMING_SNAKE_CASE     				=  torch.sum(torch.abs(UpperCAmelCase_					)					)
									_SCREAMING_SNAKE_CASE     				=  torch.mean(torch.abs(UpperCAmelCase_					)					)

									assert abs(result_sum.item() - 2_52.2_68_24_95					) < 1E-2
									assert abs(result_mean.item() - 0.3_28_47_43					) < 1E-3







			def 							UpperCamelCase				(     self:  List[str]					):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE     				=  self.scheduler_classes[0]
									_SCREAMING_SNAKE_CASE     				=  self.get_scheduler_config()
									_SCREAMING_SNAKE_CASE     				=  scheduler_class(**UpperCAmelCase_					)

									scheduler.set_timesteps(25					)

									_SCREAMING_SNAKE_CASE     				=  scheduler.timesteps

									_SCREAMING_SNAKE_CASE     				=  self.dummy_model()
									_SCREAMING_SNAKE_CASE     				=  self.dummy_sample_deter
									_SCREAMING_SNAKE_CASE     				=  torch.manual_seed(0					)

									for i, t in enumerate(UpperCAmelCase_					):
															# 1. predict noise residual
															_SCREAMING_SNAKE_CASE     				=  model(UpperCAmelCase_				,     UpperCAmelCase_					)

															if i + 1 == timesteps.shape[0]:
																					_SCREAMING_SNAKE_CASE     				=  None
															else:
																					_SCREAMING_SNAKE_CASE     				=  timesteps[i + 1]

															# 2. predict previous mean of sample x_t-1
															_SCREAMING_SNAKE_CASE     				=  scheduler.step(
															    UpperCAmelCase_				,     UpperCAmelCase_				,     UpperCAmelCase_				,     prev_timestep=UpperCAmelCase_				,     generator=UpperCAmelCase_					).prev_sample

															_SCREAMING_SNAKE_CASE     				=  pred_prev_sample

									_SCREAMING_SNAKE_CASE     				=  torch.sum(torch.abs(UpperCAmelCase_					)					)
									_SCREAMING_SNAKE_CASE     				=  torch.mean(torch.abs(UpperCAmelCase_					)					)

									assert abs(result_sum.item() - 2_58.2_04_49_83					) < 1E-2
									assert abs(result_mean.item() - 0.3_36_20_38					) < 1E-3







			def 							UpperCamelCase				(     self:  List[Any]					):







									'''simple docstring'''




									pass







			def 							UpperCamelCase				(     self:  str					):







									'''simple docstring'''




									pass

