class_docstr: DiffRec is a generative recommender model which infers users' interaction probabilities in a denoising manner.
  Note that DiffRec simultaneously ranks all items for each user.
  We implement the the DiffRec model with only user dataloader.
class_docstr_tok: ["DiffRec","is","a","generative","recommender","model","which","infers","users","'","interaction","probabilities","in","a","denoising","manner",".","Note","that","DiffRec","simultaneously","ranks","all","items","for","each","user",".","We","implement","the","the","DiffRec","model","with","only","user","dataloader","."]
code: def __init__(self, config, dataset):
      super(DiffRec, self).__init__(config, dataset)
  
      if config["mean_type"] == "x0":
          self.mean_type = ModelMeanType.START_X
      elif config["mean_type"] == "eps":
          self.mean_type = ModelMeanType.EPSILON
      else:
          raise ValueError(
              "Unimplemented mean type %s" % config["mean_type"]
          )
      self.time_aware = config["time-aware"]
      self.w_max = config["w_max"]
      self.w_min = config["w_min"]
      self.build_histroy_items(dataset)
  
      self.noise_schedule = config["noise_schedule"]
      self.noise_scale = config["noise_scale"]
      self.noise_min = config["noise_min"]
      self.noise_max = config["noise_max"]
      self.steps = config["steps"]
      self.beta_fixed = config["beta_fixed"]
      self.emb_size = config["embedding_size"]
      self.norm = config["norm"]  # True or False
      self.reweight = config[
          "reweight"
      ]  # reweight the loss for different timesteps
      if self.noise_scale == 0.0:
          self.reweight = False
      self.sampling_noise = config[
          "sampling_noise"
      ]  # whether sample noise during predict
      self.sampling_steps = config["sampling_steps"]
      self.mlp_act_func = config["mlp_act_func"]
      assert (
          self.sampling_steps <= self.steps
      ), "Too much steps in inference."
  
      self.history_num_per_term = config["history_num_per_term"]
      self.Lt_history = torch.zeros(
          self.steps, self.history_num_per_term, dtype=torch.float64
      ).to(self.device)
      self.Lt_count = torch.zeros(self.steps, dtype=int).to(self.device)
  
      dims = [self.n_items] + config["dims_dnn"] + [self.n_items]
  
      self.mlp = DNN(
          dims=dims,
          emb_size=self.emb_size,
          time_type="cat",
          norm=self.norm,
          act_func=self.mlp_act_func,
      ).to(self.device)
  
      if self.noise_scale != 0.0:
          self.betas = torch.tensor(
              self.get_betas(), dtype=torch.float64
          ).to(self.device)
          if self.beta_fixed:
              self.betas[
                  0
              ] = 0.00001  # Deep Unsupervised Learning using Noneequilibrium Thermodynamics 2.4.1
              # The variance \beta_1 of the first step is fixed to a small constant to prevent overfitting.
          assert len(self.betas.shape) == 1, "betas must be 1-D"
          assert (
              len(self.betas) == self.steps
          ), "num of betas must equal to diffusion steps"
          assert (self.betas > 0).all() and (
              self.betas <= 1
          ).all(), "betas out of range"
  
          self.calculate_for_diffusion()
  
imports: import enum
  import math
  import copy
  import numpy
  import torch
  import torch.nn.functional
  import torch.nn
  from recbole.model.init import xavier_normal_initialization
  from recbole.utils.enum_type import InputType
  from recbole.model.abstract_recommender import AutoEncoderMixin, GeneralRecommender
  from recbole.model.layers import MLPLayers
  import typing
label_desc: Use image node_id 1 to create a new DiffRec object from inherited base classes: GeneralRecommender, AutoEncoderMixin with example: obj = DiffRec(config, dataset)