class_docstr: ## DDIM Sampler
  
  This extends the [`DiffusionSampler` base class](index.html).
  
  DDIM samples images by repeatedly removing noise by sampling step by step using,
  
  egin{align}
  x_{ au_{i-1}} &= \sqrt{lpha_{      au_{i-1}}}\Bigg(
          rac{x_{    au_i} - \sqrt{1 - lpha_{       au_i}}\epsilon_ heta(x_{        au_i})}{\sqrt{lpha_{   au_i}}}
          \Bigg) \
          &+ \sqrt{1 - lpha_{        au_{i- 1}} - \sigma_{   au_i}^2} \cdot \epsilon_        heta(x_{        au_i}) \
          &+ \sigma_{ au_i} \epsilon_{        au_i}
  \end{align}
  
  where $\epsilon_{   au_i}$ is random noise,
  $   au$ is a subsequence of $[1,2,\dots,T]$ of length $S$,
  and
  $$\sigma_{  au_i} =
  \eta \sqrt{rac{1 - lpha_{ au_{i-1}}}{1 - lpha_{  au_i}}}
  \sqrt{1 - rac{lpha_{      au_i}}{lpha_{  au_{i-1}}}}$$
  
  Note that, $lpha_t$ in DDIM paper refers to ${\color{lightgreen}arlpha_t}$ from [DDPM](ddpm.html).
docstr: ### Sample from $q_{\sigma,     au}(x_{ au_i}|x_0)$
  
  $$q_{\sigma,    au}(x_t|x_0) =
   \mathcal{N} \Big(x_t; \sqrt{lpha_{    au_i}} x_0, (1-lpha_{  au_i}) \mathbf{I} \Big)$$
  
  :param x0: is $x_0$ of shape `[batch_size, channels, height, width]`
  :param index: is the time step $        au_i$ index $i$
  :param noise: is the noise, $\epsilon$
docstr_tok: ["#","#","#","Sample","from","$","q_","{","\\sigma",",","au","}","(","x_","{","au_i","}","|x_0",")","$","$","$","q_","{","\\sigma",",","au","}","(","x_t|x_0",")","=","\\mathcal","{","N","}","\\Big","(","x_t",";","\\sqrt","{","\u0007lpha_","{","au_i","}","}","x_0",",","(","1-\u0007lpha_","{","au_i","}",")","\\mathbf","{","I","}","\\Big",")","$","$",":","param","x0",":","is","$","x_0","$","of","shape","`","[","batch_size",",","channels",",","height",",","width","]","`",":","param","index",":","is","the","time","step","$","au_i","$","index","$","i","$",":","param","noise",":","is","the","noise",",","$","\\epsilon","$"]
code: def q_sample(
      self,
      x0: torch.Tensor,
      index: int,
      noise: Optional[torch.Tensor] = None,
  ):
      """
      ### Sample from $q_{\sigma,\tau}(x_{\tau_i}|x_0)$
  
      $$q_{\sigma,\tau}(x_t|x_0) =
       \mathcal{N} \Big(x_t; \sqrt{\alpha_{\tau_i}} x_0, (1-\alpha_{\tau_i}) \mathbf{I} \Big)$$
  
      :param x0: is $x_0$ of shape `[batch_size, channels, height, width]`
      :param index: is the time step $\tau_i$ index $i$
      :param noise: is the noise, $\epsilon$
      """
  
      # Random noise, if noise is not specified
      if noise is None:
          noise = torch.randn_like(x0)
  
      # Sample from
      #  $$q_{\sigma,\tau}(x_t|x_0) =
      #          \mathcal{N} \Big(x_t; \sqrt{\alpha_{\tau_i}} x_0, (1-\alpha_{\tau_i}) \mathbf{I} \Big)$$
      return (
          self.ddim_alpha_sqrt[index] * x0
          + self.ddim_sqrt_one_minus_alpha[index] * noise
      )
  
file_path: annotated_deep_learning_paper_implementations/labml_nn/diffusion/stable_diffusion/sampler/ddim.py
imports: from typing import Optional, List
  import numpy
  import torch
  from labml import monit
  from labml_nn.diffusion.stable_diffusion.latent_diffusion import LatentDiffusion
  from labml_nn.diffusion.stable_diffusion.sampler import DiffusionSampler
label_desc: Use image node_id 5 for calling the DDIMSampler obj's underlying member method code with example usage: obj.q_sample(x0, index, noise) and returns: unknown