






'''simple docstring'''



import torch

from diffusers import DDIMParallelScheduler

from .test_schedulers import SchedulerCommonTest
class 							__SCREAMING_SNAKE_CASE       (							_lowerCAmelCase     ):
						__a  					=(DDIMParallelScheduler,)
						__a  					=(("eta", 0.0), ("num_inference_steps", 50))




						def  __UpperCamelCase							(  self ,   **lowerCamelCase      )							->int:



									'''simple docstring'''
									__a				     =    {
									    'num_train_timesteps': 1000,
									    'beta_start': 0.0001,
									    'beta_end': 0.02,
									    'beta_schedule': 'linear',
									    'clip_sample': True,
									}

									config.update(**lowerCamelCase      )
									return config




						def  __UpperCamelCase							(  self ,   **lowerCamelCase      )							->Optional[Any]:



									'''simple docstring'''
									__a				     =    self.scheduler_classes[0]
									__a				     =    self.get_scheduler_config(**lowerCamelCase      )
									__a				     =    scheduler_class(**lowerCamelCase      )

									__a     ,			__a				     =    10, 0.0

									__a				     =    self.dummy_model()
									__a				     =    self.dummy_sample_deter

									scheduler.set_timesteps(lowerCamelCase      )

									for t in scheduler.timesteps:
												__a				     =    model(lowerCamelCase ,   lowerCamelCase      )
												__a				     =    scheduler.step(lowerCamelCase ,   lowerCamelCase ,   lowerCamelCase ,   lowerCamelCase      ).prev_sample

									return sample




						def  __UpperCamelCase							(  self      )							->str:



									'''simple docstring'''
									for timesteps in [100, 500, 1000]:
												self.check_over_configs(num_train_timesteps=lowerCamelCase      )




						def  __UpperCamelCase							(  self      )							->Any:



									'''simple docstring'''
									for steps_offset in [0, 1]:
												self.check_over_configs(steps_offset=lowerCamelCase      )

									__a				     =    self.scheduler_classes[0]
									__a				     =    self.get_scheduler_config(steps_offset=1      )
									__a				     =    scheduler_class(**lowerCamelCase      )
									scheduler.set_timesteps(5      )
									assert torch.equal(scheduler.timesteps ,   torch.LongTensor([801, 601, 401, 201, 1]      )      )




						def  __UpperCamelCase							(  self      )							->Dict:



									'''simple docstring'''
									for beta_start, beta_end in zip([0.0001, 0.001, 0.01, 0.1] ,   [0.002, 0.02, 0.2, 2]      ):
												self.check_over_configs(beta_start=lowerCamelCase ,   beta_end=lowerCamelCase      )




						def  __UpperCamelCase							(  self      )							->List[str]:



									'''simple docstring'''
									for schedule in ["linear", "squaredcos_cap_v2"]:
												self.check_over_configs(beta_schedule=lowerCamelCase      )




						def  __UpperCamelCase							(  self      )							->List[Any]:



									'''simple docstring'''
									for prediction_type in ["epsilon", "v_prediction"]:
												self.check_over_configs(prediction_type=lowerCamelCase      )




						def  __UpperCamelCase							(  self      )							->int:



									'''simple docstring'''
									for clip_sample in [True, False]:
												self.check_over_configs(clip_sample=lowerCamelCase      )




						def  __UpperCamelCase							(  self      )							->List[Any]:



									'''simple docstring'''
									for timestep_spacing in ["trailing", "leading"]:
												self.check_over_configs(timestep_spacing=lowerCamelCase      )




						def  __UpperCamelCase							(  self      )							->List[Any]:



									'''simple docstring'''
									for rescale_betas_zero_snr in [True, False]:
												self.check_over_configs(rescale_betas_zero_snr=lowerCamelCase      )




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



									'''simple docstring'''
									self.check_over_configs(thresholding=lowerCamelCase      )
									for threshold in [0.5, 1.0, 2.0]:
												for prediction_type in ["epsilon", "v_prediction"]:
															self.check_over_configs(
															    thresholding=lowerCamelCase ,   prediction_type=lowerCamelCase ,   sample_max_value=lowerCamelCase ,   )




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



									'''simple docstring'''
									for t in [1, 10, 49]:
												self.check_over_forward(time_step=lowerCamelCase      )




						def  __UpperCamelCase							(  self      )							->int:



									'''simple docstring'''
									for t, num_inference_steps in zip([1, 10, 50] ,   [10, 50, 500]      ):
												self.check_over_forward(time_step=lowerCamelCase ,   num_inference_steps=lowerCamelCase      )




						def  __UpperCamelCase							(  self      )							->str:



									'''simple docstring'''
									for t, eta in zip([1, 10, 49] ,   [0.0, 0.5, 1.0]      ):
												self.check_over_forward(time_step=lowerCamelCase ,   eta=lowerCamelCase      )




						def  __UpperCamelCase							(  self      )							->Optional[Any]:



									'''simple docstring'''
									__a				     =    self.scheduler_classes[0]
									__a				     =    self.get_scheduler_config()
									__a				     =    scheduler_class(**lowerCamelCase      )

									assert torch.sum(torch.abs(scheduler._get_variance(0 ,   0      ) - 0.0      )      ) < 1e-5
									assert torch.sum(torch.abs(scheduler._get_variance(420 ,   400      ) - 0.14771      )      ) < 1e-5
									assert torch.sum(torch.abs(scheduler._get_variance(980 ,   960      ) - 0.32460      )      ) < 1e-5
									assert torch.sum(torch.abs(scheduler._get_variance(0 ,   0      ) - 0.0      )      ) < 1e-5
									assert torch.sum(torch.abs(scheduler._get_variance(487 ,   486      ) - 0.00979      )      ) < 1e-5
									assert torch.sum(torch.abs(scheduler._get_variance(999 ,   998      ) - 0.02      )      ) < 1e-5




						def  __UpperCamelCase							(  self      )							->Tuple:



									'''simple docstring'''
									__a				     =    self.scheduler_classes[0]
									__a				     =    self.get_scheduler_config()
									__a				     =    scheduler_class(**lowerCamelCase      )

									__a     ,			__a				     =    10, 0.0
									scheduler.set_timesteps(lowerCamelCase      )

									__a				     =    self.dummy_model()
									__a				     =    self.dummy_sample_deter
									__a				     =    self.dummy_sample_deter + 0.1
									__a				     =    self.dummy_sample_deter - 0.1

									__a				     =    samplea.shape[0]
									__a				     =    torch.stack([samplea, samplea, samplea] ,   dim=0      )
									__a				     =    torch.arange(lowerCamelCase      )[0:3, None].repeat(1 ,   lowerCamelCase      )

									__a				     =    model(samples.flatten(0 ,   1      ) ,   timesteps.flatten(0 ,   1      )      )
									__a				     =    scheduler.batch_step_no_noise(lowerCamelCase ,   timesteps.flatten(0 ,   1      ) ,   samples.flatten(0 ,   1      ) ,   lowerCamelCase      )

									__a				     =    torch.sum(torch.abs(lowerCamelCase      )      )
									__a				     =    torch.mean(torch.abs(lowerCamelCase      )      )

									assert abs(result_sum.item() - 1147.7904      ) < 1e-2
									assert abs(result_mean.item() - 0.4982      ) < 1e-3




						def  __UpperCamelCase							(  self      )							->Any:



									'''simple docstring'''
									__a				     =    self.full_loop()

									__a				     =    torch.sum(torch.abs(lowerCamelCase      )      )
									__a				     =    torch.mean(torch.abs(lowerCamelCase      )      )

									assert abs(result_sum.item() - 172.0067      ) < 1e-2
									assert abs(result_mean.item() - 0.223967      ) < 1e-3




						def  __UpperCamelCase							(  self      )							->Optional[Any]:



									'''simple docstring'''
									__a				     =    self.full_loop(prediction_type='v_prediction'      )

									__a				     =    torch.sum(torch.abs(lowerCamelCase      )      )
									__a				     =    torch.mean(torch.abs(lowerCamelCase      )      )

									assert abs(result_sum.item() - 52.5302      ) < 1e-2
									assert abs(result_mean.item() - 0.0684      ) < 1e-3




						def  __UpperCamelCase							(  self      )							->int:



									'''simple docstring'''
									__a				     =    self.full_loop(set_alpha_to_one=lowerCamelCase ,   beta_start=0.01      )
									__a				     =    torch.sum(torch.abs(lowerCamelCase      )      )
									__a				     =    torch.mean(torch.abs(lowerCamelCase      )      )

									assert abs(result_sum.item() - 149.8295      ) < 1e-2
									assert abs(result_mean.item() - 0.1951      ) < 1e-3






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



									'''simple docstring'''
									__a				     =    self.full_loop(set_alpha_to_one=lowerCamelCase ,   beta_start=0.01      )
									__a				     =    torch.sum(torch.abs(lowerCamelCase      )      )
									__a				     =    torch.mean(torch.abs(lowerCamelCase      )      )

									assert abs(result_sum.item() - 149.0784      ) < 1e-2
									assert abs(result_mean.item() - 0.1941      ) < 1e-3







'''simple docstring'''



__UpperCamelCase      :       Tuple      			=      """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