code: def __init__(
      self,
      num_sample_steps=50,
      num_train_timesteps=1000,
      denoiser=None,
      ddpm=True,
      alpha_bar=None,
  ):
      self.denoiser = denoiser
  
      self.num_train_timesteps, self.num_sample_steps = (
          num_train_timesteps,
          num_sample_steps,
      )
  
      self.ddpm_sigmas = ((1 - alpha_bar) / alpha_bar).sqrt()
      self.t0 = self.ddpm_sigmas[-1]  # or sigma_max/max noise
  
      self.stride = len(alpha_bar) // num_sample_steps
      self.timesteps = torch.arange(num_train_timesteps + 1)
  
      # table 1
      sigma_min, sigma_max, rho = (
          self.ddpm_sigmas[0],
          self.ddpm_sigmas[-1],
          7,
      )  # stable diff.
      _heun_sigmas = (
          sigma_max ** (1 / rho)
          + (self.timesteps / self.num_sample_steps)
          * (sigma_min ** (1 / rho) - sigma_max ** (1 / rho))
      ) ** rho
      self.heun_sigmas = _heun_sigmas
      self.sigma_data = 0.5
      self.timesteps = torch.arange(num_sample_steps - 1)
  
      self.ddpm = ddpm
  
file_path: diffusion-for-beginners/samplers/heun.py
imports: import torch
  from math import sqrt
label_desc: Use image node_id 1 to create a new HeunSampler object  with example: obj = HeunSampler(num_sample_steps, num_train_timesteps, denoiser, ddpm, alpha_bar)