class_docstr: ## Denoise Diffusion
class_docstr_tok: ["#","#","Denoise","Diffusion"]
docstr: * `eps_model` is $      extcolor{lightgreen}{\epsilon_  heta}(x_t, t)$ model
  * `n_steps` is $t$
  * `device` is the device to place constants on
docstr_tok: ["*","`","eps_model","`","is","$","extcolor","{","lightgreen","}","{","\\epsilon_","heta","}","(","x_t",",","t",")","$","model","*","`","n_steps","`","is","$","t","$","*","`","device","`","is","the","device","to","place","constants","on"]
code: def __init__(
      self, eps_model: nn.Module, n_steps: int, device: torch.device
  ):
      """
      * `eps_model` is $\textcolor{lightgreen}{\epsilon_\theta}(x_t, t)$ model
      * `n_steps` is $t$
      * `device` is the device to place constants on
      """
      super().__init__()
      self.eps_model = eps_model
  
      # Create $\beta_1, \dots, \beta_T$ linearly increasing variance schedule
      self.beta = torch.linspace(0.0001, 0.02, n_steps).to(device)
  
      # $\alpha_t = 1 - \beta_t$
      self.alpha = 1.0 - self.beta
      # $\bar\alpha_t = \prod_{s=1}^t \alpha_s$
      self.alpha_bar = torch.cumprod(self.alpha, dim=0)
      # $T$
      self.n_steps = n_steps
      # $\sigma^2 = \beta$
      self.sigma2 = self.beta
  
file_path: annotated_deep_learning_paper_implementations/labml_nn/diffusion/ddpm/__init__.py
imports: from typing import Tuple, Optional
  import torch
  import torch.nn.functional
  import torch.utils.data
  from torch import nn
  from labml_nn.diffusion.ddpm.utils import gather
label_desc: Use image node_id 1 to create a new DenoiseDiffusion object  with example: obj = DenoiseDiffusion(eps_model, n_steps, device)