class_docstr: Euler scheduler.
  
  This model inherits from [`SchedulerMixin`] and [`ConfigMixin`]. Check the superclass documentation for the generic
  methods the library implements for all schedulers such as loading and saving.
  
  Args:
      num_train_timesteps (`int`, defaults to 1000):
          The number of diffusion steps to train the model.
      beta_start (`float`, defaults to 0.0001):
          The starting `beta` value of inference.
      beta_end (`float`, defaults to 0.02):
          The final `beta` value.
      beta_schedule (`str`, defaults to `"linear"`):
          The beta schedule, a mapping from a beta range to a sequence of betas for stepping the model. Choose from
          `linear` or `scaled_linear`.
      trained_betas (`np.ndarray`, *optional*):
          Pass an array of betas directly to the constructor to bypass `beta_start` and `beta_end`.
      prediction_type (`str`, defaults to `epsilon`, *optional*):
          Prediction type of the scheduler function; can be `epsilon` (predicts the noise of the diffusion process),
          `sample` (directly predicts the noisy sample`) or `v_prediction` (see section 2.4 of [Imagen
          Video](https://imagen.research.google/video/paper.pdf) paper).
      interpolation_type(`str`, defaults to `"linear"`, *optional*):
          The interpolation type to compute intermediate sigmas for the scheduler denoising steps. Should be on of
          `"linear"` or `"log_linear"`.
      use_karras_sigmas (`bool`, *optional*, defaults to `False`):
          Whether to use Karras sigmas for step sizes in the noise schedule during the sampling process. If `True`,
          the sigmas are determined according to a sequence of noise levels {σi}.
      timestep_spacing (`str`, defaults to `"linspace"`):
          The way the timesteps should be scaled. Refer to Table 2 of the [Common Diffusion Noise Schedules and
          Sample Steps are Flawed](https://huggingface.co/papers/2305.08891) for more information.
      steps_offset (`int`, defaults to 0):
          An offset added to the inference steps. You can use a combination of `offset=1` and
          `set_alpha_to_one=False` to make the last step use step 0 for the previous alpha product like in Stable
          Diffusion.
      rescale_betas_zero_snr (`bool`, defaults to `False`):
          Whether to rescale the betas to have zero terminal SNR. This enables the model to generate very bright and
          dark samples instead of limiting it to samples with medium brightness. Loosely related to
          [`--offset_noise`](https://github.com/huggingface/diffusers/blob/74fd735eb073eb1d774b1ab4154a0876eb82f055/examples/dreambooth/train_dreambooth.py#L506).
class_docstr_tok: ["Euler","scheduler",".","This","model","inherits","from","[","`","SchedulerMixin","`","]","and","[","`","ConfigMixin","`","]",".","Check","the","superclass","documentation","for","the","generic","methods","the","library","implements","for","all","schedulers","such","as","loading","and","saving",".","Args",":","num_train_timesteps","(","`","int","`",",","defaults","to","1000",")",":","The","number","of","diffusion","steps","to","train","the","model",".","beta_start","(","`","float","`",",","defaults","to","0.0001",")",":","The","starting","`","beta","`","value","of","inference",".","beta_end","(","`","float","`",",","defaults","to","0.02",")",":","The","final","`","beta","`","value",".","beta_schedule","(","`","str","`",",","defaults","to","`","``","linear","''","`",")",":","The","beta","schedule",",","a","mapping","from","a","beta","range","to","a","sequence","of","betas","for","stepping","the","model",".","Choose","from","`","linear","`","or","`","scaled_linear","`",".","trained_betas","(","`","np.ndarray","`",",","*","optional","*",")",":","Pass","an","array","of","betas","directly","to","the","constructor","to","bypass","`","beta_start","`","and","`","beta_end","`",".","prediction_type","(","`","str","`",",","defaults","to","`","epsilon","`",",","*","optional","*",")",":","Prediction","type","of","the","scheduler","function",";","can","be","`","epsilon","`","(","predicts","the","noise","of","the","diffusion","process",")",",","`","sample","`","(","directly","predicts","the","noisy","sample","`",")","or","`","v_prediction","`","(","see","section","2.4","of","[","Imagen","Video","]","(","https",":","\/\/imagen.research.google\/video\/paper.pdf",")","paper",")",".","interpolation_type","(","`","str","`",",","defaults","to","`","``","linear","''","`",",","*","optional","*",")",":","The","interpolation","type","to","compute","intermediate","sigmas","for","the","scheduler","denoising","steps",".","Should","be","on","of","`","``","linear","''","`","or","`","``","log_linear","''","`",".","use_karras_sigmas","(","`","bool","`",",","*","optional","*",",","defaults","to","`","False","`",")",":","Whether","to","use","Karras","sigmas","for","step","sizes","in","the","noise","schedule","during","the","sampling","process",".","If","`","True","`",",","the","sigmas","are","determined","according","to","a","sequence","of","noise","levels","{","\u03c3i","}",".","timestep_spacing","(","`","str","`",",","defaults","to","`","``","linspace","''","`",")",":","The","way","the","timesteps","should","be","scaled",".","Refer","to","Table","2","of","the","[","Common","Diffusion","Noise","Schedules","and","Sample","Steps","are","Flawed","]","(","https",":","\/\/huggingface.co\/papers\/2305.08891",")","for","more","information",".","steps_offset","(","`","int","`",",","defaults","to","0",")",":","An","offset","added","to","the","inference","steps",".","You","can","use","a","combination","of","`","offset=1","`","and","`","set_alpha_to_one=False","`","to","make","the","last","step","use","step","0","for","the","previous","alpha","product","like","in","Stable","Diffusion",".","rescale_betas_zero_snr","(","`","bool","`",",","defaults","to","`","False","`",")",":","Whether","to","rescale","the","betas","to","have","zero","terminal","SNR",".","This","enables","the","model","to","generate","very","bright","and","dark","samples","instead","of","limiting","it","to","samples","with","medium","brightness",".","Loosely","related","to","[","`","--","offset_noise","`","]","(","https",":","\/\/github.com\/huggingface\/diffusers\/blob\/74fd735eb073eb1d774b1ab4154a0876eb82f055\/examples\/dreambooth\/train_dreambooth.py","#","L506",")","."]
docstr: Sets the discrete timesteps used for the diffusion chain (to be run before inference).
  
  Args:
      num_inference_steps (`int`):
          The number of diffusion steps used when generating samples with a pre-trained model.
      device (`str` or `torch.device`, *optional*):
          The device to which the timesteps should be moved to. If `None`, the timesteps are not moved.
docstr_tok: ["Sets","the","discrete","timesteps","used","for","the","diffusion","chain","(","to","be","run","before","inference",")",".","Args",":","num_inference_steps","(","`","int","`",")",":","The","number","of","diffusion","steps","used","when","generating","samples","with","a","pre-trained","model",".","device","(","`","str","`","or","`","torch.device","`",",","*","optional","*",")",":","The","device","to","which","the","timesteps","should","be","moved","to",".","If","`","None","`",",","the","timesteps","are","not","moved","."]
code: def set_timesteps(
      self,
      num_inference_steps: int,
      device: Union[str, torch.device] = None,
  ):
      """
      Sets the discrete timesteps used for the diffusion chain (to be run before inference).
  
      Args:
          num_inference_steps (`int`):
              The number of diffusion steps used when generating samples with a pre-trained model.
          device (`str` or `torch.device`, *optional*):
              The device to which the timesteps should be moved to. If `None`, the timesteps are not moved.
      """
      self.num_inference_steps = num_inference_steps
  
      # "linspace", "leading", "trailing" corresponds to annotation of Table 2. of https://arxiv.org/abs/2305.08891
      if self.config.timestep_spacing == "linspace":
          timesteps = np.linspace(
              0,
              self.config.num_train_timesteps - 1,
              num_inference_steps,
              dtype=np.float32,
          )[::-1].copy()
      elif self.config.timestep_spacing == "leading":
          step_ratio = (
              self.config.num_train_timesteps
              // self.num_inference_steps
          )
          # creates integer timesteps by multiplying by ratio
          # casting to int to avoid issues when num_inference_step is power of 3
          timesteps = (
              (np.arange(0, num_inference_steps) * step_ratio)
              .round()[::-1]
              .copy()
              .astype(np.float32)
          )
          timesteps += self.config.steps_offset
      elif self.config.timestep_spacing == "trailing":
          step_ratio = (
              self.config.num_train_timesteps / self.num_inference_steps
          )
          # creates integer timesteps by multiplying by ratio
          # casting to int to avoid issues when num_inference_step is power of 3
          timesteps = (
              (
                  np.arange(
                      self.config.num_train_timesteps, 0, -step_ratio
                  )
              )
              .round()
              .copy()
              .astype(np.float32)
          )
          timesteps -= 1
      else:
          raise ValueError(
              f"{self.config.timestep_spacing} is not supported. Please make sure to choose one of 'linspace', 'leading' or 'trailing'."
          )
  
      sigmas = np.array(
          ((1 - self.alphas_cumprod) / self.alphas_cumprod) ** 0.5
      )
      log_sigmas = np.log(sigmas)
  
      if self.config.interpolation_type == "linear":
          sigmas = np.interp(
              timesteps, np.arange(0, len(sigmas)), sigmas
          )
      elif self.config.interpolation_type == "log_linear":
          sigmas = (
              torch.linspace(
                  np.log(sigmas[-1]),
                  np.log(sigmas[0]),
                  num_inference_steps + 1,
              )
              .exp()
              .numpy()
          )
      else:
          raise ValueError(
              f"{self.config.interpolation_type} is not implemented. Please specify interpolation_type to either"
              " 'linear' or 'log_linear'"
          )
  
      if self.use_karras_sigmas:
          sigmas = self._convert_to_karras(
              in_sigmas=sigmas,
              num_inference_steps=self.num_inference_steps,
          )
          timesteps = np.array(
              [self._sigma_to_t(sigma, log_sigmas) for sigma in sigmas]
          )
  
      sigmas = torch.from_numpy(sigmas).to(
          dtype=torch.float32, device=device
      )
  
      # TODO: Support the full EDM scalings for all prediction types and timestep types
      if (
          self.config.timestep_type == "continuous"
          and self.config.prediction_type == "v_prediction"
      ):
          self.timesteps = torch.Tensor(
              [0.25 * sigma.log() for sigma in sigmas]
          ).to(device=device)
      else:
          self.timesteps = torch.from_numpy(
              timesteps.astype(np.float32)
          ).to(device=device)
  
      self.sigmas = torch.cat(
          [sigmas, torch.zeros(1, device=sigmas.device)]
      )
      self._step_index = None
      self.sigmas.to("cpu")
  
imports: import math
  from dataclasses import dataclass
  from typing import List, Optional, Tuple, Union
  import numpy
  import torch
  from ..configuration_utils import ConfigMixin, register_to_config
  from ..utils import BaseOutput, logging
  from ..utils.torch_utils import randn_tensor
  from .scheduling_utils import KarrasDiffusionSchedulers, SchedulerMixin
label_desc: Use image node_id 5 for calling the EulerDiscreteScheduler obj's underlying member method code with example usage: obj.set_timesteps(num_inference_steps, device) without return types