code: def ddim(
      model,
      x,
      timesteps,
      extra_args=None,
      callback=None,
      disable=None,
      eta=0.0,
  ):
      alphas_cumprod = model.inner_model.inner_model.alphas_cumprod
      alphas = alphas_cumprod[timesteps]
      alphas_prev = alphas_cumprod[
          torch.nn.functional.pad(timesteps[:-1], pad=(1, 0))
      ].to(
          torch.float64
          if x.device.type != "mps" and x.device.type != "xpu"
          else torch.float32
      )
      sqrt_one_minus_alphas = torch.sqrt(1 - alphas)
      sigmas = eta * np.sqrt(
          (1 - alphas_prev.cpu().numpy())
          / (1 - alphas.cpu())
          * (1 - alphas.cpu() / alphas_prev.cpu().numpy())
      )
  
      extra_args = {} if extra_args is None else extra_args
      s_in = x.new_ones((x.shape[0]))
      s_x = x.new_ones((x.shape[0], 1, 1, 1))
      for i in tqdm.trange(len(timesteps) - 1, disable=disable):
          index = len(timesteps) - 1 - i
  
          e_t = model(x, timesteps[index].item() * s_in, **extra_args)
  
          a_t = alphas[index].item() * s_x
          a_prev = alphas_prev[index].item() * s_x
          sigma_t = sigmas[index].item() * s_x
          sqrt_one_minus_at = sqrt_one_minus_alphas[index].item() * s_x
  
          pred_x0 = (x - sqrt_one_minus_at * e_t) / a_t.sqrt()
          dir_xt = (1.0 - a_prev - sigma_t**2).sqrt() * e_t
          noise = sigma_t * k_diffusion.sampling.torch.randn_like(x)
          x = a_prev.sqrt() * pred_x0 + dir_xt + noise
  
          if callback is not None:
              callback(
                  {
                      "x": x,
                      "i": i,
                      "sigma": 0,
                      "sigma_hat": 0,
                      "denoised": pred_x0,
                  }
              )
  
      return x
  
file_path: stable-diffusion-webui/modules/sd_samplers_timesteps_impl.py
imports: import torch
  import tqdm
  import k_diffusion.sampling
  import numpy
  from modules import shared
  from modules.models.diffusion.uni_pc import uni_pc
label_desc: Use image node_id 1 for calling a global function with example usage: ddim(model, x, timesteps, extra_args, callback, disable, eta) and returns: x