class_docstr: Denoising diffusion implicit models is a scheduler that extends the denoising procedure introduced in denoising
  diffusion probabilistic models (DDPMs) with non-Markovian guidance.
  
  [`~ConfigMixin`] takes care of storing all config attributes that are passed in the scheduler's `__init__`
  function, such as `num_train_timesteps`. They can be accessed via `scheduler.config.num_train_timesteps`.
  [`SchedulerMixin`] provides general loading and saving functionality via the [`SchedulerMixin.save_pretrained`] and
  [`~SchedulerMixin.from_pretrained`] functions.
  
  For more details, see the original paper: https://arxiv.org/abs/2010.02502
  
  Args:
      num_train_timesteps (`int`): number of diffusion steps used to train the model.
      beta_start (`float`): the starting `beta` value of inference.
      beta_end (`float`): the final `beta` value.
      beta_schedule (`str`):
          the beta schedule, a mapping from a beta range to a sequence of betas for stepping the model. Choose from
          `linear`, `scaled_linear`, or `squaredcos_cap_v2`.
      trained_betas (`np.ndarray`, optional):
          option to pass an array of betas directly to the constructor to bypass `beta_start`, `beta_end` etc.
      clip_sample (`bool`, default `True`):
          option to clip predicted sample for numerical stability.
      clip_sample_range (`float`, default `1.0`):
          the maximum magnitude for sample clipping. Valid only when `clip_sample=True`.
      set_alpha_to_one (`bool`, default `True`):
          each diffusion step uses the value of alphas product at that step and at the previous one. For the final
          step there is no previous alpha. When this option is `True` the previous alpha product is fixed to `1`,
          otherwise it uses the value of alpha at step 0.
      steps_offset (`int`, default `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, as done in
          stable diffusion.
      prediction_type (`str`, default `epsilon`, optional):
          prediction type of the scheduler function, one of `epsilon` (predicting the noise of the diffusion
          process), `sample` (directly predicting the noisy sample`) or `v_prediction` (see section 2.4
          https://imagen.research.google/video/paper.pdf)
      thresholding (`bool`, default `False`):
          whether to use the "dynamic thresholding" method (introduced by Imagen, https://arxiv.org/abs/2205.11487).
          Note that the thresholding method is unsuitable for latent-space diffusion models (such as
          stable-diffusion).
      dynamic_thresholding_ratio (`float`, default `0.995`):
          the ratio for the dynamic thresholding method. Default is `0.995`, the same as Imagen
          (https://arxiv.org/abs/2205.11487). Valid only when `thresholding=True`.
      sample_max_value (`float`, default `1.0`):
          the threshold value for dynamic thresholding. Valid only when `thresholding=True`.
      timestep_spacing (`str`, default `"leading"`):
          The way the timesteps should be scaled. Refer to Table 2. of [Common Diffusion Noise Schedules and Sample
          Steps are Flawed](https://arxiv.org/abs/2305.08891) for more information.
      rescale_betas_zero_snr (`bool`, default `False`):
          whether to rescale the betas to have zero terminal SNR (proposed by https://arxiv.org/pdf/2305.08891.pdf).
          This can enable 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: ["Denoising","diffusion","implicit","models","is","a","scheduler","that","extends","the","denoising","procedure","introduced","in","denoising","diffusion","probabilistic","models","(","DDPMs",")","with","non-Markovian","guidance",".","[","`","~ConfigMixin","`","]","takes","care","of","storing","all","config","attributes","that","are","passed","in","the","scheduler","'s","`","__init__","`","function",",","such","as","`","num_train_timesteps","`",".","They","can","be","accessed","via","`","scheduler.config.num_train_timesteps","`",".","[","`","SchedulerMixin","`","]","provides","general","loading","and","saving","functionality","via","the","[","`","SchedulerMixin.save_pretrained","`","]","and","[","`","~SchedulerMixin.from_pretrained","`","]","functions",".","For","more","details",",","see","the","original","paper",":","https",":","\/\/arxiv.org\/abs\/2010.02502","Args",":","num_train_timesteps","(","`","int","`",")",":","number","of","diffusion","steps","used","to","train","the","model",".","beta_start","(","`","float","`",")",":","the","starting","`","beta","`","value","of","inference",".","beta_end","(","`","float","`",")",":","the","final","`","beta","`","value",".","beta_schedule","(","`","str","`",")",":","the","beta","schedule",",","a","mapping","from","a","beta","range","to","a","sequence","of","betas","for","stepping","the","model",".","Choose","from","`","linear","`",",","`","scaled_linear","`",",","or","`","squaredcos_cap_v2","`",".","trained_betas","(","`","np.ndarray","`",",","optional",")",":","option","to","pass","an","array","of","betas","directly","to","the","constructor","to","bypass","`","beta_start","`",",","`","beta_end","`","etc",".","clip_sample","(","`","bool","`",",","default","`","True","`",")",":","option","to","clip","predicted","sample","for","numerical","stability",".","clip_sample_range","(","`","float","`",",","default","`","1.0","`",")",":","the","maximum","magnitude","for","sample","clipping",".","Valid","only","when","`","clip_sample=True","`",".","set_alpha_to_one","(","`","bool","`",",","default","`","True","`",")",":","each","diffusion","step","uses","the","value","of","alphas","product","at","that","step","and","at","the","previous","one",".","For","the","final","step","there","is","no","previous","alpha",".","When","this","option","is","`","True","`","the","previous","alpha","product","is","fixed","to","`","1","`",",","otherwise","it","uses","the","value","of","alpha","at","step","0.","steps_offset","(","`","int","`",",","default","`","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",",","as","done","in","stable","diffusion",".","prediction_type","(","`","str","`",",","default","`","epsilon","`",",","optional",")",":","prediction","type","of","the","scheduler","function",",","one","of","`","epsilon","`","(","predicting","the","noise","of","the","diffusion","process",")",",","`","sample","`","(","directly","predicting","the","noisy","sample","`",")","or","`","v_prediction","`","(","see","section","2.4","https",":","\/\/imagen.research.google\/video\/paper.pdf",")","thresholding","(","`","bool","`",",","default","`","False","`",")",":","whether","to","use","the","``","dynamic","thresholding","''","method","(","introduced","by","Imagen",",","https",":","\/\/arxiv.org\/abs\/2205.11487",")",".","Note","that","the","thresholding","method","is","unsuitable","for","latent-space","diffusion","models","(","such","as","stable-diffusion",")",".","dynamic_thresholding_ratio","(","`","float","`",",","default","`","0.995","`",")",":","the","ratio","for","the","dynamic","thresholding","method",".","Default","is","`","0.995","`",",","the","same","as","Imagen","(","https",":","\/\/arxiv.org\/abs\/2205.11487",")",".","Valid","only","when","`","thresholding=True","`",".","sample_max_value","(","`","float","`",",","default","`","1.0","`",")",":","the","threshold","value","for","dynamic","thresholding",".","Valid","only","when","`","thresholding=True","`",".","timestep_spacing","(","`","str","`",",","default","`","``","leading","''","`",")",":","The","way","the","timesteps","should","be","scaled",".","Refer","to","Table","2.","of","[","Common","Diffusion","Noise","Schedules","and","Sample","Steps","are","Flawed","]","(","https",":","\/\/arxiv.org\/abs\/2305.08891",")","for","more","information",".","rescale_betas_zero_snr","(","`","bool","`",",","default","`","False","`",")",":","whether","to","rescale","the","betas","to","have","zero","terminal","SNR","(","proposed","by","https",":","\/\/arxiv.org\/pdf\/2305.08891.pdf",")",".","This","can","enable","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",")","."]
code: def get_velocity(
      self,
      sample: torch.FloatTensor,
      noise: torch.FloatTensor,
      timesteps: torch.IntTensor,
  ) -> torch.FloatTensor:
      # Make sure alphas_cumprod and timestep have same device and dtype as sample
      alphas_cumprod = self.alphas_cumprod.to(
          device=sample.device, dtype=sample.dtype
      )
      timesteps = timesteps.to(sample.device)
  
      sqrt_alpha_prod = alphas_cumprod[timesteps] ** 0.5
      sqrt_alpha_prod = sqrt_alpha_prod.flatten()
      while len(sqrt_alpha_prod.shape) < len(sample.shape):
          sqrt_alpha_prod = sqrt_alpha_prod.unsqueeze(-1)
  
      sqrt_one_minus_alpha_prod = (1 - alphas_cumprod[timesteps]) ** 0.5
      sqrt_one_minus_alpha_prod = sqrt_one_minus_alpha_prod.flatten()
      while len(sqrt_one_minus_alpha_prod.shape) < len(sample.shape):
          sqrt_one_minus_alpha_prod = (
              sqrt_one_minus_alpha_prod.unsqueeze(-1)
          )
  
      velocity = (
          sqrt_alpha_prod * noise - sqrt_one_minus_alpha_prod * sample
      )
      return velocity
  
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
  from ..utils.torch_utils import randn_tensor
  from .scheduling_utils import KarrasDiffusionSchedulers, SchedulerMixin
label_desc: Use image node_id 10 for calling the DDIMParallelScheduler obj's underlying member method code with example usage: obj.get_velocity(sample, noise, timesteps) and returns: velocity